Upload facebook_MobileLLM-Pro_1.py with huggingface_hub
Browse files- facebook_MobileLLM-Pro_1.py +13 -0
facebook_MobileLLM-Pro_1.py
CHANGED
|
@@ -15,6 +15,19 @@ try:
|
|
| 15 |
|
| 16 |
tokenizer = AutoTokenizer.from_pretrained("facebook/MobileLLM-Pro", trust_remote_code=True)
|
| 17 |
model = AutoModelForCausalLM.from_pretrained("facebook/MobileLLM-Pro", trust_remote_code=True)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 18 |
with open('facebook_MobileLLM-Pro_1.txt', 'w') as f:
|
| 19 |
f.write('Everything was good in facebook_MobileLLM-Pro_1.txt')
|
| 20 |
except Exception as e:
|
|
|
|
| 15 |
|
| 16 |
tokenizer = AutoTokenizer.from_pretrained("facebook/MobileLLM-Pro", trust_remote_code=True)
|
| 17 |
model = AutoModelForCausalLM.from_pretrained("facebook/MobileLLM-Pro", trust_remote_code=True)
|
| 18 |
+
messages = [
|
| 19 |
+
{"role": "user", "content": "Who are you?"},
|
| 20 |
+
]
|
| 21 |
+
inputs = tokenizer.apply_chat_template(
|
| 22 |
+
messages,
|
| 23 |
+
add_generation_prompt=True,
|
| 24 |
+
tokenize=True,
|
| 25 |
+
return_dict=True,
|
| 26 |
+
return_tensors="pt",
|
| 27 |
+
).to(model.device)
|
| 28 |
+
|
| 29 |
+
outputs = model.generate(**inputs, max_new_tokens=40)
|
| 30 |
+
print(tokenizer.decode(outputs[0][inputs["input_ids"].shape[-1]:]))
|
| 31 |
with open('facebook_MobileLLM-Pro_1.txt', 'w') as f:
|
| 32 |
f.write('Everything was good in facebook_MobileLLM-Pro_1.txt')
|
| 33 |
except Exception as e:
|