feat(conversion): add direct ModelConfig mapping#4543
Draft
yaoyu-33 wants to merge 6 commits into
Draft
Conversation
Signed-off-by: yaoyu-33 <yaoyu.094@gmail.com>
Contributor
Author
|
/ok to test b0775aa |
Signed-off-by: yaoyu-33 <yaoyu.094@gmail.com>
Contributor
Author
|
/ok to test 381d193 |
Contributor
Author
|
/ok to test 381d193 |
Signed-off-by: yaoyu-33 <yaoyu.094@gmail.com>
Contributor
Author
|
/ok to test 3c453cc |
Signed-off-by: yaoyu-33 <yaoyu.094@gmail.com>
Contributor
Author
|
/ok to test d7a27b1fa68c66f7b92d8983e3a9246e80cb10af |
@yaoyu-33, there was an error processing your request: See the following link for more information: https://docs.gha-runners.nvidia.com/cpr/e/2/ |
Contributor
Author
|
/ok to test d7a27b1 |
Signed-off-by: yaoyu-33 <yaoyu.094@gmail.com>
Contributor
Author
|
/ok to test c5154c1 |
Signed-off-by: yaoyu-33 <yaoyu.094@gmail.com>
Contributor
Author
|
/ok to test 03c781b |
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?
Add the first direct
ModelConfig/ModelBuilderfoundation to the conversion API for RL and external-trainer integrations.AutoBridge.to_megatron_model_config()MegatronModelBridge.hf_config_to_model_config()as the canonical HF-config-to-ModelConfigpathCONFIG_MAPPINGwithout routing the new path throughprovider_bridge()ModelConfigdefaults differRelated to #4294. This also incorporates the useful direction from the incomplete reference draft #2810, rebuilt against current
mainwith focused parity tests.Design
The dependency direction is intentionally:
to_megatron_model_config()is configuration-only: it does not load weights, initialize distributed state, finalize the config, or build a model.Model families opt in explicitly with
MODEL_CONFIG_CLASSand may specializehf_config_to_model_config()for architecture defaults. Llama maps directly toGPTModelConfig; Nemotron-H maps directly toHybridModelConfig. Tests patchprovider_bridge()and the provider-era mapping alias to fail if the new path accidentally depends on either one.The shared
CONFIG_MAPPINGtraversal is kept private.hf_config_to_provider_kwargs()remains as the provider compatibility hook, andprovider_bridge()continues calling it so downstream subclasses that override the hook are not broken.The direct path explicitly carries Bridge construction defaults such as loss/gradient fusions and pipeline output deallocation. Nemotron-H additionally preserves its Hybrid-specific RMSNorm, flash-attention, fusion, and MTP defaults. This avoids silently changing training behavior merely because upstream builder dataclasses use more conservative defaults.
This PR does not emit a runtime deprecation warning for
provider_bridge()/to_megatron_provider()yet: current model construction and checkpoint import still depend on them. Formal deprecation should follow the builder-backedto_megatron_model()migration, when callers have a complete replacement.Tests
Added focused coverage for:
ModelConfigparity across all overlapping transformer and model fieldsModelConfigparity across all overlapping fieldsprovider_bridge()andhf_config_to_provider_kwargs()AutoBridge.to_megatron_model_config()delegationValidation:
uvx pre-commit run --all-files: passedgit diff --check: passedThe focused pytest command covered the two Llama config tests, the Nemotron-H parity test, and AutoBridge delegation. The local macOS ARM environment cannot resolve the full project because
nvidia-resiliency-extis distributed only as Linux wheels; no dependency or lockfile changes were made.Intentional limitations / follow-up
TypeVarhelper are addedprovider_bridgeabstraction is introducedto_megatron_model()and then formally deprecate the public provider pathChecklist
3rdparty/Megatron-LMchanges