Skip to content

Broaden packages.find.include to expose megatron.training#33

Closed
Shi-Dong wants to merge 3 commits into
miles/move-plugins-to-milesfrom
miles/broaden-packages
Closed

Broaden packages.find.include to expose megatron.training#33
Shi-Dong wants to merge 3 commits into
miles/move-plugins-to-milesfrom
miles/broaden-packages

Conversation

@Shi-Dong
Copy link
Copy Markdown

Summary

  • Broaden [tool.setuptools.packages.find].include to also expose megatron.training and megatron.training.* (in addition to the existing megatron.core / megatron.core.*).

Why

miles imports from several modules under megatron.training.* (arguments, checkpointing, global_vars, tokenizer.tokenizer, training). Until now those imports succeed only because pip install -e . adds the project root to sys.path as a side effect — not because megatron.training is an explicitly declared package.

miles' CPU CI runner makes that side effect explicit via PYTHONPATH=$workspace/third_party/Megatron-LM. That PYTHONPATH workaround doesn't survive packaging miles as a wheel (the eventual pip install miles goal in the broader Phase 2 roadmap).

Declaring megatron.training.* in the explicit package list lets a normal pip install (editable, wheel, or otherwise) expose it. No code in this PR changes; only the discovery list does.

What this does NOT change

  • Runtime semantics for code already importing from megatron.training: the same modules resolve.
  • megatron-core's project name. The wheel is still megatron-core, just with a slightly broader set of sub-packages.

Test plan

  • miles PR (linked below) bumps its third_party/Megatron-LM submodule pointer to this branch's HEAD and removes the PYTHONPATH=$workspace/third_party/Megatron-LM override from _run-ci.yml. CI on that PR is the validation gate: stage-a-fast (CPU runner) must pass — that's the path that previously needed the PYTHONPATH hack to find megatron.training.
  • Smoke on H200 devbox with a rebuilt image: unset PYTHONPATH && python -c "import megatron.training; import megatron.training.training" succeeds.

Stacked on

radixark/Megatron-LM PR #32 (Phase 1: remove miles_megatron_plugins/). After both this PR and #32 merge, the miles-main branch carries both changes; the miles repo's submodule pointer flips back to branch = miles-main.

In addition to `megatron.core`, also expose `megatron.training` (and its
sub-packages) via setuptools' package discovery, so that
`pip install -e .` against this checkout makes `from megatron.training
import ...` work without callers having to set PYTHONPATH.

Why: miles imports from `megatron.training.arguments`,
`megatron.training.checkpointing`, `megatron.training.global_vars`,
`megatron.training.tokenizer.tokenizer`, and `megatron.training.training`.
Until now those imports only worked because the production environment
adds `/root/Megatron-LM` (the editable install's root) to sys.path,
which is a side effect of `pip install -e` rather than a deliberate
package export. miles' CPU CI runner makes that side effect explicit
via `PYTHONPATH=$workspace:$workspace/third_party/Megatron-LM`, but
that override doesn't survive packaging miles as a wheel for the
eventual `pip install miles` goal.

By exposing `megatron.training.*` in pyproject.toml, the side-effect
dependency goes away. Callers can rely on the explicit Python package
list instead of the editable-install path trick.

This change does not affect runtime semantics for code that was already
importing from `megatron.training` (those callers continue to find the
same modules); it only changes which sys.path entries make the imports
resolve, broadening it from "editable-install root only" to "any pip
install location (editable, wheel, or otherwise)".
Shi Dong added 2 commits May 24, 2026 09:04
megatron.training.initialize unconditionally imports from megatron.legacy at module-load time, so any narrower include list (e.g. exposing only core+training) breaks transitively. Expose all megatron.* sub-packages instead.
megatron, megatron.legacy, and a few sub-packages have no __init__.py — they are namespace packages. The default find_packages mode skips namespace packages, so the previous broaden-to-megatron* commit did not actually expose megatron.legacy. Enable namespaces=true so the discovery is namespace-package-aware. Now pip install -e exposes the full megatron.* namespace without relying on the editable-install side effect that adds the project root to sys.path.
@Shi-Dong Shi-Dong marked this pull request as ready for review May 28, 2026 06:50
@Shi-Dong
Copy link
Copy Markdown
Author

Superseded by #50, which folds this broadening onto the current miles-main (post-#49) in a single commit and keeps miles_megatron_plugins packaged by megatron-core.

@Shi-Dong Shi-Dong closed this May 30, 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