ynanxiu/coffee-sft-dataset
Viewer • Updated • 3.31k • 32
How to use ynanxiu/olmo3-7b-coffee-lora with Unsloth Studio:
curl -fsSL https://unsloth.ai/install.sh | sh # Run unsloth studio unsloth studio -H 0.0.0.0 -p 8888 # Then open http://localhost:8888 in your browser # Search for ynanxiu/olmo3-7b-coffee-lora to start chatting
irm https://unsloth.ai/install.ps1 | iex # Run unsloth studio unsloth studio -H 0.0.0.0 -p 8888 # Then open http://localhost:8888 in your browser # Search for ynanxiu/olmo3-7b-coffee-lora to start chatting
# No setup required # Open https://huggingface.co/spaces/unsloth/studio in your browser # Search for ynanxiu/olmo3-7b-coffee-lora to start chatting
pip install unsloth
from unsloth import FastModel
model, tokenizer = FastModel.from_pretrained(
model_name="ynanxiu/olmo3-7b-coffee-lora",
max_seq_length=2048,
)用 coffee-sft-dataset(4,768 条)对 OLMo-3-7B-Instruct 做 QLoRA 微调,让 7B 模型学会咖啡领域知识。
| 项目 | 值 |
|---|---|
| 基座模型 | allenai/OLMo-3-7B-Instruct |
| 微调方式 | QLoRA(4-bit NF4 量化) |
| LoRA Rank | r=16, alpha=16 |
| 训练数据 | coffee-sft-dataset (4,768条) |
| Epochs | 1 |
| Batch Size | 1 × 4 grad_accum |
| Learning Rate | 2e-4 → cosine decay |
| 训练步数 | 1,192 steps |
| 训练时间 | ~60 分钟 (RTX 4060 8GB) |
| Loss | 1.33 → 1.03 |
| Token Accuracy | 72.6% → 81.5% |
import torch
from transformers import AutoModelForCausalLM, AutoTokenizer, BitsAndBytesConfig
from peft import PeftModel
# 加载 4-bit 基座模型
bnb = BitsAndBytesConfig(load_in_4bit=True, bnb_4bit_compute_dtype=torch.bfloat16)
model = AutoModelForCausalLM.from_pretrained(
"allenai/OLMo-3-7B-Instruct",
quantization_config=bnb,
device_map="auto",
torch_dtype=torch.bfloat16,
)
tokenizer = AutoTokenizer.from_pretrained("allenai/OLMo-3-7B-Instruct")
# 加载 LoRA adapter
model = PeftModel.from_pretrained(model, "ynanxiu/olmo3-7b-coffee-lora")
model.eval()
# 推理
messages = [{"role": "user", "content": "手冲咖啡需要注意什么?"}]
text = tokenizer.apply_chat_template(messages, tokenize=False, add_generation_prompt=True)
inputs = tokenizer(text, return_tensors="pt").to(model.device)
outputs = model.generate(**inputs, max_new_tokens=256, temperature=0.6, top_p=0.9)
print(tokenizer.decode(outputs[0][len(inputs['input_ids'][0]):], skip_special_tokens=True))
在 8 道咖啡领域问题上的表现:
| 问题 | 结果 |
|---|---|
| 阿拉比卡 vs 罗布斯塔 | ✅ 正确 |
| 咖啡主要产地 | ⚠️ 有地名幻觉 |
| 手冲咖啡关键参数 | ✅ 水温/研磨/粉水比全对 |
| 法压壶使用方法 | ⚠️ 描述偏复杂 |
| 浓缩咖啡因含量 | ✅ 50-60mg 精准 |
| 脱因咖啡制作 | ❌ 答非所问 |
| SOE 咖啡定义 | ❌ 概念混淆 |
| 冷萃 vs 冰滴 | ⚠️ 部分幻觉 |
正确率约 50%,后续将优化数据后迭代 v2。