Instructions to use Qwen/Qwen-7B-Chat-Int8 with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use Qwen/Qwen-7B-Chat-Int8 with Transformers:
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("text-generation", model="Qwen/Qwen-7B-Chat-Int8", trust_remote_code=True, device_map="auto")# Load model directly from transformers import AutoModelForCausalLM model = AutoModelForCausalLM.from_pretrained("Qwen/Qwen-7B-Chat-Int8", trust_remote_code=True, dtype="auto", device_map="auto") - Notebooks
- Google Colab
- Kaggle
- Local Apps Settings
- vLLM
How to use Qwen/Qwen-7B-Chat-Int8 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-Int8" # 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-Int8", "prompt": "Once upon a time,", "max_tokens": 512, "temperature": 0.5 }'Use Docker
docker model run hf.co/Qwen/Qwen-7B-Chat-Int8
- SGLang
How to use Qwen/Qwen-7B-Chat-Int8 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-Int8" \ --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-Int8", "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-Int8" \ --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-Int8", "prompt": "Once upon a time,", "max_tokens": 512, "temperature": 0.5 }' - Docker Model Runner
How to use Qwen/Qwen-7B-Chat-Int8 with Docker Model Runner:
docker model run hf.co/Qwen/Qwen-7B-Chat-Int8
7B-int8模型运行问题
from transformers import AutoTokenizer, AutoModelForCausalLM
from transformers.generation import GenerationConfig
import torch
rev="c04bccd3a8ec5e2fe955196de6a8da1be1d41066"
tokenizer = AutoTokenizer.from_pretrained("Qwen/Qwen-7B-Chat-Int8", trust_remote_code=True, revision=rev)
model = AutoModelForCausalLM.from_pretrained(
"Qwen/Qwen-7B-Chat-Int8",
device_map="auto",
trust_remote_code=True,
revision=rev
).eval()
print(model)
model.generation_config = GenerationConfig.from_pretrained("Qwen/Qwen-7B-Chat-Int8", trust_remote_code=True, revision=rev)
response, history = model.chat(tokenizer, "你好", history=None)
print(response)
按官方demo运行Int8模型,输出会出现乱码,打印from_pretrained后的model(print(model)),发现mlp和attention_prj层都是Linear, 比如w1:(w1): Linear(in_features=4096, out_features=11008, bias=False), 明显没有量化?是配置的问题么