CustomizeDeployment
LoRA Adapter
这个 recipe 展示真实的 MinT LoRA checkpoint workflow:
- 创建 LoRA
TrainingClient。 - 用
forward_backward(..., loss_fn="cross_entropy")跑一个或多个 SFT steps。 - 用
save_state()保存 training state。 - 用
save_weights_for_sampler()保存 sampler weights。 - 用保存的 sampler weights 创建
SamplingClient,并从它采样。
它不会导出 PEFT files,也不会生成 vLLM-ready 的本地 weights。这个 recipe 里没有 export_lora_to_peft() API。
Use Case
- Checkpoint verification:确认训练后的 LoRA adapter 可以保存和采样。
- 短训练 demo:跑一个最小 SFT step,并查看保存的 checkpoint paths。
- MinT deployment path:通过
create_sampling_client()使用 MinT sampler weights。 - API sanity check:验证你的 account 和 model 可以使用
save_state()和save_weights_for_sampler()。
核心训练步骤
recipe 构造一个很小的 arithmetic SFT batch,并用低层 TrainingClient API 训练:
training_client = service_client.create_lora_training_client(
base_model="Qwen/Qwen3-0.6B",
rank=16,
train_mlp=True,
train_attn=True,
train_unembed=True,
)
tokenizer = training_client.get_tokenizer()
data = [process_sft_example(example, tokenizer) for example in generate_sft_examples()]
for step in range(1, SFT_STEPS + 1):
fb_result = training_client.forward_backward(
data,
loss_fn="cross_entropy",
).result()
loss = compute_cross_entropy(fb_result, data)
training_client.optim_step(types.AdamParams(learning_rate=5e-5)).result()
print(f"Step {step}: train_cross_entropy={loss:.6f}")保存 Checkpoints
这里展示两个 save APIs:
state_checkpoint = training_client.save_state(
name="lora-adapter-state"
).result()
sampler_checkpoint = training_client.save_weights_for_sampler(
name="lora-adapter-sampler"
).result()区别:
| API | 用途 |
|---|---|
save_state() | 保存 training state。用于 resume 或检查。 |
save_weights_for_sampler() | 保存可以被 SamplingClient 使用的 weights。 |
从保存的 Weights 采样
sampling_client = service_client.create_sampling_client(
model_path=sampler_checkpoint.path,
base_model="Qwen/Qwen3-0.6B",
)
result = sampling_client.sample(
prompt=types.ModelInput.from_ints(tokens=prompt_tokens),
num_samples=1,
sampling_params=types.SamplingParams(max_tokens=32, temperature=0.0),
).result()
response = tokenizer.decode(result.sequences[0].tokens).strip()完整源码:https://github.com/MindLab-Research/mint-quickstart/blob/main/recipes/lora_adapter.py
Verified Run
已在 MinT 上验证:Qwen/Qwen3-0.6B,1 个 SFT step:
Step 1: train_cross_entropy=6.009224
State checkpoint: tinker://1cbd1a15-dc76-4c63-8683-e8df2a46a45c_0/weights/lora-adapter-state
Sampler weights: tinker://1cbd1a15-dc76-4c63-8683-e8df2a46a45c_0/sampler_weights/lora-adapter-sampler
Sampling from saved weights: success采样例子:
Prompt: Question: What is 4 + 5?
Answer:
Response: 9这个 recipe 验证的是 MinT checkpoint 和 sampling APIs。如果你需要本地 PEFT/vLLM export,请等单独文档化的 weight-export 路径;不要假设存在假的 export_lora_to_peft() API。
为什么这个形状有效
TrainingClient
│ forward_backward(cross_entropy) + optim_step
▼
LoRA adapter state
├─ save_state() ───────────────▶ training/resume checkpoint
└─ save_weights_for_sampler() ─▶ sampler checkpoint
│
▼
create_sampling_client()
│
▼
sample()这是 MinT LoRA adapters 最小的真实 checkpoint 生命周期。