Downloads · 30 days
7
11% of all-time downloads
daisuke-hoshina/qwen3-4b-structured-output-phase2-merged
qwen3-4b-structured-output-phase2-merged is a machine learning model from daisuke-hoshina. Use it for the machine learning task on the model card, and read the license before you ship it in a product. The card lists the license as apache-2.0.
python from transformers import AutoModelForCausalLM, AutoTokenizer from peft import PeftModel import torch
Downloads · 30 days
7
11% of all-time downloads
All-time downloads
64
Public
Parameters
4B
8.1 GB on disk
Likes
0
Public
Click a slice to open those files.
.safetensors8 GB · 100%
From the Hugging Face model README
# **qwen3-4b-structured-output-lora-phase2**
This repository provides a LoRA adapter fine-tuned from Qwen/Qwen3-4B-Instruct-2507 using QLoRA (4-bit, bitsandbytes).
This repository contains LoRA adapter weights (and tokenizer files) only. The base model must be loaded separately.
## **Training Objective**
This adapter is trained to improve structured output accuracy (JSON / YAML / XML / TOML / CSV).
Loss is applied only to the final assistant output (completion-only loss), while the prompt portion is masked (labels = -100).
Additionally, intermediate reasoning markers such as `<think>...</think>` and code fences were removed during data preparation to prioritize parseable outputs.
## **Training Configuration**
* Base model: Qwen/Qwen3-4B-Instruct-2507
* Method: QLoRA (4-bit, bitsandbytes) + PEFT LoRA
* Training: Phase1 (mixed) → Phase2 (hard-only resume)
* Epochs: 1 epoch (Phase1) + 1 epoch (Phase2)
* Learning rate: 5e-05 (Phase2)
* Packing: disabled (completion-only loss)
* Framework: transformers + trl + peft
* LoRA: (see adapter_config.json in this repo)
## **Usage**
```python
from transformers import AutoModelForCausalLM, AutoTokenizer
from peft import PeftModel
import torch
base = "Qwen/Qwen3-4B-Instruct-2507"
adapter = "your_id/your-repo"
tokenizer = AutoTokenizer.from_pretrained(base, trust_remote_code=True)
model = AutoModelForCausalLM.from_pretrained(
base,
torch_dtype=torch.float16,
device_map="auto",
trust_remote_code=True,
)
model = PeftModel.from_pretrained(model, adapter)
このリポジトリは、Qwen/Qwen3-4B-Instruct-2507 をベースモデルとし、QLoRA (4-bit, bitsandbytes) を用いてファインチューニングされた LoRA アダプターを提供します。
【重要】本リポジトリには **LoRA アダプターの重み(および tokenizer)**のみが含まれています。ベースモデルは別途ロードする必要があります。
このアダプターは、構造化出力(JSON / YAML / XML / TOML / CSV)の精度向上を目的としてトレーニングされています。
学習時の損失(Loss)は 最終アシスタント出力(completion)のみに適用され、プロンプト部分はマスク(labels=-100)されています。
また、パース可能な出力を優先するため、データ整形時に <think>...</think> やコードフェンスを除去しています。
from transformers import AutoModelForCausalLM, AutoTokenizer
from peft import PeftModel
import torch
base = "Qwen/Qwen3-4B-Instruct-2507"
adapter = "your_id/your-repo"
tokenizer = AutoTokenizer.from_pretrained(base, trust_remote_code=True)
model = AutoModelForCausalLM.from_pretrained(
base,
torch_dtype=torch.float16,
device_map="auto",
trust_remote_code=True,
)
model = PeftModel.from_pretrained(model, adapter)
---
# B) README.md(マージ済みモデル用:提出URL向け・サンプル準拠)
```md
# **qwen3-4b-structured-output-phase2-merged**
This repository provides a merged FP16 model built from Qwen/Qwen3-4B-Instruct-2507 and a Phase2 LoRA adapter.
This repository contains the full merged model weights, so it can be loaded directly with `from_pretrained()`.
## **Training Objective**
This model is trained to improve structured output accuracy (JSON / YAML / XML / TOML / CSV).
Loss is applied only to the final assistant output (completion-only loss), while the prompt portion is masked (labels = -100).
Data preparation removes `<think>...</think>` and code fences to prioritize strict, parseable outputs.
## **Training Configuration**
* Base model: Qwen/Qwen3-4B-Instruct-2507
* Method: QLoRA SFT (4-bit) → merged into FP16 weights for inference
* Training: Phase1 (mixed) → Phase2 (hard-only resume)
* Epochs: 1 epoch (Phase1) + 1 epoch (Phase2)
* Learning rate: 5e-05 (Phase2)
* Framework: transformers + trl + peft
* Output: merged FP16 model (safe_serialization)
## **Usage**
```python
from transformers import AutoModelForCausalLM, AutoTokenizer
model_id = "your_id/your-repo"
tokenizer = AutoTokenizer.from_pretrained(model_id, trust_remote_code=True)
model = AutoModelForCausalLM.from_pretrained(
model_id,
device_map="auto",
trust_remote_code=True,
)
このリポジトリは、Qwen/Qwen3-4B-Instruct-2507 と Phase2 の LoRA アダプターから作成した マージ済み FP16 モデルを提供します。
本リポジトリには マージ済みのフルモデル重みが含まれているため、from_pretrained() で直接ロードできます。
このモデルは、構造化出力(JSON / YAML / XML / TOML / CSV)の精度向上を目的としてトレーニングされています。
学習時の損失(Loss)は 最終アシスタント出力(completion)のみに適用され、プロンプト部分はマスク(labels=-100)されています。
また、厳密にパース可能な出力を優先するため、データ整形時に <think>...</think> やコードフェンスを除去しています。
from transformers import AutoModelForCausalLM, AutoTokenizer
model_id = "your_id/your-repo"
tokenizer = AutoTokenizer.from_pretrained(model_id, trust_remote_code=True)
model = AutoModelForCausalLM.from_pretrained(
model_id,
device_map="auto",
trust_remote_code=True,
)
---
## どっちを使うべき?
- **提出URL用(推奨)**:B(merged)
- **再現・継続学習用**:A(LoRA)
---
必要なら、あなたの実際の学習ログに合わせて README の数値をさらに厳密化できます(例:Phase1/2 の lr、bs、ga、max_len、データ件数を明記)。ただ、今の版でもサンプルの粒度と整合しています。
::contentReference[oaicite:0]{index=0}