Skip to content

support embedding MRL#9528

Merged
Jintao-Huang merged 6 commits into
modelscope:mainfrom
Jintao-Huang:support_embedding_mrl
Jun 10, 2026
Merged

support embedding MRL#9528
Jintao-Huang merged 6 commits into
modelscope:mainfrom
Jintao-Huang:support_embedding_mrl

Conversation

@Jintao-Huang

Copy link
Copy Markdown
Collaborator

No description provided.

@gemini-code-assist gemini-code-assist 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.

Code Review

This pull request introduces support for Matryoshka Representation Learning (MRL) in both Megatron and standard embedding trainers by adding the mrl_dims argument. This argument allows users to specify multiple embedding dimensions and their corresponding loss weights, computing and aggregating the weighted losses across these truncated dimensions. The review feedback highlights two key areas for improvement: first, validating that the configured MRL dimensions do not exceed the model's actual hidden dimension to prevent silent slicing errors; second, ensuring that the parsed mrl_dims is explicitly validated as a dictionary before accessing its items to avoid potential runtime errors.

Important

The consumer version of Gemini Code Assist on GitHub is being sunset. Starting June 18, 2026, new organization installations will be blocked, and all code review activity will officially cease on July 17, 2026.
For more details on the timeline and next steps, please review the Help Documentation.

Comment thread swift/megatron/trainers/embedding_trainer.py
Comment thread swift/trainers/embedding_trainer.py
Comment thread swift/megatron/arguments/megatron_args.py
Comment thread swift/trainers/arguments.py
@Jintao-Huang

Copy link
Copy Markdown
Collaborator Author

/gemini review

@gemini-code-assist gemini-code-assist 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.

Code Review

This pull request introduces Matryoshka Representation Learning (MRL) support for embedding training by adding the mrl_dims parameter to both standard and Megatron training arguments, along with corresponding documentation updates. The embedding trainers are updated to slice the last hidden state, apply L2 normalization, and compute weighted losses across the specified dimensions. The review feedback highlights critical issues that need to be addressed: an evaluation discrepancy where metrics are computed on unnormalized, full-dimensional embeddings instead of the truncated and normalized MRL dimensions; a potential crash if all configured dimensions exceed the model's hidden size; and a lack of type validation when parsing mrl_dims which could lead to runtime AttributeError crashes.

Important

The consumer version of Gemini Code Assist on GitHub is being sunset. Starting June 18, 2026, new organization installations will be blocked, and all code review activity will officially cease on July 17, 2026.
For more details on the timeline and next steps, please review the Help Documentation.

Comment thread swift/megatron/trainers/embedding_trainer.py
Comment thread swift/trainers/embedding_trainer.py
Comment thread swift/megatron/arguments/megatron_args.py
Comment thread swift/trainers/arguments.py
@Jintao-Huang Jintao-Huang merged commit 79ffd7c into modelscope:main Jun 10, 2026
2 of 3 checks passed
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.

3 participants