Views
No views yet
Output: marker
are masked and excluded from the loss calculation.| Parameter | Value |
|---|---|
| Base model | Qwen/Qwen3-4B-Instruct-2507 |
| Method | QLoRA (4-bit, Unsloth) |
| Max sequence length | 512 |
| Epochs | 2 |
| Learning rate | 1e-04 |
| LR scheduler | cosine |
| Warmup ratio | 0.1 |
| Gradient accumulation steps | 4 |
| Weight decay | 0.05 |
| LoRA rank (r) | 16 |
| LoRA alpha | 16 |
| LoRA dropout | 0.0 |
| LoRA target modules | q_proj, k_proj, v_proj, o_proj, gate_proj, up_proj, down_proj |
1from transformers import AutoModelForCausalLM, AutoTokenizer
2from peft import PeftModel
3import torch
4
5base = "Qwen/Qwen3-4B-Instruct-2507"
6adapter = "noirchan/qwen3-4b-structured-output-lora-v4"
7
8tokenizer = AutoTokenizer.from_pretrained(base)
9model = AutoModelForCausalLM.from_pretrained(
10 base,
11 torch_dtype=torch.float16,
12 device_map="auto",
13)
14model = PeftModel.from_pretrained(model, adapter)
15
16# 推論例
17messages = [{"role": "user", "content": "Convert the following to JSON: name=Alice, age=30"}]
18text = tokenizer.apply_chat_template(messages, tokenize=False, add_generation_prompt=True)
19inputs = tokenizer(text, return_tensors="pt").to(model.device)
20outputs = model.generate(**inputs, max_new_tokens=512, temperature=0.0, do_sample=False)
21print(tokenizer.decode(outputs[0][inputs["input_ids"].shape[1]:], skip_special_tokens=True))