fix: coerce unsloth target_modules for composite VLMs - #10663
fix: coerce unsloth target_modules for composite VLMs#10663rohanprichard wants to merge 1 commit into
Conversation
There was a problem hiding this comment.
Code Review
This pull request introduces a helper function _coerce_unsloth_target_modules to convert expanded VLM target modules back to leaf names for Unsloth, ensuring adapters are correctly applied to composite VLMs. It also adds corresponding unit tests. The review feedback highlights a potential issue where target_modules might be passed as a string or a set instead of a list, which would cause unexpected behavior during iteration, and provides a code suggestion to handle these types safely.
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.
patch_target_modules expands short LoRA target names into full module paths for composite VLMs so PEFT can skip frozen submodules like the vision tower. Unsloth's get_peft_regex treats every target_modules entry as a leaf name, so a full path never matches and no adapters get applied. Reduce back to leaf names before handing target_modules to unsloth. Fixes hiyouga#10662
be30aee to
9bc81f3
Compare
|
Thanks for the update, @rohanprichard. The addition of |
|
Good catch @gemini-code-assist — added |
|
Glad to hear that, @rohanprichard! The |
Summary
patch_target_modulesexpands short LoRA target names (e.g.out_proj) into full module paths for composite VLMs, so standard PEFT can skip frozen submodules like the vision tower.get_peft_regextreats everytarget_modulesentry as a leaf name and matches modules ending in it, so a full path never matches and no adapters get applied when training a VLM withuse_unsloth: true._coerce_unsloth_target_modulesinsrc/llamafactory/model/model_utils/unsloth.pyto reduce expanded paths back to unique leaf names before handingtarget_modulesto unsloth, only for composite VLM model types.Fixes #10662
Test plan
tests/model/model_utils/test_unsloth.pycovering leaf-name passthrough, path coercion for composite VLMs, and non-composite models being left untouched.pytest -vv --import-mode=importlib tests/model/model_utils/test_unsloth.py