Skip to content

[megatron] qwen3.5 use megatron-core#8126

Open
Jintao-Huang wants to merge 6 commits intomodelscope:mainfrom
Jintao-Huang:qwen3_5_use_megatron_core
Open

[megatron] qwen3.5 use megatron-core#8126
Jintao-Huang wants to merge 6 commits intomodelscope:mainfrom
Jintao-Huang:qwen3_5_use_megatron_core

Conversation

@Jintao-Huang
Copy link
Collaborator

@gemini-code-assist
Copy link
Contributor

Summary of Changes

Hello, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request significantly enhances the megatron-core framework by integrating specific support for Qwen3.5 models. It introduces advanced configuration options for attention mechanisms, allowing for fine-grained control over the distribution of linear and scaled dot-product attention layers. These changes ensure that Qwen3.5 models can be effectively built and utilized within the Megatron ecosystem, leveraging its distributed training capabilities.

Highlights

  • Qwen3.5 Integration: Enabled Qwen3.5 models to utilize megatron-core by configuring specific attention variants, layer normalization, and attention output gating.
  • Flexible Linear Attention Frequency: Introduced a new linear_attn_freq_type function and linear_attention_freq configuration option, allowing for highly customizable patterns of linear attention and scaled dot-product attention layers within the model architecture.
  • Model Configuration Refinements: Updated MegatronModelConfig to include new parameters relevant to Qwen3.5's attention mechanisms and adjusted the processing of frequency parameters to support string-based pattern definitions.

🧠 New Feature in Public Preview: You can now enable Memory to help Gemini Code Assist learn from your team's feedback. This makes future code reviews more consistent and personalized to your project's style. Click here to enable Memory in your admin console.

Changelog
  • swift/megatron/model/gpts/qwen3_next.py
    • Removed a TODO comment related to layernorm_zero_centered_gamma.
    • Explicitly set enorm submodule to Qwen3NextRMSNorm within get_mtp_block_spec.
  • swift/megatron/model/model_config.py
    • Added linear_attn_freq_type function with detailed documentation for defining linear attention layer patterns.
    • Changed the default type of moe_layer_freq from integer 1 to string '1'.
    • Reordered and added new configuration parameters for Qwen3_next/Qwen3_5 models in MegatronModelConfig, including experimental_attention_variant, linear_attention_freq, and attention_output_gate.
    • Removed the layer_types parameter from MegatronModelConfig.
    • Updated _format_config to process linear_attention_freq using the new linear_attn_freq_type function.
    • Modified _HF_CONFIG_MAP to correctly map linear_attention_freq to full_attention_interval and adjust other Qwen3_next related mappings.
    • Revised convert_hf_config for qwen3_next and qwen3_5 models to directly set experimental_attention_variant, layernorm_zero_centered_gamma, attention_output_gate, and linear_attention_freq.
Activity
  • No human activity has been recorded on this pull request yet.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Copy link
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

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 updates the configuration for qwen3.5 models to use megatron-core. The changes involve adding new configuration options, updating mappings, and modifying how model configurations are converted from Hugging Face format.

I've found a critical issue in swift/megatron/model/model_config.py where the generation of layer_types has been removed for qwen3_next and qwen3_5 models. This will cause a runtime error as Qwen3NextLoader (and by extension Qwen3_5Loader) still depends on this configuration to build the model layers. I have provided a detailed comment and a code suggestion to fix this.

@Jintao-Huang
Copy link
Collaborator Author

/gemini review

@gemini-code-assist
Copy link
Contributor

Warning

Gemini is experiencing higher than usual traffic and was unable to create the review. Please try again in a few hours by commenting /gemini review.

@Jintao-Huang
Copy link
Collaborator Author

/gemini review

Copy link
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

The pull request introduces support for Qwen3.5 models by integrating megatron-core's experimental attention variants, specifically gated_delta_net. This involves significant refactoring, including the removal of custom attention and normalization classes in favor of megatron-core's functionalities and a new GatedSelfAttention module. Configuration parameters have been updated to reflect these changes, and version checks for megatron-core have been added for compatibility. However, a critical correctness issue was identified in the handling of lora_A consistency checks.

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