Views
No views yet
Qwen/Qwen3-4B-Instruct-2507 for structured output generation tasks (JSON, YAML, XML, TOML, CSV).add_generation_prompt=True during training to match inference behavior| Parameter | Value |
|---|---|
| Base Model | Qwen/Qwen3-4B-Instruct-2507 |
| Method | QLoRA (4-bit quantization) |
| Dataset | u-10bei/structured_data_with_cot_dataset_512_v2 |
| Max Sequence Length | 512 |
| Epochs | 1 |
| Learning Rate | 2e-6 |
| LoRA Rank (r) | 64 |
| LoRA Alpha | 128 |
| LoRA Dropout | 0.0 |
| LoRA Target Modules | q_proj, k_proj, v_proj, o_proj, gate_proj, up_proj, down_proj |
| Batch Size | 2 (per device) |
| Gradient Accumulation | 16 |
| Effective Batch Size | 32 |
| Warmup Ratio | 0.1 |
| Weight Decay | 0.05 |
1from transformers import AutoModelForCausalLM, AutoTokenizer
2from peft import PeftModel
3import torch
4
5# Model IDs
6base_model_id = "Qwen/Qwen3-4B-Instruct-2507"
7adapter_id = "astom-M/qwen3-4b-struct-eval-v3-colab"
8
9# Load tokenizer
10tokenizer = AutoTokenizer.from_pretrained(base_model_id)
11
12# Load base model
13model = AutoModelForCausalLM.from_pretrained(
14 base_model_id,
15 torch_dtype=torch.float16,
16 device_map="auto",
17)
18
19# Apply LoRA adapter
20model = PeftModel.from_pretrained(model, adapter_id)1# Prepare input
2messages = [
3 {"role": "system", "content": "You are a helpful assistant that generates structured outputs."},
4 {"role": "user", "content": "Generate a JSON object with name and age fields for a person named Alice who is 25 years old."}
5]
6
7# Apply chat template
8input_text = tokenizer.apply_chat_template(
9 messages,
10 tokenize=False,
11 add_generation_prompt=True # Important: matches training
12)
13
14# Tokenize
15inputs = tokenizer(input_text, return_tensors="pt").to(model.device)
16
17# Generate
18outputs = model.generate(
19 **inputs,
20 max_new_tokens=512,
21 temperature=0.7,
22 do_sample=True,
23 top_p=0.9,
24)
25
26# Decode
27response = tokenizer.decode(outputs[0], skip_special_tokens=True)
28print(response)u-10bei/structured_data_with_cot_dataset_512_v2Qwen3-4B-Instruct-2507u-10bei/structured_data_with_cot_dataset_512_v21@article{qwen3-2507,
2 title={Qwen3 Technical Report},
3 author={Qwen Team},
4 year={2025},
5 url={https://huggingface.co/Qwen/Qwen3-4B-Instruct-2507}
6}Qwen/Qwen3-4B-Instruct-2507 (Apache 2.0).