ariG23498 HF Staff commited on
Commit
77e7fcd
·
verified ·
1 Parent(s): 6fba137

Upload HuggingFaceTB_SmolLM3-3B_4.py with huggingface_hub

Browse files
Files changed (1) hide show
  1. HuggingFaceTB_SmolLM3-3B_4.py +81 -0
HuggingFaceTB_SmolLM3-3B_4.py ADDED
@@ -0,0 +1,81 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # /// script
2
+ # requires-python = ">=3.12"
3
+ # dependencies = [
4
+ # "torch",
5
+ # "torchvision",
6
+ # "transformers",
7
+ # "diffusers",
8
+ # "sentence-transformers",
9
+ # "accelerate",
10
+ # "peft",
11
+ # "slack-sdk",
12
+ # ]
13
+ # ///
14
+
15
+ try:
16
+ # prepare the model input
17
+ prompt = "Give me a brief explanation of gravity in simple terms."
18
+ messages_think = [
19
+ {"role": "user", "content": prompt}
20
+ ]
21
+
22
+ text = tokenizer.apply_chat_template(
23
+ messages_think,
24
+ tokenize=False,
25
+ add_generation_prompt=True,
26
+ )
27
+ model_inputs = tokenizer([text], return_tensors="pt").to(model.device)
28
+
29
+ # Generate the output
30
+ generated_ids = model.generate(**model_inputs, max_new_tokens=32768)
31
+
32
+ # Get and decode the output
33
+ output_ids = generated_ids[0][len(model_inputs.input_ids[0]) :]
34
+ print(tokenizer.decode(output_ids, skip_special_tokens=True))
35
+ with open('HuggingFaceTB_SmolLM3-3B_4.txt', 'w', encoding='utf-8') as f:
36
+ f.write('Everything was good in HuggingFaceTB_SmolLM3-3B_4.txt')
37
+ except Exception as e:
38
+ import os
39
+ from slack_sdk import WebClient
40
+ client = WebClient(token=os.environ['SLACK_TOKEN'])
41
+ client.chat_postMessage(
42
+ channel='#hub-model-metadata-snippets-sprint',
43
+ text='Problem in <https://huggingface.co/datasets/model-metadata/code_execution_files/blob/main/HuggingFaceTB_SmolLM3-3B_4.txt|HuggingFaceTB_SmolLM3-3B_4.txt>',
44
+ )
45
+
46
+ with open('HuggingFaceTB_SmolLM3-3B_4.txt', 'a', encoding='utf-8') as f:
47
+ import traceback
48
+ f.write('''```CODE:
49
+ # prepare the model input
50
+ prompt = "Give me a brief explanation of gravity in simple terms."
51
+ messages_think = [
52
+ {"role": "user", "content": prompt}
53
+ ]
54
+
55
+ text = tokenizer.apply_chat_template(
56
+ messages_think,
57
+ tokenize=False,
58
+ add_generation_prompt=True,
59
+ )
60
+ model_inputs = tokenizer([text], return_tensors="pt").to(model.device)
61
+
62
+ # Generate the output
63
+ generated_ids = model.generate(**model_inputs, max_new_tokens=32768)
64
+
65
+ # Get and decode the output
66
+ output_ids = generated_ids[0][len(model_inputs.input_ids[0]) :]
67
+ print(tokenizer.decode(output_ids, skip_special_tokens=True))
68
+ ```
69
+
70
+ ERROR:
71
+ ''')
72
+ traceback.print_exc(file=f)
73
+
74
+ finally:
75
+ from huggingface_hub import upload_file
76
+ upload_file(
77
+ path_or_fileobj='HuggingFaceTB_SmolLM3-3B_4.txt',
78
+ repo_id='model-metadata/code_execution_files',
79
+ path_in_repo='HuggingFaceTB_SmolLM3-3B_4.txt',
80
+ repo_type='dataset',
81
+ )