ariG23498 HF Staff commited on
Commit
a7f1744
·
verified ·
1 Parent(s): c3fb07a

Upload MiniMaxAI_MiniMax-M2_2.py with huggingface_hub

Browse files
Files changed (1) hide show
  1. MiniMaxAI_MiniMax-M2_2.py +77 -0
MiniMaxAI_MiniMax-M2_2.py ADDED
@@ -0,0 +1,77 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # /// script
2
+ # requires-python = ">=3.12"
3
+ # dependencies = [
4
+ # "torch",
5
+ # "torchvision",
6
+ # "transformers",
7
+ # "accelerate",
8
+ # "peft",
9
+ # "slack-sdk",
10
+ # ]
11
+ # ///
12
+
13
+ try:
14
+ # Load model directly
15
+ from transformers import AutoTokenizer, AutoModelForCausalLM
16
+
17
+ tokenizer = AutoTokenizer.from_pretrained("MiniMaxAI/MiniMax-M2")
18
+ model = AutoModelForCausalLM.from_pretrained("MiniMaxAI/MiniMax-M2")
19
+ messages = [
20
+ {"role": "user", "content": "Who are you?"},
21
+ ]
22
+ inputs = tokenizer.apply_chat_template(
23
+ messages,
24
+ add_generation_prompt=True,
25
+ tokenize=True,
26
+ return_dict=True,
27
+ return_tensors="pt",
28
+ ).to(model.device)
29
+
30
+ outputs = model.generate(**inputs, max_new_tokens=40)
31
+ print(tokenizer.decode(outputs[0][inputs["input_ids"].shape[-1]:]))
32
+ with open('MiniMaxAI_MiniMax-M2_2.txt', 'w', encoding='utf-8') as f:
33
+ f.write('Everything was good in MiniMaxAI_MiniMax-M2_2.txt')
34
+ except Exception as e:
35
+ import os
36
+ from slack_sdk import WebClient
37
+ client = WebClient(token=os.environ['SLACK_TOKEN'])
38
+ client.chat_postMessage(
39
+ channel='#exp-slack-alerts',
40
+ text='Problem in <https://huggingface.co/datasets/model-metadata/code_execution_files/blob/main/MiniMaxAI_MiniMax-M2_2.txt|MiniMaxAI_MiniMax-M2_2.txt>',
41
+ )
42
+
43
+ with open('MiniMaxAI_MiniMax-M2_2.txt', 'a', encoding='utf-8') as f:
44
+ import traceback
45
+ f.write('''```CODE:
46
+ # Load model directly
47
+ from transformers import AutoTokenizer, AutoModelForCausalLM
48
+
49
+ tokenizer = AutoTokenizer.from_pretrained("MiniMaxAI/MiniMax-M2")
50
+ model = AutoModelForCausalLM.from_pretrained("MiniMaxAI/MiniMax-M2")
51
+ messages = [
52
+ {"role": "user", "content": "Who are you?"},
53
+ ]
54
+ inputs = tokenizer.apply_chat_template(
55
+ messages,
56
+ add_generation_prompt=True,
57
+ tokenize=True,
58
+ return_dict=True,
59
+ return_tensors="pt",
60
+ ).to(model.device)
61
+
62
+ outputs = model.generate(**inputs, max_new_tokens=40)
63
+ print(tokenizer.decode(outputs[0][inputs["input_ids"].shape[-1]:]))
64
+ ```
65
+
66
+ ERROR:
67
+ ''')
68
+ traceback.print_exc(file=f)
69
+
70
+ finally:
71
+ from huggingface_hub import upload_file
72
+ upload_file(
73
+ path_or_fileobj='MiniMaxAI_MiniMax-M2_2.txt',
74
+ repo_id='model-metadata/code_execution_files',
75
+ path_in_repo='MiniMaxAI_MiniMax-M2_2.txt',
76
+ repo_type='dataset',
77
+ )