Skip to content

Fix Studio CPT overwriting LFM2 all-linear LoRA targets - #9870

Merged
Etherll merged 7 commits into
unslothai:mainfrom
Souravrajvi0:feat/cpt-preserve-all-linear-7610
Aug 28, 2026
Merged

Etherll merged 7 commits into
unslothai:mainfrom
Souravrajvi0:feat/cpt-preserve-all-linear-7610

Conversation

@Souravrajvi0

Copy link
Copy Markdown
Contributor

Summary

Fixes #9866

When switching to Continued Pretraining (CPT) in Studio, the UI was replacing model-specific all-linear LoRA defaults with hardcoded Llama-style target module names (q_proj, o_proj, gate_proj, etc.).

For LiquidAI/LFM2-1.2B, this silently attached LoRA to only 18 modules (q/k/v projections) instead of all 92 eligible linear layers, because LFM2 uses architecture-specific names like out_proj, in_proj, w1, w2, and w3.

Changes

  • Add resolveCptTargetModules() to preserve all-linear when entering CPT
  • Store and restore targetModulesBeforeCpt in training method provenance
  • Show all-linear in the CPT advanced-settings UI when applicable
  • Apply CPT defaults from model YAML target modules when loading model config

Reproduction

Before fix (Studio CPT defaults on LFM2):

  • 18 wrapped modules, 884,736 trainable LoRA parameters

With all-linear:

  • 92 wrapped modules, 11,108,352 trainable LoRA parameters

Test plan

  • npm test -- tests/cpt-target-modules.test.ts tests/training-method-provenance.test.ts tests/training-config-persistence.test.ts
  • Python reproduction confirms fixed CPT payload (all-linear + modules_to_save) covers all LFM2 linear modules

When switching to continued pretraining, preserve architecture-specific
all-linear defaults instead of replacing them with Llama-style module names.
Restore the pre-CPT target list when leaving CPT and expose all-linear in
the CPT advanced-settings UI for models like LFM2.

Fixes unslothai#9866
@Souravrajvi0
Souravrajvi0 force-pushed the feat/cpt-preserve-all-linear-7610 branch from 5d448ec to c226fd7 Compare August 27, 2026 15:18
Souravrajvi0 and others added 2 commits August 27, 2026 16:18
Use `as const` for chatml so tsc -p tsconfig.test.json passes in CI.
@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Chef's kiss.

Reviewed commit: b313e951a4

ℹ️ 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".

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: fd03eff8b8

ℹ️ 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".

Comment on lines +279 to +284
targetModulesBeforeCpt:
persistedState.trainingMethod === "cpt" &&
Array.isArray(targetModulesBeforeCpt) &&
targetModulesBeforeCpt.length > 0
? [...targetModulesBeforeCpt]
: null,

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P1 Badge Recover pre-CPT targets when hydrating legacy sessions

For a persisted CPT session created before this change, targetModulesBeforeCpt is absent, so this normalization always stores null even when advancedSettingsBaseline.targetModules records the model's original all-linear default. Because the persistence version remains 21 and an already-applied model is reloaded without applying its defaults, switching such an LFM2 session away from CPT falls back to the hardcoded Llama targets; switching back to CPT then preserves those wrong targets, so existing users affected by the reported issue remain affected after upgrading. Recover the value from the persisted model baseline or add a migration that forces the model-specific targets to be reapplied.

Useful? React with 👍 / 👎.

chatgpt-codex-connector[bot]

This comment was marked as resolved.

chatgpt-codex-connector[bot]

This comment was marked as resolved.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: f9ecd6c5a0

ℹ️ 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".

Comment on lines +196 to +200
{(isCpt ? getCptUiTargetModules() : TARGET_MODULES).map(
(module) => {
const active = isCpt
? isCptTargetModuleActive(store.targetModules, module)
: store.targetModules.includes(module);

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P1 Badge Handle all-linear in non-CPT target controls

When LFM2's new defaults are loaded in QLoRA/LoRA, or when the user leaves CPT and the new provenance logic restores ["all-linear"], this branch still renders only TARGET_MODULES, so every control appears inactive. Clicking one then appends it to the hidden sentinel, producing ["all-linear", "q_proj"]; trainer.py:1295-1300 explicitly removes all-linear from mixed lists, silently training only the clicked projection instead of every linear layer. Render and toggle the exclusive all-linear option for non-CPT adapter methods too, or normalize it away before named modules are edited.

Useful? React with 👍 / 👎.

@unslothai unslothai deleted a comment from chatgpt-codex-connector Bot Aug 27, 2026
@unslothai unslothai deleted a comment from chatgpt-codex-connector Bot Aug 27, 2026
@unslothai unslothai deleted a comment from chatgpt-codex-connector Bot Aug 27, 2026
@Etherll

Etherll commented Aug 27, 2026

Copy link
Copy Markdown
Collaborator

@codex review

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. What shall we delve into next?

Reviewed commit: f9ecd6c5a0

ℹ️ 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".

@Etherll

Etherll commented Aug 27, 2026

Copy link
Copy Markdown
Collaborator

Final review update — converged at f9ecd6c5a0969c2b3a8b1e234c820dd3c0f92469.

The CPT target-module change is now hardened across the full state lifecycle:

  • all-linear is treated as an active sentinel, including in mixed persisted states.
  • Embedding and LM-head controls can be toggled independently without dropping all-linear; switching back to named LoRA targets preserves the intended explicit modules.
  • Model-default responses are provenance-aware, preventing an in-flight async response from overwriting a target edited meanwhile. Unrelated edits and YAML imports continue to behave correctly.
  • LiquidAI/LFM2 and the Unsloth 4-bit alias resolve to the tuned defaults.
  • LFM2 CPT VRAM estimation uses the effective gated-FFN width and exact trainable-module count.

Validation on the exact pushed head:

  • Frontend suite: 5,827 passed; TypeScript typecheck passed.
  • Focused CPT/state tests: 12 passed, including seven async/provenance ordering regressions.
  • Combined backend matrix: 2,783 passed, covering model-default aliases, VRAM estimation, coexistence, modules-to-save branches, and finetune-target coverage.
  • Ruff, compileall, diff checks, and the pre-push gate passed.
  • Final security scan was clean, and the exact-head Codex review found no major issues: Fix Studio CPT overwriting LFM2 all-linear LoRA targets #9870 (comment)

Deterministic UI comparison using the same persisted state (["all-linear", "embed_tokens", "lm_head"]) against merge base 5409ea338dcc8841ac7a9f1c06cfe9a300bf3bd6 and the final head:

Initial state — the base has no active all-linear control; the final head shows it active:

CPT initial-state comparison

After turning off embed_tokens, all-linear remains active and the persisted state becomes ["all-linear", "lm_head"]:

CPT embedding-toggle comparison

After turning off all-linear, the seven named LoRA targets become active while lm_head remains selected:

CPT LoRA-mode comparison

CI is not fully green. More than thirty exact-head jobs pass, including Studio parity, all Chat UI shards, source lint, Windows frontend tests, API/auth, wheel, Tauri, startup, GGUF, llama.cpp, Windows install, Rust, and pre-commit. The completed red checks reproduce on the merge base or are outside this PR's diff: workflow-trigger lint, frontend bundle smoke (CHAT_GPU_MEMORY_MODE_KEY initialization), two repository hygiene tests, the Python 3.13 GPU-init test contract, and the default dependency matrix. Two Core matrices, dispatch, and the aggregate Chat/UI job remain pending in the current GitHub snapshot.

The branch is pushed and the PR-specific review is converged. I did not merge it; GitHub still reports unrelated failing or pending checks.

@Etherll Etherll left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

LGTM!

@Etherll
Etherll merged commit d89c43d into unslothai:main Aug 28, 2026
35 of 42 checks passed
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.

[Studio Bug] CPT overrides LFM2 all-linear defaults with incompatible Llama target names

2 participants