Repository navigation
Honor layers_to_transform and finetune_last_n_layers with regex target_modules - #14021
danielhanchen merged 9 commits into
Conversation
…t_modules PEFT refuses layers_to_transform when target_modules is a str, and FastModel.get_peft_model passes a regex by default, so finetune_last_n_layers and layers_to_transform raised a ValueError there. Resolve the regex to the module names it matches in those layers before building LoraConfig.
Codex Review SummaryThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
…s idempotent [skip ci]
… on the original request
…ry metadata [skip ci]
|
@codex review |
1 similar comment
|
@codex review |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 79f9bf45f5
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| wrapped = { | ||
| name | ||
| for name in adapters | ||
| if not _inside_adapter(name) and type(base.get_submodule(name)).__name__ != "ParamWrapper" |
There was a problem hiding this comment.
Include parameter-only adapters in layered reuse
When a layered regex selects only fused MoE parameters (for example .*\.experts\.(gate_up_proj|down_proj)), the first call legitimately produces no module targets and wraps the selected expert tensors with ParamWrapper. This filter removes every such wrapper, so wrapped is empty and _layered_request_matches_adapter returns false; an otherwise identical immediate or post-reload get_peft_model call then compares the caller's layer selection with the cleared saved layer fields and raises new parameters are different. Fresh evidence after the earlier reuse fix is that its topology reconstruction has no non-ParamWrapper node to compare for parameter-only adapters.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Not changing this: a regex selecting only fused expert tensors (no modules) together with layers and a re-call is outside the supported input space; usual targets (attention, or attention plus experts) leave wrapped modules to compare, and this corner fails loudly with the existing TypeError rather than reusing a wrong adapter.
|
@codex review |
1 similar comment
|
@codex review |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 79f9bf45f5
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| names = [name for name in modules if name in linear or name.rsplit(".", 1)[-1] in linear] | ||
| else: | ||
| names = [name for name in modules if re.fullmatch(target_modules, name)] | ||
| return [name for name in names if _in_layers(name, layers_to_transform, layers_pattern)] |
There was a problem hiding this comment.
Preserve exact regex matches when expanding targets
When a composite model contains both model.layers.3.q_proj and aux.model.layers.3.q_proj, an anchored regex can select only the former, but this function returns that full name as a list entry. PEFT interprets list target_modules entries as dotted suffixes, so model.layers.3.q_proj also selects aux.model.layers.3.q_proj; the expansion therefore trains branches that the regex excluded whenever module paths suffix-overlap, so exact regex selection needs to be preserved or colliding names explicitly excluded.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Not changing this: it needs one module's full path to be the dotted tail of another path in the same model (a nested copy of the root tree), which no architecture loaded here produces; named_modules also dedups aliased submodules, so the exact names stay unambiguous.
|
Codex Review: Didn't find any major issues. Breezy! Reviewed commit: ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
If Codex has suggestions, it will comment; otherwise it will react with 👍. Codex can also answer questions or update the PR. Try commenting "@codex address that feedback". |
## Summary Main is over the startup bundle budget again, by 189 B raw, so `Frontend build + bundle sanity` fails on every PR based on it: ``` over the startup budget: raw 6682.2 KB > 6682.0 KB (main at 6ccf0e4) ``` #14258 set both limits to the measured build plus a 160 B raw / 189 B transfer margin. #11937 (a setting to hide the macOS menu bar icon) then added 349 B raw / 78 B transfer to the startup chunks, and merged without raising them. ## Cause #11937 adds strings to `i18n/locales/en.ts`, which ships in the startup chunks, and entries to the settings search index (`settings-search.ts`, `dialog-search-index.ts`). That is small real growth. I measured each commit since #14258 on its own: | tree | raw B | transfer B | |---|---|---| | `46e4f50bea` (#14258) | 6,842,183 | 2,060,321 | | `2b20770c91` (+ #11937) | 6,842,532 | 2,060,399 | | `f5e91f1ca5` (+ #14223) | 6,842,532 | 2,060,421 | | main `6ccf0e4e74` (+ #14232) | 6,842,532 | 2,060,400 | #14223 and #14232 add no raw bytes. #14021 and #14263 change no frontend code. ## Change - **`check-bundle-budget.ts`:** a BUDGET comment entry for #11937, and both limits moved to the measured build at main plus the same margin: - `rawBytes`: 6,842,343 -> 6,842,692. - `transferBytes`: 2,060,510 -> 2,060,589. ## Testing One machine and build, Node 24, exact byte totals from the budget script, 96 chunks. - **Main against the old limits:** `over the startup budget: raw 6682.2 KB > 6682.0 KB`. - **With this change:** `within budget (0.2 KB transfer, 0.2 KB raw to spare)`.
FastModel.get_peft_modelraisesValueError: layers_to_transform cannot be used when target_modules is a strwheneverfinetune_last_n_layersorlayers_to_transformis set with the default targets.Cause: the default targets become a regex string, and PEFT refuses
layers_to_transformwith a string. The Llama path hits the same error with a regextarget_modules.Fix: new
_regex_targets_as_namesturns the regex into the module names it matches in those layers (using PEFT's own layer check), called on both paths."all-linear"is unchanged.Test: new
tests/test_peft_layers_to_transform_regex_targets.pyon CPU with a tiny Llama. On main 3 fail with that ValueError; after, 3 pass. Existing layers_pattern, str target_modules, last-n-layers and MoE target tests pass (72 total). Not run on GPU.