|
| 1 | +# Copyright 2026 FlagOS Contributors |
| 2 | +# Licensed under the Apache License, Version 2.0. |
| 3 | + |
| 4 | +name: Build Docker Images - MetaX |
| 5 | + |
| 6 | +on: |
| 7 | + workflow_dispatch: |
| 8 | + inputs: |
| 9 | + task: |
| 10 | + description: MetaX image to build |
| 11 | + required: true |
| 12 | + type: choice |
| 13 | + options: [train, inference, all] |
| 14 | + default: train |
| 15 | + push: |
| 16 | + description: Push candidate to shared Harbor |
| 17 | + required: true |
| 18 | + type: boolean |
| 19 | + default: true |
| 20 | + run_tests: |
| 21 | + description: Run the current MetaX matrix after build |
| 22 | + required: true |
| 23 | + type: boolean |
| 24 | + default: true |
| 25 | + no_cache: |
| 26 | + description: Disable Docker cache |
| 27 | + required: true |
| 28 | + type: boolean |
| 29 | + default: false |
| 30 | + tag: |
| 31 | + description: Optional tag override |
| 32 | + required: false |
| 33 | + type: string |
| 34 | + base_image: |
| 35 | + description: Validated MetaX base image (prefer an immutable digest) |
| 36 | + required: true |
| 37 | + type: string |
| 38 | + default: harbor.baai.ac.cn/flagscale/megatron-lm-with-te:202603231839 |
| 39 | + |
| 40 | +permissions: |
| 41 | + contents: read |
| 42 | + |
| 43 | +concurrency: |
| 44 | + group: build-image-metax-${{ github.ref }}-${{ inputs.task }} |
| 45 | + cancel-in-progress: false |
| 46 | + |
| 47 | +env: |
| 48 | + REGISTRY: harbor.baai.ac.cn |
| 49 | + REGISTRY_NAMESPACE: flagos-dev |
| 50 | + CURRENT_TRAIN_IMAGE: harbor.baai.ac.cn/flagscale/megatron-lm-with-te:202603231839 |
| 51 | + CURRENT_INFERENCE_IMAGE: harbor.baai.ac.cn/flagscale/megatron-lm-with-te:202603231839 |
| 52 | + |
| 53 | +jobs: |
| 54 | + prepare: |
| 55 | + name: Prepare MetaX candidate |
| 56 | + runs-on: ubuntu-latest |
| 57 | + outputs: |
| 58 | + matrix: ${{ steps.params.outputs.matrix }} |
| 59 | + candidate: ${{ steps.params.outputs.candidate }} |
| 60 | + train_image: ${{ steps.params.outputs.train_image }} |
| 61 | + inference_image: ${{ steps.params.outputs.inference_image }} |
| 62 | + steps: |
| 63 | + - name: Resolve build parameters |
| 64 | + id: params |
| 65 | + shell: bash |
| 66 | + run: | |
| 67 | + set -euo pipefail |
| 68 | + short_sha="${GITHUB_SHA::7}" |
| 69 | + tag='${{ inputs.tag }}' |
| 70 | + if [ -z "$tag" ]; then |
| 71 | + tag="${short_sha}-metax-dev" |
| 72 | + fi |
| 73 | + candidate="${REGISTRY}/${REGISTRY_NAMESPACE}/flagscale-${{ inputs.task }}:${tag}" |
| 74 | + train_image="$CURRENT_TRAIN_IMAGE" |
| 75 | + inference_image="$CURRENT_INFERENCE_IMAGE" |
| 76 | + case '${{ inputs.task }}' in |
| 77 | + train) train_image="$candidate" ;; |
| 78 | + inference) inference_image="$candidate" ;; |
| 79 | + all) train_image="$candidate"; inference_image="$candidate" ;; |
| 80 | + esac |
| 81 | + echo 'matrix={"task":["${{ inputs.task }}"]}' >> "$GITHUB_OUTPUT" |
| 82 | + echo "candidate=$candidate" >> "$GITHUB_OUTPUT" |
| 83 | + echo "train_image=$train_image" >> "$GITHUB_OUTPUT" |
| 84 | + echo "inference_image=$inference_image" >> "$GITHUB_OUTPUT" |
| 85 | +
|
| 86 | + runtime_contract: |
| 87 | + name: Validate MetaX base runtime |
| 88 | + needs: prepare |
| 89 | + runs-on: flagscale-metax-c550-gpu2-8c-256g |
| 90 | + steps: |
| 91 | + - name: Validate devices and framework imports |
| 92 | + shell: bash |
| 93 | + run: | |
| 94 | + set -euo pipefail |
| 95 | + base_image='${{ inputs.base_image }}' |
| 96 | + docker pull "$base_image" |
| 97 | + docker run --rm \ |
| 98 | + --ipc=host --group-add video \ |
| 99 | + --device=/dev/dri --device=/dev/mxcd --device=/dev/infiniband \ |
| 100 | + --entrypoint bash "$base_image" -lc ' |
| 101 | + set -euo pipefail |
| 102 | + python - <<"PY" |
| 103 | + import torch |
| 104 | + import transformer_engine |
| 105 | + from megatron.core.models.gpt import GPTModel |
| 106 | +
|
| 107 | + count = torch.cuda.device_count() |
| 108 | + print("torch:", torch.__version__) |
| 109 | + print("devices:", count) |
| 110 | + print("transformer_engine:", transformer_engine.__file__) |
| 111 | + print("megatron GPTModel:", GPTModel) |
| 112 | + assert count == 8, f"expected 8 MetaX devices, found {count}" |
| 113 | + PY |
| 114 | + cat >/tmp/metax_collective.py <<"PY" |
| 115 | + import os |
| 116 | + import torch |
| 117 | + import torch.distributed as dist |
| 118 | +
|
| 119 | + rank = int(os.environ["LOCAL_RANK"]) |
| 120 | + torch.cuda.set_device(rank) |
| 121 | + dist.init_process_group("nccl") |
| 122 | + value = torch.tensor([rank + 1.0], device=f"cuda:{rank}") |
| 123 | + dist.all_reduce(value) |
| 124 | + assert value.item() == 3.0, value |
| 125 | + print(f"rank={rank} all_reduce={value.item()}") |
| 126 | + dist.destroy_process_group() |
| 127 | + PY |
| 128 | + torchrun --standalone --nnodes=1 --nproc-per-node=2 /tmp/metax_collective.py |
| 129 | + ' |
| 130 | +
|
| 131 | + - name: Validate MetaX vLLM contract |
| 132 | + if: inputs.task == 'inference' || inputs.task == 'all' |
| 133 | + shell: bash |
| 134 | + run: | |
| 135 | + set -euo pipefail |
| 136 | + base_image='${{ inputs.base_image }}' |
| 137 | + docker run --rm \ |
| 138 | + --ipc=host --group-add video \ |
| 139 | + --device=/dev/dri --device=/dev/mxcd \ |
| 140 | + --entrypoint python "$base_image" -c ' |
| 141 | + import importlib.metadata as metadata |
| 142 | + import vllm |
| 143 | + print("vllm:", metadata.version("vllm")) |
| 144 | + print("module:", vllm.__file__) |
| 145 | + ' |
| 146 | +
|
| 147 | + build: |
| 148 | + name: Build MetaX candidate |
| 149 | + needs: [prepare, runtime_contract] |
| 150 | + uses: ./.github/workflows/build_image_common.yml |
| 151 | + secrets: inherit |
| 152 | + with: |
| 153 | + platform: metax |
| 154 | + runs_on: '["flagscale-metax-c550-gpu2-8c-256g"]' |
| 155 | + matrix: ${{ needs.prepare.outputs.matrix }} |
| 156 | + target: dev |
| 157 | + build_images: true |
| 158 | + no_cache: ${{ inputs.no_cache }} |
| 159 | + push: ${{ inputs.push }} |
| 160 | + registry: harbor.baai.ac.cn |
| 161 | + train_image: ${{ needs.prepare.outputs.candidate }} |
| 162 | + inference_image: ${{ needs.prepare.outputs.candidate }} |
| 163 | + all_image: ${{ needs.prepare.outputs.candidate }} |
| 164 | + base_image: ${{ inputs.base_image }} |
| 165 | + build_args: BASE_IMAGE=${{ inputs.base_image }} |
| 166 | + |
| 167 | + tests: |
| 168 | + name: Test MetaX candidate |
| 169 | + needs: [prepare, build] |
| 170 | + if: inputs.push && inputs.run_tests |
| 171 | + uses: ./.github/workflows/all_tests_common.yml |
| 172 | + secrets: inherit |
| 173 | + with: |
| 174 | + platform: metax |
| 175 | + ci_train_image: ${{ needs.prepare.outputs.train_image }} |
| 176 | + ci_inference_image: ${{ needs.prepare.outputs.inference_image }} |
0 commit comments