Views
No views yet
meta-llama/Llama-3.1-8B-Instruct model, optimized for efficient inference on resource-constrained environments like Google Colab's NVIDIA T4 GPU.bitsandbytes library to reduce memory usage while maintaining performance for instruction-following tasks.meta-llama/Llama-3.1-8B-Instructbitsandbytes==0.43.3transformers==4.45.1README.md: This fileconfig.json, pytorch_model.bin (or sharded checkpoints): Model weightsspecial_tokens_map.json, tokenizer.json, tokenizer_config.json: Tokenizer files1from transformers import AutoModelForCausalLM, AutoTokenizer, BitsAndBytesConfig, pipeline
2import torch
3
4# Define quantization configuration
5quant_config = BitsAndBytesConfig(
6 load_in_4bit=True,
7 bnb_4bit_compute_dtype=torch.float16,
8 bnb_4bit_quant_type="nf4",
9 bnb_4bit_use_double_quant=True
10)
11
12# Load the quantized model
13model = AutoModelForCausalLM.from_pretrained(
14 "your-username/quantized_Llama-3.1-8B-Instruct", # Replace with your Hugging Face repo ID
15 quantization_config=quant_config,
16 device_map="auto"
17)
18tokenizer = AutoTokenizer.from_pretrained("your-username/quantized_Llama-3.1-8B-Instruct")
19
20# Create a text generation pipeline
21generator = pipeline("text-generation", model=model, tokenizer=tokenizer)
22
23# Perform inference
24prompt = "Hello, how can I assist you today?"
25output = generator(prompt, max_length=50, num_return_sequences=1)
26print(output)1from transformers import AutoModelForCausalLM, AutoTokenizer, BitsAndBytesConfig
2import torch
3from huggingface_hub import login
4
5# Log in to Hugging Face
6login() # Requires a Hugging Face token
7
8# Define quantization configuration
9quantization_config = BitsAndBytesConfig(
10 load_in_4bit=True,
11 bnb_4bit_compute_dtype=torch.float16,
12 bnb_4bit_quant_type="nf4",
13 bnb_4bit_use_double_quant=True
14)
15
16# Load and quantize the model
17model = AutoModelForCausalLM.from_pretrained(
18 "meta-llama/Llama-3.1-8B-Instruct",
19 quantization_config=quantization_config,
20 device_map="auto"
21)
22tokenizer = AutoTokenizer.from_pretrained("meta-llama/Llama-3.1-8B-Instruct")
23tokenizer.pad_token = tokenizer.eos_token if tokenizer.pad_token is None else tokenizer.pad_token
24
25# Save the quantized model
26quant_path = "/content/quantized_Llama-3.1-8B-Instruct"
27model.save_pretrained(quant_path)
28tokenizer.save_pretrained(quant_path)transformers==4.45.1bitsandbytes==0.43.3accelerate==0.33.0torch (with CUDA support)/content/quantized_Llama-3.1-8B-Instruct in the Colab environment.meta-llama/Llama-3.1-8B-Instruct. Refer to the original model card: Meta AI Llama 3.1-8B-Instruct.bitsandbytes for quantization.