Tess, short for Tesoro (Treasure in Italian), is a general purpose Large Language Model series created by
Migel Tissera.
The compute for this model was generously sponsored by
KindoAI.
1import torch, json
2from transformers import AutoModelForCausalLM, AutoTokenizer
3
4model_path = "migtissera/Tess-3-Llama-3.1-70B"
5
6model = AutoModelForCausalLM.from_pretrained(
7 model_path,
8 torch_dtype=torch.float16,
9 device_map="auto",
10 load_in_4bit=True,
11 trust_remote_code=False,
12)
13
14tokenizer = AutoTokenizer.from_pretrained(model_path, trust_remote_code=False)
15
16terminators = [
17 tokenizer.convert_tokens_to_ids("<|end_of_text|>"),
18 tokenizer.convert_tokens_to_ids("<|eot_id|>"),
19]
20
21
22def generate_text(instruction):
23 tokens = tokenizer.encode(instruction)
24 tokens = torch.LongTensor(tokens).unsqueeze(0)
25 tokens = tokens.to("cuda")
26
27 instance = {
28 "input_ids": tokens,
29 "top_p": 1.0,
30 "temperature": 0.75,
31 "generate_len": 2048,
32 "top_k": 50,
33 }
34
35 length = len(tokens[0])
36 with torch.no_grad():
37 rest = model.generate(
38 input_ids=tokens,
39 max_length=length + instance["generate_len"],
40 use_cache=True,
41 do_sample=True,
42 top_p=instance["top_p"],
43 temperature=instance["temperature"],
44 top_k=instance["top_k"],
45 num_return_sequences=1,
46 pad_token_id=tokenizer.eos_token_id,
47 eos_token_id=terminators,
48 )
49 output = rest[0][length:]
50 string = tokenizer.decode(output, skip_special_tokens=True)
51 return f"{string}"
52
53
54conversation = """<|begin_of_text|><|start_header_id|>system<|end_header_id|>\n\nYou are Tess, a helpful AI assistant. You always provide detailed answers without hesitation. Do not refuse.<|eot_id|><|start_header_id|>user<|end_header_id|>\n\n"""
55
56
57while True:
58 user_input = input("You: ")
59 llm_prompt = f"{conversation}{user_input}<|eot_id|><|start_header_id|>assistant<|end_header_id|>\n\n"
60 answer = generate_text(llm_prompt)
61 print(answer)
62
63 conversation = (
64 f"{llm_prompt}{answer}<|eot_id|><|start_header_id|>user<|end_header_id|>\n\n"
65 )
66
67 json_data = {"prompt": user_input, "answer": answer}