Repository navigation
[OMNIML-6054] [19/20] Route load_pretrained by the distribution plan - #2774
Merged
shengliangxu merged 0 commit intoOct 13, 2026
Merged
shengliangxu merged 0 commit into
shengliangxu merged 0 commit into
Conversation
|
Auto-sync is disabled for draft pull requests in this repository. Workflows must be run manually. Contributors can view more details about this message here. |
Contributor
|
Important Draft PR not reviewedDraft PRs are not automatically reviewed by default.
To automatically review draft PRs, update your CodeRabbit configuration: reviews:
auto_review:
drafts: true
Comment |
shengliangxu
added this pull request to stack #2775
October 13, 2026 17:43
shengliangxu
force-pushed
the
shengliangx/hfep-13b-load-routing
branch
from
October 13, 2026 19:38
22cf9dd to
3ac7c7b
Compare
Contributor
|
This was referenced Oct 13, 2026
Collaborator
Author
|
Superseded by #2779 ([3/21], this routing without expert parallelism, now right after #2737) and #2780 ([13/21], the expert-parallel half, after the EP loader and model specs it needs). Moving this branch down the stack made it part of this PR's old base, |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What does this PR do?
Type of change: New feature
load_pretrained(#2733) loads a model whole. The distributed loads,load_and_prepare_ep([6/20]-[8/20]) andparallel_load_and_prepare_fsdp2(main), are separate entry points, and every caller picked one itself,hf_ptq.pywith its own copy of the plan decision. A caller that picks a loader also gets what that loader skips. On the expert-parallel path that was the Nemotron-H MTP head:prepare_model_for_loadingbuilds it only on a whole model, so the expert-parallel load carried it into the export unquantized, without a word.This PR makes
load_pretrainedthe one loader, whole or distributed:distributionpicks the load."sequential":from_pretrained, as before."fsdp2":parallel_load_and_prepare_fsdp2.DistributionPlan: the experts sharded at load (load_and_prepare_ep, the dense part replicated or FSDP2-sharded asfsdp_sizesays), FSDP2 over the world, or a whole copy on every rank's own GPU.None, the session decides. A single process loads whole. A distributedModelOptSessiondecides with the newresolve_distribution_plan: the model's spec first, which for several models is what supplies the expert-parallel plan, thendecide_distribution_plan([2/20]) with theMODELOPT_EP_DEGREE/MODELOPT_FSDP_SIZEknobs (modelopt.torch.utils.env, moved here from [20/20]). It refuses a plan that would leave an expert-parallel MoE whole on every rank. A caller that loads a whole model its own way decides first:resolve_distribution_planreturns the plan and the config the load must use.from_pretrained's placement arguments (device_map,max_memory, ...) and a model class it does not build, rather than ignore them.fsdp_sizewithout expert parallelism, which it cannot shard.Usage
Testing
tests/unit/torch/utils/test_load_pretrained_distribution.py(36 cases, CPU, no process group; stand-in loaders record their calls):tests/gpu/torch/utils/test_load_pretrained_distribution.py, on every GPU of the node,load_pretrainedleft to decide: a dense model loads whole on each rank; withMODELOPT_FSDP_SIZE=world, FSDP2-sharded; a Qwen3-MoE with its experts sharded. Each rank's weights match the checkpoint, and the load records its unplaced keys. Not run before opening this PR; CI's GPU workflow runs it.tests/uniton this branch, in CI's linux-lane environment (Python 3.12, torch 2.14, transformers 5.18, CPU): 5274 passed, 27 skipped, 12 xfailed, none failed. The Sphinx docs build is clean.Before your PR is "Ready for review"
load_pretrainedkeeps its behavior outside a distributed session;distributionandresolve_distribution_planare new.CONTRIBUTING.md: N/AAdditional Information
Part 19 of 20 of expert-parallel PTQ for Hugging Face MoE models; merges after [18/20].