Upload HuggingFaceTB_SmolLM3-3B_1.py with huggingface_hub
Browse files
HuggingFaceTB_SmolLM3-3B_1.py
ADDED
@@ -0,0 +1,42 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
# /// script
|
2 |
+
# requires-python = ">=3.12"
|
3 |
+
# dependencies = [
|
4 |
+
# "transformers",
|
5 |
+
# "torch",
|
6 |
+
# ]
|
7 |
+
# ///
|
8 |
+
|
9 |
+
try:
|
10 |
+
# prepare the model input
|
11 |
+
prompt = "Give me a brief explanation of gravity in simple terms."
|
12 |
+
messages_think = [
|
13 |
+
{"role": "user", "content": prompt}
|
14 |
+
]
|
15 |
+
|
16 |
+
text = tokenizer.apply_chat_template(
|
17 |
+
messages_think,
|
18 |
+
tokenize=False,
|
19 |
+
add_generation_prompt=True,
|
20 |
+
)
|
21 |
+
model_inputs = tokenizer([text], return_tensors="pt").to(model.device)
|
22 |
+
|
23 |
+
# Generate the output
|
24 |
+
generated_ids = model.generate(**model_inputs, max_new_tokens=32768)
|
25 |
+
|
26 |
+
# Get and decode the output
|
27 |
+
output_ids = generated_ids[0][len(model_inputs.input_ids[0]) :]
|
28 |
+
print(tokenizer.decode(output_ids, skip_special_tokens=True))
|
29 |
+
with open('HuggingFaceTB_SmolLM3-3B_1.txt', 'w') as f:
|
30 |
+
f.write('Everything was good in HuggingFaceTB_SmolLM3-3B_1.txt')
|
31 |
+
except Exception as e:
|
32 |
+
with open('HuggingFaceTB_SmolLM3-3B_1.txt', 'w') as f:
|
33 |
+
import traceback
|
34 |
+
traceback.print_exc(file=f)
|
35 |
+
finally:
|
36 |
+
from huggingface_hub import upload_file
|
37 |
+
upload_file(
|
38 |
+
path_or_fileobj='HuggingFaceTB_SmolLM3-3B_1.txt',
|
39 |
+
repo_id='model-metadata/custom_code_execution_files',
|
40 |
+
path_in_repo='HuggingFaceTB_SmolLM3-3B_1.txt',
|
41 |
+
repo_type='dataset',
|
42 |
+
)
|