refactor: 调优创建提取表单模型

将默认参数、命令构建、payload 构造逻辑抽离为 fineTuneFormModel.ts,新增 FineTuneStartPayload 类型约束启动训练接口,FineTuneCreateView 瘦身为视图层,列表微调,回归脚本适配。
This commit is contained in:
caoxiaozhu
2026-07-13 15:28:17 +08:00
parent bff07b7a31
commit 735a8a71f5
6 changed files with 262 additions and 170 deletions

View File

@@ -1,10 +1,12 @@
import { readFileSync } from 'node:fs'
import { resolve } from 'node:path'
import { fileURLToPath } from 'node:url'
import ts from 'typescript'
const root = resolve(fileURLToPath(new URL('..', import.meta.url)))
const source = readFileSync(resolve(root, 'src/views/fine-tune/FineTuneCreateView.vue'), 'utf8')
const modelDialogSource = readFileSync(resolve(root, 'src/components/ModelSelectDialog.vue'), 'utf8')
const formModelSource = readFileSync(resolve(root, 'src/views/fine-tune/fineTuneFormModel.ts'), 'utf8')
function assert(condition, message) {
if (!condition) {
@@ -24,11 +26,32 @@ assert(modelDialogSource.includes('width="860px"'), 'Model dialog should use a c
assert(modelDialogSource.includes('model-series-list'), 'Model dialog should include a model series list column')
assert(modelDialogSource.includes('model-version-list'), 'Model dialog should include a snapshot/version list column')
assert(modelDialogSource.includes('handleConfirm'), 'Model dialog should confirm the selected model before updating the form')
assert(source.includes("auto_merge: false"), 'Auto merge should default to disabled')
assert(formModelSource.includes('auto_merge: false'), 'Auto merge should default to disabled')
assert(source.includes('v-if="form.train_type === \'SFT\'"'), 'Merge model settings should only be visible for SFT')
assert(source.includes('content-position="left">合并模型'), 'SFT form should include a merge model section below data configuration')
assert(source.includes('v-model="form.auto_merge"'), 'Merge model section should provide an auto merge selector')
assert(source.includes('label="自动合并权重并保存"'), 'Auto merge selector should use a clear visible label')
assert((source.match(/auto_merge: form\.train_type === 'SFT' && form\.auto_merge/g) || []).length === 2, 'Auto merge should be sent for SFT when creating and starting the task')
assert(formModelSource.includes("auto_merge: form.train_type === 'SFT' && form.auto_merge"), 'Auto merge should be normalized by the shared payload builder')
assert(source.includes('const payload = buildFineTunePayload(form, selectedGpus.value)'), 'Create and start should share one normalized payload')
assert(source.includes('startFineTune({ ...payload, task_id: taskId })'), 'Start request should reuse the normalized payload')
assert(source.includes('Object.assign(form, DEFAULT_TRAINING_PARAMS)'), 'Reset should reuse the canonical defaults')
assert(!source.includes('const taskData = {'), 'The duplicated create payload should be removed')
assert(!source.includes('const createRes: any'), 'Create response should use the API return type')
assert(!source.includes('(check as any).exists'), 'Name-check response should use its API return type')
assert(source.includes('任务名校验失败'), 'Name-check failures should be visible and block submission')
const runnableSource = ts.transpileModule(
formModelSource.replace("import type { FineTuneStartPayload, FineTuneTask } from '@/types'", ''),
{ compilerOptions: { module: ts.ModuleKind.ESNext, target: ts.ScriptTarget.ES2022 } },
).outputText
const model = await import(`data:text/javascript;base64,${Buffer.from(runnableSource).toString('base64')}`)
const defaults = model.createDefaultFineTuneForm()
const customized = { ...defaults, train_type: 'DPO', train_method: 'full', auto_merge: true, quantization_bit: 4 }
const payload = model.buildFineTunePayload(customized, [0, 2])
assert(payload.auto_merge === false, 'Non-SFT tasks must never enable auto merge')
assert(payload.quantization_bit === 0, 'Full fine-tuning must never send QLoRA quantization')
assert(payload.gpus.join(',') === '0,2', 'Selected GPUs should be preserved in the shared payload')
const resetDefaults = { ...model.DEFAULT_TRAINING_PARAMS }
assert(resetDefaults.lora_alpha === defaults.lora_alpha, 'Reset and initial defaults must share LoRA values')
console.log('fine-tune create UI regression checks passed')