Pankaj Mathur
commited on
Commit
•
45eb5a1
1
Parent(s):
bb961f4
Update README.md
Browse files
README.md
CHANGED
@@ -52,38 +52,41 @@ tokenizer = LlamaTokenizer.from_pretrained(model_path)
|
|
52 |
model = LlamaForCausalLM.from_pretrained(
|
53 |
model_path, torch_dtype=torch.float16, device_map='auto',
|
54 |
)
|
55 |
-
# check more details here https://github.com/openlm-research/open_llama
|
56 |
-
tokenizer.bos_token_id, tokenizer.eos_token_id = 1,2
|
57 |
|
58 |
-
# same prompt as provided by Orca Research Paper
|
59 |
-
system = 'You are an AI assistant. User will you give you a task. Your goal is to complete the task as faithfully as you can. While performing the task think step-by-step and justify your steps.'
|
60 |
-
instruction = 'Use the given data to calculate the median.'
|
61 |
-
input = '[7, 3, 8, 2, 10]'
|
62 |
|
63 |
-
|
64 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
65 |
|
66 |
-
|
67 |
-
tokens = torch.LongTensor(tokens).unsqueeze(0)
|
68 |
-
tokens = tokens.to('cuda')
|
69 |
|
70 |
-
|
71 |
-
|
72 |
-
|
73 |
-
with torch.no_grad():
|
74 |
-
rest = model.generate(
|
75 |
input_ids=tokens,
|
76 |
max_length=length+instance['generate_len'],
|
77 |
use_cache=True,
|
78 |
do_sample=True,
|
79 |
-
top_p=instance['top_p'],
|
80 |
-
|
81 |
-
|
82 |
-
|
83 |
-
|
84 |
-
|
85 |
-
|
86 |
-
|
|
|
|
|
|
|
|
|
87 |
|
88 |
```
|
89 |
|
@@ -93,3 +96,19 @@ Next Goals:
|
|
93 |
3) Try better GPU for training, couldn't get 8xA100 (40GB), I guess they are in hot demand now.
|
94 |
4) Provide more options for Text generation UI. (may be https://github.com/oobabooga/text-generation-webui)
|
95 |
6) Provide 4bit GGML/GPTQ quantized model (may be [TheBloke](https://huggingface.co/TheBloke) can help here)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
52 |
model = LlamaForCausalLM.from_pretrained(
|
53 |
model_path, torch_dtype=torch.float16, device_map='auto',
|
54 |
)
|
|
|
|
|
55 |
|
|
|
|
|
|
|
|
|
56 |
|
57 |
+
#generate text function
|
58 |
+
def generate_text(system, instruction, input=None):
|
59 |
+
|
60 |
+
if input:
|
61 |
+
prompt = f"### System:\n{system}\n\n#\n\n### User:\n{instruction}\n\n### Input:\n{input}\n\n### Response:\n"
|
62 |
+
else:
|
63 |
+
prompt = f"### System:\n{system}\n\n#\n\n### User:\n{instruction}\n\n### Response:\n"
|
64 |
+
|
65 |
+
tokens = tokenizer.encode(prompt)
|
66 |
+
tokens = torch.LongTensor(tokens).unsqueeze(0)
|
67 |
+
tokens = tokens.to('cuda')
|
68 |
|
69 |
+
instance = {'input_ids': tokens,'top_p': 1.0, 'temperature':0.7, 'generate_len': 1024}
|
|
|
|
|
70 |
|
71 |
+
length = len(tokens[0])
|
72 |
+
with torch.no_grad():
|
73 |
+
rest = model.generate(
|
|
|
|
|
74 |
input_ids=tokens,
|
75 |
max_length=length+instance['generate_len'],
|
76 |
use_cache=True,
|
77 |
do_sample=True,
|
78 |
+
top_p=instance['top_p'],
|
79 |
+
temperature=instance['temperature']
|
80 |
+
)
|
81 |
+
output = rest[0][length:]
|
82 |
+
string = tokenizer.decode(output, skip_special_tokens=True)
|
83 |
+
print(f'[!] Response: {string}')
|
84 |
+
|
85 |
+
# same prompt as provided by Orca Research Paper
|
86 |
+
system = 'You are an AI assistant. User will you give you a task. Your goal is to complete the task as faithfully as you can. While performing the task think step-by-step and justify your steps.'
|
87 |
+
instruction = 'Use the given data to calculate the median.'
|
88 |
+
input = '[7, 3, 8, 2, 10]'
|
89 |
+
generate_text(system, instruction, input)
|
90 |
|
91 |
```
|
92 |
|
|
|
96 |
3) Try better GPU for training, couldn't get 8xA100 (40GB), I guess they are in hot demand now.
|
97 |
4) Provide more options for Text generation UI. (may be https://github.com/oobabooga/text-generation-webui)
|
98 |
6) Provide 4bit GGML/GPTQ quantized model (may be [TheBloke](https://huggingface.co/TheBloke) can help here)
|
99 |
+
|
100 |
+
|
101 |
+
**P.S. I am #opentowork and #collaboration, please reach out to me at [email protected]**
|
102 |
+
|
103 |
+
|
104 |
+
Reference:
|
105 |
+
If you found [alpaca_orca_open_llama_3b](psmathur/alpaca_orca_open_llama_3b) useful in your research or applications, please kindly cite using the following BibTeX:
|
106 |
+
|
107 |
+
@misc{alpaca_orca_open_llama_3b,
|
108 |
+
author = {Pankaj Mathur},
|
109 |
+
title = {alpaca_orca_open_llama_3b: A custom explain tuned Alpaca Model Based On OpenLLaMA},
|
110 |
+
year = {2023},
|
111 |
+
publisher = {GitHub},
|
112 |
+
journal = {GitHub repository},
|
113 |
+
howpublished = {\url{https://github.com/pankajarm/alpaca_orca_open_llama_3b}},
|
114 |
+
}
|