Views
No views yet
1import torch
2from transformers import AutoModelForCausalLM, AutoTokenizer, pipeline
3
4torch.random.manual_seed(0)
5model = AutoModelForCausalLM.from_pretrained(
6 "Majipa/phi-3-samhog-psychology-6k-v1",
7 device_map="cuda",
8 torch_dtype="auto",
9 trust_remote_code=True,
10)
11
12tokenizer = AutoTokenizer.from_pretrained("microsoft/Phi-3-mini-4k-instruct")
13
14messages = [
15 {"role": "system", "content": "You are a helpful AI assistant."},
16 {"role": "user", "content": "Can you provide ways to eat combinations of bananas and dragonfruits?"},
17 {"role": "assistant", "content": "Sure! Here are some ways to eat bananas and dragonfruits together: 1. Banana and dragonfruit smoothie: Blend bananas and dragonfruits together with some milk and honey. 2. Banana and dragonfruit salad: Mix sliced bananas and dragonfruits together with some lemon juice and honey."},
18 {"role": "user", "content": "What about solving an 2x + 3 = 7 equation?"},
19]
20
21pipe = pipeline(
22 "text-generation",
23 model=model,
24 tokenizer=tokenizer,
25)
26
27generation_args = {
28 "max_new_tokens": 500,
29 "return_full_text": False,
30 "temperature": 0.0,
31 "do_sample": False,
32}
33
34output = pipe(messages, **generation_args)
35print(output[0]['generated_text'])
36