File size: 1,016 Bytes
46c8cfc
 
b02a8ce
d4b6d9f
46c8cfc
0710e36
46c8cfc
 
 
 
d4b6d9f
46c8cfc
d4b6d9f
 
46c8cfc
 
d142b67
46c8cfc
 
 
d4b6d9f
 
 
 
 
 
46c8cfc
 
 
 
 
 
0710e36
 
46c8cfc
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
# Install necessary libraries
# !pip install transformers

from transformers import AutoTokenizer, AutoModelForCausalLM, pipeline
import torch

# Model and prompt details
model_name = "mlabonne/llama-2-7b-guanaco"
prompt = "What is a large language model?"

# Load tokenizer and model
tokenizer = AutoTokenizer.from_pretrained(model_name)
model = AutoModelForCausalLM.from_pretrained(
    model_name,
    torch_dtype=torch.float16,
    device_map="auto",
    offload_folder="offload/folder"  # Replace with the path to the offload folder
)

# Generate text using the provided prompt
sequences = pipeline(
    "text-generation",
    model=model,
    tokenizer=tokenizer,
    device=0,  # Change to the appropriate device index or "cuda" if using GPU
)(
    f'<s>[INST] {prompt} [/INST]',
    do_sample=True,
    top_k=10,
    num_return_sequences=1,
    eos_token_id=tokenizer.eos_token_id,
    max_length=200,
)

# Print the generated text
for seq in sequences:
    print(f"Generated Text: {seq['generated_text']}")