Instructions to use tugstugi/Qwen2.5-Coder-0.5B-QwQ-draft with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use tugstugi/Qwen2.5-Coder-0.5B-QwQ-draft with Transformers:
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("text-generation", model="tugstugi/Qwen2.5-Coder-0.5B-QwQ-draft") messages = [ {"role": "user", "content": "Who are you?"}, ] pipe(messages)# Load model directly from transformers import AutoTokenizer, AutoModelForCausalLM tokenizer = AutoTokenizer.from_pretrained("tugstugi/Qwen2.5-Coder-0.5B-QwQ-draft") model = AutoModelForCausalLM.from_pretrained("tugstugi/Qwen2.5-Coder-0.5B-QwQ-draft") 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 tugstugi/Qwen2.5-Coder-0.5B-QwQ-draft with vLLM:
Install from pip and serve model
# Install vLLM from pip: pip install vllm # Start the vLLM server: vllm serve "tugstugi/Qwen2.5-Coder-0.5B-QwQ-draft" # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:8000/v1/chat/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "tugstugi/Qwen2.5-Coder-0.5B-QwQ-draft", "messages": [ { "role": "user", "content": "What is the capital of France?" } ] }'Use Docker
docker model run hf.co/tugstugi/Qwen2.5-Coder-0.5B-QwQ-draft
- SGLang
How to use tugstugi/Qwen2.5-Coder-0.5B-QwQ-draft 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 "tugstugi/Qwen2.5-Coder-0.5B-QwQ-draft" \ --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": "tugstugi/Qwen2.5-Coder-0.5B-QwQ-draft", "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 "tugstugi/Qwen2.5-Coder-0.5B-QwQ-draft" \ --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": "tugstugi/Qwen2.5-Coder-0.5B-QwQ-draft", "messages": [ { "role": "user", "content": "What is the capital of France?" } ] }' - Docker Model Runner
How to use tugstugi/Qwen2.5-Coder-0.5B-QwQ-draft with Docker Model Runner:
docker model run hf.co/tugstugi/Qwen2.5-Coder-0.5B-QwQ-draft
Tokenizer Details
Great work on this!
I was wondering, how did you get the tokenizer to have the same vocab size as QwQ 32B Preview? I would like to do this for some other models too!
If you have a script or just a set of steps to do this, I'd appreciate if you could share it :)
The tokenizer is actually the same, you only need to change the embedding layer size.
model.resize_token_embeddings(152064)
So, one more thing – when you do this: model.resize_token_embeddings(152064), does it affect the model's performance in any way, or is the vocabulary just filled up with pad tokens?
Just wondering since I got this warning while running it myself:
The new embeddings will be initialized from a multivariate normal distribution that has old embeddings' mean and covariance. As described in this article: https://nlp.stanford.edu/~johnhew/vocab-expansion.html. To disable this, use `mean_resizing=False`
@djuna I don't know too much about this and how the model architecture uses the vocab; please enlighten me :)
@qingy2024 If the tokenizer is not changed, resize_token_embeddings should have no effect. Here is a test for the embedding:
import torch
with torch.no_grad():
embed_dim = 5
old_num_embed, new_num_embed = 5, 8
old_embeddings = torch.nn.Embedding(old_num_embed, embed_dim)
new_embeddings = torch.nn.Embedding(new_num_embed, embed_dim, device=old_embeddings.weight.device, dtype=old_embeddings.weight.dtype)
new_embeddings.weight.data[:old_num_embed, :] = old_embeddings.weight.data[:old_num_embed, :]
out1 = new_embeddings(torch.LongTensor([range(old_num_embed)]))
out2 = old_embeddings(torch.LongTensor([range(old_num_embed)]))
assert torch.allclose(out1, out2)
Oh, very interesting; thanks for clarifying!