Skip to content

feat(container): add app image build/verify workflow and Dockerfiles - #86

Open
wuwentao wants to merge 18 commits into
mainfrom
feature/app-image-sglang-verify
Open

wuwentao wants to merge 18 commits into
mainfrom
feature/app-image-sglang-verify

Conversation

@wuwentao

@wuwentao wuwentao commented Nov 27, 2026 •

Copy link
Copy Markdown
Collaborator

Summary

Adds the optest-managed application container images (vLLM, Megatron, sglang) with a build -> serve-verify -> op-gate -> push workflow, and uses a platform-first container/configs.yaml: the hardware runtime image is described once, and each app is an overlay on top of it.

Config model: platform-first

The config is inverted from app-first to a single platform tree with per-app overlays:

platforms:
  ascend:                 # L1 vendor  = flagos-gpu-check vendor key
    910B:                 # L2 backend = gpu-check device = backends/910B.yaml stem
      cann9.0.0:          # L3 runtime + runtime_version
        base_image: harbor.baai.ac.cn/flagos-runtime/...
        flagtree_package: flagtree-ascend-cann9.0.0
        apps:             # key presence admits (app, platform) to the matrix
          vllm:     {plugin_fl_version: "0.5.0.dev0_g814b6d3.d20261117"}
          megatron: {}
          sglang:   {}

Why: the old apps.<app>.vendors.<vendor>.{defaults,stacks} shape duplicated the platform skeleton across all three apps, and could not express one vendor with several hardware backends (ascend 910B and a future 910C on the same cann9.0.0; enflame S60 now, L600 later) without repeating a whole stack block.

  • Synced to flagos-gpu-check: the three key levels map 1:1 onto the fields the tool reports (vendor / device / runtime+version). gen_matrix.py validates vendor and runtime against the 13-entry gpu-check sets mirrored from gpu_metadata.py and exits on drift (the set-matrix job has no optest install, so the sets are hardcoded with a keep-in-sync comment).
  • Runner reuse: runner_labels and output_base_dir are read from each backend's own .github/configs/backends/<backend>.yaml, reused by matching the L2 backend key to the YAML stem exactly. No build-infra runner is referenced. All 25 entries resolve a non-empty runner (e.g. H800 -> h800-flaggems-weekly, 910B -> 910b-flaggems-weekly, S60 -> s60-flaggems-weekly, PPU-ZW810E -> 810e-flaggems-weekly).

Stack key / image tag change

Stack key and image tag now embed the backend:

{vendor}-{backend-lowercased}-{runtime}{version}

e.g. ascend-910b-cann9.0.0, nvidia-h800-cuda13.0. This keeps two hardware models that share one runtime distinct. matrix.backend stays original-cased (910B) for the backend-YAML lookup; only the tag segment is lowercased (Docker repo paths must be lowercase). Published tag:

harbor.baai.ac.cn/flagos-optest/<app><app_version>-<vendor>-<backend>-<runtime><version>:<image_version>

Nothing is published yet, so this one-time rename is free.

apt / pip escape hatch (additive)

Generic apt: and pip: maps install on top of the specialized FlagTree/FlagGems/app steps without reordering them:

        apt:
          libgomp1:                       # latest
          libopenblas-dev: {version: "0.3.21+ds-4"}
        pip:
          some-helper:                     # latest from vendor index
          extra-pkg: {version: "1.2.3", index_url: "https://..."}

pip packages install after every baked step with -c /tmp/protect.txt, so torch/triton/runtime pins are never replaced; each index_url is added as an extra index URL. The specialized version fields (flagtree_version, plugin_fl_version, flagcx_version, sgl_kernel_shim_version) and their ordered Dockerfile steps are preserved.

Verify

  • Latent bug fixed: verify-vllm-backend.sh / verify-sglang-backend.sh previously parsed configs.yaml directly and still expected the old flat apps.<app>.stacks.<stack> shape (they would resolve an empty base image and exit 2). They now take --runtime-image, which the workflow passes from matrix.base_image.
  • The three verify-gate JSONs are renamed to the new stack keys (via git mv, content unchanged) so the per-operator op gate keeps matching:
    • flagattention/nvidia-cuda13.0.json -> nvidia-h800-cuda13.0.json
    • flagattention/ascend-cann9.0.0.json -> ascend-910b-cann9.0.0.json
    • flaggems/ascend-cann9.0.0.json -> ascend-910b-cann9.0.0.json

Changed files

File Change
container/configs.yaml platform-first rewrite (relocation only, no value changes)
container/scripts/gen_matrix.py traverse platforms, overlay apps, gpu-check guard, runtime/runtime_version/pip_* fields
container/{vllm,megatron,sglang}/Dockerfile PIP_PACKAGES / PIP_EXTRA_INDEX_URLS ARGs + additive guarded uv pip install block
.github/workflows/app-image.yaml pass the two PIP build-args; pass --runtime-image to verify
container/verify/verify-{vllm,sglang}-backend.sh --runtime-image arg; drop the obsolete configs.yaml read
container/verify/**/*.json renamed to new stack keys
container/scripts/verify_image.py doc/example strings to new keys (no logic change)
container/README.md platform-first structure, stack-key convention, apt/pip section

Testing

  • gen_matrix.py --app all -> 25 entries (8 vllm + 9 megatron + 8 sglang), stacks embed the backend, every entry has a non-empty runner, apt/pip empty for current stacks, build_args carry the per-app version ARGs.
  • gpu-check guard rejects a typo'd vendor and a typo'd runtime (non-zero exit).
  • Full suite: 306 passed, 100% statement+branch coverage.
  • A full image build needs vendor hardware/runners, so the Dockerfile --check lint and the image build run in CI, not locally.

Add optest-managed application container images (vllm, megatron, sglang):
- container/configs.yaml: central config (renamed from images.yaml) listing
  apps, stacks, versions, base images, and per-stack build parameters.
- container/vllm/Dockerfile, container/megatron/Dockerfile,
  container/sglang/Dockerfile: single Dockerfiles per app covering all vendor
  stacks; bake FlagTree/FlagGems/plugin-fl at build time behind a
  torch/runtime constraint file so base packages are never replaced.
- container/vllm/vllm-serve, container/sglang/sglang-serve: server launcher
  scripts.
- container/verify/verify-vllm-backend.sh,
  container/verify/verify-sglang-backend.sh: ported from build-infra; run
  dependency matrix check and serve test (Qwen3-4B/0.6B) before the op gate.
- container/scripts/gen_matrix.py: generate GitHub Actions matrix from
  configs.yaml; image_version auto-computed as YYYYMMDD-sha8.
- container/scripts/verify_image.py: op gate reading per-operator passing
  lists from container/verify/<repo>/<stack>.json.
- container/verify/{flaggems,flagattention}/*.json: initial passing-op lists
  for ascend-cann9.0.0 and nvidia-cuda13.0.
- .github/workflows/app-image.yaml: build → serve-verify → op-gate → push
  workflow; proxy values never echoed in logs; Harbor login with 3 retries
  and logout in if:always step.
- Restructure configs.yaml from flat stacks to apps.<app>.vendors.<vendor>.{defaults,stacks}
  so shared fields live in vendor defaults and per-stack entries only carry overrides.
  vendor is implicit from the dict key; no explicit vendor: field inside entries.
- Add apt_packages: [] to every vendor defaults block. The Dockerfiles install
  listed packages via apt-get before any uv pip install, trying Chinese mirrors
  (tsinghua → aliyun → tencent → 163) with fallback to image default sources.
  BuildKit cache mount (flagos-apt-<app>) reuses .deb archives between builds.
- Add ARG APT_PACKAGES="" and apt install RUN block to vllm, megatron, and sglang
  Dockerfiles (cache ids: flagos-apt-vllm, flagos-apt-megatron, flagos-apt-sglang).
- Add --build-arg APT_PACKAGES=${{ matrix.apt_packages }} to app-image.yaml Build step.
- Update gen_matrix.py to iterate vendors → stacks, merge defaults+stack cfg,
  and emit apt_packages as a space-joined string in every matrix entry.
- Add vendor hierarchy and apt_packages sections to container/README.md.
… backend -> runtime)

Replace the app-first configs.yaml shape
(apps.<app>.vendors.<vendor>.{defaults,stacks}) with a single platform
tree (platforms.<vendor>.<backend>.<runtime+version>) plus per-app
overlays admitted by key presence under each leaf's apps: map. The
platform skeleton (base_image, flagtree_package, env) is described once
per hardware runtime image instead of duplicated across all three apps,
and one vendor can now carry several hardware backends (e.g. ascend 910B
plus a future 910C on the same cann9.0.0) without repeating a stack.

- The three key levels are synced to flagos-gpu-check vocabulary
  (vendor / device / runtime+version). gen_matrix.py validates vendor
  and runtime against the 13-entry gpu-check sets mirrored from
  gpu_metadata.py and exits on drift.
- Stack key and image tag now embed the backend:
  {vendor}-{backend-lowercased}-{runtime}{version} (e.g.
  ascend-910b-cann9.0.0, nvidia-h800-cuda13.0), so two hardware models
  sharing one runtime stay distinct. matrix.backend keeps its original
  case for the backend-YAML lookup.
- Runner labels and output_base_dir still come from each backend's own
  .github/configs/backends/<backend>.yaml (not build-infra), reused by
  matching the L2 backend key to the YAML stem exactly.
- Add additive apt/pip escape hatches: generic apt:/pip: maps extend the
  specialized FlagTree/FlagGems/app steps without reordering them. pip
  installs after every baked step with -c /tmp/protect.txt so the
  torch/runtime matrix stays pinned; each index_url becomes an extra
  index URL. The specialized version fields and their ordered Dockerfile
  steps are preserved.
- Fix a latent bug: verify-vllm-backend.sh / verify-sglang-backend.sh no
  longer parse configs.yaml (they expected the old flat shape and would
  exit 2). They now take --runtime-image, passed by the workflow from
  matrix.base_image.
- Rename the three verify-gate JSONs to the new stack keys so the op gate
  keeps matching.

Matrix still yields 25 entries (8 vllm + 9 megatron + 8 sglang); no
config values changed, only their placement. Full suite: 306 passed,
100% statement+branch coverage. Docs updated in container/README.md.
…+ hygon sglang

- Rename the pip: config key to uv: (all app installs run via uv pip install).

- Split the escape hatch into UV_PACKAGES (no index_url -> public pip mirror
  fallback: tsinghua -> aliyun -> tencent -> 163) and UV_INDEXED_PACKAGES
  ('spec|index_url' tokens installed directly from their own index).

- Publish images under harbor.baai.ac.cn/flaggems/ (was flagos-optest).

- Metax: bump runtime to maca3.10.1.11 and build vllm 0.32.0 reusing the
  generic 0.32 plugin.

- Hygon sglang: install the published sglang-fl wheel from the vendor index
  (drop the git-clone build) plus sgl-kernel-shim.

All three Dockerfiles keep -c /tmp/protect.txt on every uv pip install. No
  tests touch container/; full suite passes at 100% coverage.
…ck-yaml)

The multi-line 'python3 -c' block in the Build image step sat at column 0,
de-denting below the 'run: |' block scalar; PyYAML's check-yaml rejected it
(could not find expected ':'). Collapse to a single-line expression with
identical key=value output.
The set-matrix job only runs gen_matrix.py on the checkout (no GPU, no
Harbor, no internal network), but it was pinned to [self-hosted, h20],
a label no runner in this org carries, so every dispatch sat queued at
Set matrix and never reached the per-backend build job. Use a
GitHub-hosted runner like ops-test.yaml's matrix-prep job. The build
job still binds to each backend's own self-hosted runner via
matrix.runner_labels read from .github/configs/backends/<backend>.yaml.
Two self-hosted-runner fixes so the app-image build job succeeds on the
backend's own host:

- Reset workspace ownership before checkout. ops-test.yaml runs its test
  job inside a container as root and leaves root-owned files in the shared
  runner workspace; this build job runs on the host as a non-root user, so
  actions/checkout failed with "Permission denied" on .git/index.lock /
  FETCH_HEAD (observed on the metax C550 runner). A best-effort pre-checkout
  step chowns the tree back to the runner user via passwordless sudo, and is
  a no-op where the runner already owns it.

- Drop --cache-to/--cache-from type=local. The default buildx docker driver
  cannot export a local layer cache; only the docker-container driver can,
  and that needs the moby/buildkit image the runners cannot pull and would
  keep the built image out of the local store the verify step uses. The
  Dockerfiles' RUN --mount=type=cache mounts plus dockerd's own layer cache
  already persist between runs on these long-lived runners.
The daily index publishes the Hygon FlagTree wheel as flagtree-hcu, not
flagtree-hygon-dtk26.04 (which does not exist there), so the sglang/vllm
build failed resolving the package. README.md, README.zh-CN.md, and
run_tests.py _FLAGTREE_DISTRIBUTIONS already use flagtree-hcu; this syncs
configs.yaml to the same name. Version 0.7.1.dev20261125 is unchanged and
present on the index.
output_base_dir can be root-owned from a prior ops-test container job that
ran as root, so the non-root host runner could not mkdir the per-vendor
cache subdir (metax /data/github-outputs). Create it with passwordless
sudo and chown the leaf back to the runner user when a plain mkdir/write
is denied; stays a no-op where the runner already owns the path.
…e applies

The base runtime images ship flag-gems==5.4.0, which `uv pip freeze` captures
into /tmp/protect.txt. The FlagGems step then installs the configured
flag-gems==5.5.0.dev20261123 with -c /tmp/protect.txt, and the frozen 5.4.0 pin
makes it unsatisfiable ("No solution found"). flag-gems is the one runtime
component the app image deliberately re-bakes (two-layer model), so it must not
constrain itself. Filter only flag-gems (hyphen/underscore, any operator) out
of protect.txt after generation; torch/triton/numpy pins stay, and the bake
already uses --no-deps so no dependency shifts.

Applies identically to vllm, megatron, and sglang.
Every uv pip install that pairs --index-url (FlagOS daily or vendor) with --extra-index-url (public tencent mirror) now adds --index-strategy unsafe-best-match. uv's default first-index strategy only considers versions from the first index that lists a package, so the tencent mirror shadowed the daily flag-gems dev wheel and the vendor +flagos wheels and resolution failed. -c /tmp/protect.txt still pins torch/triton/numpy. The single-index UV_PACKAGES loop is unchanged. Verified on the hygon runner with uv --dry-run.
…-fl (metax)

sglang-fl 0.1.dev1+g440208beb returns 404 on the hygon and daily indexes, so hygon sglang now builds with sgl-kernel-shim only. vllm-plugin-fl 0.5.0.dev0_g814b6d3.d20261117 is absent from the metax index (only maca-tagged 0.2.x / 0.3.0 builds exist), so metax vllm builds without the plugin. Both pins are commented with re-enable notes for when a matching wheel is published.
…iton

Two install-time corrections to all three app Dockerfiles for the
two-layer version model:

- Drop setuptools from /tmp/protect.txt alongside flag-gems. A repacked
  app wheel (e.g. vllm==0.32.0+flagos) can require setuptools<81 while the
  base freeze pins a newer one (84.x), making the app install
  unsatisfiable. torch/triton/numpy stay pinned.

- Add a base-aware triton-provenance guard. FlagTree installs to
  /opt/flagtree (first on PYTHONPATH) and provides 'import triton'; a
  repacked wheel's triton dependency can pull a generic triton (wrong ABI)
  into site-packages. Record the base triton version at protect.txt time,
  then remove only a generic triton this build newly introduced, never a
  base-shipped one.
Adapt the serve+dep verify scripts to the two-layer model:

- Narrow the critical-package matrix to torch/triton/numpy. flag_gems
  (and, for vllm, flagtree) are intentionally (re)baked by the app image,
  so diffing them against the runtime base produced false failures. triton
  stays watched as a tripwire: FlagTree provides 'import triton', so a
  triton visible to importlib.metadata means a generic wheel leaked into
  site-packages.

- Read every watched package (including triton) from site-packages via
  importlib.metadata in the vllm snapshot, instead of the obsolete
  /opt/triton dist-info path, so the triton tripwire can actually fire.

- Gate the sglang_fl / vllm_fl import and the vllm native-plugin check on
  the configured plugin being present (sglang-fl / vllm-plugin-fl), and log
  a skip when intentionally omitted. Add a non-fatal warning when
  'import triton' does not resolve under /opt/flagtree.
A non-login 'docker exec bash -c' does not source /etc/profile.d, but the
sglang-serve/vllm-serve launchers do — that is where vendor LD_LIBRARY_PATH
(e.g. hygon DTK libamd_smi.so, loaded by torch.cuda at 'import torch') is set.
The verify scripts ran python/serve directly, bypassing the launchers, so the
import check failed on hygon with KeyError: 'libamd_smi.so' once the matrix
check started passing. Mirror the launchers in every exec block that imports
torch or serves. snapshot() reads only importlib.metadata (no torch import) and
is left untouched.
optest backend YAMLs have no 'docker_run_flags' key — the ported verify
scripts always resolved it to empty, so the verify container ran with only
'--network host': no --privileged, no GPU devices, and no vendor volume mounts.
On hygon that left /opt/hyhal unmounted, so torch.cuda's amdsmi could not find
libamd_smi.so. Compose RUN_FLAGS from 'container_options' + 'container_volumes'
(the keys ops-test.yaml consumes via options:/volumes:), giving the runtime and
app containers the same devices and HAL mounts as a real ops-test run.
The metax vllm build failed at 'uv pip install vllm==0.32.0+flagos' with an
unsatisfiable resolution: the vllm+flagos wheel requires transformers<5.20.0,
but the base runtime image ships transformers==5.24.0, which 'uv pip freeze'
bakes into /tmp/protect.txt as an exact pin. transformers is not part of the
protected torch/triton/numpy matrix, so the app owns its compatible range —
drop it from the freeze exactly as flag-gems and setuptools already are. Applied
to the vllm Dockerfile only; sglang/megatron build without this conflict and are
left untouched to avoid perturbing their resolved transformers version.
The fleet stores models under the HuggingFace org-prefixed path
(/data/models/Qwen/Qwen3-4B, /data/models/Qwen/Qwen3-0.6B), as
downloaded by ModelScope, but the verify scripts defaulted to a flat
/data/models/Qwen3-* that no runner uses. The serve test's host-side
[[ -d "${MODEL_PATH}" ]] guard therefore failed with "Model not found"
even on runners that hold the model (e.g. metax C550), aborting the
serve check after matrix + import already passed.

Point both defaults at the actual fleet layout. app-image.yaml does not
pass --model-path, so the script default is the only lever.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant