Skip to content

Add the YARN support for hybrid_model - #4244

Merged
Phlip79 merged 7 commits into
NVIDIA:mainfrom
guihong-nv:yarn_in_hybrid
Apr 24, 2026
Merged

Add the YARN support for hybrid_model#4244
Phlip79 merged 7 commits into
NVIDIA:mainfrom
guihong-nv:yarn_in_hybrid

Conversation

@guihong-nv

@guihong-nv guihong-nv commented Apr 9, 2026

Copy link
Copy Markdown
Contributor

Add YaRN positional embedding support to MambaModel

Summary

  • megatron/core/models/mamba/mamba_model.py: Extended position_embedding_type to accept 'yarn'. Adds a YarnRotaryEmbedding in __init__ and calls it in forward (discarding the returned mscale), mirroring the existing RoPE path.
  • mamba_builders.py: Injects YaRN-specific config attributes (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) onto TransformerConfig before MambaModel is constructed, so pretrain_mamba.py can accept --position-embedding-type yarn.
  • megatron/training/arguments.py: Added 'yarn' to the allowed values for --position-embedding-type.
  • tests/unit_tests/models/test_mamba_model.py: Added TestMambaModelWithYarn with three tests — constructor (checks YarnRotaryEmbedding is created), forward pass, and inference (static context, prefill + decode steps).

Contribution process

Pre-checks

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

Code review

Feel free to message or comment the @mcore-oncall to help accelerate your merge into main. The less complex your PR is, the faster it will be approved and merged!

All PRs start as draft. If you open a non-draft PR, it will be automatically converted to draft.

Step 1: Mark PR as "Ready for Review"

  1. When your PR is ready, click Ready for Review.
  2. An oncall reviewer is auto-assigned and expert reviewers are notified based on your changes.
    • Some PRs may jump straight to step 2. This is determined by .github/CODEOWNERS.

⚠️ Only mark as ready once merge-conflicts are resolved and the CI is passing.
Final Review might get declined if these requirements are not fulfilled.

Step 2: Final Review

For PRs that change megatron/core, once all expert reviewers have approved, the Final Review label is applied automatically and final reviewers are assigned.

For PRs outside megatron/core, this step is skipped.

Step 3: Approved

Once all required reviewers have approved, the Approved label is applied automatically.

Merge

Any member of mcore-engineers will be able to merge your PR.

For MRs into `dev` branch The proposed review process for `dev` branch is under active discussion.

MRs are mergable after one approval by either eharper@nvidia.com or zijiey@nvidia.com.

@copy-pr-bot

copy-pr-bot Bot commented Apr 9, 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.

@Phlip79

Phlip79 commented Apr 9, 2026

Copy link
Copy Markdown
Member

/ok to test c7c9d79

@svcnvidia-nemo-ci svcnvidia-nemo-ci added this to the Core 0.16 milestone Apr 9, 2026
@guihong-nv

Copy link
Copy Markdown
Contributor Author

/ok to test 3ace27b

@guihong-nv
guihong-nv marked this pull request as ready for review April 10, 2026 21:14
@guihong-nv
guihong-nv requested review from a team as code owners April 10, 2026 21:14
@svcnvidia-nemo-ci
svcnvidia-nemo-ci requested a review from a team April 10, 2026 21:14
@Phlip79

Phlip79 commented Apr 10, 2026

Copy link
Copy Markdown
Member

/claude review

@claude claude 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.

LGTM

Comment thread megatron/core/models/mamba/mamba_model.py Outdated
@guihong-nv
guihong-nv requested a review from a team as a code owner April 21, 2026 01:49
@svcnvidia-nemo-ci svcnvidia-nemo-ci added the Final Review PR is in the "final review" stage label Apr 21, 2026
@Phlip79
Phlip79 removed request for a team April 21, 2026 02:37
@guihong-nv
guihong-nv enabled auto-merge April 21, 2026 12:18
@guihong-nv
guihong-nv disabled auto-merge April 21, 2026 12:18
@guihong-nv guihong-nv changed the title Add the YARN support for mamba_model Add the YARN support for hybrid_model Apr 22, 2026
@Phlip79
Phlip79 enabled auto-merge April 23, 2026 04:55
@Phlip79
Phlip79 added this pull request to the merge queue Apr 23, 2026
@github-merge-queue
github-merge-queue Bot removed this pull request from the merge queue due to a conflict with the base branch Apr 23, 2026
@guihong-nv
guihong-nv enabled auto-merge April 23, 2026 12:33
@guihong-nv
guihong-nv added this pull request to the merge queue Apr 23, 2026
@svcnvidia-nemo-ci

Copy link
Copy Markdown
Contributor

🔄 Merge queue validation started!

You can track the progress here: https://github.com/NVIDIA/Megatron-LM/actions/runs/24838266239

@github-merge-queue
github-merge-queue Bot removed this pull request from the merge queue due to no response for status checks Apr 23, 2026
@Phlip79
Phlip79 added this pull request to the merge queue Apr 24, 2026
@svcnvidia-nemo-ci

Copy link
Copy Markdown
Contributor

🔄 Merge queue validation started!

You can track the progress here: https://github.com/NVIDIA/Megatron-LM/actions/runs/24867274470

@github-merge-queue
github-merge-queue Bot removed this pull request from the merge queue due to failed status checks Apr 24, 2026
@Phlip79

Phlip79 commented Apr 24, 2026

Copy link
Copy Markdown
Member

/ok to test 5f895dd

@Phlip79
Phlip79 enabled auto-merge April 24, 2026 02:58
@Phlip79
Phlip79 added this pull request to the merge queue Apr 24, 2026
@svcnvidia-nemo-ci

Copy link
Copy Markdown
Contributor

🔄 Merge queue validation started!

You can track the progress here: https://github.com/NVIDIA/Megatron-LM/actions/runs/24872833192

@svcnvidia-nemo-ci

Copy link
Copy Markdown
Contributor

🔄 Merge queue validation started!

You can track the progress here: https://github.com/NVIDIA/Megatron-LM/actions/runs/24873177343

Merged via the queue into NVIDIA:main with commit 4d6cdd5 Apr 24, 2026
68 checks passed
yangbofun pushed a commit to xlm-research/Megatron-LM that referenced this pull request May 22, 2026
Co-authored-by: Philip Petrakian <ppetrakian@nvidia.com>
yhgalaxy pushed a commit to yhgalaxy/Megatron-LM that referenced this pull request Jun 17, 2026
Co-authored-by: Philip Petrakian <ppetrakian@nvidia.com>
Signed-off-by: yhgalaxy <yhgalaxy@outlook.com>
guihong-nv added a commit to guihong-nv/Megatron-LM that referenced this pull request Jun 23, 2026
HybridModel already builds YarnRotaryEmbedding from getattr(self.config,
"yarn_*") (NVIDIA#4244), but those attributes were never declared on
TransformerConfig and had no CLI plumbing, so --position-embedding-type yarn
raised AttributeError and YaRN could not be configured from the command line.

- transformer_config.py: declare the 7 yarn_* fields with safe defaults
  (yarn_rotary_scaling_factor default 1.0 is a no-op).
- arguments.py: add matching --yarn-* args; dest names match the field names
  so core_transformer_config_from_args plumbs them through automatically.
- 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>
jon-barker pushed a commit to jon-barker/Megatron-LM that referenced this pull request Jul 10, 2026
Co-authored-by: Philip Petrakian <ppetrakian@nvidia.com>
Signed-off-by: Jon Barker <jbarker@aws-cmh-slurm-1-vscode-02.cm.cluster>
terminator123 pushed a commit to 021ai/Megatron-LM that referenced this pull request Aug 3, 2026
Co-authored-by: Philip Petrakian <ppetrakian@nvidia.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Approved All necessary approvals have been made complexity: low

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants