基础模型:
- google/gemma-3-1b-it
标签:
- 文本生成推理
- transformers框架
- unsloth优化
- GRPO算法
- 对话式AI
- gemma3文本模型
- 推理能力
许可证: apache-2.0
语言:
- 英语
训练数据集:
- NuclearAi/HyperThink-v1
模型说明
- 开发团队: NuclearAi
- 许可证: apache-2.0
- 微调基础模型: google/gemma-3-1b-it
Gemma是谷歌推出的轻量级尖端开源模型系列,采用与Gemini模型相同的研究技术构建。然而原版Gemma在逻辑推理能力方面存在不足,相较其他模型略显逊色。
Nuclear AI团队通过GRPO算法和专用训练数据集显著提升了Gemma的推理能力。作为实验性模型,我们使用150条高质量数据进行了5个步骤的微调,耗时约30分钟。
测试结果表明该模型表现令人惊艳!我们期待您的反馈,以便在更大算力支持下进行更多步骤的扩展微调。
库安装指南
pip install --no-deps git+https://github.com/huggingface/transformers@v4.49.0-Gemma-3
pip install "unsloth[colab-new]@git+https://github.com/unslothai/unsloth.git"
pip install accelerate bitsandbytes
运行代码
import torch
from unsloth import FastModel
from transformers import TextStreamer
max_seq_length = 1024
model_name = "NuclearAi/Nuke_X_Gemma3_1B_Reasoner_Testing"
print(f"正在加载模型: {model_name}...")
model, tokenizer = FastModel.from_pretrained(
model_name = model_name,
max_seq_length = max_seq_length,
dtype = None,
load_in_4bit = False,
device_map = "auto",
)
print("模型加载完成")
reasoning_start = "<think>"
reasoning_end = "</think>"
solution_start = "<response>"
solution_end = "</response>"
system_prompt = \
f"""请解决以下问题。
先进行思考并将推理过程放在{reasoning_start}和{reasoning_end}之间。
然后将最终答案放在{solution_start}{solution_end}之间"""
user_question = "写一个关于学会飞行的猫的短篇故事"
messages = [
{"role": "system", "content": system_prompt},
{"role": "user", "content": user_question},
]
text_input = tokenizer.apply_chat_template(
messages,
tokenize=False,
add_generation_prompt=True
)
device = model.device if hasattr(model, 'device') else ('cuda' if torch.cuda.is_available() else 'cpu')
inputs = tokenizer([text_input], return_tensors="pt").to(device)
streamer = TextStreamer(tokenizer, skip_prompt=True, skip_special_tokens=True)
print("\n--- 模型响应 ---")
with torch.no_grad():
outputs = model.generate(
**inputs,
streamer=streamer,
max_new_tokens=1024,
temperature=0.7,
top_p=0.9,
top_k=50,
do_sample=True,
pad_token_id=tokenizer.eos_token_id
)
print("\n--- 响应结束 ---")
感谢您的支持!
Jay Shree Ram 🚩🚩