migtissera
commited on
Commit
•
aed2c88
1
Parent(s):
1c706e3
Update README.md
Browse files
README.md
CHANGED
@@ -1,3 +1,84 @@
|
|
1 |
---
|
2 |
license: apache-2.0
|
|
|
|
|
|
|
|
|
3 |
---
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
---
|
2 |
license: apache-2.0
|
3 |
+
pipeline_tag: text-generation
|
4 |
+
language:
|
5 |
+
- en
|
6 |
+
library_name: transformers
|
7 |
---
|
8 |
+
## Example Usage
|
9 |
+
|
10 |
+
### Prompt format:
|
11 |
+
|
12 |
+
```
|
13 |
+
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.
|
14 |
+
USER: How is insulin synthesized?
|
15 |
+
ASSISTANT:
|
16 |
+
```
|
17 |
+
|
18 |
+
### Code example:
|
19 |
+
|
20 |
+
```python
|
21 |
+
import torch, json
|
22 |
+
from transformers import AutoModelForCausalLM, AutoTokenizer
|
23 |
+
|
24 |
+
model_path = "migtissera/SynthIA-7B-v2.0"
|
25 |
+
output_file_path = "./SynthIA-7B-v2.0-conversations.jsonl"
|
26 |
+
|
27 |
+
model = AutoModelForCausalLM.from_pretrained(
|
28 |
+
model_path,
|
29 |
+
torch_dtype=torch.float16,
|
30 |
+
device_map="auto",
|
31 |
+
load_in_8bit=False,
|
32 |
+
trust_remote_code=True,
|
33 |
+
)
|
34 |
+
|
35 |
+
tokenizer = AutoTokenizer.from_pretrained(model_path, trust_remote_code=True)
|
36 |
+
|
37 |
+
|
38 |
+
def generate_text(instruction):
|
39 |
+
tokens = tokenizer.encode(instruction)
|
40 |
+
tokens = torch.LongTensor(tokens).unsqueeze(0)
|
41 |
+
tokens = tokens.to("cuda")
|
42 |
+
|
43 |
+
instance = {
|
44 |
+
"input_ids": tokens,
|
45 |
+
"top_p": 1.0,
|
46 |
+
"temperature": 0.75,
|
47 |
+
"generate_len": 1024,
|
48 |
+
"top_k": 50,
|
49 |
+
}
|
50 |
+
|
51 |
+
length = len(tokens[0])
|
52 |
+
with torch.no_grad():
|
53 |
+
rest = model.generate(
|
54 |
+
input_ids=tokens,
|
55 |
+
max_length=length + instance["generate_len"],
|
56 |
+
use_cache=True,
|
57 |
+
do_sample=True,
|
58 |
+
top_p=instance["top_p"],
|
59 |
+
temperature=instance["temperature"],
|
60 |
+
top_k=instance["top_k"],
|
61 |
+
num_return_sequences=1,
|
62 |
+
)
|
63 |
+
output = rest[0][length:]
|
64 |
+
string = tokenizer.decode(output, skip_special_tokens=True)
|
65 |
+
answer = string.split("USER:")[0].strip()
|
66 |
+
return f"{answer}"
|
67 |
+
|
68 |
+
|
69 |
+
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."
|
70 |
+
|
71 |
+
|
72 |
+
while True:
|
73 |
+
user_input = input("You: ")
|
74 |
+
llm_prompt = f"{conversation} \nUSER: {user_input} \nASSISTANT: "
|
75 |
+
answer = generate_text(llm_prompt)
|
76 |
+
print(answer)
|
77 |
+
conversation = f"{llm_prompt}{answer}"
|
78 |
+
json_data = {"prompt": user_input, "answer": answer}
|
79 |
+
|
80 |
+
## Save your conversation
|
81 |
+
with open(output_file_path, "a") as output_file:
|
82 |
+
output_file.write(json.dumps(json_data) + "\n")
|
83 |
+
|
84 |
+
```
|