Instructions to use Qwen/Qwen-7B-Chat with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use Qwen/Qwen-7B-Chat with Transformers:
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("text-generation", model="Qwen/Qwen-7B-Chat", trust_remote_code=True)# pip install -U transformers accelerate # Load model directly from transformers import AutoModelForCausalLM model = AutoModelForCausalLM.from_pretrained("Qwen/Qwen-7B-Chat", trust_remote_code=True, device_map="auto") - Notebooks
- Google Colab
- Kaggle
- Local Apps Settings
- vLLM
How to use Qwen/Qwen-7B-Chat with vLLM:
Install from pip and serve model
# Install vLLM from pip: pip install vllm # Start the vLLM server: vllm serve "Qwen/Qwen-7B-Chat" # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:8000/v1/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "Qwen/Qwen-7B-Chat", "prompt": "Once upon a time,", "max_tokens": 512, "temperature": 0.5 }'Use Docker
docker model run hf.co/Qwen/Qwen-7B-Chat
- SGLang
How to use Qwen/Qwen-7B-Chat 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/Qwen-7B-Chat" \ --host 0.0.0.0 \ --port 30000 # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:30000/v1/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "Qwen/Qwen-7B-Chat", "prompt": "Once upon a time,", "max_tokens": 512, "temperature": 0.5 }'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/Qwen-7B-Chat" \ --host 0.0.0.0 \ --port 30000 # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:30000/v1/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "Qwen/Qwen-7B-Chat", "prompt": "Once upon a time,", "max_tokens": 512, "temperature": 0.5 }' - Docker Model Runner
How to use Qwen/Qwen-7B-Chat with Docker Model Runner:
docker model run hf.co/Qwen/Qwen-7B-Chat
update tokenization.py
Browse files- tokenization_qwen.py +2 -1
tokenization_qwen.py
CHANGED
|
@@ -42,6 +42,7 @@ SPECIAL_TOKENS = tuple(
|
|
| 42 |
start=SPECIAL_START_ID,
|
| 43 |
)
|
| 44 |
)
|
|
|
|
| 45 |
|
| 46 |
|
| 47 |
def _load_tiktoken_bpe(tiktoken_bpe_file: str) -> Dict[bytes, int]:
|
|
@@ -160,7 +161,7 @@ class QWenTokenizer(PreTrainedTokenizer):
|
|
| 160 |
raise ValueError("Adding regular tokens is not supported")
|
| 161 |
for token in new_tokens:
|
| 162 |
surface_form = token.content if isinstance(token, AddedToken) else token
|
| 163 |
-
if surface_form not in
|
| 164 |
raise ValueError("Adding unknown special tokens is not supported")
|
| 165 |
return 0
|
| 166 |
|
|
|
|
| 42 |
start=SPECIAL_START_ID,
|
| 43 |
)
|
| 44 |
)
|
| 45 |
+
SPECIAL_TOKENS_SET = set(t for i, t in SPECIAL_TOKENS)
|
| 46 |
|
| 47 |
|
| 48 |
def _load_tiktoken_bpe(tiktoken_bpe_file: str) -> Dict[bytes, int]:
|
|
|
|
| 161 |
raise ValueError("Adding regular tokens is not supported")
|
| 162 |
for token in new_tokens:
|
| 163 |
surface_form = token.content if isinstance(token, AddedToken) else token
|
| 164 |
+
if surface_form not in SPECIAL_TOKENS_SET:
|
| 165 |
raise ValueError("Adding unknown special tokens is not supported")
|
| 166 |
return 0
|
| 167 |
|