File size: 1,102 Bytes
0efa1fa
 
731de2e
 
 
 
0efa1fa
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
8e31cc1
 
 
 
 
 
 
 
 
 
0efa1fa
 
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
from transformers import AutoModelForCausalLM, AutoTokenizer
import torch
model = AutoModelForCausalLM.from_pretrained(
    "Girinath11/recursive-language-model-48m",
    trust_remote_code=True
)
tokenizer = AutoTokenizer.from_pretrained("gpt2")
tokenizer.pad_token = tokenizer.eos_token
device = "cuda" if torch.cuda.is_available() else "cpu"
model = model.to(device)
model.eval()
print(f"Model loaded on {device}\n")
prompts = [
    "The future of artificial intelligence",
    "Once upon a time",
    "The key to success is"
]
for prompt in prompts:
    print(f"Prompt: {prompt}")
    inputs = tokenizer.encode(prompt, return_tensors="pt").to(device)
    with torch.no_grad():
        outputs = model.generate(
        input_ids,
        max_new_tokens=60,          
        temperature=0.7,             
        top_p=0.9,
        top_k=50,                   
        repetition_penalty=1.2,      
        no_repeat_ngram_size=3,      
        do_sample=True,
        pad_token_id=tokenizer.eos_token_id
    )
    text = tokenizer.decode(outputs[0], skip_special_tokens=True)
    print(f"{text}\n")