update readme
Browse files
README.md
CHANGED
@@ -104,14 +104,27 @@ Alan Turing was a British mathematician and computer scientist who made importan
|
|
104 |
## CPU Inference
|
105 |
|
106 |
```python
|
|
|
|
|
107 |
from transformers import AutoTokenizer, AutoModelForCausalLM
|
|
|
|
|
|
|
|
|
|
|
|
|
108 |
# init
|
109 |
tokenizer = AutoTokenizer.from_pretrained("togethercomputer/RedPajama-INCITE-Chat-3B-v1")
|
110 |
model = AutoModelForCausalLM.from_pretrained("togethercomputer/RedPajama-INCITE-Chat-3B-v1", torch_dtype=torch.bfloat16)
|
111 |
# infer
|
112 |
-
|
113 |
-
|
114 |
-
|
|
|
|
|
|
|
|
|
|
|
115 |
print(output_str)
|
116 |
"""
|
117 |
Alan Turing was a British mathematician and computer scientist. He is widely regarded as the father of computer science and artificial intelligence. He was a pioneer in the field of computer science and artificial intelligence, and his work has had a significant impact on the development of computing technology.
|
|
|
104 |
## CPU Inference
|
105 |
|
106 |
```python
|
107 |
+
import torch
|
108 |
+
import transformers
|
109 |
from transformers import AutoTokenizer, AutoModelForCausalLM
|
110 |
+
|
111 |
+
MIN_TRANSFORMERS_VERSION = '4.25.1'
|
112 |
+
|
113 |
+
# check transformers version
|
114 |
+
assert transformers.__version__ >= MIN_TRANSFORMERS_VERSION, f'Please upgrade transformers to version {MIN_TRANSFORMERS_VERSION} or higher.'
|
115 |
+
|
116 |
# init
|
117 |
tokenizer = AutoTokenizer.from_pretrained("togethercomputer/RedPajama-INCITE-Chat-3B-v1")
|
118 |
model = AutoModelForCausalLM.from_pretrained("togethercomputer/RedPajama-INCITE-Chat-3B-v1", torch_dtype=torch.bfloat16)
|
119 |
# infer
|
120 |
+
prompt = "<human>: Who is Alan Turing?\n<bot>:"
|
121 |
+
inputs = tokenizer(prompt, return_tensors='pt').to(model.device)
|
122 |
+
input_length = inputs.input_ids.shape[1]
|
123 |
+
outputs = model.generate(
|
124 |
+
**inputs, max_new_tokens=128, do_sample=True, temperature=0.7, top_p=0.7, top_k=50, return_dict_in_generate=True
|
125 |
+
)
|
126 |
+
token = outputs.sequences[0, input_length:]
|
127 |
+
output_str = tokenizer.decode(token)
|
128 |
print(output_str)
|
129 |
"""
|
130 |
Alan Turing was a British mathematician and computer scientist. He is widely regarded as the father of computer science and artificial intelligence. He was a pioneer in the field of computer science and artificial intelligence, and his work has had a significant impact on the development of computing technology.
|