Skip to content

[megatron, model] feat: qwen3.5 example #5381

Open
ISEEKYAN wants to merge 2 commits intoverl-project:mainfrom
ISEEKYAN:mcore_qwen35
Open

[megatron, model] feat: qwen3.5 example #5381
ISEEKYAN wants to merge 2 commits intoverl-project:mainfrom
ISEEKYAN:mcore_qwen35

Conversation

@ISEEKYAN
Copy link
Collaborator

@ISEEKYAN ISEEKYAN commented Feb 24, 2026

What does this PR do?

thanks to @LiuXTao 's great work on ISEEKYAN/mbridge#83, the mbridge has supported qwen3.5.

This PR succeeded in running qwen3.5 SFT on verl based on mbridge supports for qwen3.5

Checklist Before Starting

  • Search for similar PRs. Paste at least one query link here: ...
  • Format the PR title as [{modules}] {type}: {description} (This will be checked by the CI)
    • {modules} include fsdp, megatron, veomni, sglang, vllm, rollout, trainer, ci, training_utils, recipe, hardware, deployment, ray, worker, single_controller, misc, perf, model, algo, env, tool, ckpt, doc, data, cfg, reward
    • If this PR involves multiple modules, separate them with , like [megatron, fsdp, doc]
    • {type} is in feat, fix, refactor, chore, test
    • If this PR breaks any API (CLI arguments, config, function signature, etc.), add [BREAKING] to the beginning of the title.
    • Example: [BREAKING][fsdp, megatron] feat: dynamic batching

Test

see examples/sft/gsm8k/run_qwen3_5_megatron.sh
and examples/grpo_trainer/run_qwen3_5-35b-megatron.sh

API and Usage Example

Demonstrate how the API changes if any, and provide usage example(s) if possible.

# Add code snippet or script demonstrating how to use this

Design & Code Changes

Demonstrate the high-level design if this PR is complex, and list the specific changes.

Checklist Before Submitting

Important

Please check all the following items before requesting a review, otherwise the reviewer might deprioritize this PR for 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

This pull request adds support for Qwen3.5 SFT with Megatron. The changes are mostly workarounds and fixes to support the Qwen3.5 architecture, particularly its Gated Delta Net (GDN) and chat template requirements. The changes look reasonable and well-commented, improving compatibility and robustness. I have one major concern about catching a broad Exception which could hide bugs.

return_tensors="pt",
**apply_chat_template_kwargs,
)
except (jinja2.exceptions.TemplateError, Exception) as e:
Copy link
Contributor

Choose a reason for hiding this comment

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

high

Catching a generic Exception is risky as it can suppress unexpected errors, making debugging difficult. It's better to catch more specific exceptions. Since jinja2.exceptions.TemplateError is a subclass of Exception, the tuple (jinja2.exceptions.TemplateError, Exception) is redundant and equivalent to except Exception:. Please replace Exception with the specific exception type(s) that are expected to contain the 'No user query' message. If the exact type is unknown, consider catching a narrower set of exceptions like ValueError or TypeError which are common for such issues.

@wuyaoxuehun
Copy link

@ISEEKYAN does this pr can also support rl?

@ISEEKYAN
Copy link
Collaborator Author

@ISEEKYAN does this pr can also support rl?

just updated a script with RL supports. But it is not easy to prepare a right vllm dependency now🥲

@ISEEKYAN ISEEKYAN changed the title [megatron, model] feat: qwen3.5 megatron example of SFT [megatron, model] feat: qwen3.5 example Feb 26, 2026
@wuyaoxuehun
Copy link

@ISEEKYAN does this pr can also support rl?

just updated a script with RL supports. But it is not easy to prepare a right vllm dependency now🥲

Many thanks.
"I succeeded in running this script with the main branch of vllm on 20260225, yet there are still some minor issues

the vllm qwen3.5 during initialization, need to be fixed."

so what issue is there with vllm qwen3.5 initialization?

I see in vllm doc that vllm can indeed serve qwen3.5(https://docs.vllm.ai/projects/recipes/en/latest/Qwen/Qwen3.5.html).

@khazic
Copy link
Contributor

khazic commented Feb 27, 2026

Successfully ran Qwen3.5 SFT (verl megatron example) with the following setup:

(1) mbridge: install from source for qwen3_5 support —
pip install git+https://github.com/ISEEKYAN/mbridge.git
(PyPI 0.15.1 does not register qwen3_5; use git to get qwen3_5.)

(2) megatron-core == 0.16.0 — required for attention_output_gate and other GDN options.

(3) verl patch in verl/models/mcore/patch.py: applies the gate-slicing fix when
num_query_groups < tp_size (same as Megatron-LM PR #3529), plus the existing
mbridge compatibility patch. Without the gate patch, training fails with a
shape mismatch in _apply_output_gate.

Key library versions used:

  • mbridge: from git (reports 0.15.1)
  • megatron-core: 0.16.0
  • transformers: 5.2.0
  • torch: 2.9.0+cu129
  • flash_attn: 2.8.1
  • flash-linear-attention: 0.4.1

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