Skip to content

Local UI to run and train LLMs and diffusion models. Supports GGUF, MLX, Qwen3.8, DeepSeek-V4.1, MiniMax-H3, Gemma 4, FLUX and more.

Studio: keep the LoRA rank, alpha and variant when leaving CPT (#10555)

Nilay785061815b3e
diff --git a/studio/frontend/src/config/training.ts b/studio/frontend/src/config/training.ts
index 72a2886d249..d19f917af1d 100644
--- a/studio/frontend/src/config/training.ts
+++ b/studio/frontend/src/config/training.ts
@@ -133,6 +133,13 @@ export const LR_DEFAULT_LORA = 2e-4;
export const LR_DEFAULT_FULL = 2e-5;
export const LR_DEFAULT_CPT = 5e-5;
+// Also the advanced-settings summary's "unchanged" reference while CPT is selected.
+export const CPT_LORA_HYPERPARAMS = {
+ loraRank: 128,
+ loraAlpha: 32,
+ loraVariant: "rslora",
+} as const;
+
export const DEFAULT_HYPERPARAMS = {
epochs: 3,
contextLength: 2048,
diff --git a/studio/frontend/src/features/studio/wizard/advanced-settings-summary.ts b/studio/frontend/src/features/studio/wizard/advanced-settings-summary.ts
index 23f0f45a3e9..13b542dc5ab 100644
--- a/studio/frontend/src/features/studio/wizard/advanced-settings-summary.ts
+++ b/studio/frontend/src/features/studio/wizard/advanced-settings-summary.ts
@@ -1,7 +1,11 @@
// SPDX-License-Identifier: AGPL-3.0-only
// Copyright 2026-present the Unsloth AI Inc. team. All rights reserved. See /studio/LICENSE.AGPL-3.0
-import { DEFAULT_HYPERPARAMS, resolveCptTargetModules } from "@/config/training";
+import {
+ CPT_LORA_HYPERPARAMS,
+ DEFAULT_HYPERPARAMS,
+ resolveCptTargetModules,
+} from "@/config/training";
import type {
AdvancedSettingsBaseline,
TrainingConfigState,
@@ -70,10 +74,10 @@ function countNonDefaultLoraSettings(
const isCpt = state.trainingMethod === "cpt";
const loraDefaults = {
loraRank: isCpt
- ? 128
+ ? CPT_LORA_HYPERPARAMS.loraRank
: baselineValue(baseline, "loraRank", DEFAULT_HYPERPARAMS.loraRank),
loraAlpha: isCpt
- ? 32
+ ? CPT_LORA_HYPERPARAMS.loraAlpha
: baselineValue(baseline, "loraAlpha", DEFAULT_HYPERPARAMS.loraAlpha),
loraDropout: baselineValue(
baseline,
@@ -81,7 +85,7 @@ function countNonDefaultLoraSettings(
DEFAULT_HYPERPARAMS.loraDropout,
),
loraVariant: isCpt
- ? "rslora"
+ ? CPT_LORA_HYPERPARAMS.loraVariant
: baselineValue(baseline, "loraVariant", DEFAULT_HYPERPARAMS.loraVariant),
} as const;
const count = Object.entries(loraDefaults).reduce(
diff --git a/studio/frontend/src/features/training/stores/training-config-persistence.ts b/studio/frontend/src/features/training/stores/training-config-persistence.ts
index a14d8fd1cea..6f7f7caaac4 100644
--- a/studio/frontend/src/features/training/stores/training-config-persistence.ts
+++ b/studio/frontend/src/features/training/stores/training-config-persistence.ts
@@ -2,6 +2,7 @@
// Copyright 2026-present the Unsloth AI Inc. team. All rights reserved. See /studio/LICENSE.AGPL-3.0
import {
+ CPT_LORA_HYPERPARAMS,
CPT_TARGET_MODULES,
DEFAULT_HYPERPARAMS,
LR_DEFAULT_CPT,
@@ -13,6 +14,7 @@ import { stageLegacyHfTokenForMigration } from "@/features/hub/stores/hf-token-s
import { isTrainingMethod } from "@/types/training";
import type { DatasetFormat } from "@/types/training";
import type {
+ LoraVariant,
TrainingConfigState,
TrainingConfigStore,
TrainingMethodProvenance,
@@ -24,7 +26,7 @@ import {
} from "./training-config-policy";
export const TRAINING_CONFIG_PERSISTENCE_NAME = "unsloth_training_config_v1";
-export const TRAINING_CONFIG_PERSISTENCE_VERSION = 21;
+export const TRAINING_CONFIG_PERSISTENCE_VERSION = 22;
const NON_PERSISTED_STATE_KEYS: ReadonlySet<keyof TrainingConfigState> =
new Set([
@@ -223,6 +225,9 @@ function migrateThroughVersion19(
modelAdapterLearningRate: null,
datasetFormatBeforeCpt: null,
targetModulesBeforeCpt: null,
+ loraRankBeforeCpt: null,
+ loraAlphaBeforeCpt: null,
+ loraVariantBeforeCpt: null,
} satisfies TrainingMethodProvenance;
}
}
@@ -238,6 +243,51 @@ function migrateThroughVersion21(
}
}
+// Recover the pre-CPT slots from the defaults advancedSettingsBaseline froze.
+function migrateThroughVersion22(
+ state: PersistedTrainingConfig,
+ version: number,
+): void {
+ if (version >= 22 || state.trainingMethod !== "cpt") return;
+ const provenance = state.trainingMethodProvenance;
+ if (typeof provenance !== "object" || provenance === null) return;
+ // mergeTrainingConfig's own identity test, empty string included.
+ if (
+ typeof state.modelDefaultsAppliedFor !== "string" ||
+ state.modelDefaultsAppliedFor.length === 0 ||
+ state.modelDefaultsAppliedFor !== state.selectedModel
+ ) {
+ return;
+ }
+ const baseline = state.advancedSettingsBaseline;
+ if (typeof baseline !== "object" || baseline === null) return;
+ const { loraRank, loraAlpha, loraVariant } = baseline as Record<
+ string,
+ unknown
+ >;
+ // Exactly the CPT triple: captured after CPT applied, so it says nothing.
+ if (
+ loraRank === CPT_LORA_HYPERPARAMS.loraRank &&
+ loraAlpha === CPT_LORA_HYPERPARAMS.loraAlpha &&
+ loraVariant === CPT_LORA_HYPERPARAMS.loraVariant
+ ) {
+ return;
+ }
+ // Gaps only: a real pre-CPT edit outranks the defaults the baseline froze.
+ const record = provenance as Record<string, unknown>;
+ if (positiveIntOrNull(record.loraRankBeforeCpt) === null) {
+ record.loraRankBeforeCpt = positiveIntOrNull(loraRank);
+ }
+ if (positiveIntOrNull(record.loraAlphaBeforeCpt) === null) {
+ record.loraAlphaBeforeCpt = positiveIntOrNull(loraAlpha);
+ }
+ if (!isLoraVariant(record.loraVariantBeforeCpt)) {
+ record.loraVariantBeforeCpt = isLoraVariant(loraVariant)
+ ? loraVariant
+ : null;
+ }
+}
+
function isDatasetFormat(value: unknown): value is DatasetFormat {
return (
value === "auto" ||
@@ -248,6 +298,21 @@ function isDatasetFormat(value: unknown): value is DatasetFormat {
);
}
+function isLoraVariant(value: unknown): value is LoraVariant {
+ return (
+ value === "lora" ||
+ value === "rslora" ||
+ value === "loftq" ||
+ value === "dora"
+ );
+}
+
+function positiveIntOrNull(value: unknown): number | null {
+ return typeof value === "number" && Number.isInteger(value) && value > 0
+ ? value
+ : null;
+}
+
function normalizeTrainingMethodProvenance(
value: unknown,
persistedState: PersistedTrainingConfig,
@@ -259,6 +324,7 @@ function normalizeTrainingMethodProvenance(
const modelAdapterLearningRate = provenance.modelAdapterLearningRate;
const datasetFormatBeforeCpt = provenance.datasetFormatBeforeCpt;
const targetModulesBeforeCpt = provenance.targetModulesBeforeCpt;
+ const wasCpt = persistedState.trainingMethod === "cpt";
return {
learningRateManuallySet:
typeof provenance.learningRateManuallySet === "boolean"
@@ -271,17 +337,27 @@ function normalizeTrainingMethodProvenance(
? modelAdapterLearningRate
: null,
datasetFormatBeforeCpt:
- persistedState.trainingMethod === "cpt" &&
+ wasCpt &&
isDatasetFormat(datasetFormatBeforeCpt) &&
datasetFormatBeforeCpt !== "raw"
? datasetFormatBeforeCpt
: null,
targetModulesBeforeCpt:
- persistedState.trainingMethod === "cpt" &&
+ wasCpt &&
Array.isArray(targetModulesBeforeCpt) &&
targetModulesBeforeCpt.length > 0
? [...targetModulesBeforeCpt]
: null,
+ loraRankBeforeCpt: wasCpt
+ ? positiveIntOrNull(provenance.loraRankBeforeCpt)
+ : null,
+ loraAlphaBeforeCpt: wasCpt
+ ? positiveIntOrNull(provenance.loraAlphaBeforeCpt)
+ : null,
+ loraVariantBeforeCpt:
+ wasCpt && isLoraVariant(provenance.loraVariantBeforeCpt)
+ ? provenance.loraVariantBeforeCpt
+ : null,
};
}
@@ -297,6 +373,7 @@ export function migrateTrainingConfig(
migrateThroughVersion18(state, version);
migrateThroughVersion19(state, version);
migrateThroughVersion21(state, version);
+ migrateThroughVersion22(state, version);
return state as unknown as TrainingConfigStore;
}
diff --git a/studio/frontend/src/features/training/stores/training-config-policy.ts b/studio/frontend/src/features/training/stores/training-config-policy.ts
index b3dead66c7a..816f9366001 100644
--- a/studio/frontend/src/features/training/stores/training-config-policy.ts
+++ b/studio/frontend/src/features/training/stores/training-config-policy.ts
@@ -66,6 +66,9 @@ export const initialTrainingConfigState: TrainingConfigState = {
modelAdapterLearningRate: null,
datasetFormatBeforeCpt: null,
targetModulesBeforeCpt: null,
+ loraRankBeforeCpt: null,
+ loraAlphaBeforeCpt: null,
+ loraVariantBeforeCpt: null,
},
datasetSource: "huggingface",
browseDatasetSelection: createHfBrowseDatasetSelection(null),
diff --git a/studio/frontend/src/features/training/stores/training-config-store.ts b/studio/frontend/src/features/training/stores/training-config-store.ts
index d509b09078e..cf410cfa61f 100644
--- a/studio/frontend/src/features/training/stores/training-config-store.ts
+++ b/studio/frontend/src/features/training/stores/training-config-store.ts
@@ -82,9 +82,17 @@ let _trainOnCompletionsManuallySet = false;
let _trainingMethodEditGeneration = 0;
let _modelDefaultsEditGeneration = 0;
let _targetModulesEditGeneration = 0;
+const LORA_PARAM_KEYS = ["loraRank", "loraAlpha", "loraVariant"] as const;
+type LoraParamKey = (typeof LORA_PARAM_KEYS)[number];
+const _loraParamEditGenerations: Record<LoraParamKey, number> = {
+ loraRank: 0,
+ loraAlpha: 0,
+ loraVariant: 0,
+};
let _modelDefaultsEditBaseline: {
modelName: string;
editGeneration: number;
+ loraParamEditGenerations: Record<LoraParamKey, number>;
} | null = null;
function canReapplyModelDefaults(modelName: string): boolean {
@@ -159,8 +167,18 @@ export const useTrainingConfigStore = create<TrainingConfigStore>()(
_modelDefaultsEditBaseline = {
modelName,
editGeneration: requestedModelDefaultsEditGeneration,
+ loraParamEditGenerations: { ..._loraParamEditGenerations },
};
}
+ // A cache restart re-requests the same model, so it must measure against the
+ // original selection's snapshot or it forgets the edits made since. False after
+ // a reload, where the provenance came off disk and nothing here has a claim on it.
+ const requestedSelectionOwnsLoraSnapshot =
+ _modelDefaultsEditBaseline?.modelName === modelName;
+ const requestedLoraParamEditGenerations =
+ requestedSelectionOwnsLoraSnapshot && _modelDefaultsEditBaseline
+ ? { ..._modelDefaultsEditBaseline.loraParamEditGenerations }
+ : { ..._loraParamEditGenerations };
const requestedKnownCached =
requestState.selectedModel === modelName &&
requestState.modelKnownCached;
@@ -304,9 +322,17 @@ export const useTrainingConfigStore = create<TrainingConfigStore>()(
const cptTargetOverrides = shouldApplyCptTargetDefaults
? { targetModules: cptDefaultsPatch.targetModules }
: {};
+ // Only trainOnCompletions: CPT's forced adapter values are not the model's.
+ // Targets are pinned to what cptDefaultsPatch resolved FROM, so the summary's
+ // resolveCptTargetModules(baseline) reproduces the live set even when the model
+ // config carries none and cptTargetModules falls back to live state.
+ const cptBaselineOverride = {
+ trainOnCompletions: cptDefaultsPatch.trainOnCompletions,
+ targetModules: [...cptTargetModules],
+ };
const modelDefaultsBaseline = {
...modelDefaultsPatch,
- ...(get().trainingMethod === "cpt" ? cptDefaultsPatch : {}),
+ ...(get().trainingMethod === "cpt" ? cptBaselineOverride : {}),
};
const advancedSettingsBaseline =
get().advancedSettingsBaseline ?? modelDefaultsBaseline;
@@ -327,6 +353,49 @@ export const useTrainingConfigStore = create<TrainingConfigStore>()(
}
: {};
+ // Per field, so editing the rank does not freeze alpha and variant.
+ const loraParamUnedited = (key: LoraParamKey): boolean =>
+ _loraParamEditGenerations[key] ===
+ requestedLoraParamEditGenerations[key];
+ const inCpt = get().trainingMethod === "cpt";
+ // Gated separately, or a target edit strands the LoRA slots.
+ const cptTargetProvenanceRefresh =
+ inCpt && modelDefaultsPatch.targetModules !== undefined
+ ? {
+ targetModulesBeforeCpt: [
+ ...modelDefaultsPatch.targetModules,
+ ],
+ }
+ : {};
+ const cptLoraProvenanceRefresh = inCpt
+ ? {
+ ...(loraParamUnedited("loraRank") &&
+ modelDefaultsPatch.loraRank !== undefined
+ ? { loraRankBeforeCpt: modelDefaultsPatch.loraRank }
+ : {}),
+ ...(loraParamUnedited("loraAlpha") &&
+ modelDefaultsPatch.loraAlpha !== undefined
+ ? { loraAlphaBeforeCpt: modelDefaultsPatch.loraAlpha }
+ : {}),
+ ...(loraParamUnedited("loraVariant") &&
+ modelDefaultsPatch.loraVariant !== undefined
+ ? { loraVariantBeforeCpt: modelDefaultsPatch.loraVariant }
+ : {}),
+ }
+ : {};
+ const cptProvenanceRefresh = {
+ ...cptTargetProvenanceRefresh,
+ ...cptLoraProvenanceRefresh,
+ };
+ const cptFallbackProvenanceRefresh = {
+ ...(shouldApplyCptTargetDefaults
+ ? cptTargetProvenanceRefresh
+ : {}),
+ ...(requestedSelectionOwnsLoraSnapshot
+ ? cptLoraProvenanceRefresh
+ : {}),
+ };
+
set({
...patch,
...cptOverrides,
@@ -338,24 +407,14 @@ export const useTrainingConfigStore = create<TrainingConfigStore>()(
...get().trainingMethodProvenance,
learningRateManuallySet: false,
modelAdapterLearningRate,
- ...(get().trainingMethod === "cpt" &&
- modelDefaultsPatch.targetModules !== undefined
- ? {
- targetModulesBeforeCpt: [
- ...modelDefaultsPatch.targetModules,
- ],
- }
- : {}),
+ ...cptProvenanceRefresh,
},
}
- : shouldApplyCptTargetDefaults &&
- modelDefaultsPatch.targetModules !== undefined
+ : Object.keys(cptFallbackProvenanceRefresh).length > 0
? {
trainingMethodProvenance: {
...get().trainingMethodProvenance,
- targetModulesBeforeCpt: [
- ...modelDefaultsPatch.targetModules,
- ],
+ ...cptFallbackProvenanceRefresh,
},
}
: {}),
@@ -364,7 +423,7 @@ export const useTrainingConfigStore = create<TrainingConfigStore>()(
: shouldApplyCptTargetDefaults
? {
...advancedSettingsBaseline,
- targetModules: cptDefaultsPatch.targetModules,
+ targetModules: [...cptTargetModules],
}
: advancedSettingsBaseline,
modelType: inferredModelType,
@@ -1239,10 +1298,19 @@ export const useTrainingConfigStore = create<TrainingConfigStore>()(
setOptimizerType: (optimizerType) => setUserEdit({ optimizerType }),
setLrSchedulerType: (lrSchedulerType) =>
setUserEdit({ lrSchedulerType }),
- setLoraRank: (loraRank) => setUserEdit({ loraRank }),
- setLoraAlpha: (loraAlpha) => setUserEdit({ loraAlpha }),
+ setLoraRank: (loraRank) => {
+ _loraParamEditGenerations.loraRank += 1;
+ setUserEdit({ loraRank });
+ },
+ setLoraAlpha: (loraAlpha) => {
+ _loraParamEditGenerations.loraAlpha += 1;
+ setUserEdit({ loraAlpha });
+ },
setLoraDropout: (loraDropout) => setUserEdit({ loraDropout }),
- setLoraVariant: (loraVariant) => setUserEdit({ loraVariant }),
+ setLoraVariant: (loraVariant) => {
+ _loraParamEditGenerations.loraVariant += 1;
+ setUserEdit({ loraVariant });
+ },
setBatchSize: (batchSize) => setUserEdit({ batchSize }),
setGradientAccumulation: (gradientAccumulation) =>
setUserEdit({ gradientAccumulation }),
@@ -1310,6 +1378,9 @@ export const useTrainingConfigStore = create<TrainingConfigStore>()(
trainingDatasetCacheRejections.reset();
_trainOnCompletionsManuallySet = false;
_targetModulesEditGeneration += 1;
+ for (const key of LORA_PARAM_KEYS) {
+ _loraParamEditGenerations[key] += 1;
+ }
_modelDefaultsEditBaseline = null;
setUserEdit(initialTrainingConfigState);
},
@@ -1328,6 +1399,9 @@ export const useTrainingConfigStore = create<TrainingConfigStore>()(
if (patch.targetModules !== undefined) {
_targetModulesEditGeneration += 1;
}
+ for (const key of LORA_PARAM_KEYS) {
+ if (patch[key] !== undefined) _loraParamEditGenerations[key] += 1;
+ }
setUserEdit((state) => ({
...patch,
...(patch.trainOnCompletions !== undefined
diff --git a/studio/frontend/src/features/training/stores/training-method-transition.ts b/studio/frontend/src/features/training/stores/training-method-transition.ts
index 5a8b919346e..8bfc77e8ec0 100644
--- a/studio/frontend/src/features/training/stores/training-method-transition.ts
+++ b/studio/frontend/src/features/training/stores/training-method-transition.ts
@@ -2,6 +2,7 @@
// Copyright 2026-present the Unsloth AI Inc. team. All rights reserved. See /studio/LICENSE.AGPL-3.0
import {
+ CPT_LORA_HYPERPARAMS,
DEFAULT_HYPERPARAMS,
LR_DEFAULT_CPT,
LR_DEFAULT_FULL,
@@ -12,7 +13,10 @@ import {
import { isAdapterMethod } from "@/types/training";
import type { TrainingMethod } from "@/types/training";
import { isRawTextDatasetFormat } from "../lib/training-methods";
-import type { TrainingConfigState } from "../types/config";
+import type {
+ TrainingConfigState,
+ TrainingMethodProvenance,
+} from "../types/config";
type TrainingMethodStatePatch = Partial<
Pick<
@@ -33,9 +37,7 @@ function getCptTrainingPatch(
currentTargetModules: readonly string[],
): TrainingMethodStatePatch {
return {
- loraRank: 128,
- loraAlpha: 32,
- loraVariant: "rslora",
+ ...CPT_LORA_HYPERPARAMS,
targetModules: resolveCptTargetModules(currentTargetModules),
datasetFormat: "raw",
trainOnCompletions: false,
@@ -52,13 +54,14 @@ export function getCptModelDefaultsPatch(
}
function getRestoreFromCptPatch(
- targetModulesBeforeCpt: string[] | null,
+ provenance: TrainingMethodProvenance,
): TrainingMethodStatePatch {
return {
- loraRank: DEFAULT_HYPERPARAMS.loraRank,
- loraAlpha: DEFAULT_HYPERPARAMS.loraAlpha,
- loraVariant: DEFAULT_HYPERPARAMS.loraVariant,
- targetModules: targetModulesBeforeCpt ?? TARGET_MODULES,
+ loraRank: provenance.loraRankBeforeCpt ?? DEFAULT_HYPERPARAMS.loraRank,
+ loraAlpha: provenance.loraAlphaBeforeCpt ?? DEFAULT_HYPERPARAMS.loraAlpha,
+ loraVariant:
+ provenance.loraVariantBeforeCpt ?? DEFAULT_HYPERPARAMS.loraVariant,
+ targetModules: provenance.targetModulesBeforeCpt ?? TARGET_MODULES,
};
}
@@ -97,6 +100,9 @@ export function buildTrainingMethodPatch(
| "trainingMethodProvenance"
| "datasetFormat"
| "targetModules"
+ | "loraRank"
+ | "loraAlpha"
+ | "loraVariant"
>,
nextMethod: TrainingMethod,
): TrainingMethodStatePatch {
@@ -111,18 +117,21 @@ export function buildTrainingMethodPatch(
? null
: state.datasetFormat;
provenance.targetModulesBeforeCpt = [...state.targetModules];
+ provenance.loraRankBeforeCpt = state.loraRank;
+ provenance.loraAlphaBeforeCpt = state.loraAlpha;
+ provenance.loraVariantBeforeCpt = state.loraVariant;
Object.assign(patch, getCptTrainingPatch(state.targetModules));
}
if (prevMethod === "cpt" && nextMethod !== "cpt") {
- Object.assign(
- patch,
- getRestoreFromCptPatch(provenance.targetModulesBeforeCpt),
- );
+ Object.assign(patch, getRestoreFromCptPatch(provenance));
if (provenance.datasetFormatBeforeCpt !== null) {
patch.datasetFormat = provenance.datasetFormatBeforeCpt;
}
provenance.datasetFormatBeforeCpt = null;
provenance.targetModulesBeforeCpt = null;
+ provenance.loraRankBeforeCpt = null;
+ provenance.loraAlphaBeforeCpt = null;
+ provenance.loraVariantBeforeCpt = null;
}
const learningRate = resolveTrainingMethodLearningRate(
diff --git a/studio/frontend/src/features/training/types/config.ts b/studio/frontend/src/features/training/types/config.ts
index e69f3bcbaf6..24327702711 100644
--- a/studio/frontend/src/features/training/types/config.ts
+++ b/studio/frontend/src/features/training/types/config.ts
@@ -50,6 +50,9 @@ export interface TrainingMethodProvenance {
modelAdapterLearningRate: number | null;
datasetFormatBeforeCpt: DatasetFormat | null;
targetModulesBeforeCpt: string[] | null;
+ loraRankBeforeCpt: number | null;
+ loraAlphaBeforeCpt: number | null;
+ loraVariantBeforeCpt: LoraVariant | null;
}
/** Column-to-role mapping, e.g. { "problem": "user", "solution": "assistant", "context": "system" } */
diff --git a/studio/frontend/tests/training-config-persistence.test.ts b/studio/frontend/tests/training-config-persistence.test.ts
index 0ec565e962a..f16d0ae4dbe 100644
--- a/studio/frontend/tests/training-config-persistence.test.ts
+++ b/studio/frontend/tests/training-config-persistence.test.ts
@@ -16,6 +16,12 @@ const {
} = await import(
"../src/features/training/stores/training-config-persistence.ts"
);
+const { buildTrainingMethodPatch } = await import(
+ "../src/features/training/stores/training-method-transition.ts"
+);
+const { initialTrainingConfigState } = await import(
+ "../src/features/training/stores/training-config-policy.ts"
+);
test("persists the applied model defaults identity and summary baseline", () => {
const persisted = partializeTrainingConfig({
@@ -62,7 +68,7 @@ test("migration preserves tuned values while protecting them from model defaults
16,
);
- assert.equal(TRAINING_CONFIG_PERSISTENCE_VERSION, 21);
+ assert.equal(TRAINING_CONFIG_PERSISTENCE_VERSION, 22);
assert.equal(migrated.learningRate, 0.000031);
assert.equal(migrated.loraRank, 48);
assert.equal(migrated.modelDefaultsAppliedFor, "org/model");
@@ -72,6 +78,9 @@ test("migration preserves tuned values while protecting them from model defaults
modelAdapterLearningRate: null,
datasetFormatBeforeCpt: null,
targetModulesBeforeCpt: null,
+ loraRankBeforeCpt: null,
+ loraAlphaBeforeCpt: null,
+ loraVariantBeforeCpt: null,
});
assert.equal("wandbToken" in migrated, false);
});
@@ -243,3 +252,167 @@ test("persistence preserves valid Hub streaming", () => {
assert.equal(merged.datasetStreaming, true);
});
+
+test("a recovered CPT session restores its LoRA params on the way out", () => {
+ const persisted = {
+ selectedModel: "org/model",
+ modelDefaultsAppliedFor: "org/model",
+ trainingMethod: "cpt",
+ loraRank: 128,
+ loraAlpha: 32,
+ loraVariant: "rslora",
+ advancedSettingsBaseline: {
+ loraRank: 8,
+ loraAlpha: 8,
+ loraVariant: "lora",
+ },
+ trainingMethodProvenance: {
+ learningRateManuallySet: false,
+ modelAdapterLearningRate: null,
+ datasetFormatBeforeCpt: null,
+ targetModulesBeforeCpt: null,
+ },
+ };
+ const merged = mergeTrainingConfig(
+ migrateTrainingConfig(persisted, 21),
+ initialTrainingConfigState as never,
+ );
+
+ assert.equal(merged.trainingMethodProvenance.loraRankBeforeCpt, 8);
+ const restored = { ...merged, ...buildTrainingMethodPatch(merged, "qlora") };
+ assert.equal(restored.loraRank, 8);
+ assert.equal(restored.loraAlpha, 8);
+ assert.equal(restored.loraVariant, "lora");
+});
+
+test("a session persisted inside CPT recovers its pre-CPT LoRA params", () => {
+ const migrated = migrateTrainingConfig(
+ {
+ selectedModel: "org/model",
+ modelDefaultsAppliedFor: "org/model",
+ trainingMethod: "cpt",
+ advancedSettingsBaseline: {
+ loraRank: 8,
+ loraAlpha: 8,
+ loraVariant: "lora",
+ },
+ trainingMethodProvenance: {
+ learningRateManuallySet: false,
+ modelAdapterLearningRate: null,
+ datasetFormatBeforeCpt: null,
+ targetModulesBeforeCpt: null,
+ },
+ },
+ 21,
+ );
+
+ assert.equal(migrated.trainingMethodProvenance.loraRankBeforeCpt, 8);
+ assert.equal(migrated.trainingMethodProvenance.loraAlphaBeforeCpt, 8);
+ assert.equal(migrated.trainingMethodProvenance.loraVariantBeforeCpt, "lora");
+});
+
+test("a baseline captured inside CPT is not mistaken for pre-CPT params", () => {
+ const migrated = migrateTrainingConfig(
+ {
+ selectedModel: "org/model",
+ modelDefaultsAppliedFor: "org/model",
+ trainingMethod: "cpt",
+ advancedSettingsBaseline: {
+ loraRank: 128,
+ loraAlpha: 32,
+ loraVariant: "rslora",
+ },
+ trainingMethodProvenance: {
+ learningRateManuallySet: false,
+ modelAdapterLearningRate: null,
+ datasetFormatBeforeCpt: null,
+ targetModulesBeforeCpt: null,
+ },
+ },
+ 21,
+ );
+
+ assert.equal(migrated.trainingMethodProvenance.loraRankBeforeCpt, undefined);
+});
+
+test("an empty model identifier is not treated as a baseline match", () => {
+ const persisted = {
+ selectedModel: "",
+ modelDefaultsAppliedFor: "",
+ trainingMethod: "cpt",
+ advancedSettingsBaseline: {
+ loraRank: 8,
+ loraAlpha: 8,
+ loraVariant: "lora",
+ },
+ trainingMethodProvenance: {
+ learningRateManuallySet: false,
+ modelAdapterLearningRate: null,
+ datasetFormatBeforeCpt: null,
+ targetModulesBeforeCpt: null,
+ },
+ };
+ const migrated = migrateTrainingConfig(persisted, 21);
+
+ // The merge drops it, so the migration must not have copied it first.
+ assert.equal(migrated.trainingMethodProvenance.loraRankBeforeCpt, undefined);
+ const merged = mergeTrainingConfig(
+ migrated,
+ initialTrainingConfigState as never,
+ );
+ assert.equal(merged.advancedSettingsBaseline, null);
+ assert.equal(merged.trainingMethodProvenance.loraRankBeforeCpt, null);
+});
+
+test("recovery does not overwrite a pre-CPT value the record already has", () => {
+ const migrated = migrateTrainingConfig(
+ {
+ selectedModel: "org/model",
+ modelDefaultsAppliedFor: "org/model",
+ trainingMethod: "cpt",
+ advancedSettingsBaseline: {
+ loraRank: 8,
+ loraAlpha: 8,
+ loraVariant: "lora",
+ },
+ trainingMethodProvenance: {
+ learningRateManuallySet: false,
+ modelAdapterLearningRate: null,
+ datasetFormatBeforeCpt: null,
+ targetModulesBeforeCpt: null,
+ loraRankBeforeCpt: 48,
+ loraAlphaBeforeCpt: 0,
+ loraVariantBeforeCpt: "loftq",
+ },
+ },
+ 21,
+ );
+
+ assert.equal(migrated.trainingMethodProvenance.loraRankBeforeCpt, 48);
+ assert.equal(migrated.trainingMethodProvenance.loraAlphaBeforeCpt, 8);
+ assert.equal(migrated.trainingMethodProvenance.loraVariantBeforeCpt, "loftq");
+});
+
+test("a baseline left over from another model is not used as pre-CPT params", () => {
+ const migrated = migrateTrainingConfig(
+ {
+ selectedModel: "org/other-model",
+ modelDefaultsAppliedFor: "org/model",
+ trainingMethod: "cpt",
+ advancedSettingsBaseline: {
+ loraRank: 8,
+ loraAlpha: 8,
+ loraVariant: "lora",
+ },
+ trainingMethodProvenance: {
+ learningRateManuallySet: false,
+ modelAdapterLearningRate: null,
+ datasetFormatBeforeCpt: null,
+ targetModulesBeforeCpt: null,
+ },
+ },
+ 21,
+ );
+
+ assert.equal(migrated.trainingMethodProvenance.loraRankBeforeCpt, undefined);
+});
diff --git a/studio/frontend/tests/training-cpt-model-switch.test.ts b/studio/frontend/tests/training-cpt-model-switch.test.ts
index 9c0b7f5d10f..0d85d241437 100644
--- a/studio/frontend/tests/training-cpt-model-switch.test.ts
+++ b/studio/frontend/tests/training-cpt-model-switch.test.ts
@@ -16,6 +16,9 @@ const { setAuthFetchHandler } = await import("./helpers/store-stubs/auth.ts");
const { useTrainingConfigStore } = await import(
"../src/features/training/stores/training-config-store.ts"
);
+const { countNonDefaultAdvancedSettings } = await import(
+ "../src/features/studio/wizard/advanced-settings-summary.ts"
+);
const LLAMA_TARGETS = [
"q_proj",
@@ -80,6 +83,9 @@ test("leaving CPT after a model switch restores the new model targets", async ()
modelAdapterLearningRate: null,
datasetFormatBeforeCpt: "chatml",
targetModulesBeforeCpt: [...LLAMA_TARGETS],
+ loraRankBeforeCpt: null,
+ loraAlphaBeforeCpt: null,
+ loraVariantBeforeCpt: null,
},
});
@@ -178,9 +184,7 @@ test("a target edit before entering CPT still wins", async () => {
["q_proj"],
);
useTrainingConfigStore.getState().setTrainingMethod("qlora");
- assert.deepEqual(useTrainingConfigStore.getState().targetModules, [
- "q_proj",
- ]);
+ assert.deepEqual(useTrainingConfigStore.getState().targetModules, ["q_proj"]);
});
test("an unrelated edit does not block the model targets", async () => {
@@ -237,7 +241,586 @@ test("targets imported during the defaults request still win", async () => {
resolveModelConfig();
await waitForModelDefaults("LiquidAI/LFM2-1.2B");
- assert.deepEqual(useTrainingConfigStore.getState().targetModules, [
- "q_proj",
+ assert.deepEqual(useTrainingConfigStore.getState().targetModules, ["q_proj"]);
+});
+
+test("leaving CPT after a model switch restores the new model adapter params", async () => {
+ useTrainingConfigStore.getState().reset();
+ setAuthFetchHandler(() =>
+ Promise.resolve(
+ Response.json({
+ id: "old/llama",
+ config: {
+ lora: {
+ lora_r: 8,
+ lora_alpha: 8,
+ target_modules: [...LLAMA_TARGETS],
+ },
+ },
+ is_vision: false,
+ is_embedding: false,
+ is_audio: false,
+ audio_type_known: true,
+ is_lora: false,
+ model_type: "text",
+ model_size_bytes: null,
+ max_position_embeddings: 32768,
+ }),
+ ),
+ );
+ useTrainingConfigStore.getState().selectTrainingModel("old/llama", "text");
+ await waitForModelDefaults("old/llama");
+ assert.equal(useTrainingConfigStore.getState().loraRank, 8);
+
+ useTrainingConfigStore.getState().setTrainingMethod("cpt");
+
+ setAuthFetchHandler(() =>
+ Promise.resolve(
+ Response.json({
+ id: "LiquidAI/LFM2-1.2B",
+ config: {
+ lora: {
+ lora_r: 64,
+ lora_alpha: 128,
+ use_dora: true,
+ target_modules: ["all-linear"],
+ },
+ },
+ is_vision: false,
+ is_embedding: false,
+ is_audio: false,
+ audio_type_known: true,
+ is_lora: false,
+ model_type: "text",
+ model_size_bytes: null,
+ max_position_embeddings: 32768,
+ }),
+ ),
+ );
+ useTrainingConfigStore
+ .getState()
+ .selectTrainingModel("LiquidAI/LFM2-1.2B", "text");
+ await waitForModelDefaults("LiquidAI/LFM2-1.2B");
+ assert.equal(useTrainingConfigStore.getState().loraRank, 128);
+
+ useTrainingConfigStore.getState().setTrainingMethod("qlora");
+ const state = useTrainingConfigStore.getState();
+ assert.equal(state.loraRank, 64);
+ assert.equal(state.loraAlpha, 128);
+ assert.equal(state.loraVariant, "dora");
+ assert.deepEqual(state.targetModules, ["all-linear"]);
+});
+
+test("an unrelated edit does not strand the previous model adapter params", async () => {
+ useTrainingConfigStore.getState().reset();
+ setAuthFetchHandler(() =>
+ Promise.resolve(
+ Response.json({
+ id: "old/llama",
+ config: {
+ lora: {
+ lora_r: 8,
+ lora_alpha: 8,
+ target_modules: [...LLAMA_TARGETS],
+ },
+ },
+ is_vision: false,
+ is_embedding: false,
+ is_audio: false,
+ audio_type_known: true,
+ is_lora: false,
+ model_type: "text",
+ model_size_bytes: null,
+ max_position_embeddings: 32768,
+ }),
+ ),
+ );
+ useTrainingConfigStore.getState().selectTrainingModel("old/llama", "text");
+ await waitForModelDefaults("old/llama");
+ useTrainingConfigStore.getState().setTrainingMethod("cpt");
+
+ let resolveModelConfig!: (response: Response) => void;
+ setAuthFetchHandler(
+ () =>
+ new Promise<Response>((resolve) => {
+ resolveModelConfig = resolve;
+ }),
+ );
+ useTrainingConfigStore
+ .getState()
+ .selectTrainingModel("LiquidAI/LFM2-1.2B", "text");
+ useTrainingConfigStore.getState().setBatchSize(3);
+ resolveModelConfig(
+ Response.json({
+ id: "LiquidAI/LFM2-1.2B",
+ config: {
+ lora: {
+ lora_r: 64,
+ lora_alpha: 128,
+ use_dora: true,
+ target_modules: ["all-linear"],
+ },
+ },
+ is_vision: false,
+ is_embedding: false,
+ is_audio: false,
+ audio_type_known: true,
+ is_lora: false,
+ model_type: "text",
+ model_size_bytes: null,
+ max_position_embeddings: 32768,
+ }),
+ );
+ await waitForModelDefaults("LiquidAI/LFM2-1.2B");
+
+ useTrainingConfigStore.getState().setTrainingMethod("qlora");
+ const state = useTrainingConfigStore.getState();
+ assert.equal(state.loraRank, 64);
+ assert.equal(state.loraAlpha, 128);
+ assert.equal(state.loraVariant, "dora");
+ assert.deepEqual(state.targetModules, ["all-linear"]);
+});
+
+test("a LoRA edit before entering CPT still wins", async () => {
+ useTrainingConfigStore.getState().reset();
+ const resolveModelConfig = deferLfmDefaults();
+
+ useTrainingConfigStore
+ .getState()
+ .selectTrainingModel("LiquidAI/LFM2-1.2B", "text");
+ useTrainingConfigStore.getState().setLoraRank(64);
+ useTrainingConfigStore.getState().setLoraAlpha(64);
+ useTrainingConfigStore.getState().setLoraVariant("dora");
+ useTrainingConfigStore.getState().setTrainingMethod("cpt");
+ resolveModelConfig();
+ await waitForModelDefaults("LiquidAI/LFM2-1.2B");
+
+ assert.equal(useTrainingConfigStore.getState().loraRank, 128);
+ useTrainingConfigStore.getState().setTrainingMethod("qlora");
+ const state = useTrainingConfigStore.getState();
+ assert.equal(state.loraRank, 64);
+ assert.equal(state.loraAlpha, 64);
+ assert.equal(state.loraVariant, "dora");
+});
+
+test("LoRA params imported before entering CPT still win", async () => {
+ useTrainingConfigStore.getState().reset();
+ const resolveModelConfig = deferLfmDefaults();
+
+ useTrainingConfigStore
+ .getState()
+ .selectTrainingModel("LiquidAI/LFM2-1.2B", "text");
+ useTrainingConfigStore
+ .getState()
+ .applyConfigPatch({ lora: { lora_r: 64, lora_alpha: 64 } });
+ useTrainingConfigStore.getState().setTrainingMethod("cpt");
+ resolveModelConfig();
+ await waitForModelDefaults("LiquidAI/LFM2-1.2B");
+
+ useTrainingConfigStore.getState().setTrainingMethod("qlora");
+ const state = useTrainingConfigStore.getState();
+ assert.equal(state.loraRank, 64);
+ assert.equal(state.loraAlpha, 64);
+});
+
+test("editing one LoRA field does not freeze the other two on a model switch", async () => {
+ useTrainingConfigStore.getState().reset();
+ setAuthFetchHandler(() =>
+ Promise.resolve(
+ Response.json({
+ id: "old/llama",
+ config: {
+ lora: {
+ lora_r: 8,
+ lora_alpha: 8,
+ target_modules: [...LLAMA_TARGETS],
+ },
+ },
+ is_vision: false,
+ is_embedding: false,
+ is_audio: false,
+ audio_type_known: true,
+ is_lora: false,
+ model_type: "text",
+ model_size_bytes: null,
+ max_position_embeddings: 32768,
+ }),
+ ),
+ );
+ useTrainingConfigStore.getState().selectTrainingModel("old/llama", "text");
+ await waitForModelDefaults("old/llama");
+ useTrainingConfigStore.getState().setTrainingMethod("cpt");
+
+ let resolveModelConfig!: (response: Response) => void;
+ setAuthFetchHandler(
+ () =>
+ new Promise<Response>((resolve) => {
+ resolveModelConfig = resolve;
+ }),
+ );
+ useTrainingConfigStore
+ .getState()
+ .selectTrainingModel("LiquidAI/LFM2-1.2B", "text");
+ useTrainingConfigStore.getState().setLoraRank(32);
+ resolveModelConfig(
+ Response.json({
+ id: "LiquidAI/LFM2-1.2B",
+ config: {
+ lora: {
+ lora_r: 64,
+ lora_alpha: 128,
+ use_dora: true,
+ target_modules: ["all-linear"],
+ },
+ },
+ is_vision: false,
+ is_embedding: false,
+ is_audio: false,
+ audio_type_known: true,
+ is_lora: false,
+ model_type: "text",
+ model_size_bytes: null,
+ max_position_embeddings: 32768,
+ }),
+ );
+ await waitForModelDefaults("LiquidAI/LFM2-1.2B");
+
+ useTrainingConfigStore.getState().setTrainingMethod("qlora");
+ const state = useTrainingConfigStore.getState();
+ // The rank edit is protected; the two untouched fields follow the new model.
+ assert.equal(state.loraRank, 8);
+ assert.equal(state.loraAlpha, 128);
+ assert.equal(state.loraVariant, "dora");
+});
+
+test("a target-modules edit does not strand the previous model adapter params", async () => {
+ useTrainingConfigStore.getState().reset();
+ setAuthFetchHandler(() =>
+ Promise.resolve(
+ Response.json({
+ id: "old/llama",
+ config: {
+ lora: {
+ lora_r: 8,
+ lora_alpha: 8,
+ target_modules: [...LLAMA_TARGETS],
+ },
+ },
+ is_vision: false,
+ is_embedding: false,
+ is_audio: false,
+ audio_type_known: true,
+ is_lora: false,
+ model_type: "text",
+ model_size_bytes: null,
+ max_position_embeddings: 32768,
+ }),
+ ),
+ );
+ useTrainingConfigStore.getState().selectTrainingModel("old/llama", "text");
+ await waitForModelDefaults("old/llama");
+ useTrainingConfigStore.getState().setTrainingMethod("cpt");
+
+ let resolveModelConfig!: (response: Response) => void;
+ setAuthFetchHandler(
+ () =>
+ new Promise<Response>((resolve) => {
+ resolveModelConfig = resolve;
+ }),
+ );
+ useTrainingConfigStore
+ .getState()
+ .selectTrainingModel("LiquidAI/LFM2-1.2B", "text");
+ useTrainingConfigStore
+ .getState()
+ .setTargetModules([...LLAMA_TARGETS, "embed_tokens"]);
+ resolveModelConfig(
+ Response.json({
+ id: "LiquidAI/LFM2-1.2B",
+ config: {
+ lora: {
+ lora_r: 64,
+ lora_alpha: 128,
+ use_dora: true,
+ target_modules: ["all-linear"],
+ },
+ },
+ is_vision: false,
+ is_embedding: false,
+ is_audio: false,
+ audio_type_known: true,
+ is_lora: false,
+ model_type: "text",
+ model_size_bytes: null,
+ max_position_embeddings: 32768,
+ }),
+ );
+ await waitForModelDefaults("LiquidAI/LFM2-1.2B");
+
+ useTrainingConfigStore.getState().setTrainingMethod("qlora");
+ const state = useTrainingConfigStore.getState();
+ assert.equal(state.loraRank, 64);
+ assert.equal(state.loraAlpha, 128);
+ assert.equal(state.loraVariant, "dora");
+});
+
+test("leaving CPT does not report untouched adapter params as modified", async () => {
+ useTrainingConfigStore.getState().reset();
+ setAuthFetchHandler(() =>
+ Promise.resolve(
+ Response.json({
+ id: "old/llama",
+ config: {
+ lora: {
+ lora_r: 8,
+ lora_alpha: 8,
+ target_modules: [...LLAMA_TARGETS],
+ },
+ },
+ is_vision: false,
+ is_embedding: false,
+ is_audio: false,
+ audio_type_known: true,
+ is_lora: false,
+ model_type: "text",
+ model_size_bytes: null,
+ max_position_embeddings: 32768,
+ }),
+ ),
+ );
+ // Chosen inside CPT, so the baseline freezes there: the regressing case.
+ useTrainingConfigStore.getState().setTrainingMethod("cpt");
+ useTrainingConfigStore.getState().selectTrainingModel("old/llama", "text");
+ await waitForModelDefaults("old/llama");
+
+ // Inside CPT the summary reads CPT's own values, so nothing is modified there.
+ const inCpt = useTrainingConfigStore.getState();
+ assert.equal(
+ countNonDefaultAdvancedSettings(inCpt, inCpt.advancedSettingsBaseline),
+ 0,
+ );
+
+ useTrainingConfigStore.getState().setTrainingMethod("qlora");
+ const state = useTrainingConfigStore.getState();
+ assert.equal(state.loraRank, 8);
+ assert.equal(state.loraAlpha, 8);
+ assert.equal(
+ countNonDefaultAdvancedSettings(state, state.advancedSettingsBaseline),
+ 0,
+ );
+});
+
+// load_model_defaults returns {} when its YAML read raises or default.yaml is gone,
+// so the patch carries no target modules and cptTargetModules falls back to live state.
+// The baseline has to follow that fallback or the summary compares the all-linear set
+// the UI is showing against the generic CPT list and reports a phantom edit.
+test("an empty model config does not invent a modified target-modules setting", async () => {
+ useTrainingConfigStore.getState().reset();
+ useTrainingConfigStore
+ .getState()
+ .setTargetModules(["all-linear", "embed_tokens", "lm_head"]);
+ useTrainingConfigStore.getState().setTrainingMethod("cpt");
+ setAuthFetchHandler(() =>
+ Promise.resolve(
+ Response.json({
+ id: "org/no-defaults",
+ config: {},
+ is_vision: false,
+ is_embedding: false,
+ is_audio: false,
+ audio_type_known: true,
+ is_lora: false,
+ model_type: "text",
+ model_size_bytes: null,
+ max_position_embeddings: 32768,
+ }),
+ ),
+ );
+ useTrainingConfigStore.getState().selectTrainingModel("org/no-defaults", "text");
+ await waitForModelDefaults("org/no-defaults");
+
+ const inCpt = useTrainingConfigStore.getState();
+ assert.deepEqual(inCpt.targetModules, [
+ "all-linear",
+ "embed_tokens",
+ "lm_head",
]);
+ assert.equal(
+ countNonDefaultAdvancedSettings(inCpt, inCpt.advancedSettingsBaseline),
+ 0,
+ );
+
+ useTrainingConfigStore.getState().setTrainingMethod("qlora");
+ const out = useTrainingConfigStore.getState();
+ assert.equal(
+ countNonDefaultAdvancedSettings(out, out.advancedSettingsBaseline),
+ 0,
+ );
+});
+
+// Cache reconciliation restarts the request with applyTrainingDefaults: false.
+async function cacheRestartInsideCpt(beforeRestart: () => void): Promise<void> {
+ useTrainingConfigStore.getState().reset();
+ setAuthFetchHandler(() =>
+ Promise.resolve(
+ Response.json({
+ id: "old/llama",
+ config: {
+ lora: {
+ lora_r: 8,
+ lora_alpha: 8,
+ target_modules: [...LLAMA_TARGETS],
+ },
+ },
+ is_vision: false,
+ is_embedding: false,
+ is_audio: false,
+ audio_type_known: true,
+ is_lora: false,
+ model_type: "text",
+ model_size_bytes: null,
+ max_position_embeddings: 32768,
+ }),
+ ),
+ );
+ useTrainingConfigStore.getState().selectTrainingModel("old/llama", "text");
+ await waitForModelDefaults("old/llama");
+ useTrainingConfigStore.getState().setTrainingMethod("cpt");
+
+ let resolveModelConfig!: (response: Response) => void;
+ setAuthFetchHandler(
+ () =>
+ new Promise<Response>((resolve) => {
+ resolveModelConfig = resolve;
+ }),
+ );
+ useTrainingConfigStore
+ .getState()
+ .selectTrainingModel("LiquidAI/LFM2-1.2B", "text");
+ beforeRestart();
+
+ const lfmDefaults = () =>
+ Response.json({
+ id: "LiquidAI/LFM2-1.2B",
+ config: {
+ lora: {
+ lora_r: 64,
+ lora_alpha: 128,
+ use_dora: true,
+ target_modules: ["all-linear"],
+ },
+ },
+ is_vision: false,
+ is_embedding: false,
+ is_audio: false,
+ audio_type_known: true,
+ is_lora: false,
+ model_type: "text",
+ model_size_bytes: null,
+ max_position_embeddings: 32768,
+ });
+ setAuthFetchHandler(() => Promise.resolve(lfmDefaults()));
+ useTrainingConfigStore
+ .getState()
+ .setSelectedModelCacheReference("LiquidAI/LFM2-1.2B", {
+ localPath: "/models/lfm2",
+ modelFormat: "safetensors",
+ });
+ resolveModelConfig(lfmDefaults());
+ await waitForModelDefaults("LiquidAI/LFM2-1.2B");
+}
+
+test("a cache-reference restart still refreshes the pre-CPT LoRA params", async () => {
+ await cacheRestartInsideCpt(() => {
+ useTrainingConfigStore.getState().setBatchSize(3);
+ });
+
+ useTrainingConfigStore.getState().setTrainingMethod("qlora");
+ const state = useTrainingConfigStore.getState();
+ assert.equal(state.loraRank, 64);
+ assert.equal(state.loraAlpha, 128);
+ assert.equal(state.loraVariant, "dora");
+});
+
+test("a cache-reference restart does not forget an edit made before it", async () => {
+ await cacheRestartInsideCpt(() => {
+ useTrainingConfigStore.getState().setLoraRank(40);
+ });
+
+ useTrainingConfigStore.getState().setTrainingMethod("qlora");
+ const state = useTrainingConfigStore.getState();
+ // The edit predates the restart, so its guard has to survive the new request.
+ assert.equal(state.loraRank, 8);
+ assert.equal(state.loraAlpha, 128);
+ assert.equal(state.loraVariant, "dora");
+});
+
+test("a reload inside CPT keeps the pre-CPT LoRA params the session saved", async () => {
+ useTrainingConfigStore.getState().reset();
+ let calls = 0;
+ setAuthFetchHandler(() => {
+ calls += 1;
+ return Promise.resolve(
+ Response.json({
+ id: "org/reload-model",
+ config: {
+ lora: {
+ lora_r: 8,
+ lora_alpha: 8,
+ target_modules: [...LLAMA_TARGETS],
+ },
+ },
+ is_vision: false,
+ is_embedding: false,
+ is_audio: false,
+ audio_type_known: true,
+ is_lora: false,
+ model_type: "text",
+ model_size_bytes: null,
+ max_position_embeddings: 32768,
+ }),
+ );
+ });
+
+ // The shape a rehydrate leaves: CPT active, pre-CPT values persisted, defaults applied.
+ useTrainingConfigStore.setState({
+ selectedModel: "org/reload-model",
+ modelDefaultsAppliedFor: "org/reload-model",
+ trainingMethod: "cpt",
+ loraRank: 128,
+ loraAlpha: 32,
+ loraVariant: "rslora",
+ trainingMethodProvenance: {
+ learningRateManuallySet: false,
+ modelAdapterLearningRate: null,
+ datasetFormatBeforeCpt: null,
+ targetModulesBeforeCpt: null,
+ loraRankBeforeCpt: 64,
+ loraAlphaBeforeCpt: 64,
+ loraVariantBeforeCpt: "dora",
+ },
+ });
+
+ useTrainingConfigStore.getState().ensureModelDefaultsLoaded();
+ for (let attempt = 0; attempt < 100; attempt += 1) {
+ if (
+ calls > 0 &&
+ !useTrainingConfigStore.getState().isLoadingModelDefaults
+ ) {
+ break;
+ }
+ await new Promise((resolve) => setTimeout(resolve, 5));
+ }
+ assert.ok(calls > 0, "the mount-time defaults request never ran");
+
+ const provenance = useTrainingConfigStore.getState().trainingMethodProvenance;
+ assert.equal(provenance.loraRankBeforeCpt, 64);
+ assert.equal(provenance.loraAlphaBeforeCpt, 64);
+ assert.equal(provenance.loraVariantBeforeCpt, "dora");
+
+ useTrainingConfigStore.getState().setTrainingMethod("qlora");
+ const state = useTrainingConfigStore.getState();
+ assert.equal(state.loraRank, 64);
+ assert.equal(state.loraAlpha, 64);
+ assert.equal(state.loraVariant, "dora");
});
diff --git a/studio/frontend/tests/training-method-provenance.test.ts b/studio/frontend/tests/training-method-provenance.test.ts
index 77251cae3ae..a4855b48301 100644
--- a/studio/frontend/tests/training-method-provenance.test.ts
+++ b/studio/frontend/tests/training-method-provenance.test.ts
@@ -96,6 +96,9 @@ test("switching away from CPT restores pre-CPT target modules", () => {
modelAdapterLearningRate: null,
datasetFormatBeforeCpt: "chatml" as const,
targetModulesBeforeCpt: ["all-linear"],
+ loraRankBeforeCpt: null,
+ loraAlphaBeforeCpt: null,
+ loraVariantBeforeCpt: null,
},
};
const patch = buildTrainingMethodPatch(state, "qlora");
@@ -104,3 +107,27 @@ test("switching away from CPT restores pre-CPT target modules", () => {
assert.equal(patch.datasetFormat, "chatml");
assert.equal(patch.trainingMethodProvenance?.targetModulesBeforeCpt, null);
});
+
+test("switching away from CPT restores the pre-CPT LoRA rank, alpha and variant", () => {
+ const state = {
+ ...initialTrainingConfigState,
+ trainingMethod: "qlora" as const,
+ loraRank: 8,
+ loraAlpha: 8,
+ loraVariant: "lora" as const,
+ };
+ const cptState = { ...state, ...buildTrainingMethodPatch(state, "cpt") };
+
+ assert.equal(cptState.loraRank, 128);
+ assert.equal(cptState.trainingMethodProvenance.loraRankBeforeCpt, 8);
+
+ const restored = {
+ ...cptState,
+ ...buildTrainingMethodPatch(cptState, "qlora"),
+ };
+
+ assert.equal(restored.loraRank, 8);
+ assert.equal(restored.loraAlpha, 8);
+ assert.equal(restored.loraVariant, "lora");
+ assert.equal(restored.trainingMethodProvenance.loraRankBeforeCpt, null);
+});