Views
No views yet
meta-llama/Meta-Llama-3.1-8B-Instruct model within the multi-modal AI system developed in this Colab environment.Llama-3.1-8B-Instruct is a powerful 8-billion parameter large language model from Meta, fine-tuned for instruction following. It excels at a wide range of natural language processing tasks, including question answering, summarization, creative writing, and conversational AI. In this setup, it's loaded in a 4-bit quantized format for memory efficiency, making it suitable for deployment in resource-constrained environments like Colab GPUs.meta-llama/Meta-Llama-3.1-8B-Instructunsloth.FastLanguageModel for optimized performance and memory usage.unsloth library. Below are Python code examples demonstrating how to load the model and perform inference.unsloth and torch are installed and the necessary environment setup is complete:1# Install unsloth and other dependencies (if not already installed)
2!pip install unsloth[colab-new] accelerate bitsandbytes peft transformers
3
4import torch
5from unsloth import FastLanguageModel
6from transformers import AutoTokenizer
7
8# Load the model and tokenizer
9model_name = "meta-llama/Meta-Llama-3.1-8B-Instruct" # Or your pushed model path, e.g., "Google Colab AI/llama-3.1-colab"
10max_seq_length = 2048
11dtype = None # Use None for auto detect or torch.bfloat16 for Ampere+ GPUs
12load_in_4bit = True
13
14model, tokenizer = FastLanguageModel.from_pretrained(
15 model_name = model_name,
16 max_seq_length = max_seq_length,
17 dtype = dtype,
18 load_in_4bit = load_in_4bit,
19)
20
21# Example function to generate text (similar to the wrapper used in the notebook)
22def generate_text_response(prompt: str) -> str:
23 inputs = tokenizer(prompt, return_tensors="pt").to("cuda")
24 outputs = model.generate(**inputs, max_new_tokens=256, use_cache=True)
25 response = tokenizer.decode(outputs[0], skip_special_tokens=True)
26 return response
27
28# Perform inference
29user_prompt = "Explain the concept of quantum entanglement in simple terms."
30response = generate_text_response(user_prompt)
31print("
32User Prompt:", user_prompt)
33print("AI Response:", response)unsloth library provides optimized methods for efficient fine-tuning.