Instructions to use Saktsant/DeepSeek-R1-Distill-Llama-8B-quantized.w4a16 with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use Saktsant/DeepSeek-R1-Distill-Llama-8B-quantized.w4a16 with Transformers:
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("text-generation", model="Saktsant/DeepSeek-R1-Distill-Llama-8B-quantized.w4a16") 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("Saktsant/DeepSeek-R1-Distill-Llama-8B-quantized.w4a16") model = AutoModelForCausalLM.from_pretrained("Saktsant/DeepSeek-R1-Distill-Llama-8B-quantized.w4a16", 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 Saktsant/DeepSeek-R1-Distill-Llama-8B-quantized.w4a16 with vLLM:
Install from pip and serve model
# Install vLLM from pip: pip install vllm # Start the vLLM server: vllm serve "Saktsant/DeepSeek-R1-Distill-Llama-8B-quantized.w4a16" # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:8000/v1/chat/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "Saktsant/DeepSeek-R1-Distill-Llama-8B-quantized.w4a16", "messages": [ { "role": "user", "content": "What is the capital of France?" } ] }'Use Docker
docker model run hf.co/Saktsant/DeepSeek-R1-Distill-Llama-8B-quantized.w4a16
- SGLang
How to use Saktsant/DeepSeek-R1-Distill-Llama-8B-quantized.w4a16 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 "Saktsant/DeepSeek-R1-Distill-Llama-8B-quantized.w4a16" \ --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": "Saktsant/DeepSeek-R1-Distill-Llama-8B-quantized.w4a16", "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 "Saktsant/DeepSeek-R1-Distill-Llama-8B-quantized.w4a16" \ --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": "Saktsant/DeepSeek-R1-Distill-Llama-8B-quantized.w4a16", "messages": [ { "role": "user", "content": "What is the capital of France?" } ] }' - Docker Model Runner
How to use Saktsant/DeepSeek-R1-Distill-Llama-8B-quantized.w4a16 with Docker Model Runner:
docker model run hf.co/Saktsant/DeepSeek-R1-Distill-Llama-8B-quantized.w4a16
DeepSeek-R1-Distill-Llama-8B-quantized.w4a16
Model Overview
- Model Architecture: LlamaForCausalLM
- Input: Text
- Output: Text
- Model Optimizations:
- Weight quantization: INT4
- Release Date: 2/1/2025
- Version: 1.0
- Model Developers: Neural Magic
Quantized version of DeepSeek-R1-Distill-Llama-8B.
Model Optimizations
This model was obtained by quantizing the weights of DeepSeek-R1-Distill-Llama-8B to INT4 data type. This optimization reduces the number of bits per parameter from 16 to 4, reducing the disk size and GPU memory requirements by approximately 75%.
Only the weights of the linear operators within transformers blocks are quantized. Weights are quantized using asymmetric per-group scheme, with group size 128. The GPTQ algorithm is applied for quantization, as implemented in the llm-compressor library.
Use with vLLM
This model can be deployed efficiently using the vLLM backend, as shown in the example below.
from transformers import AutoTokenizer
from vllm import LLM, SamplingParams
number_gpus = 1
model_name = "Saktsant/DeepSeek-R1-Distill-Llama-8B-quantized.w4a16"
tokenizer = AutoTokenizer.from_pretrained(model_name)
sampling_params = SamplingParams(temperature=0.6, max_tokens=256, stop_token_ids=[tokenizer.eos_token_id])
llm = LLM(model=model_name, tensor_parallel_size=number_gpus, trust_remote_code=True)
messages_list = [
[{"role": "user", "content": "Who are you? Please respond in pirate speak!"}],
]
prompt_token_ids = [tokenizer.apply_chat_template(messages, add_generation_prompt=True) for messages in messages_list]
outputs = llm.generate(prompt_token_ids=prompt_token_ids, sampling_params=sampling_params)
generated_text = [output.outputs[0].text for output in outputs]
print(generated_text)
vLLM also supports OpenAI-compatible serving. See the documentation for more details.
Creation
from transformers import AutoModelForCausalLM, AutoTokenizer
from llmcompressor.modifiers.awq import AWQModifier
from llmcompressor import oneshot
from datasets import load_dataset
model_stub = "deepseek-ai/DeepSeek-R1-Distill-Llama-8B"
model_name = model_stub.split("/")[-1]
num_samples = 512
max_seq_len = 2048
tokenizer = AutoTokenizer.from_pretrained(model_stub)
model = AutoModelForCausalLM.from_pretrained(
model_stub,
device_map="auto",
torch_dtype="auto",
)
def preprocess_fn(example):
return {
"text": tokenizer.apply_chat_template(
example["messages"], add_generation_prompt=False, tokenize=False
)
}
ds = load_dataset("neuralmagic/LLM_compression_calibration", split="train")
ds = ds.map(preprocess_fn)
recipe = [
AWQModifier(ignore=["lm_head"], scheme="W4A16_ASYM", targets=["Linear"]),
]
oneshot(
model=model,
dataset=ds,
recipe=recipe,
max_seq_length=max_seq_len,
num_calibration_samples=num_samples,
)
save_path = model_name + "-quantized.w4a16"
model.save_pretrained(save_path)
tokenizer.save_pretrained(save_path)
- Downloads last month
- 19
Model tree for Saktsant/DeepSeek-R1-Distill-Llama-8B-quantized.w4a16
Base model
deepseek-ai/DeepSeek-R1-Distill-Llama-8B