Skip to content

Source sglang and Megatron-LM from third_party submodules in docker build - #1169

Closed
Shi-Dong wants to merge 3 commits into
shi/move-sglang-megatron-to-submodulesfrom
shi/dockerfile-use-submodules
Closed

Source sglang and Megatron-LM from third_party submodules in docker build#1169
Shi-Dong wants to merge 3 commits into
shi/move-sglang-megatron-to-submodulesfrom
shi/dockerfile-use-submodules

Conversation

@Shi-Dong

Copy link
Copy Markdown
Contributor

Summary

  • docker/Dockerfile: replace the in-build git clone of sglang and Megatron-LM with COPY third_party/{sglang,Megatron-LM} from the new submodules; drop the now-unused build args (SGLANG_BRANCH, SGLANG_COMMIT, MEGATRON_REPO, MEGATRON_BRANCH); also rm -rf /sgl-workspace/sglang/.git before COPY so the resulting image doesn't carry the base image's stale gitdir.
  • .github/workflows/docker-build.yml: checkout with submodules: recursive; add a step that writes each submodule's SHA into a .miles-submodule-sha sidecar inside the submodule worktree and then strips the gitlink .git file (so docker COPY doesn't carry a dangling reference); extend the push path-trigger to include third_party/sglang and third_party/Megatron-LM so bumping a submodule pointer auto-fires a rebuild.

Why

After step 1, the submodule pointer is the authoritative version pin for sglang and Megatron-LM. This PR makes the docker image build from that pointer (COPY from the submodule snapshot) instead of issuing its own git fetch against sgl-project/sglang / radixark/Megatron-LM at build time. The image is now reproducible from a commit alone: "same miles commit, same image content" without depending on remote branch tips moving.

The sidecar file (/sgl-workspace/sglang/.miles-submodule-sha, /root/Megatron-LM/.miles-submodule-sha) carries the SHA the COPY came from, so it's trivial to confirm at runtime what was baked in.

Test plan

  • docker-build.yml run 26169858537 (variant=primary, image_tag=custom, custom_tag=dev-submodule-test) succeeded → image radixark/miles:dev-submodule-test pushed to Docker Hub. Production :dev was not touched.
  • Smoke-tested on a 1-node H200 devbox (shi-img-smoke, image radixark/miles:dev-submodule-test):
    • /sgl-workspace/sglang/.miles-submodule-sha = 363403a2… ← matches step 1's submodule pointer.
    • /root/Megatron-LM/.miles-submodule-sha = 23924a0b… ← matches step 1's submodule pointer.
    • pip show sglang Editable location = /sgl-workspace/sglang/python
    • pip show megatron-core Editable location = /root/Megatron-LM
    • import sglang ✓, import megatron.core ✓ (with PYTHONPATH=/root/Megatron-LM, same constraint as production), import miles_megatron_plugins.true_on_policy.contracts
    • Stale base-image .git/ at /sgl-workspace/sglang/ is gone; submodule .git files were correctly stripped before COPY.

Stacked on

#1168 (step 1: add submodules). Once that merges, this PR's base auto-updates to main.

Shi-Dong added 3 commits May 19, 2026 14:30
sglang  -> sgl-project/sglang   @ sglang-miles

megatron -> radixark/Megatron-LM @ miles-main

Step 1 of moving these deps in-tree. No build wiring yet: docker/Dockerfile still clones into the image at the same paths it always has, so runtime behavior is unchanged. Follow-up PR will switch the Dockerfile to COPY from third_party/.
…uild

Dockerfile: replace the in-build git clones of sglang and Megatron-LM with COPY from the new third_party/sglang and third_party/Megatron-LM submodules. The submodule pointer is now the source of truth for which sglang/Megatron-LM revision the image carries; the SGLANG_BRANCH, SGLANG_COMMIT, MEGATRON_REPO, MEGATRON_BRANCH build args are removed.

docker-build.yml: checkout submodules recursively; strip the gitlink .git files in third_party/ before docker build (they would otherwise copy into the image as dangling references); extend the push path-trigger to include third_party/sglang and third_party/Megatron-LM so a submodule bump auto-fires a rebuild.
The lmsysorg/sglang base image ships a .git/ directory at /sgl-workspace/sglang from its own upstream checkout. After our COPY overlays the submodule source on top, that .git/ no longer matches the working tree (the index references files from the base image checkout, not the submodule snapshot). Drop it explicitly so the resulting image does not carry a misleading git state.

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request updates the Dockerfile to use git submodules for the sglang and Megatron-LM dependencies, replacing the previous method of using build arguments and runtime git clones. This change ensures that the submodule pointers serve as the source of truth for dependency versions. A review comment suggests that instead of only removing the .git directory in /sgl-workspace/sglang, the entire directory should be deleted before the COPY command to prevent stale files from the base image from persisting.

Comment thread docker/Dockerfile
# base image ships a stale `.git/` dir at this path — drop it before COPY
# so the resulting image isn't carrying a git index that disagrees with
# the working tree.
RUN rm -rf /sgl-workspace/sglang/.git

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

The COPY command merges the source directory contents into the destination if it already exists. Since the base image lmsysorg/sglang already contains an installation in /sgl-workspace/sglang, simply removing the .git directory might leave behind stale source files or artifacts that are not present in the submodule (e.g., if files were renamed or removed in the submodule version). To ensure a clean state where the directory contains exactly what is in the submodule, it is safer to remove the entire directory before copying.

RUN rm -rf /sgl-workspace/sglang

@Shi-Dong
Shi-Dong force-pushed the shi/move-sglang-megatron-to-submodules branch 2 times, most recently from 573294d to af93e38 Compare June 3, 2026 15:02
@Shi-Dong
Shi-Dong force-pushed the shi/move-sglang-megatron-to-submodules branch from af93e38 to b1217cb Compare June 4, 2026 13:10
@Shi-Dong

Copy link
Copy Markdown
Contributor Author

Closing as obsolete. This PR is superseded by a thin packaging slice cut fresh off current `main`:

  • radixark/miles#PRA — re-add `third_party/sglang` + `third_party/Megatron-LM` submodules
  • radixark/miles#PRB — `setup.py` bundling + `publish-pypi.yml` + `miles-rl` 0.0.3

Why this one is no longer needed: see the per-PR note below. The branch is left in place; nothing is lost.

@Shi-Dong Shi-Dong closed this Aug 13, 2026
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