| 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") |