Instructions to use devatar/quantized_Llama-3.1-8B-Instruct with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use devatar/quantized_Llama-3.1-8B-Instruct with Transformers:
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("text-generation", model="devatar/quantized_Llama-3.1-8B-Instruct") messages = [ {"role": "user", "content": "Who are you?"}, ] pipe(messages)# Load model directly from transformers import AutoTokenizer, AutoModelForCausalLM tokenizer = AutoTokenizer.from_pretrained("devatar/quantized_Llama-3.1-8B-Instruct") model = AutoModelForCausalLM.from_pretrained("devatar/quantized_Llama-3.1-8B-Instruct") 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=40) print(tokenizer.decode(outputs[0][inputs["input_ids"].shape[-1]:])) - Notebooks
- Google Colab
- Kaggle
- Local Apps
- vLLM
How to use devatar/quantized_Llama-3.1-8B-Instruct with vLLM:
Install from pip and serve model
# Install vLLM from pip: pip install vllm # Start the vLLM server: vllm serve "devatar/quantized_Llama-3.1-8B-Instruct" # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:8000/v1/chat/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "devatar/quantized_Llama-3.1-8B-Instruct", "messages": [ { "role": "user", "content": "What is the capital of France?" } ] }'Use Docker
docker model run hf.co/devatar/quantized_Llama-3.1-8B-Instruct
- SGLang
How to use devatar/quantized_Llama-3.1-8B-Instruct 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 "devatar/quantized_Llama-3.1-8B-Instruct" \ --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": "devatar/quantized_Llama-3.1-8B-Instruct", "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 "devatar/quantized_Llama-3.1-8B-Instruct" \ --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": "devatar/quantized_Llama-3.1-8B-Instruct", "messages": [ { "role": "user", "content": "What is the capital of France?" } ] }' - Docker Model Runner
How to use devatar/quantized_Llama-3.1-8B-Instruct with Docker Model Runner:
docker model run hf.co/devatar/quantized_Llama-3.1-8B-Instruct
Use Docker
docker model run hf.co/devatar/quantized_Llama-3.1-8B-Instruct馃殌 Quantized Llama-3.1-8B-Instruct Model
This is a 4-bit quantized version of the meta-llama/Llama-3.1-8B-Instruct model, optimized for efficient inference on resource-constrained environments like Google Colab's NVIDIA T4 GPU.
馃 Model Description
The model was quantized using the bitsandbytes library to reduce memory usage while maintaining performance for instruction-following tasks.
馃М Quantization Details
- Base Model:
meta-llama/Llama-3.1-8B-Instruct - Quantization Method: 4-bit (NormalFloat4, NF4) with double quantization
- Compute Dtype: float16
- Library:
bitsandbytes==0.43.3 - Framework:
transformers==4.45.1 - Hardware: NVIDIA T4 GPU (16GB VRAM) in Google Colab
- Date: Quantized on June 20, 2025
馃摝 Files Included
README.md: This fileconfig.json,pytorch_model.bin(or sharded checkpoints): Model weightsspecial_tokens_map.json,tokenizer.json,tokenizer_config.json: Tokenizer files
Usage
To load and use the quantized model for inference:
from transformers import AutoModelForCausalLM, AutoTokenizer, BitsAndBytesConfig, pipeline
import torch
# Define quantization configuration
quant_config = BitsAndBytesConfig(
load_in_4bit=True,
bnb_4bit_compute_dtype=torch.float16,
bnb_4bit_quant_type="nf4",
bnb_4bit_use_double_quant=True
)
# Load the quantized model
model = AutoModelForCausalLM.from_pretrained(
"your-username/quantized_Llama-3.1-8B-Instruct", # Replace with your Hugging Face repo ID
quantization_config=quant_config,
device_map="auto"
)
tokenizer = AutoTokenizer.from_pretrained("your-username/quantized_Llama-3.1-8B-Instruct")
# Create a text generation pipeline
generator = pipeline("text-generation", model=model, tokenizer=tokenizer)
# Perform inference
prompt = "Hello, how can I assist you today?"
output = generator(prompt, max_length=50, num_return_sequences=1)
print(output)
Quantization Process
The model was quantized in Google Colab using the following script:
from transformers import AutoModelForCausalLM, AutoTokenizer, BitsAndBytesConfig
import torch
from huggingface_hub import login
# Log in to Hugging Face
login() # Requires a Hugging Face token
# Define quantization configuration
quantization_config = BitsAndBytesConfig(
load_in_4bit=True,
bnb_4bit_compute_dtype=torch.float16,
bnb_4bit_quant_type="nf4",
bnb_4bit_use_double_quant=True
)
# Load and quantize the model
model = AutoModelForCausalLM.from_pretrained(
"meta-llama/Llama-3.1-8B-Instruct",
quantization_config=quantization_config,
device_map="auto"
)
tokenizer = AutoTokenizer.from_pretrained("meta-llama/Llama-3.1-8B-Instruct")
tokenizer.pad_token = tokenizer.eos_token if tokenizer.pad_token is None else tokenizer.pad_token
# Save the quantized model
quant_path = "/content/quantized_Llama-3.1-8B-Instruct"
model.save_pretrained(quant_path)
tokenizer.save_pretrained(quant_path)
Requirements
- Hardware: NVIDIA GPU with CUDA 11.4+ (e.g., T4, A100)
- Python: 3.10+
- Dependencies:
transformers==4.45.1bitsandbytes==0.43.3accelerate==0.33.0torch(with CUDA support)
Notes
- The quantized model is stored in
/content/quantized_Llama-3.1-8B-Instructin the Colab environment. - Due to Colab's ephemeral storage, consider pushing to Hugging Face Hub or saving to Google Drive for persistence.
- Access to the base model requires a Hugging Face token and approval from Meta AI.
License
This model inherits the license of the base model meta-llama/Llama-3.1-8B-Instruct. Refer to the original model card: Meta AI Llama 3.1-8B-Instruct.
Acknowledgments
- Created using Hugging Face Transformers and
bitsandbytesfor quantization. - Quantized in Google Colab with a T4 GPU on June 20, 2025.
- Downloads last month
- 5
Install from pip and serve model
# Install vLLM from pip: pip install vllm# Start the vLLM server: vllm serve "devatar/quantized_Llama-3.1-8B-Instruct"# Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:8000/v1/chat/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "devatar/quantized_Llama-3.1-8B-Instruct", "messages": [ { "role": "user", "content": "What is the capital of France?" } ] }'