Downloads · 30 days
37
1% of all-time downloads
pytorch/Qwen3-32B-FP8
Qwen3-32B-FP8 is a text generation model from pytorch. Use it when you need the model to write or continue text. It is set up for transformers. The card lists the license as apache-2.0.
Qwen3-32B model quantized with torchao float8 dynamic activation and float8 weight quantization (per row granularity), by PyTorch team. Use it directly, or serve using vLLM with 47% VRAM reduction (34.54 GB needed), a…
Downloads · 30 days
37
1% of all-time downloads
All-time downloads
5.1K
Public
Repo size
103 GB
Likes
0
Public
Click a slice to open those files.
.bin34.3 GB · 100%
From the Hugging Face model README
Qwen3-32B model quantized with torchao float8 dynamic activation and float8 weight quantization (per row granularity), by PyTorch team. Use it directly, or serve using vLLM with 47% VRAM reduction (34.54 GB needed), around 1.7x speedup and little to no accuracy impact on H100.
# Server
VLLM_DISABLE_COMPILE_CACHE=1 vllm serve pytorch/Qwen3-32B-FP8 --tokenizer Qwen/Qwen3-32B -O3
# Client
curl http://localhost:8000/v1/chat/completions -H "Content-Type: application/json" -d '{
"model": "pytorch/Qwen3-32B-FP8",
"messages": [
{"role": "user", "content": "Give me a short introduction to large language models."}
],
"temperature": 0.6,
"top_p": 0.95,
"top_k": 20,
"max_tokens": 32768
}'
import torch
from transformers import AutoModelForCausalLM, AutoTokenizer
model_name = "pytorch/Qwen3-32B-FP8"
# load the tokenizer and the model
tokenizer = AutoTokenizer.from_pretrained(model_name)
model = AutoModelForCausalLM.from_pretrained(
model_name,
torch_dtype="auto",
device_map="auto"
)
# prepare the model input
prompt = "Give me a short introduction to large language model."
messages = [
{"role": "user", "content": prompt}
]
text = tokenizer.apply_chat_template(
messages,
tokenize=False,
add_generation_prompt=True,
enable_thinking=True # Switches between thinking and non-thinking modes. Default is True.
)
model_inputs = tokenizer([text], return_tensors="pt").to(model.device)
# conduct text completion
generated_ids = model.generate(
**model_inputs,
max_new_tokens=32768
)
output_ids = generated_ids[0][len(model_inputs.input_ids[0]):].tolist()
# parsing thinking content
try:
# rindex finding 151668 (</think>)
index = len(output_ids) - output_ids[::-1].index(151668)
except ValueError:
index = 0
thinking_content = tokenizer.decode(output_ids[:index], skip_special_tokens=True).strip("\n")
content = tokenizer.decode(output_ids[index:], skip_special_tokens=True).strip("\n")
print("thinking content:", thinking_content)
print("content:", content)
Install the required packages:
pip install git+https://github.com/huggingface/transformers@main
pip install --pre torchao torch --index-url https://download.pytorch.org/whl/nightly/cu126
pip install accelerate
Use the following code to get the float8 model using torchao library:
import torch
from transformers import AutoModelForCausalLM, AutoTokenizer, TorchAoConfig
model_id = "Qwen/Qwen3-32B"
from torchao.quantization import Float8DynamicActivationFloat8WeightConfig, PerRow
quant_config = Float8DynamicActivationFloat8WeightConfig(granularity=PerRow())
quantization_config = TorchAoConfig(quant_type=quant_config)
quantized_model = AutoModelForCausalLM.from_pretrained(
model_id,
device_map="auto",
torch_dtype=torch.bfloat16,
quantization_config=quantization_config,
)
tokenizer = AutoTokenizer.from_pretrained(model_id)
Optionally, upload to your HF hub
USER_ID = "YOUR_USER_ID"
MODEL_NAME = model_id.split("/")[-1]
save_to = f"{USER_ID}/{MODEL_NAME}-FP8"
quantized_model.push_to_hub(save_to, safe_serialization=False)
tokenizer.push_to_hub(save_to)
We rely on lm-evaluation-harness to evaluate the quality of the quantized model.
| Benchmark | ||
|---|---|---|
| Qwen3-32B | Qwen3-32B-FP8 | |
| General | ||
| mmlu | 80.71 | 80.67 |
| bbh | 37.49 | 38.01 |
| Multilingual | ||
| mgsm_en_cot_es | 58.4 | 52.0 |
| Math | ||
| gpqa_main_zeroshot | 41.96 | 42.63 |
| Overall | 54.64 | 53.33 |
Need to install lm-eval from source: https://github.com/EleutherAI/lm-evaluation-harness#install
lm_eval --model hf --model_args pretrained=Qwen/Qwen3-32B --tasks mmlu --device cuda:0 --batch_size 8
export MODEL=pytorch/Qwen3-32B-FP8
# or
# export MODEL=Qwen/Qwen3-32B
lm_eval --model hf --model_args pretrained=$MODEL --tasks mmlu --device cuda:0 --batch_size 8
</details>
| Memory (tested on H100) | ||
|---|---|---|
| Qwen3-32B | Qwen3-32B-FP8 | |
| Peak Memory | 65.63 GB | 34.71 GB (47.1% reduction) |
Code
import torch
from transformers import AutoModelForCausalLM, AutoTokenizer
model_name = "Qwen/Qwen3-32B" # pytorch/Qwen3-32B-FP8
# load the tokenizer and the model
tokenizer = AutoTokenizer.from_pretrained(model_name)
model = AutoModelForCausalLM.from_pretrained(
model_name,
torch_dtype="auto",
device_map="cuda:0"
)
torch.cuda.reset_peak_memory_stats()
# prepare the model input
prompt = "Give me a short introduction to large language model."
messages = [
{"role": "user", "content": prompt}
]
text = tokenizer.apply_chat_template(
messages,
tokenize=False,
add_generation_prompt=True,
enable_thinking=True # Switches between thinking and non-thinking modes. Default is True.
)
model_inputs = tokenizer([text], return_tensors="pt").to(model.device)
# conduct text completion
generated_ids = model.generate(
**model_inputs,
max_new_tokens=32768
)
output_ids = generated_ids[0][len(model_inputs.input_ids[0]):].tolist()
# parsing thinking content
try:
# rindex finding 151668 (</think>)
index = len(output_ids) - output_ids[::-1].index(151668)
except ValueError:
index = 0
thinking_content = tokenizer.decode(output_ids[:index], skip_special_tokens=True).strip("\n")
content = tokenizer.decode(output_ids[index:], skip_special_tokens=True).strip("\n")
print("thinking content:", thinking_content)
print("content:", content)
mem = torch.cuda.max_memory_reserved() / 1e9
print(f"Peak Memory Usage: {mem:.02f} GB")
</details>
| Benchmark (Tested on H100) | ||
|---|---|---|
| Qwen3-32B | Qwen3-32B-FP8 | |
| latency (batch_size=1) | 8.93s | 5.16s (1.73x speedup) |
| latency (batch_size=256) | 33.85s | 16.15s (2.10x speedup) |
Note: tested with fbgemm-gpu-genai installed.
1. Setup
git clone [email protected]:vllm-project/vllm.git
cd vllm
VLLM_USE_PRECOMPILED=1 pip install --editable .
To use fbgemm kernels:
pip install fbgemm-gpu-genai
2. Latency benchmarking
export MODEL=Qwen/Qwen3-32B # or pytorch/Qwen3-32B-FP8
VLLM_DISABLE_COMPILE_CACHE=1 vllm bench latency --input-len 256 --output-len 256 --model $MODEL --batch-size 1
</details>
The model's quantization is powered by TorchAO, a framework presented in the paper TorchAO: PyTorch-Native Training-to-Serving Model Optimization.
Abstract: We present TorchAO, a PyTorch-native model optimization framework leveraging quantization and sparsity to provide an end-to-end, training-to-serving workflow for AI models. TorchAO supports a variety of popular model optimization techniques, including FP8 quantized training, quantization-aware training (QAT), post-training quantization (PTQ), and 2:4 sparsity, and leverages a novel tensor subclass abstraction to represent a variety of widely-used, backend agnostic low precision data types, including INT4, INT8, FP8, MXFP4, MXFP6, and MXFP8. TorchAO integrates closely with the broader ecosystem at each step of the model optimization pipeline, from pre-training (TorchTitan) to fine-tuning (TorchTune, Axolotl) to serving (HuggingFace, vLLM, SGLang, ExecuTorch), connecting an otherwise fragmented space in a single, unified workflow. TorchAO has enabled recent launches of the quantized Llama 3.2 1B/3B and LlamaGuard3-8B models and is open-source at this https URL .
PyTorch has not performed safety evaluations or red teamed the quantized models. Performance characteristics, outputs, and behaviors may differ from the original models. Users are solely responsible for selecting appropriate use cases, evaluating and mitigating for accuracy, safety, and fairness, ensuring security, and complying with all applicable laws and regulations.
Nothing contained in this Model Card should be interpreted as or deemed a restriction or modification to the licenses the models are released under, including any limitations of liability or disclaimers of warranties provided therein.