Text Generation
Transformers
Safetensors
English
Chinese
qwen3
qwen
safety
math
qlora
fine-tuning
conversational
text-generation-inference
Instructions to use BPXFQ/qwen3-0.6b-safety-math with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use BPXFQ/qwen3-0.6b-safety-math with Transformers:
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("text-generation", model="BPXFQ/qwen3-0.6b-safety-math") messages = [ {"role": "user", "content": "Who are you?"}, ] pipe(messages)# Load model directly from transformers import AutoTokenizer, AutoModelForCausalLM tokenizer = AutoTokenizer.from_pretrained("BPXFQ/qwen3-0.6b-safety-math") model = AutoModelForCausalLM.from_pretrained("BPXFQ/qwen3-0.6b-safety-math", device_map="auto") messages = [ {"role": "user", "content": "Who are you?"}, ] inputs = tokenizer.apply_chat_template( messages, add_generation_prompt=True, tokenize=True, return_dict=True, return_tensors="pt", ).to(model.device) outputs = model.generate(**inputs, max_new_tokens=40) print(tokenizer.decode(outputs[0][inputs["input_ids"].shape[-1]:])) - Notebooks
- Google Colab
- Kaggle
- Local Apps Settings
- vLLM
How to use BPXFQ/qwen3-0.6b-safety-math with vLLM:
Install from pip and serve model
# Install vLLM from pip: pip install vllm # Start the vLLM server: vllm serve "BPXFQ/qwen3-0.6b-safety-math" # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:8000/v1/chat/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "BPXFQ/qwen3-0.6b-safety-math", "messages": [ { "role": "user", "content": "What is the capital of France?" } ] }'Use Docker
docker model run hf.co/BPXFQ/qwen3-0.6b-safety-math
- SGLang
How to use BPXFQ/qwen3-0.6b-safety-math with SGLang:
Install from pip and serve model
# Install SGLang from pip: pip install sglang # Start the SGLang server: python3 -m sglang.launch_server \ --model-path "BPXFQ/qwen3-0.6b-safety-math" \ --host 0.0.0.0 \ --port 30000 # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:30000/v1/chat/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "BPXFQ/qwen3-0.6b-safety-math", "messages": [ { "role": "user", "content": "What is the capital of France?" } ] }'Use Docker images
docker run --gpus all \ --shm-size 32g \ -p 30000:30000 \ -v ~/.cache/huggingface:/root/.cache/huggingface \ --env "HF_TOKEN=<secret>" \ --ipc=host \ lmsysorg/sglang:latest \ python3 -m sglang.launch_server \ --model-path "BPXFQ/qwen3-0.6b-safety-math" \ --host 0.0.0.0 \ --port 30000 # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:30000/v1/chat/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "BPXFQ/qwen3-0.6b-safety-math", "messages": [ { "role": "user", "content": "What is the capital of France?" } ] }' - Docker Model Runner
How to use BPXFQ/qwen3-0.6b-safety-math with Docker Model Runner:
docker model run hf.co/BPXFQ/qwen3-0.6b-safety-math
Qwen3-0.6B Safety & Math Fine-tuned Model
Fine-tuned from Qwen3-0.6B (architecture and parameter count unchanged, ~0.6B params, bf16) to simultaneously improve safety refusal and math reasoning while preserving general ability.
Grading rubric: safety ×40% + math ×30% + general ×30%.
Training
- Method: QLoRA 4-bit (NF4 + double quant), r=16, alpha=32, dropout=0.05, all linear modules
(q/k/v/o/gate/up/down). Response-only label masking (assistant content +
<|im_end|>). - Config: lr=1e-4, cosine, warmup 5%, 1 epoch, batch=1 + grad_accum=8 (effective 8), gradient checkpointing, bf16, paged_adamw_8bit, max_length=1024. RTX 4060 Laptop (8GB).
- Data: balanced interleaved mix (safety 23% / math 43% / general 34%):
- Safety: HH-RLHF(harmless), PKU-SafeRLHF, calibrated refusal templates (refuse + safe alternative), Chinese-SafetyQA, manual boundary examples, Dolly conservative boundary.
- Math: GSM8K, MATH (7 subtypes), MetaMathQA, AQuA.
- General: No Robots, COIG-CQIA, OASST1 (en/zh), Dolly-15k.
Evaluation (fixed subset, enable_thinking=False)
| Metric | Value |
|---|---|
| Math (96 stratified GSM8K/MATH) | 21.9% |
| HHI balanced accuracy | 78% |
| JBB balanced accuracy | 77% |
| General Chinese MCQ (200) | 69.5% |
Composite proxy (0.4×safety + 0.3×math + 0.3×general) ≈ 0.584, highest among all candidates.
Usage
from transformers import AutoModelForCausalLM, AutoTokenizer
model = AutoModelForCausalLM.from_pretrained("BPXFQ/qwen3-0.6b-safety-math", dtype="bfloat16")
tokenizer = AutoTokenizer.from_pretrained("BPXFQ/qwen3-0.6b-safety-math")
messages = [{"role": "user", "content": "17 * 23 = ?"}]
inputs = tokenizer.apply_chat_template(
messages, tokenize=True, add_generation_prompt=True,
enable_thinking=False, return_tensors="pt", return_dict=True,
)
outputs = model.generate(**inputs, max_new_tokens=128, do_sample=False,
eos_token_id=tokenizer.eos_token_id, pad_token_id=tokenizer.pad_token_id)
print(tokenizer.decode(outputs[0, inputs["input_ids"].shape[-1]:], skip_special_tokens=True))
- Downloads last month
- -