Instructions to use xzybit/qwen2-7b-ts2 with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use xzybit/qwen2-7b-ts2 with Transformers:
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("text-generation", model="xzybit/qwen2-7b-ts2") messages = [ {"role": "user", "content": "Who are you?"}, ] pipe(messages)# Load model directly from transformers import AutoTokenizer, AutoModelForCausalLM tokenizer = AutoTokenizer.from_pretrained("xzybit/qwen2-7b-ts2") model = AutoModelForCausalLM.from_pretrained("xzybit/qwen2-7b-ts2") 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
- vLLM
How to use xzybit/qwen2-7b-ts2 with vLLM:
Install from pip and serve model
# Install vLLM from pip: pip install vllm # Start the vLLM server: vllm serve "xzybit/qwen2-7b-ts2" # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:8000/v1/chat/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "xzybit/qwen2-7b-ts2", "messages": [ { "role": "user", "content": "What is the capital of France?" } ] }'Use Docker
docker model run hf.co/xzybit/qwen2-7b-ts2
- SGLang
How to use xzybit/qwen2-7b-ts2 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 "xzybit/qwen2-7b-ts2" \ --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": "xzybit/qwen2-7b-ts2", "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 "xzybit/qwen2-7b-ts2" \ --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": "xzybit/qwen2-7b-ts2", "messages": [ { "role": "user", "content": "What is the capital of France?" } ] }' - Docker Model Runner
How to use xzybit/qwen2-7b-ts2 with Docker Model Runner:
docker model run hf.co/xzybit/qwen2-7b-ts2
Qwen2-7B-TS2
Training with Sparsemax+, Testing with Softmax
This model is a supervised fine-tuned variant of Qwen2-7B, trained with our TS^2 objective.
TS^2 is designed to improve alignment stability and mitigate token-level probability collapse during fine-tuning by incorporating entropy-aware adaptive weighting into the training objective.
More details could check our paper ICLR 2026 "TS^2: Training with Sparsemax+, Testing with Softmax for Accurate and Diverse LLM Fine-Tuning"
Model Description
- Base model:
Qwen2-7B - Training method: Sparsemax+
- Objective: token-level entropy-aware TS^2-style regularization
- Framework: PyTorch + Hugging Face Transformers
- Precision: bfloat16
Instead of applying uniform likelihood maximization across all tokens as in standard supervised fine-tuning, this model introduces an adaptive weighting mechanism that dynamically adjusts training emphasis based on predictive entropy.
This design is motivated by observations that overconfident likelihood-based training may lead to:
- degeneration of token diversity
- inference-time mode collapse
- reduced generalization under distribution shift
TS^2 modifies the training objective to improve both accuracy and diversity.
Usage
from transformers import AutoTokenizer, AutoModelForCausalLM
tokenizer = AutoTokenizer.from_pretrained("xzybit/qwen2-7b-ts2")
model = AutoModelForCausalLM.from_pretrained(
"xzybit/qwen2-7b-ts2",
device_map="auto"
)
- Downloads last month
- 4