Instructions to use Qwen/Qwen-14B-Chat-Int4 with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use Qwen/Qwen-14B-Chat-Int4 with Transformers:
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("text-generation", model="Qwen/Qwen-14B-Chat-Int4", trust_remote_code=True)# Load model directly from transformers import AutoModelForCausalLM model = AutoModelForCausalLM.from_pretrained("Qwen/Qwen-14B-Chat-Int4", trust_remote_code=True, device_map="auto") - Notebooks
- Google Colab
- Kaggle
- Local Apps Settings
- vLLM
How to use Qwen/Qwen-14B-Chat-Int4 with vLLM:
Install from pip and serve model
# Install vLLM from pip: pip install vllm # Start the vLLM server: vllm serve "Qwen/Qwen-14B-Chat-Int4" # 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-14B-Chat-Int4", "prompt": "Once upon a time,", "max_tokens": 512, "temperature": 0.5 }'Use Docker
docker model run hf.co/Qwen/Qwen-14B-Chat-Int4
- SGLang
How to use Qwen/Qwen-14B-Chat-Int4 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-14B-Chat-Int4" \ --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-14B-Chat-Int4", "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-14B-Chat-Int4" \ --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-14B-Chat-Int4", "prompt": "Once upon a time,", "max_tokens": 512, "temperature": 0.5 }' - Docker Model Runner
How to use Qwen/Qwen-14B-Chat-Int4 with Docker Model Runner:
docker model run hf.co/Qwen/Qwen-14B-Chat-Int4
update modeling.py
Browse files- modeling_qwen.py +10 -3
modeling_qwen.py
CHANGED
|
@@ -3,6 +3,7 @@
|
|
| 3 |
# This source code is licensed under the license found in the
|
| 4 |
# LICENSE file in the root directory of this source tree.
|
| 5 |
|
|
|
|
| 6 |
import importlib
|
| 7 |
import math
|
| 8 |
from typing import TYPE_CHECKING, Optional, Tuple, Union, Callable, List, Any, Generator
|
|
@@ -1177,7 +1178,6 @@ class QWenLMHeadModel(QWenPreTrainedModel):
|
|
| 1177 |
query: str,
|
| 1178 |
history: Optional[HistoryType],
|
| 1179 |
system: str = "You are a helpful assistant.",
|
| 1180 |
-
append_history: bool = True,
|
| 1181 |
stream: Optional[bool] = _SENTINEL,
|
| 1182 |
stop_words_ids: Optional[List[List[int]]] = None,
|
| 1183 |
generation_config: Optional[GenerationConfig] = None,
|
|
@@ -1189,6 +1189,10 @@ class QWenLMHeadModel(QWenPreTrainedModel):
|
|
| 1189 |
assert generation_config.chat_format == 'chatml', _ERROR_BAD_CHAT_FORMAT
|
| 1190 |
if history is None:
|
| 1191 |
history = []
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1192 |
if stop_words_ids is None:
|
| 1193 |
stop_words_ids = []
|
| 1194 |
|
|
@@ -1226,8 +1230,11 @@ class QWenLMHeadModel(QWenPreTrainedModel):
|
|
| 1226 |
errors='replace'
|
| 1227 |
)
|
| 1228 |
|
| 1229 |
-
|
| 1230 |
-
|
|
|
|
|
|
|
|
|
|
| 1231 |
|
| 1232 |
return response, history
|
| 1233 |
|
|
|
|
| 3 |
# This source code is licensed under the license found in the
|
| 4 |
# LICENSE file in the root directory of this source tree.
|
| 5 |
|
| 6 |
+
import copy
|
| 7 |
import importlib
|
| 8 |
import math
|
| 9 |
from typing import TYPE_CHECKING, Optional, Tuple, Union, Callable, List, Any, Generator
|
|
|
|
| 1178 |
query: str,
|
| 1179 |
history: Optional[HistoryType],
|
| 1180 |
system: str = "You are a helpful assistant.",
|
|
|
|
| 1181 |
stream: Optional[bool] = _SENTINEL,
|
| 1182 |
stop_words_ids: Optional[List[List[int]]] = None,
|
| 1183 |
generation_config: Optional[GenerationConfig] = None,
|
|
|
|
| 1189 |
assert generation_config.chat_format == 'chatml', _ERROR_BAD_CHAT_FORMAT
|
| 1190 |
if history is None:
|
| 1191 |
history = []
|
| 1192 |
+
else:
|
| 1193 |
+
# make a copy of the user's input such that is is left untouched
|
| 1194 |
+
history = copy.deepcopy(history)
|
| 1195 |
+
|
| 1196 |
if stop_words_ids is None:
|
| 1197 |
stop_words_ids = []
|
| 1198 |
|
|
|
|
| 1230 |
errors='replace'
|
| 1231 |
)
|
| 1232 |
|
| 1233 |
+
# as history is a copy of the user inputs,
|
| 1234 |
+
# we can always return the new turn to the user.
|
| 1235 |
+
# separating input history and output history also enables the user
|
| 1236 |
+
# to implement more complex history management
|
| 1237 |
+
history.append((query, response))
|
| 1238 |
|
| 1239 |
return response, history
|
| 1240 |
|