Views
No views yet
1from transformers import AutoTokenizer, AutoModelForCausalLM
2import torch
3
4tokenizer = AutoTokenizer.from_pretrained("Aryan-401/Aryan-401/phi-3-mini-4k-instruct-finetune-guanaco-PEFT-Merged", trust_remote_code=True)
5model = AutoModelForCausalLM.from_pretrained("Aryan-401/Aryan-401/phi-3-mini-4k-instruct-finetune-guanaco-PEFT-Merged", trust_remote_code=True)
6
7# Prompt content: "hi"
8messages = [
9 {"role": "user", "content": "What is the Value of Pi?"}
10]
11device = torch.device('cuda' if torch.cuda.is_available() else 'cpu')
12
13model = model.to(device).eval()
14
15input_ids = tokenizer.apply_chat_template(conversation=messages, tokenize=True, add_generation_prompt=True, return_tensors='pt')
16output_ids = model.generate(input_ids.to(device), max_length= 1000)
17response = tokenizer.decode(output_ids[0][input_ids.shape[1]:], skip_special_tokens=True)
18
19print(response)
20# Pi is an irrational number, which means it cannot be expressed as a simple fraction and its decimal representation goes on forever without repeating. However, the value of Pi is approximately 3.14159. It is often rounded to 3.14 for simplicity in calculations.
21