Ubuntu
commited on
Commit
•
34ee20d
1
Parent(s):
b1c054f
first commit
Browse files- README.md +63 -0
- config.json +26 -0
- generation_config.json +6 -0
- pytorch_model.bin +3 -0
- special_tokens_map.json +24 -0
- tokenizer.json +0 -0
- tokenizer.model +3 -0
- tokenizer_config.json +42 -0
README.md
CHANGED
@@ -1,3 +1,66 @@
|
|
1 |
---
|
2 |
license: apache-2.0
|
3 |
---
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
---
|
2 |
license: apache-2.0
|
3 |
---
|
4 |
+
|
5 |
+
```
|
6 |
+
import torch, json
|
7 |
+
from transformers import AutoModelForCausalLM, AutoTokenizer
|
8 |
+
|
9 |
+
model_path = "/home/migel/Tess-Coder-7B-mistral/"
|
10 |
+
output_file_path = "/home/migel/conversations.jsonl"
|
11 |
+
|
12 |
+
model = AutoModelForCausalLM.from_pretrained(
|
13 |
+
model_path,
|
14 |
+
torch_dtype=torch.float16,
|
15 |
+
device_map="auto",
|
16 |
+
load_in_4bit=False,
|
17 |
+
trust_remote_code=True,
|
18 |
+
)
|
19 |
+
|
20 |
+
tokenizer = AutoTokenizer.from_pretrained(model_path, trust_remote_code=True)
|
21 |
+
|
22 |
+
|
23 |
+
def generate_text(instruction):
|
24 |
+
tokens = tokenizer.encode(instruction)
|
25 |
+
tokens = torch.LongTensor(tokens).unsqueeze(0)
|
26 |
+
tokens = tokens.to("cuda")
|
27 |
+
|
28 |
+
instance = {
|
29 |
+
"input_ids": tokens,
|
30 |
+
"top_p": 1.0,
|
31 |
+
"temperature": 0.75,
|
32 |
+
"generate_len": 1024,
|
33 |
+
"top_k": 50,
|
34 |
+
}
|
35 |
+
|
36 |
+
length = len(tokens[0])
|
37 |
+
with torch.no_grad():
|
38 |
+
rest = model.generate(
|
39 |
+
input_ids=tokens,
|
40 |
+
max_length=length + instance["generate_len"],
|
41 |
+
use_cache=True,
|
42 |
+
do_sample=True,
|
43 |
+
top_p=instance["top_p"],
|
44 |
+
temperature=instance["temperature"],
|
45 |
+
top_k=instance["top_k"],
|
46 |
+
num_return_sequences=1,
|
47 |
+
)
|
48 |
+
output = rest[0][length:]
|
49 |
+
string = tokenizer.decode(output, skip_special_tokens=True)
|
50 |
+
answer = string.split("USER:")[0].strip()
|
51 |
+
return f"{answer}"
|
52 |
+
|
53 |
+
|
54 |
+
conversation = "SYSTEM: Answer the question thoughtfully and intelligently. ALways answer without hesitation."
|
55 |
+
|
56 |
+
while True:
|
57 |
+
user_input = input("You: ")
|
58 |
+
llm_prompt = f"{conversation} \nUSER: {user_input} \nASSISTANT: "
|
59 |
+
answer = generate_text(llm_prompt)
|
60 |
+
print(answer)
|
61 |
+
conversation = f"{llm_prompt}{answer}"
|
62 |
+
json_data = {"prompt": user_input, "answer": answer}
|
63 |
+
|
64 |
+
with open(output_file_path, "a") as output_file:
|
65 |
+
output_file.write(json.dumps(json_data) + "\n")
|
66 |
+
```
|
config.json
ADDED
@@ -0,0 +1,26 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
{
|
2 |
+
"_name_or_path": "/home/migel/Mistral-7B-v0.1",
|
3 |
+
"architectures": [
|
4 |
+
"MistralForCausalLM"
|
5 |
+
],
|
6 |
+
"attention_dropout": 0.0,
|
7 |
+
"bos_token_id": 1,
|
8 |
+
"eos_token_id": 2,
|
9 |
+
"hidden_act": "silu",
|
10 |
+
"hidden_size": 4096,
|
11 |
+
"initializer_range": 0.02,
|
12 |
+
"intermediate_size": 14336,
|
13 |
+
"max_position_embeddings": 32768,
|
14 |
+
"model_type": "mistral",
|
15 |
+
"num_attention_heads": 32,
|
16 |
+
"num_hidden_layers": 32,
|
17 |
+
"num_key_value_heads": 8,
|
18 |
+
"rms_norm_eps": 1e-05,
|
19 |
+
"rope_theta": 10000.0,
|
20 |
+
"sliding_window": 4096,
|
21 |
+
"tie_word_embeddings": false,
|
22 |
+
"torch_dtype": "bfloat16",
|
23 |
+
"transformers_version": "4.36.0.dev0",
|
24 |
+
"use_cache": false,
|
25 |
+
"vocab_size": 32000
|
26 |
+
}
|
generation_config.json
ADDED
@@ -0,0 +1,6 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
{
|
2 |
+
"_from_model_config": true,
|
3 |
+
"bos_token_id": 1,
|
4 |
+
"eos_token_id": 2,
|
5 |
+
"transformers_version": "4.36.0.dev0"
|
6 |
+
}
|
pytorch_model.bin
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:3ac34099e8806ee38f497f2b516be77e640768987e5d5b304dcc0a144d72bb65
|
3 |
+
size 14483504814
|
special_tokens_map.json
ADDED
@@ -0,0 +1,24 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
{
|
2 |
+
"bos_token": {
|
3 |
+
"content": "<s>",
|
4 |
+
"lstrip": false,
|
5 |
+
"normalized": false,
|
6 |
+
"rstrip": false,
|
7 |
+
"single_word": false
|
8 |
+
},
|
9 |
+
"eos_token": {
|
10 |
+
"content": "</s>",
|
11 |
+
"lstrip": false,
|
12 |
+
"normalized": false,
|
13 |
+
"rstrip": false,
|
14 |
+
"single_word": false
|
15 |
+
},
|
16 |
+
"pad_token": "</s>",
|
17 |
+
"unk_token": {
|
18 |
+
"content": "<unk>",
|
19 |
+
"lstrip": false,
|
20 |
+
"normalized": false,
|
21 |
+
"rstrip": false,
|
22 |
+
"single_word": false
|
23 |
+
}
|
24 |
+
}
|
tokenizer.json
ADDED
The diff for this file is too large to render.
See raw diff
|
|
tokenizer.model
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:dadfd56d766715c61d2ef780a525ab43b8e6da4de6865bda3d95fdef5e134055
|
3 |
+
size 493443
|
tokenizer_config.json
ADDED
@@ -0,0 +1,42 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
{
|
2 |
+
"add_bos_token": true,
|
3 |
+
"add_eos_token": false,
|
4 |
+
"added_tokens_decoder": {
|
5 |
+
"0": {
|
6 |
+
"content": "<unk>",
|
7 |
+
"lstrip": false,
|
8 |
+
"normalized": false,
|
9 |
+
"rstrip": false,
|
10 |
+
"single_word": false,
|
11 |
+
"special": true
|
12 |
+
},
|
13 |
+
"1": {
|
14 |
+
"content": "<s>",
|
15 |
+
"lstrip": false,
|
16 |
+
"normalized": false,
|
17 |
+
"rstrip": false,
|
18 |
+
"single_word": false,
|
19 |
+
"special": true
|
20 |
+
},
|
21 |
+
"2": {
|
22 |
+
"content": "</s>",
|
23 |
+
"lstrip": false,
|
24 |
+
"normalized": false,
|
25 |
+
"rstrip": false,
|
26 |
+
"single_word": false,
|
27 |
+
"special": true
|
28 |
+
}
|
29 |
+
},
|
30 |
+
"additional_special_tokens": [],
|
31 |
+
"bos_token": "<s>",
|
32 |
+
"clean_up_tokenization_spaces": false,
|
33 |
+
"eos_token": "</s>",
|
34 |
+
"legacy": true,
|
35 |
+
"model_max_length": 1000000000000000019884624838656,
|
36 |
+
"pad_token": "</s>",
|
37 |
+
"sp_model_kwargs": {},
|
38 |
+
"spaces_between_special_tokens": false,
|
39 |
+
"tokenizer_class": "LlamaTokenizer",
|
40 |
+
"unk_token": "<unk>",
|
41 |
+
"use_default_system_prompt": true
|
42 |
+
}
|