Adding RoPE to TransformerEncoder#15775
Merged
Merged
Conversation
Co-authored-by: Copilot <copilot@github.com> Signed-off-by: MahmoudAshraf97 <hassouna97.ma@gmail.com>
Co-authored-by: Copilot <copilot@github.com> Signed-off-by: MahmoudAshraf97 <hassouna97.ma@gmail.com>
Co-authored-by: claude[bot] <209825114+claude[bot]@users.noreply.github.com> Signed-off-by: Mahmoud Ashraf <hassouna97.ma@gmail.com>
Signed-off-by: Piotr Żelasko <pzelasko@nvidia.com>
Collaborator
|
/ok to test f5962f4 |
Member
|
pls add tests |
Signed-off-by: ipmedenn <65592416+ipmedenn@users.noreply.github.com>
Signed-off-by: ipmedenn <65592416+ipmedenn@users.noreply.github.com>
61c2362 to
25456fe
Compare
Member
|
/ok to test 25456fe |
nithinraok
previously approved these changes
Jul 1, 2026
Member
|
/claude review |
Contributor
|
[🤖]: Hi @ipmedenn 👋, We wanted to let you know that a CICD pipeline for this PR just finished successfully. So it might be time to merge this PR or get some approvals. |
Signed-off-by: ipmedenn <65592416+ipmedenn@users.noreply.github.com>
Member
|
/ok to test 8c01d64 |
nithinraok
approved these changes
Jul 4, 2026
Contributor
|
[🤖]: Hi @ipmedenn 👋, We wanted to let you know that a CICD pipeline for this PR just finished successfully. So it might be time to merge this PR or get some approvals. |
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.
Important
The
Update branchbutton must only be pressed in very rare occassions.An outdated branch is never blocking the merge of a PR.
Please reach out to the automation team before pressing that button.
What does this PR do ?
Adds RoPE (rotary position embedding) as a
self_attention_modeloption to the ASRTransformerEncoder, alongside the existing"rel_pos"(default),"abs_pos", and"no_pos"modes. Withself_attention_model="rope", position is injected by rotating Q and K inside attention — no additive positional embedding is added to the signal and attention stays plain scaled dot-product (FlexAttention withscore_mod=None). This mirrors the RoPE support recently added toConformerEncoder(#15714), keeping the two encoder surfaces aligned.Collection: ASR
Changelog
"rope"to the supportedself_attention_modelvalues ofTransformerEncoder/TransformerEncoderConfig, plusrope_base(default10000.0) androtary_fraction(default1.0) arguments and config fields.MultiHeadAttentionnow accepts an optional sharedpos_enc; inropemode it rotates Q/K in place viaRotaryPositionalEncodingbefore FlexAttention (score_mod=None), and raises ifropeis selected without a rotary module.TransformerEncoderbuilds a singleRotaryPositionalEncoding(d_k = d_model // n_heads,rope_base,rotary_fraction,max_len = pos_emb_max_len) and passes it into everyTransformerBlockso the cos/sin buffers are shared.ropemode no additive positional embedding is added;xscaling(if set) anddropout_pre_encoderare applied to the pre-encoder output inforward_internal, anddropout_embis unused.RotaryPositionalEncodingfromnemo.collections.asr.parts.submodules.multi_head_attention(no new positional-encoding module introduced).self_attention_modeltests (test_valid_modes_are_accepted,test_non_rel_pos_modes_have_no_rel_params,test_forward_each_mode_cpu) to include"rope", assertedrope_base/rotary_fractionconfig defaults, and addedtest_rope_uses_shared_rotary_pos_enc(shared-module wiring) andtest_rope_partial_rotation_forward_cpu(rotary_fraction=0.5).Usage
Config:
Python:
GitHub Actions CI
The Jenkins CI system has been replaced by GitHub Actions self-hosted runners.
The GitHub Actions CI will run automatically when the "Run CICD" label is added to the PR.
To re-run CI remove and add the label again.
To run CI on an untrusted fork, a NeMo user with write access must first click "Approve and run".
Before your PR is "Ready for review"
Pre checks:
PR Type:
Who can review?
Anyone in the community is free to review the PR once the checks have passed.
Contributor guidelines contains specific people who can review PRs to various areas.
Additional Information
Follow-up work after the initial TF encoder PRs (#15661, #15703). Adds the
ropepositional-encoding option mirroring the RoPE support added toConformerEncoder(#15714).