Upload README.md with huggingface_hub
Browse files
README.md
CHANGED
|
@@ -1,65 +1,63 @@
|
|
| 1 |
---
|
| 2 |
base_model: Qwen/Qwen3-4B-Instruct-2507
|
| 3 |
datasets:
|
| 4 |
-
- u-10bei/
|
| 5 |
language:
|
| 6 |
- en
|
| 7 |
license: apache-2.0
|
| 8 |
-
library_name:
|
| 9 |
pipeline_tag: text-generation
|
| 10 |
tags:
|
| 11 |
-
-
|
| 12 |
-
-
|
| 13 |
-
-
|
|
|
|
| 14 |
---
|
| 15 |
|
| 16 |
-
qwen3-4b-structured-output-lora
|
| 17 |
|
| 18 |
-
This
|
| 19 |
-
**Qwen/Qwen3-4B-Instruct-2507** using **QLoRA (4-bit, Unsloth)**.
|
| 20 |
|
| 21 |
-
This repository contains **
|
| 22 |
-
The base model must be loaded separately.
|
| 23 |
|
| 24 |
## Training Objective
|
| 25 |
-
|
| 26 |
-
This adapter is trained to improve **structured output accuracy**
|
| 27 |
-
(JSON / YAML / XML / TOML / CSV).
|
| 28 |
-
|
| 29 |
-
Loss is applied only to the final assistant output,
|
| 30 |
-
while intermediate reasoning (Chain-of-Thought) is masked.
|
| 31 |
|
| 32 |
## Training Configuration
|
| 33 |
-
|
| 34 |
-
-
|
| 35 |
-
-
|
| 36 |
-
-
|
| 37 |
-
-
|
| 38 |
-
-
|
| 39 |
-
- LoRA: r=64, alpha=128
|
| 40 |
|
| 41 |
## Usage
|
|
|
|
| 42 |
|
| 43 |
```python
|
| 44 |
from transformers import AutoModelForCausalLM, AutoTokenizer
|
| 45 |
-
from peft import PeftModel
|
| 46 |
import torch
|
| 47 |
|
| 48 |
-
|
| 49 |
-
adapter = "your_id/your-repo"
|
| 50 |
|
| 51 |
-
tokenizer = AutoTokenizer.from_pretrained(
|
| 52 |
model = AutoModelForCausalLM.from_pretrained(
|
| 53 |
-
|
| 54 |
torch_dtype=torch.float16,
|
| 55 |
-
device_map="auto"
|
| 56 |
)
|
| 57 |
-
model = PeftModel.from_pretrained(model, adapter)
|
| 58 |
-
```
|
| 59 |
|
| 60 |
-
#
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 61 |
|
| 62 |
-
|
| 63 |
|
| 64 |
-
|
| 65 |
-
|
|
|
|
|
|
| 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 |
+
- unsloth
|
| 13 |
+
- qwen
|
| 14 |
+
- alignment
|
| 15 |
---
|
| 16 |
|
| 17 |
+
# qwen3-4b-structured-output-lora-merged-dpo
|
| 18 |
|
| 19 |
+
This model is a fine-tuned version of **Qwen/Qwen3-4B-Instruct-2507** using **Direct Preference Optimization (DPO)** via the **Unsloth** library.
|
|
|
|
| 20 |
|
| 21 |
+
This repository contains the **full-merged 16-bit weights**. No adapter loading is required.
|
|
|
|
| 22 |
|
| 23 |
## Training Objective
|
| 24 |
+
This model has been optimized using DPO to align its responses with preferred outputs, focusing on improving reasoning (Chain-of-Thought) and structured response quality based on the provided preference dataset.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 25 |
|
| 26 |
## Training Configuration
|
| 27 |
+
- **Base model**: Qwen/Qwen3-4B-Instruct-2507
|
| 28 |
+
- **Method**: DPO (Direct Preference Optimization)
|
| 29 |
+
- **Epochs**: 1
|
| 30 |
+
- **Learning rate**: 1e-07
|
| 31 |
+
- **Beta**: 0.1
|
| 32 |
+
- **Max sequence length**: 1024
|
| 33 |
+
- **LoRA Config**: started from SFT adapter (r=64, alpha=128), updated with DPO, then merged into base (16-bit)
|
| 34 |
|
| 35 |
## Usage
|
| 36 |
+
Since this is a merged model, you can use it directly with `transformers`.
|
| 37 |
|
| 38 |
```python
|
| 39 |
from transformers import AutoModelForCausalLM, AutoTokenizer
|
|
|
|
| 40 |
import torch
|
| 41 |
|
| 42 |
+
model_id = "your_id/your-repo-name"
|
|
|
|
| 43 |
|
| 44 |
+
tokenizer = AutoTokenizer.from_pretrained(model_id)
|
| 45 |
model = AutoModelForCausalLM.from_pretrained(
|
| 46 |
+
model_id,
|
| 47 |
torch_dtype=torch.float16,
|
| 48 |
+
device_map="auto"
|
| 49 |
)
|
|
|
|
|
|
|
| 50 |
|
| 51 |
+
# Test inference
|
| 52 |
+
prompt = "Your question here"
|
| 53 |
+
inputs = tokenizer.apply_chat_template([{"role": "user", "content": prompt}], tokenize=True, add_generation_prompt=True, return_tensors="pt").to("cuda")
|
| 54 |
+
outputs = model.generate(**inputs, max_new_tokens=512)
|
| 55 |
+
print(tokenizer.decode(outputs[0]))
|
| 56 |
+
|
| 57 |
+
```
|
| 58 |
|
| 59 |
+
## Sources & License (IMPORTANT)
|
| 60 |
|
| 61 |
+
* **Training Data**: [u-10bei/dpo-dataset-qwen-cot]
|
| 62 |
+
* **License**: MIT License. (As per dataset terms).
|
| 63 |
+
* **Compliance**: Users must follow the original base model's license terms.
|