Skip to content

Add formal YaRN RoPE config fields for hybrid models - #5465

Draft
guihong-nv wants to merge 7 commits into
NVIDIA:mainfrom
guihong-nv:mbridge-yarn
Draft

Add formal YaRN RoPE config fields for hybrid models#5465
guihong-nv wants to merge 7 commits into
NVIDIA:mainfrom
guihong-nv:mbridge-yarn

Conversation

@guihong-nv

Copy link
Copy Markdown
Contributor
  • I, the PR author, have personally reviewed every line of this PR.

What does this PR do ?

Declares the YaRN RoPE parameters as formal TransformerConfig fields so that --position-embedding-type yarn is actually usable for hybrid models.

HybridModel already instantiates YarnRotaryEmbedding from getattr(self.config, "yarn_*") (added in #4244), but those yarn_* attributes were never declared on TransformerConfig — they were only set dynamically in tests. As a result, launching with --position-embedding-type yarn raised AttributeError.

  • megatron/core/transformer/transformer_config.py — declares the 7 YaRN fields on TransformerConfig with safe defaults (yarn_rotary_scaling_factor, yarn_original_max_position_embeddings, yarn_beta_fast, yarn_beta_slow, yarn_mscale, yarn_mscale_all_dim, yarn_correction_range_round_to_int). The default yarn_rotary_scaling_factor=1.0 is a no-op, so existing configs are unaffected.
  • tests/unit_tests/models/test_hybrid_model.py — drives the YaRN test config via the constructor (the formal-field path) and adds two tests: one asserting the fields exist as dataclass fields with the expected defaults, and one asserting the config values flow into the YarnRotaryEmbedding instance.

The matching --yarn-* CLI flags are produced automatically: _add_network_size_args builds a TransformerConfig argument group via ArgumentGroupFactory(TransformerConfig), which derives one CLI flag (and the args→config plumbing) per dataclass field. No manual argument plumbing is needed — adding the flags by hand would duplicate the auto-generated ones and raise argparse: conflicting option string.

No behavior change for non-YaRN paths. Validated on GPU: the full arg parser builds with the --yarn-* flags auto-generated (no conflict), and tests/unit_tests/models/test_hybrid_model.py plus tests/unit_tests/transformer/test_multi_latent_attention.py pass (one pre-existing, environment-related context-parallel SIGABRT reproduces on unmodified main and is unrelated to this change).

Issue tracking

Related to #4244 (which added the YaRN wiring in HybridModel).

Contribution process

Pre-checks

  • I have added relevant unit tests
  • I have added relevant functional tests
  • I have added proper typing to my code
  • I have added relevant documentation
  • I have run the autoformatter.sh on my PR

HybridModel already builds YarnRotaryEmbedding from getattr(self.config,
"yarn_*") (NVIDIA#4244), but those attributes were never declared on
TransformerConfig, so --position-embedding-type yarn raised AttributeError and
YaRN could not be configured.

Declaring the 7 yarn_* fields on TransformerConfig fixes this and also makes the
--yarn-* CLI flags appear automatically: _add_network_size_args builds a
TransformerConfig argument group via ArgumentGroupFactory(TransformerConfig),
which derives one CLI flag per dataclass field. No manual argument plumbing is
needed -- adding the flags by hand duplicates the auto-generated ones and raises
argparse 'conflicting option string'.

- transformer_config.py: declare the 7 yarn_* fields with safe defaults
  (yarn_rotary_scaling_factor default 1.0 is a no-op).
- test_hybrid_model.py: drive the yarn test config via the constructor and add
  tests for the dataclass fields and config->embedding plumbing.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Signed-off-by: Guihong Li <guihongl@nvidia.com>
@copy-pr-bot

copy-pr-bot Bot commented Jun 24, 2026

Copy link
Copy Markdown

This pull request requires additional validation before any workflows can run on NVIDIA's runners.

Pull request vetters can view their responsibilities here.

Contributors can view more details about this message here.

@guihong-nv

Copy link
Copy Markdown
Contributor Author

/ok to test ad69cde

guihong-nv and others added 3 commits June 24, 2026 13:04
The hybrid MoE golden-config drift test (test_hybrid_moe_model.py) pins the exact
set of TransformerConfig fields. Adding the yarn_* fields trips its [ADDED ARGS]
check, so register them in GOLDEN_CONFIG with their default values.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Signed-off-by: Guihong Li <guihongl@nvidia.com>
@NVIDIA NVIDIA deleted a comment from copy-pr-bot Bot Jun 24, 2026
@guihong-nv

Copy link
Copy Markdown
Contributor Author

/ok to test c6fd678

guihong-nv and others added 2 commits June 24, 2026 15:51
main adds the --yarn-* CLI flags manually in _add_network_size_args. Now that
the yarn_* fields are declared on TransformerConfig, ArgumentGroupFactory would
also auto-generate those flags, producing duplicate argparse option strings and
breaking every test that builds the parser. Exclude the yarn_* fields from
auto-generation so the manual flags remain the single source; the fields still
provide config storage + defaults consumed by gpt_model/hybrid_model.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Signed-off-by: Guihong Li <guihongl@nvidia.com>
@guihong-nv

Copy link
Copy Markdown
Contributor Author

/ok to test 1636571

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