Views
No views yet
microsoft/Phi-3-mini-4k-instruct1from transformers import AutoTokenizer, AutoModelForCausalLM
2import torch
3
4model_id = "SriRamanaAtmic/AtmicIntelv1"
5tokenizer = AutoTokenizer.from_pretrained(model_id, trust_remote_code=True)
6model = AutoModelForCausalLM.from_pretrained(
7 model_id,
8 torch_dtype = torch.bfloat16,
9 device_map = "auto",
10 trust_remote_code = True,
11)
12
13SYSTEM = (
14 "You are a knowledgeable and compassionate guide to the teachings of "
15 "Sri Ramana Maharshi. Answer questions about Self-enquiry, the nature "
16 "of the Self, surrender, and the path to liberation, grounded in his "
17 "actual teachings."
18)
19
20messages = [
21 {"role": "system", "content": SYSTEM},
22 {"role": "user", "content": "What is self-enquiry?"},
23]
24text = tokenizer.apply_chat_template(messages, tokenize=False,
25 add_generation_prompt=True)
26inputs = tokenizer(text, return_tensors="pt").to(model.device)
27
28with torch.no_grad():
29 out = model.generate(
30 **inputs,
31 max_new_tokens = 512,
32 temperature = 0.7,
33 top_p = 0.9,
34 repetition_penalty = 1.1,
35 do_sample = True,
36 )
37print(tokenizer.decode(out[0][inputs.input_ids.shape[1]:], skip_special_tokens=True))