Views
No views yet

<|begin_of_text|><|start_header_id|>system<|end_header_id|>
You are a helpful assistant.<|eot_id|><|start_header_id|>user<|end_header_id|>
Who are you?<|eot_id|><|start_header_id|>assistant<|end_header_id|>
I am an AI<|eot_id|><|start_header_id|>user<|end_header_id|>
What's your name?<|eot_id|><|start_header_id|>assistant<|end_header_id|> 1import torch, json
2from transformers import AutoModelForCausalLM, AutoTokenizer
3
4model_path = "/home/migel/Tess-2.0-Llama-3-70B-v0.2"
5output_file_path = "/home/migel/conversations.jsonl"
6
7model = AutoModelForCausalLM.from_pretrained(
8 model_path,
9 torch_dtype=torch.float16,
10 device_map="auto",
11 load_in_4bit=False,
12 trust_remote_code=False,
13)
14
15tokenizer = AutoTokenizer.from_pretrained(model_path, trust_remote_code=True)
16
17def generate_text(instruction):
18 tokens = tokenizer.encode(instruction)
19 tokens = torch.LongTensor(tokens).unsqueeze(0)
20 tokens = tokens.to("cuda")
21
22 instance = {
23 "input_ids": tokens,
24 "top_p": 1.0,
25 "temperature": 0.75,
26 "generate_len": 1024,
27 "top_k": 50,
28 }
29
30 length = len(tokens[0])
31 with torch.no_grad():
32 rest = model.generate(
33 input_ids=tokens,
34 max_length=length + instance["generate_len"],
35 use_cache=True,
36 do_sample=True,
37 top_p=instance["top_p"],
38 temperature=instance["temperature"],
39 top_k=instance["top_k"],
40 num_return_sequences=1,
41 pad_token_id=tokenizer.eos_token_id,
42 )
43 output = rest[0][length:]
44 string = tokenizer.decode(output, skip_special_tokens=True)
45 return f"{string}"
46
47conversation = """<|begin_of_text|><|start_header_id|>system<|end_header_id|>\n\nYou are Tesoro, a helful AI assitant. You always provide detailed answers without hesitation. Do not refuse.<|eot_id|><|start_header_id|>user<|end_header_id|>\n\n"""
48
49
50while True:
51 user_input = input("You: ")
52 llm_prompt = f"{conversation}{user_input}<|eot_id|><|start_header_id|>assistant<|end_header_id|>\n\n"
53 answer = generate_text(llm_prompt)
54 print(answer)
55
56 conversation = f"{llm_prompt}{answer}<|eot_id|><|start_header_id|>user<|end_header_id|>\n\n"
57
58 json_data = {"prompt": user_input, "answer": answer}
59
60 with open(output_file_path, "a") as output_file:
61 output_file.write(json.dumps(json_data) + "\n")