migtissera commited on
Commit
1428989
1 Parent(s): 53036b5

Update README.md

Browse files
Files changed (1) hide show
  1. README.md +85 -0
README.md CHANGED
@@ -1,3 +1,88 @@
1
  ---
2
  license: llama2
3
  ---
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
  ---
2
  license: llama2
3
  ---
4
+
5
+ <br>
6
+
7
+ ![Synthia](https://huggingface.co/migtissera/Synthia-13B/resolve/main/Synthia.jpeg)
8
+
9
+ <br>
10
+
11
+
12
+ ## Example Usage
13
+
14
+ ### Prompt format:
15
+
16
+ ```
17
+ SYSTEM: Elaborate on the topic using a Tree of Thoughts and backtrack when necessary to construct a clear, cohesive Chain of Thought reasoning. Always answer without hesitation.
18
+ USER: How is a rocket launched from the surface of the earth to Low Earth Orbit?
19
+ ASSISTANT:
20
+ ```
21
+
22
+ ### Code example:
23
+
24
+ ```python
25
+ import torch, json
26
+ from transformers import AutoModelForCausalLM, AutoTokenizer
27
+
28
+ model_path = "migtissera/Synthia-70B-v1.5"
29
+ output_file_path = "./Synthia-70B-v1.5-conversations.jsonl"
30
+
31
+ model = AutoModelForCausalLM.from_pretrained(
32
+ model_path,
33
+ torch_dtype=torch.float16,
34
+ device_map="auto",
35
+ load_in_8bit=False,
36
+ trust_remote_code=True,
37
+ )
38
+
39
+ tokenizer = AutoTokenizer.from_pretrained(model_path, trust_remote_code=True)
40
+
41
+
42
+ def generate_text(instruction):
43
+ tokens = tokenizer.encode(instruction)
44
+ tokens = torch.LongTensor(tokens).unsqueeze(0)
45
+ tokens = tokens.to("cuda")
46
+
47
+ instance = {
48
+ "input_ids": tokens,
49
+ "top_p": 1.0,
50
+ "temperature": 0.75,
51
+ "generate_len": 1024,
52
+ "top_k": 50,
53
+ }
54
+
55
+ length = len(tokens[0])
56
+ with torch.no_grad():
57
+ rest = model.generate(
58
+ input_ids=tokens,
59
+ max_length=length + instance["generate_len"],
60
+ use_cache=True,
61
+ do_sample=True,
62
+ top_p=instance["top_p"],
63
+ temperature=instance["temperature"],
64
+ top_k=instance["top_k"],
65
+ num_return_sequences=1,
66
+ )
67
+ output = rest[0][length:]
68
+ string = tokenizer.decode(output, skip_special_tokens=True)
69
+ answer = string.split("USER:")[0].strip()
70
+ return f"{answer}"
71
+
72
+
73
+ conversation = f"SYSTEM: Elaborate on the topic using a Tree of Thoughts and backtrack when necessary to construct a clear, cohesive Chain of Thought reasoning. Always answer without hesitation."
74
+
75
+
76
+ while True:
77
+ user_input = input("You: ")
78
+ llm_prompt = f"{conversation} \nUSER: {user_input} \nASSISTANT: "
79
+ answer = generate_text(llm_prompt)
80
+ print(answer)
81
+ conversation = f"{llm_prompt}{answer}"
82
+ json_data = {"prompt": user_input, "answer": answer}
83
+
84
+ ## Save your conversation
85
+ with open(output_file_path, "a") as output_file:
86
+ output_file.write(json.dumps(json_data) + "\n")
87
+
88
+ ```