ariG23498 HF Staff commited on
Commit
8126864
·
verified ·
1 Parent(s): 254c54c

Upload HuggingFaceTB_SmolLM3-3B_5.py with huggingface_hub

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