Text Generation
Transformers
Safetensors
English
deepseek_v2
quantized
int4
w4a16
weight-only
4-bit precision
llm-compressor
zendnn
compressed-tensors
amd
cpu-inference
conversational
custom_code
text-generation-inference
Instructions to use amd/DeepSeek-Coder-V2-Lite-Instruct-w4a16-llmcompressor with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use amd/DeepSeek-Coder-V2-Lite-Instruct-w4a16-llmcompressor with Transformers:
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("text-generation", model="amd/DeepSeek-Coder-V2-Lite-Instruct-w4a16-llmcompressor", trust_remote_code=True) 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("amd/DeepSeek-Coder-V2-Lite-Instruct-w4a16-llmcompressor", trust_remote_code=True) model = AutoModelForCausalLM.from_pretrained("amd/DeepSeek-Coder-V2-Lite-Instruct-w4a16-llmcompressor", trust_remote_code=True, 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 amd/DeepSeek-Coder-V2-Lite-Instruct-w4a16-llmcompressor with vLLM:
Install from pip and serve model
# Install vLLM from pip: pip install vllm # Start the vLLM server: vllm serve "amd/DeepSeek-Coder-V2-Lite-Instruct-w4a16-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": "amd/DeepSeek-Coder-V2-Lite-Instruct-w4a16-llmcompressor", "messages": [ { "role": "user", "content": "What is the capital of France?" } ] }'Use Docker
docker model run hf.co/amd/DeepSeek-Coder-V2-Lite-Instruct-w4a16-llmcompressor
- SGLang
How to use amd/DeepSeek-Coder-V2-Lite-Instruct-w4a16-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 "amd/DeepSeek-Coder-V2-Lite-Instruct-w4a16-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": "amd/DeepSeek-Coder-V2-Lite-Instruct-w4a16-llmcompressor", "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 "amd/DeepSeek-Coder-V2-Lite-Instruct-w4a16-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": "amd/DeepSeek-Coder-V2-Lite-Instruct-w4a16-llmcompressor", "messages": [ { "role": "user", "content": "What is the capital of France?" } ] }' - Docker Model Runner
How to use amd/DeepSeek-Coder-V2-Lite-Instruct-w4a16-llmcompressor with Docker Model Runner:
docker model run hf.co/amd/DeepSeek-Coder-V2-Lite-Instruct-w4a16-llmcompressor
|
Download README.md from amd/DeepSeek-Coder-V2-Lite-Instruct-w4a16-llmcompressor: direct link, hf CLI and curl.
- Browser
- Download file 7.29 kB
-
https://huggingface.co/amd/DeepSeek-Coder-V2-Lite-Instruct-w4a16-llmcompressor/resolve/main/README.md
- Command line
-
hf download hf://amd/DeepSeek-Coder-V2-Lite-Instruct-w4a16-llmcompressor/README.md
-
curl -L -o README.md https://huggingface.co/amd/DeepSeek-Coder-V2-Lite-Instruct-w4a16-llmcompressor/resolve/main/README.md
7.29 kB
| license: other | |
| license_name: deepseek-license | |
| license_link: LICENSE | |
| base_model: | |
| - deepseek-ai/DeepSeek-Coder-V2-Lite-Instruct | |
| base_model_relation: quantized | |
| library_name: transformers | |
| pipeline_tag: text-generation | |
| tags: | |
| - quantized | |
| - int4 | |
| - w4a16 | |
| - weight-only | |
| - 4-bit | |
| - llm-compressor | |
| - zendnn | |
| - compressed-tensors | |
| - amd | |
| - cpu-inference | |
| language: | |
| - en | |
| # DeepSeek-Coder-V2-Lite-Instruct-w4a16-llmcompressor | |
| ## Model Overview | |
| - **Model Architecture:** DeepseekV2ForCausalLM | |
| - **Input:** Text | |
| - **Output:** Text | |
| - **Source Model:** [DeepSeek-Coder-V2-Lite-Instruct](https://huggingface.co/deepseek-ai/DeepSeek-Coder-V2-Lite-Instruct) | |
| - **Supported Hardware:** AMD EPYC (CPU inference) | |
| - **Preferred Operating System:** Linux | |
| - **Inference Engine:** [vLLM](https://docs.vllm.ai/en/latest/) v0.33.0 | |
| - **Quantization Framework:** [LLM Compressor](https://github.com/vllm-project/llm-compressor) v0.14.0 | |
| - **Quantization Method:** 4-bit Weight-Only Quantization (W4A16) | |
| - **Compatible Stack:** | |
| - ZenDNN v6.2.0 | |
| - ZenTorch v2.14.0.3 | |
| - PyTorch v2.13.0+cpu | |
| - Transformers v5.17.0 | |
| - LLM Compressor v0.14.0 | |
| - vLLM v0.33.0 | |
| - **Published with:** LLM Compressor v0.14.0 | |
| This is a quantized version of [DeepSeek-Coder-V2-Lite-Instruct](https://huggingface.co/deepseek-ai/DeepSeek-Coder-V2-Lite-Instruct) created by AMD using LLM Compressor (compressed-tensors) for ZenDNN-optimized CPU inference. | |
| ## Quantization | |
| The model was quantized from [DeepSeek-Coder-V2-Lite-Instruct](https://huggingface.co/deepseek-ai/DeepSeek-Coder-V2-Lite-Instruct) using [LLM Compressor](https://github.com/vllm-project/llm-compressor) via the GPTQ algorithm. This reduces the model weights from 29.3 GiB to 8.4 GiB on disk (~71% reduction). | |
| - **Method:** 4-bit Weight-Only Quantization (W4A16) | |
| - **Config:** `compressed-tensors, num_bits=4, type=int, symmetric=true, group_size=64` | |
| - **Weights:** INT4, symmetric, group-wise (`group_size=64`), stored as `pack-quantized` | |
| - **Activations:** BF16 (unquantized) | |
| - **Group Size:** 64 | |
| - **Calibration:** 128 examples from `HuggingFaceH4/ultrachat_200k` at a max sequence length of 2048 | |
| - **Quantized:** `model.layers.*.mlp.experts.*.up_proj` (1664), `model.layers.*.mlp.experts.*.gate_proj` (1664), `model.layers.*.mlp.experts.*.down_proj` (1664), `model.layers.*.self_attn.q_proj` (27), `model.layers.*.self_attn.kv_a_proj_with_mqa` (27), `model.layers.*.self_attn.kv_b_proj` (27), `model.layers.*.self_attn.o_proj` (27), `model.layers.*.mlp.shared_experts.gate_proj` (26), `model.layers.*.mlp.shared_experts.up_proj` (26), `model.layers.*.mlp.shared_experts.down_proj` (26), `model.layers.*.mlp.gate_proj` (1), `model.layers.*.mlp.up_proj` (1) | |
| - **Kept in BF16:** `lm_head` (1), `embed_tokens`, and the layer norms | |
| The same checkpoint serves DA8W4 (dynamic INT8 activations, INT4 weights) on Zen CPUs, which is the default in vLLM (`VLLM_CPU_INT4_W4A8=1`). Set `VLLM_CPU_INT4_W4A8=0` to force the W4A16 path. | |
| ```python | |
| from compressed_tensors.quantization import ( | |
| QuantizationArgs, QuantizationScheme, QuantizationStrategy, QuantizationType, | |
| ) | |
| import torch | |
| import transformers | |
| from transformers import AutoConfig, AutoTokenizer | |
| from datasets import load_dataset | |
| from llmcompressor import oneshot | |
| from llmcompressor.modifiers.gptq import GPTQModifier | |
| from llmcompressor.utils import load_context | |
| model_id = "deepseek-ai/DeepSeek-Coder-V2-Lite-Instruct" | |
| output_dir = "./DeepSeek-Coder-V2-Lite-Instruct-w4a16-llmcompressor" | |
| # Step 1: Load the BF16 model and tokenizer. | |
| model_cls = transformers.AutoModelForCausalLM | |
| with load_context(model_cls): | |
| model = model_cls.from_pretrained(model_id, dtype=torch.bfloat16, trust_remote_code=False) | |
| tokenizer = AutoTokenizer.from_pretrained(model_id, trust_remote_code=False) | |
| # Step 2: Calibration data. GPTQ needs real activations to build per-layer Hessians. | |
| ds = load_dataset("HuggingFaceH4/ultrachat_200k", split="train_sft[:128]") | |
| ds = ds.map(lambda ex: {"text": "\n".join(m["content"] for m in ex["messages"] if m.get("content"))}, | |
| remove_columns=ds.column_names) | |
| if not getattr(tokenizer, "pad_token", None): | |
| tokenizer.pad_token = tokenizer.eos_token | |
| ds = ds.map( | |
| lambda ex: tokenizer(ex["text"], truncation=True, max_length=2048, add_special_tokens=False), | |
| remove_columns=["text"], | |
| ) | |
| # Step 3: W4A16 GPTQ recipe. | |
| # group_size=64: 128 does not divide every quantized in_features. | |
| weights = QuantizationArgs( | |
| num_bits=4, type=QuantizationType.INT, symmetric=True, | |
| strategy=QuantizationStrategy.GROUP, group_size=64, | |
| ) | |
| recipe = GPTQModifier( | |
| targets="Linear", | |
| config_groups={"group_0": QuantizationScheme(targets=["Linear"], weights=weights)}, | |
| ignore=[ | |
| 'lm_head', | |
| 're:.*lm_head', | |
| ], | |
| ) | |
| # Step 4: One-shot quantize with calibration. | |
| oneshot(model=model, dataset=ds, recipe=recipe, max_seq_length=2048, | |
| num_calibration_samples=128, tokenizer=tokenizer) | |
| # Save in compressed-tensors format. | |
| model.save_pretrained(output_dir, save_compressed=True) | |
| tokenizer.save_pretrained(output_dir) | |
| ``` | |
| ## Quick Start | |
| ### Use with vLLM | |
| ```python | |
| from vllm import LLM, SamplingParams | |
| model = LLM( | |
| model="amd/DeepSeek-Coder-V2-Lite-Instruct-w4a16-llmcompressor", | |
| dtype="bfloat16", | |
| ) | |
| sampling_params = SamplingParams(temperature=0.7, max_tokens=256) | |
| outputs = model.generate(["Hello, how are you?"], sampling_params) | |
| print(outputs[0].outputs[0].text) | |
| ``` | |
| ### Requirements | |
| ``` | |
| torch==2.13.0+cpu | |
| zentorch==2.14.0.3 | |
| vllm==0.33.0 | |
| llmcompressor==0.14.0 | |
| ``` | |
| ### OpenMP Setup | |
| For optimal performance, set `LD_PRELOAD` with `libomp.so` (LLVM OpenMP) or `libiomp5.so` (Intel OpenMP): | |
| ```bash | |
| # Using LLVM OpenMP (llvmopenmp) | |
| export LD_PRELOAD=$(find /path/to/env -name "libomp.so" | head -1) | |
| # Or using Intel OpenMP (libiomp) | |
| export LD_PRELOAD=$(find /path/to/env -name "libiomp5.so" | head -1) | |
| ``` | |
| > **Note:** Set `LD_PRELOAD` before launching vLLM or any inference script. | |
| ## Evaluation | |
| The model was evaluated against the BF16 (unquantized) baseline on standard benchmarks using [lm-evaluation-harness](https://github.com/EleutherAI/lm-evaluation-harness) with the vLLM engine. | |
| | Benchmark | BF16 Baseline | W4A16 (this model) | Recovery | | |
| | --- | --- | --- | --- | | |
| | GSM8K (5-shot) | 0.5322 | 0.5542 | 104.13% | | |
| ### Evaluation Command | |
| ```bash | |
| lm_eval \ | |
| --model vllm \ | |
| --model_args pretrained=amd/DeepSeek-Coder-V2-Lite-Instruct-w4a16-llmcompressor,dtype=bfloat16 \ | |
| --tasks gsm8k \ | |
| --batch_size auto \ | |
| --trust_remote_code \ | |
| --num_fewshot 5 \ | |
| --apply_chat_template \ | |
| --log_samples \ | |
| --gen_kwargs "max_gen_toks=2048" \ | |
| --output_path . | |
| ``` | |
| ## Limitations | |
| - **Version Lock:** This model is compatible with ZenDNN v6.2.0 / ZenTorch v2.14.0.3 / PyTorch v2.13.0+cpu. It may not load correctly on other versions. | |
| - **CPU Only:** This model is optimized for AMD EPYC CPU inference via ZenDNN. It is not intended for GPU inference. | |
| - **Accuracy Trade-off:** 4-bit weight-only quantization is more aggressive than INT8 and trades some accuracy for a smaller memory footprint. | |
| ## License | |
| This model is distributed under the same license as the source model. See the [LICENSE](./LICENSE) file for details. | |
| Modifications copyright (c) 2026 Advanced Micro Devices, Inc. All rights reserved. |