Martin Fixman
commited on
Commit
•
043b826
1
Parent(s):
1b778aa
Adding old falcon file.
Browse files
falcon.py
ADDED
@@ -0,0 +1,33 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import logging
|
2 |
+
logging.getLogger("transformers.tokenization_utils_base").setLevel(logging.ERROR)
|
3 |
+
logging.getLogger("transformers.modeling_utils").setLevel(logging.ERROR)
|
4 |
+
logging.basicConfig(
|
5 |
+
format='[%(asctime)s] %(message)s',
|
6 |
+
level=logging.INFO,
|
7 |
+
datefmt='%Y-%m-%d %H:%M:%S'
|
8 |
+
)
|
9 |
+
|
10 |
+
from transformers import AutoModelForCausalLM, AutoTokenizer
|
11 |
+
|
12 |
+
def main():
|
13 |
+
model_name = 'tiiuae/falcon-7b-instruct'
|
14 |
+
|
15 |
+
logging.info(f'Getting pretrained model {model_name}')
|
16 |
+
model = AutoModelForCausalLM.from_pretrained(model_name).to('cuda')
|
17 |
+
|
18 |
+
logging.info(f'Getting pretrained tokenizer {model_name}')
|
19 |
+
tokenizer = AutoTokenizer.from_pretrained(model_name).to('cuda')
|
20 |
+
|
21 |
+
logging.info('Tokenizing input')
|
22 |
+
inputs = tokenizer.encode('Where was Emmanuel Macron born?', return_tensors = 'pt').to('cuda')
|
23 |
+
|
24 |
+
logging.info('Generating output')
|
25 |
+
outputs = model.generate(inputs, max_length = 300, num_return_sequences = 1)
|
26 |
+
|
27 |
+
logging.info('Decoding result')
|
28 |
+
result = tokenizer.decode(outputs[0], skip_special_tokens = True)
|
29 |
+
|
30 |
+
print(result)
|
31 |
+
|
32 |
+
if __name__ == '__main__':
|
33 |
+
main()
|