Instructions to use wkhaifor/Qwen3.5-2B-FP8-Dynamic-LLMCompressor with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use wkhaifor/Qwen3.5-2B-FP8-Dynamic-LLMCompressor with Transformers:
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("image-text-to-text", model="wkhaifor/Qwen3.5-2B-FP8-Dynamic-LLMCompressor") messages = [ { "role": "user", "content": [ {"type": "image", "url": "https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/p-blog/candy.JPG"}, {"type": "text", "text": "What animal is on the candy?"} ] }, ] pipe(text=messages)# pip install -U transformers accelerate # Load model directly from transformers import AutoProcessor, AutoModelForMultimodalLM processor = AutoProcessor.from_pretrained("wkhaifor/Qwen3.5-2B-FP8-Dynamic-LLMCompressor") model = AutoModelForMultimodalLM.from_pretrained("wkhaifor/Qwen3.5-2B-FP8-Dynamic-LLMCompressor", device_map="auto") messages = [ { "role": "user", "content": [ {"type": "image", "url": "https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/p-blog/candy.JPG"}, {"type": "text", "text": "What animal is on the candy?"} ] }, ] inputs = processor.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(processor.decode(outputs[0][inputs["input_ids"].shape[-1]:])) - Notebooks
- Google Colab
- Kaggle
- Local Apps Settings
- vLLM
How to use wkhaifor/Qwen3.5-2B-FP8-Dynamic-LLMCompressor with vLLM:
Install from pip and serve model
# Install vLLM from pip: pip install vllm # Start the vLLM server: vllm serve "wkhaifor/Qwen3.5-2B-FP8-Dynamic-LLMCompressor" # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:8000/v1/chat/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "wkhaifor/Qwen3.5-2B-FP8-Dynamic-LLMCompressor", "messages": [ { "role": "user", "content": [ { "type": "text", "text": "Describe this image in one sentence." }, { "type": "image_url", "image_url": { "url": "https://cdn.britannica.com/61/93061-050-99147DCE/Statue-of-Liberty-Island-New-York-Bay.jpg" } } ] } ] }'Use Docker
docker model run hf.co/wkhaifor/Qwen3.5-2B-FP8-Dynamic-LLMCompressor
- SGLang
How to use wkhaifor/Qwen3.5-2B-FP8-Dynamic-LLMCompressor 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 "wkhaifor/Qwen3.5-2B-FP8-Dynamic-LLMCompressor" \ --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": "wkhaifor/Qwen3.5-2B-FP8-Dynamic-LLMCompressor", "messages": [ { "role": "user", "content": [ { "type": "text", "text": "Describe this image in one sentence." }, { "type": "image_url", "image_url": { "url": "https://cdn.britannica.com/61/93061-050-99147DCE/Statue-of-Liberty-Island-New-York-Bay.jpg" } } ] } ] }'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 "wkhaifor/Qwen3.5-2B-FP8-Dynamic-LLMCompressor" \ --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": "wkhaifor/Qwen3.5-2B-FP8-Dynamic-LLMCompressor", "messages": [ { "role": "user", "content": [ { "type": "text", "text": "Describe this image in one sentence." }, { "type": "image_url", "image_url": { "url": "https://cdn.britannica.com/61/93061-050-99147DCE/Statue-of-Liberty-Island-New-York-Bay.jpg" } } ] } ] }' - Docker Model Runner
How to use wkhaifor/Qwen3.5-2B-FP8-Dynamic-LLMCompressor with Docker Model Runner:
docker model run hf.co/wkhaifor/Qwen3.5-2B-FP8-Dynamic-LLMCompressor
Qwen3.5-2B-FP8-Dynamic-LLMCompressor
ๅบไบ Qwen3.5-2B ๅถไฝ็ ๅจๆ FP8 ้ๅๆจกๅ๏ผไฝฟ็จ llm-compressor 0.14.0 ๅถไฝ๏ผไปฅ compressed-tensors 0.19.0 ๆ ผๅผไฟๅญใ
้ๅ้ ็ฝฎ
้็จ FP8_DYNAMIC ๅฏน 96 ไธช่ฏญ่จ็บฟๆงๅฑๅ้ๅใๆ้ๆ่พๅบ้้ไฝฟ็จ้ๆๅฐบๅบฆ๏ผๆฟๆดปๆ token ๅจๆ็ผฉๆพ๏ผๅถไฝๆถๆ ้ๆ กๅๆฐๆฎใๆ้ๅ
ฑ 3.311 GiBใ visualใlinear_attnใlm_head ๅๅ
ถไป้็ฎๆ ๅฑไฟ็ๆตฎ็น็ฒพๅบฆ๏ผKV cache ๆฒฟ็จๆจ็ๅผๆ็้ป่ฎค่ฎพ็ฝฎใ
ๅถไฝๆ็จ็ไธๆธธๆไบคๅทๆช่ฎฐๅฝใ
ๆๆฌๆจ็
ๅฎๆดไธ่ฝฝไปๅบๅ๏ผๅจๆฏๆ compressed-tensors ็ vLLM 0.32.0 ็ฏๅข่ฟ่กใๆจกๅ็ฎๅฝๅบๅ ๅซๆ้ใ็ดขๅผใ้ ็ฝฎๅ tokenizerใ็คบไพไฝฟ็จๆๆฌ่พๅ ฅใ
import json
import os
from collections.abc import Mapping
from pathlib import Path
# ๅจๅฏผๅ
ฅๆจ็ๅบไนๅๅฏ็จ็ฆป็บฟๆจกๅผ๏ผไธไธ่ฝฝไปปไฝๆจกๅๆไปถใ
os.environ["HF_HUB_OFFLINE"] = "1"
os.environ["TRANSFORMERS_OFFLINE"] = "1"
MODEL_DIR = Path(".").resolve() # ไปไธ่ฝฝๅ็ๅฎๆดๆจกๅ็ฎๅฝ่ฟ่ก
def token_ids_from_template(encoded):
# Transformers 5 ๅฏ่ฝ่ฟๅ BatchEncoding/UserDict๏ผ่ไธไธๅฎๆฏๆฎ้ dictใ
if isinstance(encoded, Mapping):
if "input_ids" not in encoded:
raise ValueError("Chat template ๆช่ฟๅ input_ids")
encoded = encoded["input_ids"]
if hasattr(encoded, "tolist"):
encoded = encoded.tolist()
if (isinstance(encoded, (list, tuple)) and len(encoded) == 1
and isinstance(encoded[0], (list, tuple))):
encoded = encoded[0]
if not isinstance(encoded, (list, tuple)) or not encoded:
raise TypeError("Chat template ๅฟ
้กป่ฟๅ้็ฉบ token ID ๅบๅ")
if any(isinstance(token, bool) or not isinstance(token, int) or token < 0
for token in encoded):
raise TypeError("Token ID ๅฟ
้กปไธบ้่ดๆดๆฐ")
return list(encoded)
def main():
from vllm import LLM, SamplingParams
if not MODEL_DIR.is_dir() or not (MODEL_DIR / "config.json").is_file():
raise FileNotFoundError("่ฏทๅฐ MODEL_DIR ๆนไธบๅฎๆด็ๆฌๅฐๆจกๅ็ฎๅฝ")
if not list(MODEL_DIR.glob("*.safetensors")):
raise FileNotFoundError("ๆจกๅๆ้็ผบๅคฑ๏ผไธ่ฝไฝฟ็จๆฌๅฐๅ ไฝ็ฎๅฝ")
config = json.loads((MODEL_DIR / "config.json").read_text(encoding="utf-8"))
if config.get("quantization_config", {}).get("quant_method") != "compressed-tensors":
raise ValueError("่ฏฅ็คบไพ่ฆๆฑๆฌๆจกๅ็ compressed-tensors checkpoint")
generation_path = MODEL_DIR / "generation_config.json"
generation = json.loads(generation_path.read_text(encoding="utf-8")) if generation_path.exists() else {}
eos = generation.get("eos_token_id")
if eos is None:
eos = config.get("eos_token_id")
if eos is None:
eos = config.get("text_config", {}).get("eos_token_id")
stop_ids = eos if isinstance(eos, list) else ([eos] if eos is not None else [])
llm = LLM(
model=str(MODEL_DIR),
tokenizer=str(MODEL_DIR),
dtype="float16",
tensor_parallel_size=1,
max_model_len=4096,
gpu_memory_utilization=0.75,
enforce_eager=True,
max_num_seqs=1,
enable_prefix_caching=False,
limit_mm_per_prompt={"image": 0, "video": 0},
generation_config="vllm",
trust_remote_code=False,
seed=42,
)
tokenizer = llm.get_tokenizer()
messages = [{"role": "user", "content": "ๅฐๆๆ 2 ไธช่นๆ๏ผๅๅพๅฐ 3 ไธช๏ผ็ฐๅจไธๅ
ฑๆๅ ไธช๏ผ\n่ฏทๅจๆๅไธ่ก็จ #### ๆฐๅญ ็ปๅบ็ญๆกใ"}]
encoded = tokenizer.apply_chat_template(
messages, tokenize=True, add_generation_prompt=True,
)
# ไธไผ enable_thinking๏ผไฟ็ checkpoint ่ๅคฉๆจกๆฟ็้ป่ฎค่กไธบใ
token_ids = token_ids_from_template(encoded)
max_new_tokens = 1024
if len(token_ids) + max_new_tokens > 4096:
raise ValueError("ๆ็คบ้ฟๅบฆๅ ็ๆ้ข็ฎ่ถ
่ฟ 4096๏ผๆฌ็คบไพไธ่ชๅจๆชๆญ่พๅ
ฅ")
sampling = SamplingParams(
temperature=0.0,
top_p=1.0,
top_k=-1,
n=1,
max_tokens=max_new_tokens,
seed=42,
ignore_eos=False,
stop_token_ids=stop_ids,
repetition_penalty=generation.get("repetition_penalty", 1.0),
min_tokens=generation.get("min_new_tokens") or 0,
presence_penalty=0.0,
frequency_penalty=0.0,
skip_special_tokens=True,
)
outputs = llm.generate(
[{"prompt_token_ids": token_ids}],
sampling_params=sampling,
use_tqdm=False,
)
print(tokenizer.decode(outputs[0].outputs[0].token_ids, skip_special_tokens=True))
if __name__ == "__main__":
main()
้ช่ฏ็ปๆ
ๅจ RTX 4090 D ไธไฝฟ็จ vLLM 0.32.0๏ผๅ ่ฝฝๆฅๅฟ่ฎฐๅฝ็ๅ ๆ ธไธบ CUTLASS FP8ใไธ่กจไธบ GSM8K ๆต่ฏ้ๅ 100 ้ข๏ผ่ดชๅฟ็ๆ๏ผๆฏ้ขๆๅค 1024 ไธชๆฐ token๏ผๅ่ฏทๆฑ้กบๅบๆง่กใ FP8 Block128 ไธบๅๆนๅฏน็ งใ
| ๆจกๅ | ๆญฃ็กฎ/้ขๆฐ | ๅ็กฎ็ | ๅฏ่งฃๆ็ | ่งฆ้กถ็ | ไธฒ่ก token/s | worker peak allocated GiB | worker peak reserved GiB | ๆ้ๆไปถ GiB | ๅ ่ฝฝๆไปถๅ่ฎก GiB |
|---|---|---|---|---|---|---|---|---|---|
| FP16 | 71/100 | 71.00% | 92.00% | 7.00% | 55.823 | 17.268 | 17.324 | 4.236 | 4.257 |
| FP8 Dynamic | 70/100 | 70.00% | 97.00% | 2.00% | 47.499 | 17.113 | 17.121 | 3.311 | 3.330 |
| FP8 Block128 | 72/100 | 72.00% | 95.00% | 4.00% | 44.134 | 17.283 | 17.334 | 3.310 | 3.329 |
ๅค็ฐไธ่ฎธๅฏ
ไปฅไธๅฝไปคๅจ้ ๅฅ้ๅไปฃ็ ้กน็ฎไธญ่ฟ่กใ
python run.py quantize --tool llmcompressor --method fp8 --stage full
้ๅๅๆฐ่ง config.json ๅ recipe.yaml๏ผๆไปถๆ ก้ชๅผ่ง SHA256SUMSใๆจกๅๆฒฟ็จๅบๅบง็ Apache-2.0 ่ฎธๅฏใ
ไธ่ฝฝ
ไธไฝ่ ็ ModelScope ไปๅบๅๆญฅๅๅธ๏ผๆ้ใๆฐๆฎๅ่ฏๆต่ฎฐๅฝไฟๆไธ่ดใ
pip install -U huggingface_hub
hf download wkhaifor/Qwen3.5-2B-FP8-Dynamic-LLMCompressor --local-dir ./Qwen3.5-2B-FP8-Dynamic-LLMCompressor
ไธ่ฝฝๅ่ฟๅ ฅไปๅบ็ฎๅฝ๏ผๅๆไธ้ข็็คบไพ่ฟ่กใ
- Downloads last month
- 43