Text Generation
Transformers
Safetensors
English
qwen2
code
codeqwen
chat
qwen
qwen-coder
conversational
text-generation-inference
Instructions to use Qwen/Qwen2.5-Coder-0.5B-Instruct with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use Qwen/Qwen2.5-Coder-0.5B-Instruct with Transformers:
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("text-generation", model="Qwen/Qwen2.5-Coder-0.5B-Instruct") messages = [ {"role": "user", "content": "Who are you?"}, ] pipe(messages)# Load model directly from transformers import AutoTokenizer, AutoModelForCausalLM tokenizer = AutoTokenizer.from_pretrained("Qwen/Qwen2.5-Coder-0.5B-Instruct") model = AutoModelForCausalLM.from_pretrained("Qwen/Qwen2.5-Coder-0.5B-Instruct", 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]:])) - Inference
- Notebooks
- Google Colab
- Kaggle
- Local Apps Settings
- vLLM
How to use Qwen/Qwen2.5-Coder-0.5B-Instruct with vLLM:
Install from pip and serve model
# Install vLLM from pip: pip install vllm # Start the vLLM server: vllm serve "Qwen/Qwen2.5-Coder-0.5B-Instruct" # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:8000/v1/chat/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "Qwen/Qwen2.5-Coder-0.5B-Instruct", "messages": [ { "role": "user", "content": "What is the capital of France?" } ] }'Use Docker
docker model run hf.co/Qwen/Qwen2.5-Coder-0.5B-Instruct
- SGLang
How to use Qwen/Qwen2.5-Coder-0.5B-Instruct 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 "Qwen/Qwen2.5-Coder-0.5B-Instruct" \ --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": "Qwen/Qwen2.5-Coder-0.5B-Instruct", "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 "Qwen/Qwen2.5-Coder-0.5B-Instruct" \ --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": "Qwen/Qwen2.5-Coder-0.5B-Instruct", "messages": [ { "role": "user", "content": "What is the capital of France?" } ] }' - Docker Model Runner
How to use Qwen/Qwen2.5-Coder-0.5B-Instruct with Docker Model Runner:
docker model run hf.co/Qwen/Qwen2.5-Coder-0.5B-Instruct
feihu.hf commited on
Commit ·
03afaae
1
Parent(s): d1d892d
update README.md
Browse files
README.md
CHANGED
|
@@ -34,8 +34,7 @@ Qwen2.5-Coder is the latest series of Code-Specific Qwen large language models (
|
|
| 34 |
- Number of Paramaters (Non-Embedding): 0.36B
|
| 35 |
- Number of Layers: 24
|
| 36 |
- Number of Attention Heads (GQA): 14 for Q and 2 for KV
|
| 37 |
-
- Context Length: Full
|
| 38 |
-
- Please refer to [this section](#processing-long-texts) for detailed instructions on how to deploy Qwen2.5 for handling long texts.
|
| 39 |
|
| 40 |
For more details, please refer to our [blog](https://qwenlm.github.io/blog/qwen2.5-coder-family/), [GitHub](https://github.com/QwenLM/Qwen2.5-Coder), [Documentation](https://qwen.readthedocs.io/en/latest/), [Arxiv](https://arxiv.org/abs/2409.12186).
|
| 41 |
|
|
@@ -87,27 +86,6 @@ generated_ids = [
|
|
| 87 |
response = tokenizer.batch_decode(generated_ids, skip_special_tokens=True)[0]
|
| 88 |
```
|
| 89 |
|
| 90 |
-
### Processing Long Texts
|
| 91 |
-
|
| 92 |
-
The current `config.json` is set for context length up to 32,768 tokens.
|
| 93 |
-
To handle extensive inputs exceeding 32,768 tokens, we utilize [YaRN](https://arxiv.org/abs/2309.00071), a technique for enhancing model length extrapolation, ensuring optimal performance on lengthy texts.
|
| 94 |
-
|
| 95 |
-
For supported frameworks, you could add the following to `config.json` to enable YaRN:
|
| 96 |
-
```json
|
| 97 |
-
{
|
| 98 |
-
...,
|
| 99 |
-
"rope_scaling": {
|
| 100 |
-
"factor": 4.0,
|
| 101 |
-
"original_max_position_embeddings": 32768,
|
| 102 |
-
"type": "yarn"
|
| 103 |
-
}
|
| 104 |
-
}
|
| 105 |
-
```
|
| 106 |
-
|
| 107 |
-
For deployment, we recommend using vLLM.
|
| 108 |
-
Please refer to our [Documentation](https://qwen.readthedocs.io/en/latest/deployment/vllm.html) for usage if you are not familar with vLLM.
|
| 109 |
-
Presently, vLLM only supports static YARN, which means the scaling factor remains constant regardless of input length, **potentially impacting performance on shorter texts**.
|
| 110 |
-
We advise adding the `rope_scaling` configuration only when processing long contexts is required.
|
| 111 |
|
| 112 |
## Evaluation & Performance
|
| 113 |
|
|
|
|
| 34 |
- Number of Paramaters (Non-Embedding): 0.36B
|
| 35 |
- Number of Layers: 24
|
| 36 |
- Number of Attention Heads (GQA): 14 for Q and 2 for KV
|
| 37 |
+
- Context Length: Full 32,768 tokens
|
|
|
|
| 38 |
|
| 39 |
For more details, please refer to our [blog](https://qwenlm.github.io/blog/qwen2.5-coder-family/), [GitHub](https://github.com/QwenLM/Qwen2.5-Coder), [Documentation](https://qwen.readthedocs.io/en/latest/), [Arxiv](https://arxiv.org/abs/2409.12186).
|
| 40 |
|
|
|
|
| 86 |
response = tokenizer.batch_decode(generated_ids, skip_special_tokens=True)[0]
|
| 87 |
```
|
| 88 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 89 |
|
| 90 |
## Evaluation & Performance
|
| 91 |
|