Instructions to use Qwen/Qwen3-8B-FP8 with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use Qwen/Qwen3-8B-FP8 with Transformers:
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("text-generation", model="Qwen/Qwen3-8B-FP8") messages = [ {"role": "user", "content": "Who are you?"}, ] pipe(messages)# pip install -U transformers accelerate # Load model directly from transformers import AutoTokenizer, AutoModelForCausalLM tokenizer = AutoTokenizer.from_pretrained("Qwen/Qwen3-8B-FP8") model = AutoModelForCausalLM.from_pretrained("Qwen/Qwen3-8B-FP8", 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=256) print(tokenizer.decode(outputs[0][inputs["input_ids"].shape[-1]:])) - Notebooks
- Google Colab
- Kaggle
- Local Apps Settings
- vLLM
How to use Qwen/Qwen3-8B-FP8 with vLLM:
Install from pip and serve model
# Install vLLM from pip: pip install vllm # Start the vLLM server: vllm serve "Qwen/Qwen3-8B-FP8" # 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/Qwen3-8B-FP8", "messages": [ { "role": "user", "content": "What is the capital of France?" } ] }'Use Docker
docker model run hf.co/Qwen/Qwen3-8B-FP8
- SGLang
How to use Qwen/Qwen3-8B-FP8 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/Qwen3-8B-FP8" \ --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/Qwen3-8B-FP8", "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/Qwen3-8B-FP8" \ --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/Qwen3-8B-FP8", "messages": [ { "role": "user", "content": "What is the capital of France?" } ] }' - Docker Model Runner
How to use Qwen/Qwen3-8B-FP8 with Docker Model Runner:
docker model run hf.co/Qwen/Qwen3-8B-FP8
Remove vLLM FP8 Limitation
Browse filesThis has been fixed as of latest v0.8.5 release 🙇
README.md
CHANGED
|
@@ -112,29 +112,6 @@ You can use the Qwen3-8B-FP8 model with serveral inference frameworks, including
|
|
| 112 |
However, please pay attention to the following known issues:
|
| 113 |
- `transformers`:
|
| 114 |
- there are currently issues with the "fine-grained fp8" method in `transformers` for distributed inference. You may need to set the environment variable `CUDA_LAUNCH_BLOCKING=1` if multiple devices are used in inference.
|
| 115 |
-
- vLLM:
|
| 116 |
-
- there are currently compatibility issues with `vllm`. For a quick fix, you should make the following changes to `vllm/vllm/model_executor/layers/linear.py`:
|
| 117 |
-
```python
|
| 118 |
-
# these changes are in QKVParallelLinear.weight_loader_v2() of vllm/vllm/model_executor/layers/linear.py
|
| 119 |
-
...
|
| 120 |
-
shard_offset = self._get_shard_offset_mapping(loaded_shard_id)
|
| 121 |
-
shard_size = self._get_shard_size_mapping(loaded_shard_id)
|
| 122 |
-
|
| 123 |
-
# add the following code
|
| 124 |
-
if isinstance(param, BlockQuantScaleParameter):
|
| 125 |
-
weight_block_size = self.quant_method.quant_config.weight_block_size
|
| 126 |
-
block_n, _ = weight_block_size[0], weight_block_size[1]
|
| 127 |
-
shard_offset = (shard_offset + block_n - 1) // block_n
|
| 128 |
-
shard_size = (shard_size + block_n - 1) // block_n
|
| 129 |
-
# end of the modification
|
| 130 |
-
|
| 131 |
-
param.load_qkv_weight(loaded_weight=loaded_weight,
|
| 132 |
-
num_heads=self.num_kv_head_replicas,
|
| 133 |
-
shard_id=loaded_shard_id,
|
| 134 |
-
shard_offset=shard_offset,
|
| 135 |
-
shard_size=shard_size)
|
| 136 |
-
...
|
| 137 |
-
```
|
| 138 |
|
| 139 |
## Switching Between Thinking and Non-Thinking Mode
|
| 140 |
|
|
|
|
| 112 |
However, please pay attention to the following known issues:
|
| 113 |
- `transformers`:
|
| 114 |
- there are currently issues with the "fine-grained fp8" method in `transformers` for distributed inference. You may need to set the environment variable `CUDA_LAUNCH_BLOCKING=1` if multiple devices are used in inference.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 115 |
|
| 116 |
## Switching Between Thinking and Non-Thinking Mode
|
| 117 |
|