Instructions to use wang1r/Qwen3-0.6B-safety-math with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use wang1r/Qwen3-0.6B-safety-math with Transformers:
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("text-generation", model="wang1r/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("wang1r/Qwen3-0.6B-safety-math") model = AutoModelForCausalLM.from_pretrained("wang1r/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 wang1r/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 "wang1r/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": "wang1r/Qwen3-0.6B-safety-math", "messages": [ { "role": "user", "content": "What is the capital of France?" } ] }'Use Docker
docker model run hf.co/wang1r/Qwen3-0.6B-safety-math
- SGLang
How to use wang1r/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 "wang1r/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": "wang1r/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 "wang1r/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": "wang1r/Qwen3-0.6B-safety-math", "messages": [ { "role": "user", "content": "What is the capital of France?" } ] }' - Docker Model Runner
How to use wang1r/Qwen3-0.6B-safety-math with Docker Model Runner:
docker model run hf.co/wang1r/Qwen3-0.6B-safety-math
Qwen3-0.6B-safety-math
Fine-tuned from Qwen/Qwen3-0.6B to (1) refuse harmful / jailbreak requests, (2) improve math reasoning, and (3) preserve general capability. Architecture and parameter count are unchanged (596,049,920 params); all adaptation was done with LoRA and merged back into a standard 0.6B checkpoint, so it loads directly with transformers / vLLM. The same weights support both Qwen3 thinking and non-thinking modes.
Method
base → thinking-math SFT (M3-distilled, reject-sampled CoT) → same-word contrastive DPO (harmful→refuse / benign→help) → model soup (0.7 tuned + 0.3 base) → targeted hard-negative DPO (the model's own false refusals). Base weights frozen throughout (LoRA).
Results (base → this model, ~50 benchmarks; safety judged by an LLM judge)
- Safety — harmful ASR (avg of 7 sets) 36.8/44.4% → 8.0/7.5% (non-think/think); jailbreak (8 templates) 55.5/67.5% → 8/5.5%.
- Math (thinking) — GSM8K 74.5→76.9, MATH-500 56.0→59.0, GSM-Plus 53.9→55.2.
- General — 25/34 capability benchmarks ≥ base (MMLU +3.4, RACE +12.5, SciQ +7.8, BBH +4.3, …).
- Known trade-off — elevated over-refusal on adversarial XSTest (non-think ~49%, vs base 35%); this is a documented capacity-level Pareto trade-off for a 0.6B model.
Usage
from transformers import AutoModelForCausalLM, AutoTokenizer
m = AutoModelForCausalLM.from_pretrained("<repo_id>")
t = AutoTokenizer.from_pretrained("<repo_id>")
ids = t.apply_chat_template([{"role": "user", "content": "If 3x+7=22, what is x?"}],
add_generation_prompt=True, enable_thinking=True, return_tensors="pt") # thinking mode for math
print(t.decode(m.generate(ids, max_new_tokens=256)[0]))
Base model: Qwen/Qwen3-0.6B (Apache-2.0).
- Downloads last month
- 3