Skip to content

cp: add peft to recipe qwen3vl (2023) into r0.3.0#2220

Merged
ko3n1g merged 1 commit intor0.3.0from
cherry-pick-2023-r0.3.0
Feb 5, 2026
Merged

cp: add peft to recipe qwen3vl (2023) into r0.3.0#2220
ko3n1g merged 1 commit intor0.3.0from
cherry-pick-2023-r0.3.0

Conversation

@ko3n1g
Copy link
Copy Markdown
Contributor

@ko3n1g ko3n1g commented Feb 4, 2026

beep boop [🤖]: Hi @yashaswikarnati 👋,

we've cherry picked #2023 into  for you! 🚀

Please review and approve this cherry pick by your convenience!

Summary by CodeRabbit

Release Notes

  • New Features

    • Added PEFT (Parameter-Efficient Fine-Tuning) support for Qwen3-VL, including LoRA and DoRA methods for memory-efficient fine-tuning.
    • New command-line option to select PEFT type during training configuration.
  • Documentation

    • Updated Qwen3-VL fine-tuning guide with PEFT subsection and example commands for LoRA and DoRA.
  • Tests

    • Added functional test suite for Qwen3-VL fine-tuning recipes.

Signed-off-by: NeMo Bot <nemo-bot@nvidia.com>
@ko3n1g
Copy link
Copy Markdown
Contributor Author

ko3n1g commented Feb 4, 2026

/ok to test 581f0f6

@copy-pr-bot
Copy link
Copy Markdown

copy-pr-bot bot commented Feb 4, 2026

This pull request requires additional validation before any workflows can run on NVIDIA's runners.

Pull request vetters can view their responsibilities here.

Contributors can view more details about this message here.

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai bot commented Feb 4, 2026

📝 Walkthrough

Walkthrough

This PR adds Parameter-Efficient Fine-Tuning (PEFT) support to Qwen3-VL through documentation, a CLI argument for PEFT selection, model forward signature updates for loss masking, recipe configuration handling, and new functional tests for finetune recipes.

Changes

Cohort / File(s) Summary
Documentation
docs/models/vlm/qwen3-vl.md
Added PEFT subsection introducing LoRA and DoRA methods with example commands for 8B and 30B MoE models, noting ~1-2% parameter efficiency.
Example Finetune Script
examples/models/vlm/qwen_vl/finetune_qwen_vl.py
Added --peft CLI option (lora, dora, none) and refactored config construction to use recipe_kwargs dictionary for dynamic PEFT parameter injection.
Model Forward Signature
src/megatron/bridge/models/qwen_vl/modelling_qwen3_vl/model.py
Added optional loss_mask parameter to Qwen3VLModel forward method and propagated it to the internal language model for THD training compatibility.
Recipe Configuration
src/megatron/bridge/recipes/qwen_vl/__init__.py, src/megatron/bridge/recipes/qwen_vl/qwen3_vl.py
Exported new finetune/pretrain configs (qwen3_vl_8b_finetune_config, etc.); added PEFT integration with dynamic learning rate override, parallelism adjustments for full SFT vs PEFT modes, and config wiring through _qwen3_vl_common.
Functional Tests
tests/functional_tests/L2_Launch_recipes_qwen_vl.sh, tests/functional_tests/recipes/test_qwen3_vl_recipes_finetune.py
Updated test script to run Qwen3-VL finetune tests; added new test suite with smoke test for Qwen3-VL finetuning recipes verifying config loading, forward pass, training completion, and checkpoint creation.

Sequence Diagram

sequenceDiagram
    participant User
    participant CLI as finetune_qwen_vl.py
    participant RecipeModule as qwen3_vl Recipe
    participant PEFTConfig as PEFT Config Builder
    participant Model as Qwen3VLModel
    
    User->>CLI: Run with --peft lora
    CLI->>CLI: Build recipe_kwargs dict
    CLI->>RecipeModule: Call pretrain_config(**recipe_kwargs)
    RecipeModule->>PEFTConfig: _default_peft_config(peft)
    PEFTConfig-->>RecipeModule: PEFT config object
    RecipeModule->>RecipeModule: Adjust tensor_model_parallel_size<br/>(4 for full SFT, 1 for PEFT)
    RecipeModule->>RecipeModule: Compute effective_lr<br/>(finetune_lr override)
    RecipeModule-->>CLI: ConfigContainer with peft_config
    CLI->>Model: Initialize with config
    CLI->>Model: Forward pass with loss_mask
    Model-->>CLI: Loss output
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Possibly related PRs

  • PR #2023: Adds PEFT support integration to Qwen3-VL with similar documentation, recipe, and test coverage goals.
  • PR #2110: Modifies the same src/megatron/bridge/recipes/qwen_vl/qwen3_vl.py file, potentially conflicting with PEFT config wiring.
  • PR #1997: Threads loss\_mask and packed-sequence parameters through VLM model forward APIs for THD/CP compatibility.

Suggested labels

r0.3.0

Suggested reviewers

  • dingqingy-nv
🚥 Pre-merge checks | ✅ 3 | ❌ 1
❌ Failed checks (1 warning)
Check name Status Explanation Resolution
Test Results For Major Changes ⚠️ Warning PR with major changes lacks documented test results in description; while functional tests and CI comments exist, explicit test execution evidence is missing. Update PR description to document: (1) new functional test results, (2) existing Qwen3-VL test confirmation, (3) PEFT convergence verification, (4) performance comparisons, and address test filename reference comment.
✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title indicates a cherry-pick operation ('cp:') and references adding PEFT to the qwen3vl recipe, which aligns with the main changes across the PR (PEFT configuration integration, parameter additions, documentation updates).
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch cherry-pick-2023-r0.3.0

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🤖 Fix all issues with AI agents
In `@tests/functional_tests/recipes/test_qwen3_vl_recipes_finetune.py`:
- Around line 15-26: Update the top-file docstring in
tests/functional_tests/recipes/test_qwen3_vl_recipes_finetune.py: correct the
example run command string to reference the current file (change
test_qwen3_vl_recipes_peft.py to test_qwen3_vl_recipes_finetune.py) and add a
short hardware note indicating the GPU requirement (e.g., "Requires 2 GPUs; run
with torchrun --nproc_per_node=2"). Locate and edit the docstring text block
that contains the "Run with:" line to make these changes.
🧹 Nitpick comments (4)
src/megatron/bridge/models/qwen_vl/modelling_qwen3_vl/model.py (1)

195-221: Align loss_mask typing and docstring with Python 3.10+ conventions.

Use PEP604 for nullable typing and document the new parameter in the docstring.

Proposed fix
-        loss_mask: torch.Tensor = None,
+        loss_mask: torch.Tensor | None = None,
@@
-            labels (torch.Tensor): Optional target text labels [batch, combined_seq_len].
+            labels (torch.Tensor): Optional target text labels [batch, combined_seq_len].
+            loss_mask (torch.Tensor | None): Optional loss mask aligned with labels.

As per coding guidelines: Use 'T | None' for nullable types instead of 'Optional[T]' and Use Google style docstrings (parseable by Sphinx) for classes and functions.

src/megatron/bridge/recipes/qwen_vl/qwen3_vl.py (2)

102-105: Use PEP604 types for the new PEFT fields.

This aligns the new fields with the Python 3.10+ typing guidance already required.

Proposed fix
-    peft: Optional[Union[str, PEFT]]
-    finetune_lr: float
+    peft: PEFT | str | None
+    finetune_lr: float | None

As per coding guidelines: Use 'T | None' for nullable types instead of 'Optional[T]' and Use 'X | Y' for union types instead of 'Union[X, Y]'.


327-329: Use PEP604 types for the new _qwen3_vl_common params.

Proposed fix
-    peft: Optional[Union[str, PEFT]] = None,
-    finetune_lr: Optional[float] = None,
+    peft: PEFT | str | None = None,
+    finetune_lr: float | None = None,

As per coding guidelines: Use 'T | None' for nullable types instead of 'Optional[T]' and Use 'X | Y' for union types instead of 'Union[X, Y]'.

tests/functional_tests/recipes/test_qwen3_vl_recipes_finetune.py (1)

34-54: Add an integration mark and use the G_ global prefix.

Proposed fix
-QWEN3_VL_FINETUNE_RECIPES = [
+G_QWEN3_VL_FINETUNE_RECIPES = [
@@
-    `@pytest.mark.parametrize`(
-        "config_func,recipe_name,parallelism_overrides,model_overrides",
-        QWEN3_VL_FINETUNE_RECIPES,
-    )
+    `@pytest.mark.integration`
+    `@pytest.mark.parametrize`(
+        "config_func,recipe_name,parallelism_overrides,model_overrides",
+        G_QWEN3_VL_FINETUNE_RECIPES,
+    )

As per coding guidelines: Use pytest.mark to categorize tests (unit, integration, system) and Use upper snake_case and prefix 'G' for global variables (e.g., G_MY_GLOBAL).

Comment on lines +15 to +26
"""Functional smoke tests for Qwen3-VL finetuning recipes.

This test ensures that:
1. Qwen3-VL model forward pass works with all required parameters (including loss_mask)
2. Training loop completes without errors
3. Checkpoints are saved correctly

This catches regressions like missing parameters in the forward pass signature.

Run with:
torchrun --nproc_per_node=2 -m pytest tests/functional_tests/recipes/test_qwen3_vl_recipes_peft.py -v
"""
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.

⚠️ Potential issue | 🟡 Minor

Fix the run command and document GPU requirements.

The run command references the wrong filename, and the GPU requirement should be explicit.

Proposed fix
-Run with:
-    torchrun --nproc_per_node=2 -m pytest tests/functional_tests/recipes/test_qwen3_vl_recipes_peft.py -v
+Run with (requires 2 GPUs):
+    torchrun --nproc_per_node=2 -m pytest tests/functional_tests/recipes/test_qwen3_vl_recipes_finetune.py -v

As per coding guidelines: Document hardware requirements for GPU tests.

🤖 Prompt for AI Agents
In `@tests/functional_tests/recipes/test_qwen3_vl_recipes_finetune.py` around
lines 15 - 26, Update the top-file docstring in
tests/functional_tests/recipes/test_qwen3_vl_recipes_finetune.py: correct the
example run command string to reference the current file (change
test_qwen3_vl_recipes_peft.py to test_qwen3_vl_recipes_finetune.py) and add a
short hardware note indicating the GPU requirement (e.g., "Requires 2 GPUs; run
with torchrun --nproc_per_node=2"). Locate and edit the docstring text block
that contains the "Run with:" line to make these changes.

Copy link
Copy Markdown
Contributor Author

@ko3n1g ko3n1g left a comment

Choose a reason for hiding this comment

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

@yashaswikarnati Do we have failing tests we're fixing with this PR? If not, please split the docs changes out so that we can merge those. The code changes we should merge-post release, unless we have tests that are failing

@ko3n1g ko3n1g marked this pull request as ready for review February 5, 2026 10:05
Copy link
Copy Markdown
Contributor Author

@ko3n1g ko3n1g left a comment

Choose a reason for hiding this comment

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

Yash and I synced offline - there was no test in CI before, but this PR adds a fast for the failure. All good then, we merge it

@ko3n1g ko3n1g merged commit c22f858 into r0.3.0 Feb 5, 2026
49 checks passed
@ko3n1g ko3n1g deleted the cherry-pick-2023-r0.3.0 branch February 5, 2026 10:07
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants