CoolFace
Modelpublic

daisuke-hoshina/qwen3-4b-structured-output-unei-v1

sourceHugging Faceapache-2.0updated 7mo agoView on Hugging Face
0likes9downloads
Model Card

This repository provides a LoRA adapter fine-tuned from Qwen/Qwen3-4B-Instruct-2507 to improve strict structured output generation (JSON / YAML / XML / TOML / CSV) for the Matsuo Lab LLM Competition (main track).

✅ Adapter-only repo (PEFT / LoRA): This repository contains LoRA adapter weights only. You must load the base model separately, then apply this adapter.

Training Objective

Improve strict, machine-readable structured outputs:

  • —JSON
  • —YAML
  • —XML
  • —TOML
  • —CSV

During training, loss is applied only to the final assistant output. Any intermediate reasoning (Chain-of-Thought) is masked (not learned), so the model focuses on producing valid structured formats.

Training Configuration

  • —Base model: Qwen/Qwen3-4B-Instruct-2507
  • —Method: QLoRA (4-bit) / Unsloth
  • —Max sequence length: 2048
  • —Epochs: 1
  • —Learning rate: 2e-5
  • —LoRA: r=32, alpha=64
  • —Dataset: u-10bei/structured_data_with_cot_dataset_v2

Evaluation (public_150)

Submitted inference outputs to the competition evaluator and achieved:

  • —Public score: 0.74518

Local strict validation breakdown (by format):

  • —JSON: 100.0% (50 / 50)
  • —YAML: 100.0% (35 / 35)
  • —TOML: 56.0% (14 / 25)
  • —XML: 95.0% (19 / 20)
  • —CSV: 100.0% (20 / 20)
Note: TOML remains the main failure mode (strict parse / duplicate headers / overwrite errors, etc.).

Recommended Inference Settings

To reduce format breakage (especially TOML), start with deterministic decoding:

  • —do_sample = False
  • —temperature = 0.0
  • —top_p = 1.0
  • —max_new_tokens: large enough for the expected output

If you still see format drift, try lowering max_new_tokens or tightening the prompt to end with Output:\n.


Usage (vLLM, fp16)

This adapter is typically used by merging it into the base model and running inference with vLLM.

1) Merge the LoRA adapter into the base model (fp16)

python
import os, gc, torch
from transformers import AutoModelForCausalLM, AutoTokenizer
from peft import PeftModel

BASE_MODEL = "Qwen/Qwen3-4B-Instruct-2507"
ADAPTER_ID = "daisuke-hoshina/qwen3-4b-structured-output-unei-v1"
MERGED_DIR = "./merged_model_fp16"

base_model = AutoModelForCausalLM.from_pretrained(
    BASE_MODEL,
    dtype=torch.float16,
    device_map="auto",
    trust_remote_code=True,
)
tokenizer = AutoTokenizer.from_pretrained(BASE_MODEL, trust_remote_code=True)

model = PeftModel.from_pretrained(base_model, ADAPTER_ID)
merged = model.merge_and_unload()

os.makedirs(MERGED_DIR, exist_ok=True)
merged.save_pretrained(MERGED_DIR)
tokenizer.save_pretrained(MERGED_DIR)

del base_model, model, merged
gc.collect()
torch.cuda.empty_cache()
print("Merged model saved to:", MERGED_DIR)

2) Run inference with vLLM

python
from vllm import LLM, SamplingParams
from transformers import AutoTokenizer

model_path = "./merged_model_fp16"
tokenizer = AutoTokenizer.from_pretrained(model_path, trust_remote_code=True)

messages = [{"role": "user", "content": "Convert the following requirements into TOML: ..."}]
prompt = tokenizer.apply_chat_template(messages, tokenize=False, add_generation_prompt=True)

sampling = SamplingParams(
    temperature=0.0,
    max_tokens=2048,
)

llm = LLM(
    model=model_path,
    max_model_len=4096,
    gpu_memory_utilization=0.80,
    enforce_eager=True,
)

out = llm.generate([prompt], sampling)[0].outputs[0].text
print(out)

Recommended decoding:

  • —temperature=0.0
  • —do_sample=False (vLLM uses greedy when temperature=0)

Limitations

  • —TOML strict validity may still fail for complex nested schemas (e.g., duplicated headers, overwrite errors, malformed arrays/tables).
  • —The model may output extra text if the prompt is ambiguous (e.g., missing an explicit Output: marker).
  • —This adapter is optimized for structured-output benchmarks and may not be ideal as a general chat assistant without additional alignment.

Sources & Terms (IMPORTANT)

  • —Training data: u-10bei/structured_data_with_cot_dataset_v2
  • —Please follow the dataset’s license and attribution requirements.
  • —Base model: Qwen/Qwen3-4B-Instruct-2507
  • —Please follow the base model’s original license/terms of use.

License

This repository is released under Apache-2.0 (see the Hugging Face license field on this model page). Please also comply with the licenses/terms of the dataset and base model.