Skip to content

qwen3.5 lora compatibility (needs SGLang + Megatron-Bridge patches as well) - #1112

Open
artem-osmosis wants to merge 1 commit into
radixark:mainfrom
Osmosis-AI:qwen35_lora_miles_v3
Open

qwen3.5 lora compatibility (needs SGLang + Megatron-Bridge patches as well) #1112
artem-osmosis wants to merge 1 commit into
radixark:mainfrom
Osmosis-AI:qwen35_lora_miles_v3

Conversation

@artem-osmosis

@artem-osmosis artem-osmosis commented May 11, 2026

Copy link
Copy Markdown
  • add script for lora finetuning qwen3.5 w/ support for q_proj,k_proj,v_proj
  • Add a function to check if the model is Qwen3.5, and ignore mtp/vision modules when applying lora adapters if that's the case

for lora + qwen3.5 + megatron bridge to work, we also need patches to both the sglang-miles fork of sglang, and the bridge branch of radixark/Megatron-Bridge

changes for sglang:

  • upstream qwen3_5.py
  • patch for shape error when determining lora_b shape for q/k/v proj adapters:
    AssertionError: LoRA buffer shape torch.Size([1152, 32]) does not match weight shape torch.Size([1280, 32]).

changes for Megatron-Bridge:

  • handle both transformer_layer and mtp_model_layer keys for mtp megatron modules

Megatron-Bridge and sglang PRs:

@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 adds a LoRA training script for Qwen3.5-35B-A3B and introduces logic to filter target modules for Qwen3.5 models. Key feedback includes fixing a typo in the PYTHONUNBUFFERED environment variable, adjusting the module path pattern to ensure compatibility with text-only models, and recommending a more reliable way to identify model types than string matching on file paths.

def exclude_mtp_vision_modules(target_modules: list[str]) -> list[str]:
"""Restrict Qwen3.5-VL LoRA targets to the language model."""
return [
target if "language_model" in target else f"*language_model.decoder.layers.*.*.{target}"

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.

high

The prefix *language_model.decoder.layers.*.*. might be too restrictive for text-only Qwen3.5 models. In the Megatron backend (as seen in megatron_to_hf/qwen3_5.py), the module hierarchy typically starts with decoder.layers without a language_model wrapper. Including language_model in the pattern may cause LoRA adapters to fail to match any modules in non-VL models. Consider using a more general pattern like *decoder.layers.*.*. to target the main transformer layers while still excluding MTP modules (which are usually under mtp.layers).

Suggested change
target if "language_model" in target else f"*language_model.decoder.layers.*.*.{target}"
target if "language_model" in target else f"*decoder.layers.*.*.{target}"

set -ex

# will prevent ray from buffering stdout/stderr
export PYTHONBUFFERED=16

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.

medium

The environment variable should be PYTHONUNBUFFERED instead of PYTHONBUFFERED. Standard Python uses PYTHONUNBUFFERED to disable stream buffering, which is what the comment above indicates is the goal. Ensure the variable name matches the exact spelling expected by the system to avoid the override being ignored.

Suggested change
export PYTHONBUFFERED=16
export PYTHONUNBUFFERED=1
References
  1. Ensure environment variable names match the exact spelling expected by the system, even if it contains a typo, to avoid the override being ignored.

target_modules = convert_target_modules_to_megatron(args.target_modules, lora_type=lora_cls)

model_name = args.hf_checkpoint
if "Qwen3.5" in model_name:

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.

medium

Checking for "Qwen3.5" in the full checkpoint path is fragile, as the path might contain this string for unrelated reasons (e.g., a parent directory name) or might not contain it if the model directory was renamed. It would be more robust to retrieve model parameters and architecture details from the model configuration rather than hardcoding checks against file paths.

References
  1. Model parameters should be retrieved from the model configuration rather than being hardcoded.

@fzyzcjy
fzyzcjy requested a review from Shi-Dong as a code owner July 25, 2026 23:42
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.

1 participant