Views
No views yet
pip install --upgrade transformersbfloat16:pip install torch1import transformers
2import torch
3
4# Define the model ID
5model_id = "prithivMLmods/Llama-3.1-5B-Instruct"
6
7# Set up the pipeline for text generation
8pipeline = transformers.pipeline(
9 "text-generation",
10 model=model_id,
11 model_kwargs={"torch_dtype": torch.bfloat16},
12 device_map="auto", # Use the best device available
13)
14
15# Define conversation messages
16messages = [
17 {"role": "system", "content": "You are a pirate chatbot who always responds in pirate speak!"},
18 {"role": "user", "content": "Who are you?"},
19]
20
21# Generate a response
22outputs = pipeline(
23 messages,
24 max_new_tokens=256,
25)
26
27# Print the generated response
28print(outputs[0]["generated_text"][-1])bfloat16 to optimize memory usage and performance.