tenyyprn commited on
Commit
5b01869
·
verified ·
1 Parent(s): 5a8329d

Upload README.md with huggingface_hub

Browse files
Files changed (1) hide show
  1. README.md +76 -44
README.md CHANGED
@@ -1,72 +1,104 @@
1
  ---
2
- library_name: peft
3
- model_name: lora_exp13_dpo
 
 
 
 
 
 
4
  tags:
5
- - base_model:adapter:Qwen/Qwen3-4B-Instruct-2507
6
  - dpo
7
  - lora
8
- - transformers
9
- - trl
10
- licence: license
11
- base_model: Qwen/Qwen3-4B-Instruct-2507
12
- pipeline_tag: text-generation
13
  ---
14
 
15
- # Model Card for lora_exp13_dpo
16
 
17
- This model is a fine-tuned version of [None](https://huggingface.co/None).
18
- It has been trained using [TRL](https://github.com/huggingface/trl).
19
 
20
- ## Quick start
21
 
22
- ```python
23
- from transformers import pipeline
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
24
 
25
- question = "If you had a time machine, but could only go to the past or the future once and never return, which would you choose and why?"
26
- generator = pipeline("text-generation", model="None", device="cuda")
27
- output = generator([{"role": "user", "content": question}], max_new_tokens=128, return_full_text=False)[0]
28
- print(output["generated_text"])
29
  ```
30
 
31
- ## Training procedure
32
 
33
-
 
 
34
 
 
35
 
36
- This model was trained with DPO, a method introduced in [Direct Preference Optimization: Your Language Model is Secretly a Reward Model](https://huggingface.co/papers/2305.18290).
 
 
 
37
 
38
- ### Framework versions
 
39
 
40
- - PEFT 0.18.1
41
- - TRL: 0.28.0
42
- - Transformers: 5.1.0
43
- - Pytorch: 2.10.0+cu128
44
- - Datasets: 4.5.0
45
- - Tokenizers: 0.22.2
 
46
 
47
- ## Citations
 
 
 
 
48
 
49
- Cite DPO as:
 
 
 
 
 
 
 
 
 
 
50
 
51
  ```bibtex
52
  @inproceedings{rafailov2023direct,
53
  title = {{Direct Preference Optimization: Your Language Model is Secretly a Reward Model}},
54
  author = {Rafael Rafailov and Archit Sharma and Eric Mitchell and Christopher D. Manning and Stefano Ermon and Chelsea Finn},
55
  year = 2023,
56
- booktitle = {Advances in Neural Information Processing Systems 36: Annual Conference on Neural Information Processing Systems 2023, NeurIPS 2023, New Orleans, LA, USA, December 10 - 16, 2023},
57
  url = {http://papers.nips.cc/paper_files/paper/2023/hash/a85b405ed65c6477a4fe8302b5e06ce7-Abstract-Conference.html},
58
- editor = {Alice Oh and Tristan Naumann and Amir Globerson and Kate Saenko and Moritz Hardt and Sergey Levine},
59
  }
60
  ```
61
-
62
- Cite TRL as:
63
-
64
- ```bibtex
65
- @software{vonwerra2020trl,
66
- title = {{TRL: Transformers Reinforcement Learning}},
67
- author = {von Werra, Leandro and Belkada, Younes and Tunstall, Lewis and Beeching, Edward and Thrush, Tristan and Lambert, Nathan and Huang, Shengyi and Rasul, Kashif and Gallouédec, Quentin},
68
- license = {Apache-2.0},
69
- url = {https://github.com/huggingface/trl},
70
- year = {2020}
71
- }
72
- ```
 
1
  ---
2
+ base_model: Qwen/Qwen3-4B-Instruct-2507
3
+ datasets:
4
+ - u-10bei/dpo-dataset-qwen-cot
5
+ language:
6
+ - en
7
+ license: apache-2.0
8
+ library_name: transformers
9
+ pipeline_tag: text-generation
10
  tags:
 
11
  - dpo
12
  - lora
13
+ - peft
14
+ - qwen
15
+ - structured-data
16
+ - alignment
 
17
  ---
18
 
19
+ # Qwen3-4B Structured Data Expert (Exp13 - DPO with System Prompt)
20
 
21
+ This model is a fine-tuned version of **[Qwen/Qwen3-4B-Instruct-2507](https://huggingface.co/Qwen/Qwen3-4B-Instruct-2507)** using **Direct Preference Optimization (DPO)**.
 
22
 
23
+ This repository contains a **LoRA adapter** trained for structured data generation tasks (JSON, YAML, TOML, XML, CSV, etc.).
24
 
25
+ ## Key Feature
26
+
27
+ Training and inference formats are **fully aligned** by embedding the system prompt into DPO training data, which significantly improves output quality.
28
+
29
+ ## Training Configuration
30
+
31
+ | Parameter | Value |
32
+ |-----------|-------|
33
+ | Base model | Qwen/Qwen3-4B-Instruct-2507 + SFT (Exp5) |
34
+ | Method | DPO (Direct Preference Optimization) |
35
+ | Dataset | u-10bei/dpo-dataset-qwen-cot |
36
+ | LoRA rank (r) | 16 |
37
+ | LoRA alpha | 32 |
38
+ | Learning rate | 5e-7 |
39
+ | Epochs | 2 |
40
+ | Batch size | 4 (grad accum: 2) |
41
+ | Beta | 0.1 |
42
+ | Max length | 1024 |
43
+ | Max prompt length | 512 |
44
+ | Optimizer | AdamW |
45
+ | Warmup ratio | 0.1 |
46
+ | Seed | 3407 |
47
+
48
+ ## System Prompt (used at inference)
49
 
50
+ ```
51
+ You are a structured data expert. Output the requested format directly without any explanation, preamble, or markdown code blocks. Do not write ```json, ```yaml, ```toml, ```xml, ```csv or similar. Output only the raw structured data.
 
 
52
  ```
53
 
54
+ ## Key Improvements over baseline
55
 
56
+ - **System prompt embedded in DPO training**: Training and inference formats are fully consistent
57
+ - **Clean chosen responses**: Only the structured data portion extracted (no code blocks, no preamble)
58
+ - **Code block suppression**: 0% code block usage at inference (vs ~70% in base DPO)
59
 
60
+ ## Inference Example
61
 
62
+ ```python
63
+ from transformers import AutoModelForCausalLM, AutoTokenizer
64
+ from peft import PeftModel
65
+ import torch
66
 
67
+ BASE_MODEL_ID = "Qwen/Qwen3-4B-Instruct-2507"
68
+ ADAPTER_PATH = "tenyyprn/qwen3-4b-structeval-exp13"
69
 
70
+ SYSTEM_PROMPT = (
71
+ "You are a structured data expert. "
72
+ "Output the requested format directly without any explanation, "
73
+ "preamble, or markdown code blocks. "
74
+ "Do not write ```json, ```yaml, ```toml, ```xml, ```csv or similar. "
75
+ "Output only the raw structured data."
76
+ )
77
 
78
+ tokenizer = AutoTokenizer.from_pretrained(BASE_MODEL_ID, trust_remote_code=True)
79
+ model = AutoModelForCausalLM.from_pretrained(BASE_MODEL_ID, torch_dtype=torch.float16, device_map="auto")
80
+ model = PeftModel.from_pretrained(model, ADAPTER_PATH)
81
+ model = model.merge_and_unload()
82
+ model.eval()
83
 
84
+ messages = [
85
+ {"role": "system", "content": SYSTEM_PROMPT},
86
+ {"role": "user", "content": "Convert to JSON: name=Alice, age=30, city=Tokyo"},
87
+ ]
88
+ text = tokenizer.apply_chat_template(messages, tokenize=False, add_generation_prompt=True)
89
+ inputs = tokenizer(text, return_tensors="pt").to("cuda")
90
+ outputs = model.generate(**inputs, max_new_tokens=512, do_sample=False)
91
+ print(tokenizer.decode(outputs[0][inputs["input_ids"].shape[1]:], skip_special_tokens=True))
92
+ ```
93
+
94
+ ## Citations
95
 
96
  ```bibtex
97
  @inproceedings{rafailov2023direct,
98
  title = {{Direct Preference Optimization: Your Language Model is Secretly a Reward Model}},
99
  author = {Rafael Rafailov and Archit Sharma and Eric Mitchell and Christopher D. Manning and Stefano Ermon and Chelsea Finn},
100
  year = 2023,
101
+ booktitle = {Advances in Neural Information Processing Systems 36},
102
  url = {http://papers.nips.cc/paper_files/paper/2023/hash/a85b405ed65c6477a4fe8302b5e06ce7-Abstract-Conference.html},
 
103
  }
104
  ```