junukwon-fai MiniMax-AI commited on
Commit
1acdfe3
·
verified ·
0 Parent(s):

Duplicate from MiniMaxAI/MiniMax-M1-80k

Browse files

Co-authored-by: MiniMax <[email protected]>

This view is limited to 50 files because it contains too many changes.   See raw diff
Files changed (50) hide show
  1. .gitattributes +36 -0
  2. LICENSE +201 -0
  3. MiniMax_M1_tech_report.pdf +3 -0
  4. README.md +224 -0
  5. config.json +127 -0
  6. configuration_minimax_m1.py +152 -0
  7. docs/function_call_guide.md +424 -0
  8. docs/function_call_guide_cn.md +422 -0
  9. docs/transformers_deployment_guide.md +97 -0
  10. docs/transformers_deployment_guide_cn.md +95 -0
  11. docs/vllm_deployment_guide.md +161 -0
  12. docs/vllm_deployment_guide_cn.md +158 -0
  13. figures/TextBench.png +0 -0
  14. main.py +106 -0
  15. merges.txt +0 -0
  16. model-00000-of-00414.safetensors +3 -0
  17. model-00001-of-00414.safetensors +3 -0
  18. model-00002-of-00414.safetensors +3 -0
  19. model-00003-of-00414.safetensors +3 -0
  20. model-00004-of-00414.safetensors +3 -0
  21. model-00005-of-00414.safetensors +3 -0
  22. model-00006-of-00414.safetensors +3 -0
  23. model-00007-of-00414.safetensors +3 -0
  24. model-00008-of-00414.safetensors +3 -0
  25. model-00009-of-00414.safetensors +3 -0
  26. model-00010-of-00414.safetensors +3 -0
  27. model-00011-of-00414.safetensors +3 -0
  28. model-00012-of-00414.safetensors +3 -0
  29. model-00013-of-00414.safetensors +3 -0
  30. model-00014-of-00414.safetensors +3 -0
  31. model-00015-of-00414.safetensors +3 -0
  32. model-00016-of-00414.safetensors +3 -0
  33. model-00017-of-00414.safetensors +3 -0
  34. model-00018-of-00414.safetensors +3 -0
  35. model-00019-of-00414.safetensors +3 -0
  36. model-00020-of-00414.safetensors +3 -0
  37. model-00021-of-00414.safetensors +3 -0
  38. model-00022-of-00414.safetensors +3 -0
  39. model-00023-of-00414.safetensors +3 -0
  40. model-00024-of-00414.safetensors +3 -0
  41. model-00025-of-00414.safetensors +3 -0
  42. model-00026-of-00414.safetensors +3 -0
  43. model-00027-of-00414.safetensors +3 -0
  44. model-00028-of-00414.safetensors +3 -0
  45. model-00029-of-00414.safetensors +3 -0
  46. model-00030-of-00414.safetensors +3 -0
  47. model-00031-of-00414.safetensors +3 -0
  48. model-00032-of-00414.safetensors +3 -0
  49. model-00033-of-00414.safetensors +3 -0
  50. model-00034-of-00414.safetensors +3 -0
.gitattributes ADDED
@@ -0,0 +1,36 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ *.7z filter=lfs diff=lfs merge=lfs -text
2
+ *.arrow filter=lfs diff=lfs merge=lfs -text
3
+ *.bin filter=lfs diff=lfs merge=lfs -text
4
+ *.bz2 filter=lfs diff=lfs merge=lfs -text
5
+ *.ckpt filter=lfs diff=lfs merge=lfs -text
6
+ *.ftz filter=lfs diff=lfs merge=lfs -text
7
+ *.gz filter=lfs diff=lfs merge=lfs -text
8
+ *.h5 filter=lfs diff=lfs merge=lfs -text
9
+ *.joblib filter=lfs diff=lfs merge=lfs -text
10
+ *.lfs.* filter=lfs diff=lfs merge=lfs -text
11
+ *.mlmodel filter=lfs diff=lfs merge=lfs -text
12
+ *.model filter=lfs diff=lfs merge=lfs -text
13
+ *.msgpack filter=lfs diff=lfs merge=lfs -text
14
+ *.npy filter=lfs diff=lfs merge=lfs -text
15
+ *.npz filter=lfs diff=lfs merge=lfs -text
16
+ *.onnx filter=lfs diff=lfs merge=lfs -text
17
+ *.ot filter=lfs diff=lfs merge=lfs -text
18
+ *.parquet filter=lfs diff=lfs merge=lfs -text
19
+ *.pb filter=lfs diff=lfs merge=lfs -text
20
+ *.pickle filter=lfs diff=lfs merge=lfs -text
21
+ *.pkl filter=lfs diff=lfs merge=lfs -text
22
+ *.pt filter=lfs diff=lfs merge=lfs -text
23
+ *.pth filter=lfs diff=lfs merge=lfs -text
24
+ *.rar filter=lfs diff=lfs merge=lfs -text
25
+ *.safetensors filter=lfs diff=lfs merge=lfs -text
26
+ saved_model/**/* filter=lfs diff=lfs merge=lfs -text
27
+ *.tar.* filter=lfs diff=lfs merge=lfs -text
28
+ *.tar filter=lfs diff=lfs merge=lfs -text
29
+ *.tflite filter=lfs diff=lfs merge=lfs -text
30
+ *.tgz filter=lfs diff=lfs merge=lfs -text
31
+ *.wasm filter=lfs diff=lfs merge=lfs -text
32
+ *.xz filter=lfs diff=lfs merge=lfs -text
33
+ *.zip filter=lfs diff=lfs merge=lfs -text
34
+ *.zst filter=lfs diff=lfs merge=lfs -text
35
+ *tfevents* filter=lfs diff=lfs merge=lfs -text
36
+ MiniMax_M1_tech_report.pdf filter=lfs diff=lfs merge=lfs -text
LICENSE ADDED
@@ -0,0 +1,201 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ Apache License
2
+ Version 2.0, January 2004
3
+ http://www.apache.org/licenses/
4
+
5
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6
+
7
+ 1. Definitions.
8
+
9
+ "License" shall mean the terms and conditions for use, reproduction,
10
+ and distribution as defined by Sections 1 through 9 of this document.
11
+
12
+ "Licensor" shall mean the copyright owner or entity authorized by
13
+ the copyright owner that is granting the License.
14
+
15
+ "Legal Entity" shall mean the union of the acting entity and all
16
+ other entities that control, are controlled by, or are under common
17
+ control with that entity. For the purposes of this definition,
18
+ "control" means (i) the power, direct or indirect, to cause the
19
+ direction or management of such entity, whether by contract or
20
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
21
+ outstanding shares, or (iii) beneficial ownership of such entity.
22
+
23
+ "You" (or "Your") shall mean an individual or Legal Entity
24
+ exercising permissions granted by this License.
25
+
26
+ "Source" form shall mean the preferred form for making modifications,
27
+ including but not limited to software source code, documentation
28
+ source, and configuration files.
29
+
30
+ "Object" form shall mean any form resulting from mechanical
31
+ transformation or translation of a Source form, including but
32
+ not limited to compiled object code, generated documentation,
33
+ and conversions to other media types.
34
+
35
+ "Work" shall mean the work of authorship, whether in Source or
36
+ Object form, made available under the License, as indicated by a
37
+ copyright notice that is included in or attached to the work
38
+ (an example is provided in the Appendix below).
39
+
40
+ "Derivative Works" shall mean any work, whether in Source or Object
41
+ form, that is based on (or derived from) the Work and for which the
42
+ editorial revisions, annotations, elaborations, or other modifications
43
+ represent, as a whole, an original work of authorship. For the purposes
44
+ of this License, Derivative Works shall not include works that remain
45
+ separable from, or merely link (or bind by name) to the interfaces of,
46
+ the Work and Derivative Works thereof.
47
+
48
+ "Contribution" shall mean any work of authorship, including
49
+ the original version of the Work and any modifications or additions
50
+ to that Work or Derivative Works thereof, that is intentionally
51
+ submitted to Licensor for inclusion in the Work by the copyright owner
52
+ or by an individual or Legal Entity authorized to submit on behalf of
53
+ the copyright owner. For the purposes of this definition, "submitted"
54
+ means any form of electronic, verbal, or written communication sent
55
+ to the Licensor or its representatives, including but not limited to
56
+ communication on electronic mailing lists, source code control systems,
57
+ and issue tracking systems that are managed by, or on behalf of, the
58
+ Licensor for the purpose of discussing and improving the Work, but
59
+ excluding communication that is conspicuously marked or otherwise
60
+ designated in writing by the copyright owner as "Not a Contribution."
61
+
62
+ "Contributor" shall mean Licensor and any individual or Legal Entity
63
+ on behalf of whom a Contribution has been received by Licensor and
64
+ subsequently incorporated within the Work.
65
+
66
+ 2. Grant of Copyright License. Subject to the terms and conditions of
67
+ this License, each Contributor hereby grants to You a perpetual,
68
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
69
+ copyright license to reproduce, prepare Derivative Works of,
70
+ publicly display, publicly perform, sublicense, and distribute the
71
+ Work and such Derivative Works in Source or Object form.
72
+
73
+ 3. Grant of Patent License. Subject to the terms and conditions of
74
+ this License, each Contributor hereby grants to You a perpetual,
75
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
76
+ (except as stated in this section) patent license to make, have made,
77
+ use, offer to sell, sell, import, and otherwise transfer the Work,
78
+ where such license applies only to those patent claims licensable
79
+ by such Contributor that are necessarily infringed by their
80
+ Contribution(s) alone or by combination of their Contribution(s)
81
+ with the Work to which such Contribution(s) was submitted. If You
82
+ institute patent litigation against any entity (including a
83
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
84
+ or a Contribution incorporated within the Work constitutes direct
85
+ or contributory patent infringement, then any patent licenses
86
+ granted to You under this License for that Work shall terminate
87
+ as of the date such litigation is filed.
88
+
89
+ 4. Redistribution. You may reproduce and distribute copies of the
90
+ Work or Derivative Works thereof in any medium, with or without
91
+ modifications, and in Source or Object form, provided that You
92
+ meet the following conditions:
93
+
94
+ (a) You must give any other recipients of the Work or
95
+ Derivative Works a copy of this License; and
96
+
97
+ (b) You must cause any modified files to carry prominent notices
98
+ stating that You changed the files; and
99
+
100
+ (c) You must retain, in the Source form of any Derivative Works
101
+ that You distribute, all copyright, patent, trademark, and
102
+ attribution notices from the Source form of the Work,
103
+ excluding those notices that do not pertain to any part of
104
+ the Derivative Works; and
105
+
106
+ (d) If the Work includes a "NOTICE" text file as part of its
107
+ distribution, then any Derivative Works that You distribute must
108
+ include a readable copy of the attribution notices contained
109
+ within such NOTICE file, excluding those notices that do not
110
+ pertain to any part of the Derivative Works, in at least one
111
+ of the following places: within a NOTICE text file distributed
112
+ as part of the Derivative Works; within the Source form or
113
+ documentation, if provided along with the Derivative Works; or,
114
+ within a display generated by the Derivative Works, if and
115
+ wherever such third-party notices normally appear. The contents
116
+ of the NOTICE file are for informational purposes only and
117
+ do not modify the License. You may add Your own attribution
118
+ notices within Derivative Works that You distribute, alongside
119
+ or as an addendum to the NOTICE text from the Work, provided
120
+ that such additional attribution notices cannot be construed
121
+ as modifying the License.
122
+
123
+ You may add Your own copyright statement to Your modifications and
124
+ may provide additional or different license terms and conditions
125
+ for use, reproduction, or distribution of Your modifications, or
126
+ for any such Derivative Works as a whole, provided Your use,
127
+ reproduction, and distribution of the Work otherwise complies with
128
+ the conditions stated in this License.
129
+
130
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
131
+ any Contribution intentionally submitted for inclusion in the Work
132
+ by You to the Licensor shall be under the terms and conditions of
133
+ this License, without any additional terms or conditions.
134
+ Notwithstanding the above, nothing herein shall supersede or modify
135
+ the terms of any separate license agreement you may have executed
136
+ with Licensor regarding such Contributions.
137
+
138
+ 6. Trademarks. This License does not grant permission to use the trade
139
+ names, trademarks, service marks, or product names of the Licensor,
140
+ except as required for reasonable and customary use in describing the
141
+ origin of the Work and reproducing the content of the NOTICE file.
142
+
143
+ 7. Disclaimer of Warranty. Unless required by applicable law or
144
+ agreed to in writing, Licensor provides the Work (and each
145
+ Contributor provides its Contributions) on an "AS IS" BASIS,
146
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
147
+ implied, including, without limitation, any warranties or conditions
148
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
149
+ PARTICULAR PURPOSE. You are solely responsible for determining the
150
+ appropriateness of using or redistributing the Work and assume any
151
+ risks associated with Your exercise of permissions under this License.
152
+
153
+ 8. Limitation of Liability. In no event and under no legal theory,
154
+ whether in tort (including negligence), contract, or otherwise,
155
+ unless required by applicable law (such as deliberate and grossly
156
+ negligent acts) or agreed to in writing, shall any Contributor be
157
+ liable to You for damages, including any direct, indirect, special,
158
+ incidental, or consequential damages of any character arising as a
159
+ result of this License or out of the use or inability to use the
160
+ Work (including but not limited to damages for loss of goodwill,
161
+ work stoppage, computer failure or malfunction, or any and all
162
+ other commercial damages or losses), even if such Contributor
163
+ has been advised of the possibility of such damages.
164
+
165
+ 9. Accepting Warranty or Additional Liability. While redistributing
166
+ the Work or Derivative Works thereof, You may choose to offer,
167
+ and charge a fee for, acceptance of support, warranty, indemnity,
168
+ or other liability obligations and/or rights consistent with this
169
+ License. However, in accepting such obligations, You may act only
170
+ on Your own behalf and on Your sole responsibility, not on behalf
171
+ of any other Contributor, and only if You agree to indemnify,
172
+ defend, and hold each Contributor harmless for any liability
173
+ incurred by, or claims asserted against, such Contributor by reason
174
+ of your accepting any such warranty or additional liability.
175
+
176
+ END OF TERMS AND CONDITIONS
177
+
178
+ APPENDIX: How to apply the Apache License to your work.
179
+
180
+ To apply the Apache License to your work, attach the following
181
+ boilerplate notice, with the fields enclosed by brackets "[]"
182
+ replaced with your own identifying information. (Don't include
183
+ the brackets!) The text should be enclosed in the appropriate
184
+ comment syntax for the file format. We also recommend that a
185
+ file or class name and description of purpose be included on the
186
+ same "printed page" as the copyright notice for easier
187
+ identification within third-party archives.
188
+
189
+ Copyright 2025 MiniMax
190
+
191
+ Licensed under the Apache License, Version 2.0 (the "License");
192
+ you may not use this file except in compliance with the License.
193
+ You may obtain a copy of the License at
194
+
195
+ http://www.apache.org/licenses/LICENSE-2.0
196
+
197
+ Unless required by applicable law or agreed to in writing, software
198
+ distributed under the License is distributed on an "AS IS" BASIS,
199
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
200
+ See the License for the specific language governing permissions and
201
+ limitations under the License.
MiniMax_M1_tech_report.pdf ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:a159321f78136a4d411a6eb121fba6dda790f2810e62445f48c15fc245e11df0
3
+ size 1484632
README.md ADDED
@@ -0,0 +1,224 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ---
2
+ pipeline_tag: text-generation
3
+ license: apache-2.0
4
+ library_name: transformers
5
+ tags:
6
+ - vllm
7
+ ---
8
+
9
+ <div align="center">
10
+
11
+ <svg width="60%" height="auto" viewBox="0 0 144 48" fill="none" xmlns="http://www.w3.org/2000/svg">
12
+ <path d="M26.6782 7.96523C26.6782 7.02436 25.913 6.26087 24.9739 6.26087C24.0348 6.26087 23.2695 7.0261 23.2695 7.96523V36.2139C23.2695 38.4 21.4904 40.1791 19.3043 40.1791C17.1183 40.1791 15.3391 38.4 15.3391 36.2139V18.0904C15.3391 17.1496 14.5739 16.3861 13.6348 16.3861C12.6956 16.3861 11.9304 17.1513 11.9304 18.0904V25.7722C11.9304 27.9583 10.1513 29.7374 7.96518 29.7374C5.7791 29.7374 4 27.9583 4 25.7722V22.9878C4 22.3635 4.50609 21.8574 5.13043 21.8574C5.75478 21.8574 6.26087 22.3635 6.26087 22.9878V25.7722C6.26087 26.713 7.02605 27.4765 7.96518 27.4765C8.90431 27.4765 9.66954 26.7113 9.66954 25.7722V18.0904C9.66954 15.9044 11.4487 14.1252 13.6348 14.1252C15.8209 14.1252 17.6 15.9044 17.6 18.0904V36.2139C17.6 37.1548 18.3652 37.9183 19.3043 37.9183C20.2435 37.9183 21.0087 37.153 21.0087 36.2139V25.1322V7.96523C21.0087 5.77914 22.7878 4 24.9739 4C27.16 4 28.9391 5.77914 28.9391 7.96523V31.3565C28.9391 31.9809 28.433 32.487 27.8087 32.487C27.1843 32.487 26.6782 31.9809 26.6782 31.3565V7.96523ZM47.6539 14.1252C45.4678 14.1252 43.6887 15.9044 43.6887 18.0904V33.2296C43.6887 34.1704 42.9235 34.9339 41.9843 34.9339C41.0452 34.9339 40.28 34.1687 40.28 33.2296V7.96523C40.28 5.77914 38.5008 4 36.3148 4C34.1287 4 32.3496 5.77914 32.3496 7.96523V40.0348C32.3496 40.9756 31.5843 41.7391 30.6452 41.7391C29.7061 41.7391 28.9409 40.9739 28.9409 40.0348V36.0643C28.9409 35.44 28.4348 34.9339 27.8104 34.9339C27.1861 34.9339 26.68 35.44 26.68 36.0643V40.0348C26.68 42.2209 28.4591 44 30.6452 44C32.8313 44 34.6104 42.2209 34.6104 40.0348V7.96523C34.6104 7.02436 35.3756 6.26087 36.3148 6.26087C37.2539 6.26087 38.0191 7.0261 38.0191 7.96523V33.2296C38.0191 35.4156 39.7982 37.1948 41.9843 37.1948C44.1704 37.1948 45.9496 35.4156 45.9496 33.2296V18.0904C45.9496 17.1496 46.7148 16.3861 47.6539 16.3861C48.593 16.3861 49.3582 17.1513 49.3582 18.0904V31.3565C49.3582 31.9809 49.8643 32.487 50.4887 32.487C51.113 32.487 51.6191 31.9809 51.6191 31.3565V18.0904C51.6191 15.9044 49.84 14.1252 47.6539 14.1252Z" fill="url(#paint0_linear_17_483)"/>
13
+ <path d="M68.7671 16.5615H71.2541C71.3254 16.5615 71.3845 16.5859 71.435 16.6363C71.4836 16.6868 71.5097 16.7459 71.5097 16.8172V31.1824C71.5097 31.2537 71.4854 31.3128 71.435 31.3633C71.3845 31.4137 71.3254 31.4381 71.2541 31.4381H68.7671C68.6958 31.4381 68.6367 31.4137 68.5862 31.3633C68.5358 31.3146 68.5115 31.2537 68.5115 31.1824V21.812C68.5115 21.7563 68.4976 21.7268 68.4697 21.7268C68.4419 21.7268 68.4123 21.7476 68.3845 21.7911L66.1323 25.318C66.061 25.4311 65.9619 25.4885 65.8349 25.4885H64.581C64.4541 25.4885 64.3549 25.4328 64.2836 25.318L62.0315 21.7911C62.0036 21.7494 61.9741 21.7302 61.9462 21.7372C61.9184 21.7441 61.9045 21.7772 61.9045 21.8328V31.1824C61.9045 31.2537 61.8802 31.3128 61.8297 31.3633C61.7793 31.4137 61.7202 31.4381 61.6489 31.4381H59.1619C59.0906 31.4381 59.0315 31.4137 58.981 31.3633C58.9306 31.3146 58.9062 31.2537 58.9062 31.1824V16.8172C58.9062 16.7459 58.9306 16.6868 58.981 16.6363C59.0315 16.5859 59.0906 16.5615 59.1619 16.5615H61.6489C61.7758 16.5615 61.8749 16.6189 61.9462 16.732L65.1341 21.6833C65.1758 21.7685 65.2193 21.7685 65.261 21.6833L68.4697 16.732C68.541 16.6189 68.6402 16.5615 68.7671 16.5615Z" fill="currentColor"/>
14
+ <path d="M74.1764 31.3633C74.1259 31.3146 74.1016 31.2537 74.1016 31.1824V16.8172C74.1016 16.7459 74.1259 16.6868 74.1764 16.6363C74.2268 16.5859 74.2859 16.5615 74.3572 16.5615H76.8442C76.9155 16.5615 76.9746 16.5859 77.0251 16.6363C77.0737 16.6868 77.0998 16.7459 77.0998 16.8172V31.1824C77.0998 31.2537 77.0755 31.3128 77.0251 31.3633C76.9746 31.4137 76.9155 31.4381 76.8442 31.4381H74.3572C74.2859 31.4381 74.2268 31.4137 74.1764 31.3633Z" fill="currentColor"/>
15
+ <path d="M88.3066 16.6361C88.3553 16.5874 88.4162 16.5613 88.4875 16.5613H90.9744C91.0457 16.5613 91.1049 16.5857 91.1553 16.6361C91.204 16.6865 91.2301 16.7457 91.2301 16.817V31.1822C91.2301 31.2535 91.2057 31.3126 91.1553 31.363C91.1049 31.4135 91.0457 31.4378 90.9744 31.4378H88.5727C88.4301 31.4378 88.331 31.3822 88.2753 31.2674L82.771 22.1717C82.7431 22.13 82.7136 22.1109 82.6858 22.1178C82.6579 22.1248 82.644 22.1578 82.644 22.2135L82.6858 31.1805C82.6858 31.2518 82.6614 31.3109 82.611 31.3613C82.5606 31.4117 82.5014 31.4361 82.4301 31.4361H79.9431C79.8718 31.4361 79.8127 31.4117 79.7623 31.3613C79.7118 31.3126 79.6875 31.2518 79.6875 31.1805V16.8152C79.6875 16.7439 79.7118 16.6848 79.7623 16.6344C79.8127 16.5839 79.8718 16.5596 79.9431 16.5596H82.3449C82.4858 16.5596 82.5849 16.617 82.6423 16.73L88.124 25.7822C88.1518 25.8239 88.1797 25.8431 88.2092 25.8361C88.2371 25.8292 88.251 25.7978 88.251 25.7404L88.2301 16.8152C88.2301 16.7439 88.2545 16.6848 88.3049 16.6344L88.3066 16.6361Z" fill="currentColor"/>
16
+ <path d="M93.8951 31.3633C93.8446 31.3146 93.8203 31.2537 93.8203 31.1824V16.8172C93.8203 16.7459 93.8446 16.6868 93.8951 16.6363C93.9455 16.5859 94.0047 16.5615 94.076 16.5615H96.5629C96.6342 16.5615 96.6934 16.5859 96.7438 16.6363C96.7925 16.6868 96.8186 16.7459 96.8186 16.8172V31.1824C96.8186 31.2537 96.7942 31.3128 96.7438 31.3633C96.6934 31.4137 96.6342 31.4381 96.5629 31.4381H94.076C94.0047 31.4381 93.9455 31.4137 93.8951 31.3633Z" fill="currentColor"/>
17
+ <path d="M109.267 16.5615H111.754C111.825 16.5615 111.885 16.5859 111.935 16.6363C111.984 16.6868 112.01 16.7459 112.01 16.8172V31.1824C112.01 31.2537 111.985 31.3128 111.935 31.3633C111.885 31.4137 111.825 31.4381 111.754 31.4381H109.267C109.196 31.4381 109.137 31.4137 109.086 31.3633C109.036 31.3146 109.011 31.2537 109.011 31.1824V21.812C109.011 21.7563 108.998 21.7268 108.97 21.7268C108.942 21.7268 108.912 21.7476 108.885 21.7911L106.632 25.318C106.561 25.4311 106.462 25.4885 106.335 25.4885H105.081C104.954 25.4885 104.855 25.4328 104.784 25.318L102.531 21.7911C102.504 21.7494 102.474 21.7302 102.446 21.7372C102.418 21.7441 102.405 21.7772 102.405 21.8328V31.1824C102.405 31.2537 102.38 31.3128 102.33 31.3633C102.279 31.4137 102.22 31.4381 102.149 31.4381H99.6619C99.5906 31.4381 99.5315 31.4137 99.481 31.3633C99.4306 31.3146 99.4062 31.2537 99.4062 31.1824V16.8172C99.4062 16.7459 99.4306 16.6868 99.481 16.6363C99.5315 16.5859 99.5906 16.5615 99.6619 16.5615H102.149C102.276 16.5615 102.375 16.6189 102.446 16.732L105.634 21.6833C105.676 21.7685 105.719 21.7685 105.761 21.6833L108.97 16.732C109.041 16.6189 109.14 16.5615 109.267 16.5615Z" fill="currentColor"/>
18
+ <path d="M123.782 31.2241L123.144 29.1424C123.116 29.0867 123.079 29.0572 123.038 29.0572H117.81C117.768 29.0572 117.732 29.085 117.704 29.1424L117.088 31.2241C117.046 31.3668 116.954 31.4363 116.812 31.4363H114.112C114.027 31.4363 113.963 31.412 113.921 31.3615C113.879 31.3128 113.871 31.2381 113.9 31.1389L118.49 16.7737C118.532 16.6328 118.624 16.5615 118.766 16.5615H122.102C122.243 16.5615 122.335 16.6328 122.379 16.7737L126.968 31.1389C126.982 31.1668 126.989 31.2033 126.989 31.245C126.989 31.372 126.911 31.4363 126.756 31.4363H124.057C123.916 31.4363 123.824 31.365 123.78 31.2241H123.782ZM118.554 26.7407H122.295C122.38 26.7407 122.408 26.6989 122.38 26.6137L120.467 20.3024C120.453 20.2467 120.432 20.2207 120.403 20.2276C120.375 20.2346 120.352 20.2589 120.339 20.3024L118.469 26.6137C118.455 26.6989 118.483 26.7407 118.554 26.7407Z" fill="currentColor"/>
19
+ <path d="M128.222 31.353C128.18 31.2974 128.187 31.2261 128.243 31.1409L132.365 24.0643C132.393 24.0226 132.393 23.9791 132.365 23.9374L128.243 16.8609L128.201 16.7339C128.201 16.6209 128.28 16.5635 128.434 16.5635H131.133C131.274 16.5635 131.38 16.6209 131.452 16.7339L134.213 21.6C134.255 21.6852 134.299 21.6852 134.34 21.6L137.102 16.7339C137.173 16.6209 137.28 16.5635 137.42 16.5635H140.099C140.198 16.5635 140.269 16.5913 140.311 16.6487C140.353 16.7061 140.346 16.7756 140.29 16.8609L136.168 23.9374C136.154 23.9791 136.154 24.0226 136.168 24.0643L140.29 31.1409L140.332 31.2678C140.332 31.3809 140.253 31.4383 140.099 31.4383H137.42C137.278 31.4383 137.172 31.3826 137.102 31.2678L134.34 26.4226C134.299 26.3374 134.255 26.3374 134.213 26.4226L131.429 31.2678C131.358 31.3809 131.252 31.4383 131.111 31.4383H128.433C128.333 31.4383 128.262 31.4104 128.22 31.353H128.222Z" fill="currentColor"/>
20
+ <defs>
21
+ <linearGradient id="paint0_linear_17_483" x1="3.99826" y1="24" x2="51.6208" y2="24" gradientUnits="userSpaceOnUse">
22
+ <stop stop-color="#E21680"/>
23
+ <stop offset="1" stop-color="#FF633A"/>
24
+ </linearGradient>
25
+ </defs>
26
+ </svg>
27
+
28
+ </div>
29
+ <hr>
30
+
31
+ <div align="center" style="line-height: 1;">
32
+ <a href="https://www.minimax.io" target="_blank" style="margin: 2px;">
33
+ <img alt="Homepage" src="https://img.shields.io/badge/_Homepage-MiniMax-FF4040?style=flat-square&labelColor=2C3E50&logo=data:image/svg+xml;base64,PHN2ZyB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHhtbG5zOnhsaW5rPSJodHRwOi8vd3d3LnczLm9yZy8xOTk5L3hsaW5rIiB2aWV3Qm94PSIwIDAgNDkwLjE2IDQxMS43Ij48ZGVmcz48c3R5bGU+LmNscy0xe2ZpbGw6I2ZmZjt9PC9zdHlsZT48L2RlZnM+PHBhdGggY2xhc3M9ImNscy0xIiBkPSJNMjMzLjQ1LDQwLjgxYTE3LjU1LDE3LjU1LDAsMSwwLTM1LjEsMFYzMzEuNTZhNDAuODIsNDAuODIsMCwwLDEtODEuNjMsMFYxNDVhMTcuNTUsMTcuNTUsMCwxLDAtMzUuMDksMHY3OS4wNmE0MC44Miw0MC44MiwwLDAsMS04MS42MywwVjE5NS40MmExMS42MywxMS42MywwLDAsMSwyMy4yNiwwdjI4LjY2YTE3LjU1LDE3LjU1LDAsMCwwLDM1LjEsMFYxNDVBNDAuODIsNDAuODIsMCwwLDEsMTQwLDE0NVYzMzEuNTZhMTcuNTUsMTcuNTUsMCwwLDAsMzUuMSwwVjIxNy41aDBWNDAuODFhNDAuODEsNDAuODEsMCwxLDEsODEuNjIsMFYyODEuNTZhMTEuNjMsMTEuNjMsMCwxLDEtMjMuMjYsMFptMjE1LjksNjMuNEE0MC44Niw0MC44NiwwLDAsMCw0MDguNTMsMTQ1VjMwMC44NWExNy41NSwxNy41NSwwLDAsMS0zNS4wOSwwdi0yNjBhNDAuODIsNDAuODIsMCwwLDAtODEuNjMsMFYzNzAuODlhMTcuNTUsMTcuNTUsMCwwLDEtMzUuMSwwVjMzMGExMS42MywxMS42MywwLDEsMC0yMy4yNiwwdjQwLjg2YTQwLjgxLDQwLjgxLDAsMCwwLDgxLjYyLDBWNDAuODFhMTcuNTUsMTcuNTUsMCwwLDEsMzUuMSwwdjI2MGE0MC44Miw0MC44MiwwLDAsMCw4MS42MywwVjE0NWExNy41NSwxNy41NSwwLDEsMSwzNS4xLDBWMjgxLjU2YTExLjYzLDExLjYzLDAsMCwwLDIzLjI2LDBWMTQ1QTQwLjg1LDQwLjg1LDAsMCwwLDQ0OS4zNSwxMDQuMjFaIi8+PC9zdmc+&logoWidth=20" style="display: inline-block; vertical-align: middle;"/>
34
+ </a>
35
+ <a href="https://arxiv.org/abs/2506.13585" target="_blank" style="margin: 2px;">
36
+ <img alt="Paper" src="https://img.shields.io/badge/📖_Paper-MiniMax--M1-FF4040?style=flat-square&labelColor=2C3E50" style="display: inline-block; vertical-align: middle;"/>
37
+ </a>
38
+ <a href="https://chat.minimax.io/" target="_blank" style="margin: 2px;">
39
+ <img alt="Chat" src="https://img.shields.io/badge/_MiniMax_Chat-FF4040?style=flat-square&labelColor=2C3E50&logo=data:image/svg+xml;base64,PHN2ZyB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHhtbG5zOnhsaW5rPSJodHRwOi8vd3d3LnczLm9yZy8xOTk5L3hsaW5rIiB2aWV3Qm94PSIwIDAgNDkwLjE2IDQxMS43Ij48ZGVmcz48c3R5bGU+LmNscy0xe2ZpbGw6I2ZmZjt9PC9zdHlsZT48L2RlZnM+PHBhdGggY2xhc3M9ImNscy0xIiBkPSJNMjMzLjQ1LDQwLjgxYTE3LjU1LDE3LjU1LDAsMSwwLTM1LjEsMFYzMzEuNTZhNDAuODIsNDAuODIsMCwwLDEtODEuNjMsMFYxNDVhMTcuNTUsMTcuNTUsMCwxLDAtMzUuMDksMHY3OS4wNmE0MC44Miw0MC44MiwwLDAsMS04MS42MywwVjE5NS40MmExMS42MywxMS42MywwLDAsMSwyMy4yNiwwdjI4LjY2YTE3LjU1LDE3LjU1LDAsMCwwLDM1LjEsMFYxNDVBNDAuODIsNDAuODIsMCwwLDEsMTQwLDE0NVYzMzEuNTZhMTcuNTUsMTcuNTUsMCwwLDAsMzUuMSwwVjIxNy41aDBWNDAuODFhNDAuODEsNDAuODEsMCwxLDEsODEuNjIsMFYyODEuNTZhMTEuNjMsMTEuNjMsMCwxLDEtMjMuMjYsMFptMjE1LjksNjMuNEE0MC44Niw0MC44NiwwLDAsMCw0MDguNTMsMTQ1VjMwMC44NWExNy41NSwxNy41NSwwLDAsMS0zNS4wOSwwdi0yNjBhNDAuODIsNDAuODIsMCwwLDAtODEuNjMsMFYzNzAuODlhMTcuNTUsMTcuNTUsMCwwLDEtMzUuMSwwVjMzMGExMS42MywxMS42MywwLDEsMC0yMy4yNiwwdjQwLjg2YTQwLjgxLDQwLjgxLDAsMCwwLDgxLjYyLDBWNDAuODFhMTcuNTUsMTcuNTUsMCwwLDEsMzUuMSwwdjI2MGE0MC44Miw0MC44MiwwLDAsMCw4MS42MywwVjE0NWExNy41NSwxNy41NSwwLDEsMSwzNS4xLDBWMjgxLjU2YTExLjYzLDExLjYzLDAsMCwwLDIzLjI2LDBWMTQ1QTQwLjg1LDQwLjg1LDAsMCwwLDQ0OS4zNSwxMDQuMjFaIi8+PC9zdmc+&logoWidth=20" style="display: inline-block; vertical-align: middle;"/>
40
+ </a>
41
+ <a href="https://www.minimax.io/platform" style="margin: 2px;">
42
+ <img alt="API" src="https://img.shields.io/badge/⚡_API-Platform-FF4040?style=flat-square&labelColor=2C3E50" style="display: inline-block; vertical-align: middle;"/>
43
+ </a>
44
+ <a href="https://github.com/MiniMax-AI/MiniMax-MCP" style="margin: 2px;">
45
+ <img alt="MCP" src="https://img.shields.io/badge/🚀_MCP-MiniMax_MCP-FF4040?style=flat-square&labelColor=2C3E50" style="display: inline-block; vertical-align: middle;"/>
46
+ </a>
47
+ </div>
48
+ <div align="center" style="line-height: 1;">
49
+ <a href="https://huggingface.co/MiniMaxAI" target="_blank" style="margin: 2px;">
50
+ <img alt="Hugging Face" src="https://img.shields.io/badge/🤗_Hugging_Face-MiniMax-FF4040?style=flat-square&labelColor=2C3E50" style="display: inline-block; vertical-align: middle;"/>
51
+ </a>
52
+ <a href="https://github.com/MiniMax-AI/MiniMax-M1" target="_blank" style="margin: 2px;">
53
+ <img alt="GitHub" src="https://img.shields.io/badge/🐙_GitHub-MiniMax-FF4040?style=flat-square&labelColor=2C3E50" style="display: inline-block; vertical-align: middle;"/>
54
+ </a>
55
+ <a href="https://www.modelscope.cn/organization/MiniMax" target="_blank" style="margin: 2px;">
56
+ <img alt="ModelScope" src="https://img.shields.io/badge/🤖️_ModelScope-MiniMax-FF4040?style=flat-square&labelColor=2C3E50" style="display: inline-block; vertical-align: middle;"/>
57
+ </a>
58
+ <a href="https://github.com/MiniMax-AI/MiniMax-M1/blob/main/LICENSE" style="margin: 2px;">
59
+ <img alt="License" src="https://img.shields.io/badge/⚖️_License-Apache_2.0-FF4040?style=flat-square&labelColor=2C3E50" style="display: inline-block; vertical-align: middle;"/>
60
+ </a>
61
+ <a href="https://github.com/MiniMax-AI/MiniMax-AI.github.io/blob/main/images/wechat-qrcode.jpeg" target="_blank" style="margin: 2px;">
62
+ <img alt="WeChat" src="https://img.shields.io/badge/💬_WeChat-MiniMax-FF4040?style=flat-square&labelColor=2C3E50" style="display: inline-block; vertical-align: middle;"/>
63
+ </a>
64
+ </div>
65
+
66
+ # MiniMax-M1
67
+
68
+ ## 1. Model Overview
69
+
70
+ We introduce MiniMax-M1, the world's first open-weight, large-scale hybrid-attention reasoning model.
71
+ MiniMax-M1 is powered by a hybrid Mixture-of-Experts (MoE) architecture combined with a lightning
72
+ attention mechanism. The model is developed based on our previous [MiniMax-Text-01 model](https://huggingface.co/MiniMaxAI/MiniMax-Text-01),
73
+ which contains a total of 456 billion parameters with 45.9 billion parameters activated
74
+ per token. Consistent with MiniMax-Text-01, the M1 model natively supports a context length of 1
75
+ million tokens, 8x the context size of DeepSeek R1. Furthermore, the lightning attention mechanism
76
+ in MiniMax-M1 enables efficient scaling of test-time compute – For example, compared to DeepSeek
77
+ R1, M1 consumes 25% of the FLOPs at a generation length of 100K tokens. These properties make M1
78
+ particularly suitable for complex tasks that require processing long inputs and thinking extensively.
79
+ MiniMax-M1 is trained using large-scale reinforcement learning (RL) on diverse problems ranging from
80
+ traditional mathematical reasoning to sandbox-based, real-world software engineering environments.
81
+ We develop an efficient RL scaling framework for M1 highlighting two perspectives: (1) We propose
82
+ CISPO, a novel algorithm that clips importance sampling weights instead of token updates, which
83
+ outperforms other competitive RL variants; (2) Our hybrid-attention design naturally enhances the
84
+ efficiency of RL, where we address unique challenges when scaling RL with the hybrid architecture. We
85
+ train two versions of MiniMax-M1 models with [40K](https://huggingface.co/MiniMaxAI/MiniMax-M1-40k) and
86
+ [80K](https://huggingface.co/MiniMaxAI/MiniMax-M1-80k) thinking budgets respectively. Experiments
87
+ on standard benchmarks show that our models outperform other strong open-weight models such as
88
+ the original DeepSeek-R1 and Qwen3-235B, particularly on complex software engineering, tool using,
89
+ and long context tasks. With efficient scaling of test-time compute, MiniMax-M1 serves as a strong
90
+ foundation for next-generation language model agents to reason and tackle real-world challenges.
91
+
92
+ <p align="center">
93
+ <img width="100%" src="figures/TextBench.png">
94
+ <br>
95
+ <small><em>Benchmark performance comparison of leading commercial and open-weight models across competition-level mathematics, coding, software engineering, agentic tool use, and long-context understanding tasks. We use the MiniMax-M1-80k model here for MiniMax-M1.</em></small>
96
+ </p>
97
+
98
+
99
+ ## 2. Evaluation
100
+
101
+ **Performance of MiniMax-M1 on core benchmarks.**
102
+
103
+
104
+ | **Category** | **Task** | **MiniMax-M1-80K** | **MiniMax-M1-40K** | **Qwen3-235B-A22B** | **DeepSeek-R1-0528** | **DeepSeek-R1** | **Seed-Thinking-v1.5** | **Claude 4 Opus** | **Gemini 2.5 Pro (06-05)** | **OpenAI-o3** |
105
+ |:---|:---|:---:|:---:|:---:|:---:|:---:|:---:|:---:|:---:|:---:|
106
+ | | *Extended Thinking* | *80K* | *40K* | *32k* | *64k* | *32k* | *32k* | *64k* | *64k* | *100k* |
107
+ | ***Mathematics*** | AIME 2024 | 86.0 | 83.3 | 85.7 | 91.4 | 79.8 | 86.7 | 76.0 | 92.0 | 91.6 |
108
+ | | AIME 2025 | 76.9 | 74.6 | 81.5 | 87.5 | 70.0 | 74.0 | 75.5 | 88.0 | 88.9 |
109
+ | | MATH-500 | 96.8 | 96.0 | 96.2 | 98.0 | 97.3 | 96.7 | 98.2 | 98.8 | 98.1 |
110
+ | ***General Coding*** | LiveCodeBench *(24/8~25/5)* | 65.0 | 62.3 | 65.9 | 73.1 | 55.9 | 67.5 | 56.6 | 77.1 | 75.8 |
111
+ | | FullStackBench | 68.3 | 67.6 | 62.9 | 69.4 | 70.1 | 69.9 | 70.3 | -- | 69.3 |
112
+ | ***Reasoning & Knowledge***| GPQA Diamond | 70.0 | 69.2 | 71.1 | 81.0 | 71.5 | 77.3 | 79.6 | 86.4 | 83.3 |
113
+ | | HLE *(no tools)* | 8.4\* | 7.2\* | 7.6\* | 17.7\* | 8.6\* | 8.2 | 10.7 | 21.6 | 20.3 |
114
+ | | ZebraLogic | 86.8 | 80.1 | 80.3 | 95.1 | 78.7 | 84.4 | 95.1 | 91.6 | 95.8 |
115
+ | | MMLU-Pro | 81.1 | 80.6 | 83.0 | 85.0 | 84.0 | 87.0 | 85.0 | 86.0 | 85.0 |
116
+ | ***Software Engineering***| SWE-bench Verified| 56.0 | 55.6 | 34.4 | 57.6 | 49.2 | 47.0 | 72.5 | 67.2 | 69.1 |
117
+ | ***Long Context*** | OpenAI-MRCR *(128k)* | 73.4 | 76.1 | 27.7 | 51.5 | 35.8 | 54.3 | 48.9 | 76.8 | 56.5 |
118
+ | | OpenAI-MRCR *(1M)* | 56.2 | 58.6 | -- | -- | -- | -- | -- | 58.8 | -- |
119
+ | | LongBench-v2 | 61.5 | 61.0 | 50.1 | 52.1 | 58.3 | 52.5 | 55.6 | 65.0 | 58.8 |
120
+ | ***Agentic Tool Use***| TAU-bench *(airline)* | 62.0 | 60.0 | 34.7 | 53.5 | -- | 44.0 | 59.6 | 50.0 | 52.0 |
121
+ | | TAU-bench *(retail)* | 63.5 | 67.8 | 58.6 | 63.9 | -- | 55.7 | 81.4 | 67.0 | 73.9 |
122
+ | ***Factuality*** | SimpleQA | 18.5 | 17.9 | 11.0 | 27.8 | 30.1 | 12.9 | -- | 54.0 | 49.4 |
123
+ | ***General Assistant***| MultiChallenge | 44.7 | 44.7 | 40.0 | 45.0 | 40.7 | 43.0 | 45.8 | 51.8 | 56.5 |
124
+
125
+ \* conducted on the text-only HLE subset.
126
+
127
+ Our models are evaluated with `temperature=1.0`, `top_p=0.95`.
128
+
129
+ ### SWE-bench methodology
130
+ We report results derived from the Agentless scaffold. Departing from the original pipeline, our methodology employs a two-stage localization process (without any embedding-based retrieval mechanisms): initial coarse-grained file localization followed by fine-grained localization to specific files and code elements. The values for our models are calculated on the subset of n=486 verified tasks which work on our infrastructure. The excluded 14 test cases that were incompatible with our internal infrastructure are:
131
+ `"astropy__astropy-7606"`,
132
+ `"astropy__astropy-8707"`,
133
+ `"astropy__astropy-8872"`,
134
+ `"django__django-10097"`,
135
+ `"matplotlib__matplotlib-20488"`,
136
+ `"psf__requests-2317"`,
137
+ `"psf__requests-2931"`,
138
+ `"psf__requests-5414"`,
139
+ `"pylint-dev__pylint-6528"`,
140
+ `"pylint-dev__pylint-7277"`,
141
+ `"sphinx-doc__sphinx-10435"`,
142
+ `"sphinx-doc__sphinx-7985"`,
143
+ `"sphinx-doc__sphinx-8269"`,
144
+ `"sphinx-doc__sphinx-8475"`
145
+
146
+ ### TAU-bench methodology
147
+ We evaluate TAU-Bench with GPT-4.1 as user model and without any custom tools. The maximum number of interaction steps is 40.
148
+ Our general system prompt is:
149
+ ```
150
+ - In each round, you need to carefully examine the tools provided to you to determine if any can be used.
151
+ - You must adhere to all of the policies. Pay attention to the details in the terms. Solutions for most situations can be found within these policies.
152
+ ```
153
+
154
+ ## 3. Recommendations for Minimax-M1 Model Usage
155
+
156
+ To achieve the best results with the Minimax-M1 model, we suggest focusing on two key points: Inference Parameters and the System Prompt.
157
+
158
+ ### 3.1. Inference Parameters
159
+ - Temperature: **`1.0`**
160
+ - Top_p: **`0.95`**
161
+
162
+ This setting is optimal for encouraging creativity and diversity in the model's responses. It allows the model to explore a wider range of linguistic possibilities, preventing outputs that are too rigid or repetitive, while still maintaining strong logical coherence.
163
+
164
+ ### 3.2. System Prompt
165
+ Tailoring your system prompt to the specific task is crucial for guiding the model effectively. Below are suggested settings for different scenarios.
166
+
167
+ #### A. General-Purpose Scenarios
168
+ For common tasks like summarization, translation, Q&A, or creative writing:
169
+ ```
170
+ You are a helpful assistant.
171
+ ```
172
+ #### B. Web Development Scenarios
173
+ For complex tasks like generating code for web pages:
174
+ ```
175
+ You are a web development engineer, writing web pages according to the instructions below. You are a powerful code editing assistant capable of writing code and creating artifacts in conversations with users, or modifying and updating existing artifacts as requested by users.
176
+ All code is written in a single code block to form a complete code file for display, without separating HTML and JavaScript code. An artifact refers to a runnable complete code snippet, you prefer to integrate and output such complete runnable code rather than breaking it down into several code blocks. For certain types of code, they can render graphical interfaces in a UI window. After generation, please check the code execution again to ensure there are no errors in the output.
177
+ Output only the HTML, without any additional descriptive text. Make the UI looks modern and beautiful.
178
+ ```
179
+ #### C. Mathematical Scenarios
180
+ When dealing with problems that require calculation or logical deduction:
181
+ ```
182
+ Please reason step by step, and put your final answer within \boxed{}.
183
+ ```
184
+
185
+ ## 4. Deployment Guide
186
+
187
+ Download the model from HuggingFace repository:
188
+ - [MiniMax-M1-40k](https://huggingface.co/MiniMaxAI/MiniMax-M1-40k)
189
+ - [MiniMax-M1-80k](https://huggingface.co/MiniMaxAI/MiniMax-M1-80k)
190
+
191
+ For production deployment, we recommend using [vLLM](https://docs.vllm.ai/en/latest/) to serve MiniMax-M1. vLLM provides excellent performance for serving large language models with the following features:
192
+ - 🔥 Outstanding service throughout performance
193
+ - ⚡ Efficient and intelligent memory management
194
+ - 📦 Powerful batch request processing capability
195
+ - ⚙️ Deeply optimized underlying performance
196
+
197
+ For detailed vLLM deployment instructions, please refer to our [vLLM Deployment Guide](./docs/vllm_deployment_guide.md). Special Note: Using vLLM versions below 0.9.2 may result in incompatibility or incorrect precision for the model.
198
+ Alternatively, you can also deploy using Transformers directly. For detailed Transformers deployment instructions, you can see our [MiniMax-M1 Transformers Deployment Guide](./docs/transformers_deployment_guide.md).
199
+
200
+
201
+ ## 5. Function Calling
202
+
203
+ The MiniMax-M1 model supports function calling capabilities, enabling the model to identify when external functions need to be called and output function call parameters in a structured format. [MiniMax-M1 Function Call Guide](./docs/function_call_guide.md) provides detailed instructions on how to use the function calling feature of MiniMax-M1.
204
+
205
+
206
+ ## 6. Chatbot & API
207
+ For general use and evaluation, we provide a [Chatbot](https://chat.minimax.io/) with online search capabilities and the [online API](https://www.minimax.io/platform/) for developers. For general use and evaluation, we provide the [MiniMax MCP Server](https://github.com/MiniMax-AI/MiniMax-MCP) with video generation, image generation, speech synthesis, and voice cloning for developers.
208
+
209
+
210
+ ## 7. Citation
211
+ ```
212
+ @misc{minimax2025minimaxm1scalingtesttimecompute,
213
+ title={MiniMax-M1: Scaling Test-Time Compute Efficiently with Lightning Attention},
214
+ author={MiniMax},
215
+ year={2025},
216
+ eprint={2506.13585},
217
+ archivePrefix={arXiv},
218
+ primaryClass={cs.CL},
219
+ url={https://arxiv.org/abs/2506.13585},
220
+ }
221
+ ```
222
+
223
+ ## 8. Contact Us
224
+ Contact us at [[email protected]](mailto:[email protected]).
config.json ADDED
@@ -0,0 +1,127 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "architectures": [
3
+ "MiniMaxM1ForCausalLM"
4
+ ],
5
+ "attention_dropout": 0.0,
6
+ "attn_type_list": [
7
+ 0,
8
+ 0,
9
+ 0,
10
+ 0,
11
+ 0,
12
+ 0,
13
+ 0,
14
+ 1,
15
+ 0,
16
+ 0,
17
+ 0,
18
+ 0,
19
+ 0,
20
+ 0,
21
+ 0,
22
+ 1,
23
+ 0,
24
+ 0,
25
+ 0,
26
+ 0,
27
+ 0,
28
+ 0,
29
+ 0,
30
+ 1,
31
+ 0,
32
+ 0,
33
+ 0,
34
+ 0,
35
+ 0,
36
+ 0,
37
+ 0,
38
+ 1,
39
+ 0,
40
+ 0,
41
+ 0,
42
+ 0,
43
+ 0,
44
+ 0,
45
+ 0,
46
+ 1,
47
+ 0,
48
+ 0,
49
+ 0,
50
+ 0,
51
+ 0,
52
+ 0,
53
+ 0,
54
+ 1,
55
+ 0,
56
+ 0,
57
+ 0,
58
+ 0,
59
+ 0,
60
+ 0,
61
+ 0,
62
+ 1,
63
+ 0,
64
+ 0,
65
+ 0,
66
+ 0,
67
+ 0,
68
+ 0,
69
+ 0,
70
+ 1,
71
+ 0,
72
+ 0,
73
+ 0,
74
+ 0,
75
+ 0,
76
+ 0,
77
+ 0,
78
+ 1,
79
+ 0,
80
+ 0,
81
+ 0,
82
+ 0,
83
+ 0,
84
+ 0,
85
+ 0,
86
+ 1
87
+ ],
88
+ "auto_map": {
89
+ "AutoConfig": "configuration_minimax_m1.MiniMaxM1Config",
90
+ "AutoModelForCausalLM": "modeling_minimax_m1.MiniMaxM1ForCausalLM"
91
+ },
92
+ "bos_token_id": null,
93
+ "eos_token_id": null,
94
+ "head_dim": 128,
95
+ "hidden_act": "silu",
96
+ "hidden_size": 6144,
97
+ "initializer_range": 0.02,
98
+ "intermediate_size": 9216,
99
+ "layernorm_full_attention_alpha": 3.5565588200778455,
100
+ "layernorm_full_attention_beta": 1.0,
101
+ "layernorm_linear_attention_alpha": 3.5565588200778455,
102
+ "layernorm_linear_attention_beta": 1.0,
103
+ "layernorm_mlp_alpha": 3.5565588200778455,
104
+ "layernorm_mlp_beta": 1.0,
105
+ "max_position_embeddings": 10240000,
106
+ "model_type": "minimax_m1",
107
+ "num_attention_heads": 64,
108
+ "num_experts_per_tok": 2,
109
+ "num_hidden_layers": 80,
110
+ "num_key_value_heads": 8,
111
+ "num_local_experts": 32,
112
+ "output_router_logits": false,
113
+ "postnorm": true,
114
+ "rms_norm_eps": 1e-05,
115
+ "rope_theta": 10000000,
116
+ "rotary_dim": 64,
117
+ "router_aux_loss_coef": 0.001,
118
+ "router_jitter_noise": 0.0,
119
+ "shared_intermediate_size": 0,
120
+ "shared_moe_mode": "sigmoid",
121
+ "sliding_window": null,
122
+ "tie_word_embeddings": false,
123
+ "transformers_version": "4.45.2",
124
+ "use_cache": true,
125
+ "vocab_size": 200064
126
+ }
127
+
configuration_minimax_m1.py ADDED
@@ -0,0 +1,152 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ """ MiniMaxM1 model configuration"""
2
+
3
+ from transformers.configuration_utils import PretrainedConfig
4
+ from transformers.utils import logging
5
+
6
+
7
+ logger = logging.get_logger(__name__)
8
+
9
+
10
+ class MiniMaxM1Config(PretrainedConfig):
11
+ r"""
12
+ This is the configuration class to store the configuration of a [`MiniMaxM1Model`]. It is used to instantiate an
13
+ MiniMaxM1 model according to the specified arguments, defining the model architecture. Instantiating a configuration
14
+ with the defaults will yield a similar configuration to that of the MiniMaxM1.
15
+
16
+ Configuration objects inherit from [`PretrainedConfig`] and can be used to control the model outputs. Read the
17
+ documentation from [`PretrainedConfig`] for more information.
18
+
19
+
20
+ Args:
21
+ vocab_size (`int`, *optional*, defaults to 32000):
22
+ Vocabulary size of the MiniMaxM1 model. Defines the number of different tokens that can be represented by the
23
+ `inputs_ids` passed when calling [`MiniMaxM1Model`]
24
+ hidden_size (`int`, *optional*, defaults to 4096):
25
+ Dimension of the hidden representations.
26
+ intermediate_size (`int`, *optional*, defaults to 14336):
27
+ Dimension of the MLP representations.
28
+ num_hidden_layers (`int`, *optional*, defaults to 32):
29
+ Number of hidden layers in the Transformer encoder.
30
+ num_attention_heads (`int`, *optional*, defaults to 32):
31
+ Number of attention heads for each attention layer in the Transformer encoder.
32
+ num_key_value_heads (`int`, *optional*, defaults to 8):
33
+ This is the number of key_value heads that should be used to implement Grouped Query Attention. If
34
+ `num_key_value_heads=num_attention_heads`, the model will use Multi Head Attention (MHA), if
35
+ `num_key_value_heads=1 the model will use Multi Query Attention (MQA) otherwise GQA is used. When
36
+ converting a multi-head checkpoint to a GQA checkpoint, each group key and value head should be constructed
37
+ by meanpooling all the original heads within that group. For more details checkout [this
38
+ paper](https://arxiv.org/pdf/2305.13245.pdf). If it is not specified, will default to `8`.
39
+ hidden_act (`str` or `function`, *optional*, defaults to `"silu"`):
40
+ The non-linear activation function (function or string) in the decoder.
41
+ max_position_embeddings (`int`, *optional*, defaults to `4096*32`):
42
+ The maximum sequence length that this model might ever be used with. MiniMaxM1's sliding window attention
43
+ allows sequence of up to 4096*32 tokens.
44
+ initializer_range (`float`, *optional*, defaults to 0.02):
45
+ The standard deviation of the truncated_normal_initializer for initializing all weight matrices.
46
+ rms_norm_eps (`float`, *optional*, defaults to 1e-05):
47
+ The epsilon used by the rms normalization layers.
48
+ use_cache (`bool`, *optional*, defaults to `True`):
49
+ Whether or not the model should return the last key/values attentions (not used by all models). Only
50
+ relevant if `config.is_decoder=True`.
51
+ pad_token_id (`int`, *optional*):
52
+ The id of the padding token.
53
+ bos_token_id (`int`, *optional*, defaults to 1):
54
+ The id of the "beginning-of-sequence" token.
55
+ eos_token_id (`int`, *optional*, defaults to 2):
56
+ The id of the "end-of-sequence" token.
57
+ tie_word_embeddings (`bool`, *optional*, defaults to `False`):
58
+ Whether the model's input and output word embeddings should be tied.
59
+ rope_theta (`float`, *optional*, defaults to 1000000.0):
60
+ The base period of the RoPE embeddings.
61
+ sliding_window (`int`, *optional*):
62
+ Sliding window attention window size. If not specified, will default to `4096`.
63
+ attention_dropout (`float`, *optional*, defaults to 0.0):
64
+ The dropout ratio for the attention probabilities.
65
+ num_experts_per_tok (`int`, *optional*, defaults to 2):
66
+ The number of experts to route per-token, can be also interpreted as the `top-k` routing
67
+ parameter
68
+ num_local_experts (`int`, *optional*, defaults to 8):
69
+ Number of experts per Sparse MLP layer.
70
+ output_router_logits (`bool`, *optional*, defaults to `False`):
71
+ Whether or not the router logits should be returned by the model. Enabeling this will also
72
+ allow the model to output the auxiliary loss. See [here]() for more details
73
+ router_aux_loss_coef (`float`, *optional*, defaults to 0.001):
74
+ The aux loss factor for the total loss.
75
+ router_jitter_noise (`float`, *optional*, defaults to 0.0):
76
+ Amount of noise to add to the router.
77
+
78
+ ```python
79
+ >>> from transformers import MiniMaxM1Model, MiniMaxM1Config
80
+
81
+ >>> # Initializing a MiniMaxM1 style configuration
82
+ >>> configuration = MiniMaxM1Config()
83
+
84
+ >>> # Initializing a model from the MiniMaxM1 style configuration
85
+ >>> model = MiniMaxM1Model(configuration)
86
+
87
+ >>> # Accessing the model configuration
88
+ >>> configuration = model.config
89
+ ```"""
90
+
91
+ model_type = "MiniMaxM1"
92
+ keys_to_ignore_at_inference = ["past_key_values"]
93
+
94
+ def __init__(
95
+ self,
96
+ vocab_size=32000,
97
+ hidden_size=4096,
98
+ intermediate_size=14336,
99
+ num_hidden_layers=32,
100
+ num_attention_heads=32,
101
+ num_key_value_heads=8,
102
+ hidden_act="silu",
103
+ max_position_embeddings=4096 * 32,
104
+ initializer_range=0.02,
105
+ rms_norm_eps=1e-5,
106
+ use_cache=True,
107
+ pad_token_id=None,
108
+ bos_token_id=None,
109
+ eos_token_id=None,
110
+ tie_word_embeddings=False,
111
+ rope_theta=1e6,
112
+ sliding_window=None,
113
+ attention_dropout=0.0,
114
+ num_experts_per_tok=2,
115
+ num_local_experts=8,
116
+ output_router_logits=False,
117
+ router_aux_loss_coef=0.001,
118
+ router_jitter_noise=0.0,
119
+ **kwargs,
120
+ ):
121
+ self.vocab_size = vocab_size
122
+ self.max_position_embeddings = max_position_embeddings
123
+ self.hidden_size = hidden_size
124
+ self.intermediate_size = intermediate_size
125
+ self.num_hidden_layers = num_hidden_layers
126
+ self.num_attention_heads = num_attention_heads
127
+ self.sliding_window = sliding_window
128
+
129
+ # for backward compatibility
130
+ if num_key_value_heads is None:
131
+ num_key_value_heads = num_attention_heads
132
+
133
+ self.num_key_value_heads = num_key_value_heads
134
+ self.hidden_act = hidden_act
135
+ self.initializer_range = initializer_range
136
+ self.rms_norm_eps = rms_norm_eps
137
+ self.use_cache = use_cache
138
+ self.rope_theta = rope_theta
139
+ self.attention_dropout = attention_dropout
140
+
141
+ self.num_experts_per_tok = num_experts_per_tok
142
+ self.num_local_experts = num_local_experts
143
+ self.output_router_logits = output_router_logits
144
+ self.router_aux_loss_coef = router_aux_loss_coef
145
+ self.router_jitter_noise = router_jitter_noise
146
+ super().__init__(
147
+ pad_token_id=pad_token_id,
148
+ bos_token_id=bos_token_id,
149
+ eos_token_id=eos_token_id,
150
+ tie_word_embeddings=tie_word_embeddings,
151
+ **kwargs,
152
+ )
docs/function_call_guide.md ADDED
@@ -0,0 +1,424 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # MiniMax-M1 Function Call Guide
2
+
3
+ [FunctionCall中文使用指南](./function_call_guide_cn.md)
4
+
5
+ ## 📖 Introduction
6
+
7
+ The MiniMax-M1 model supports function calling capabilities, enabling the model to identify when external functions need to be called and output function call parameters in a structured format. This document provides detailed instructions on how to use the function calling feature of MiniMax-M1.
8
+
9
+ ## 🚀 Quick Start
10
+
11
+ ### Using vLLM for Function Calls (Recommended)
12
+
13
+ In actual deployment, to support native Function Calling (tool calling) capabilities similar to OpenAI API, the MiniMax-M1 model integrates a dedicated `tool_call_parser=minimax` parser, avoiding additional regex parsing of model output.
14
+
15
+ #### Environment Setup and vLLM Recompilation
16
+
17
+ Since this feature has not been officially released in the PyPI version, compilation from source code is required. The following is an example process based on the official vLLM Docker image `vllm/vllm-openai:v0.8.3`:
18
+
19
+ ```bash
20
+ IMAGE=vllm/vllm-openai:v0.8.3
21
+ DOCKER_RUN_CMD="--network=host --privileged --ipc=host --ulimit memlock=-1 --shm-size=32gb --rm --gpus all --ulimit stack=67108864"
22
+
23
+ # Run docker
24
+ sudo docker run -it -v $MODEL_DIR:$MODEL_DIR \
25
+ -v $CODE_DIR:$CODE_DIR \
26
+ --name vllm_function_call \
27
+ $DOCKER_RUN_CMD \
28
+ --entrypoint /bin/bash \
29
+ $IMAGE
30
+ ```
31
+
32
+ #### Compiling vLLM Source Code
33
+
34
+ After entering the container, execute the following commands to get the source code and reinstall:
35
+
36
+ ```bash
37
+ cd $CODE_DIR
38
+ git clone https://github.com/vllm-project/vllm.git
39
+ cd vllm
40
+ pip install -e .
41
+ ```
42
+
43
+ #### Starting vLLM API Service
44
+
45
+ ```bash
46
+ export SAFETENSORS_FAST_GPU=1
47
+ export VLLM_USE_V1=0
48
+
49
+ python3 -m vllm.entrypoints.openai.api_server \
50
+ --model MiniMax-M1-80k \
51
+ --tensor-parallel-size 8 \
52
+ --trust-remote-code \
53
+ --quantization experts_int8 \
54
+ --enable-auto-tool-choice \
55
+ --tool-call-parser minimax \
56
+ --chat-template vllm/examples/tool_chat_template_minimax_m1.jinja \
57
+ --max_model_len 4096 \
58
+ --dtype bfloat16 \
59
+ --gpu-memory-utilization 0.85
60
+ ```
61
+
62
+ **⚠️ Note:**
63
+ - `--tool-call-parser minimax` is a key parameter for enabling the MiniMax-M1 custom parser
64
+ - `--enable-auto-tool-choice` enables automatic tool selection
65
+ - `--chat-template` template file needs to be adapted for tool calling format
66
+
67
+ #### Function Call Test Script Example
68
+
69
+ The following Python script implements a weather query function call example based on OpenAI SDK:
70
+
71
+ ```python
72
+ from openai import OpenAI
73
+ import json
74
+
75
+ client = OpenAI(base_url="http://localhost:8000/v1", api_key="dummy")
76
+
77
+ def get_weather(location: str, unit: str):
78
+ return f"Getting the weather for {location} in {unit}..."
79
+
80
+ tool_functions = {"get_weather": get_weather}
81
+
82
+ tools = [{
83
+ "type": "function",
84
+ "function": {
85
+ "name": "get_weather",
86
+ "description": "Get the current weather in a given location",
87
+ "parameters": {
88
+ "type": "object",
89
+ "properties": {
90
+ "location": {"type": "string", "description": "City and state, e.g., 'San Francisco, CA'"},
91
+ "unit": {"type": "string", "enum": ["celsius", "fahrenheit"]}
92
+ },
93
+ "required": ["location", "unit"]
94
+ }
95
+ }
96
+ }]
97
+
98
+ response = client.chat.completions.create(
99
+ model=client.models.list().data[0].id,
100
+ messages=[{"role": "user", "content": "What's the weather like in San Francisco? use celsius."}],
101
+ tools=tools,
102
+ tool_choice="auto"
103
+ )
104
+
105
+ print(response)
106
+
107
+ tool_call = response.choices[0].message.tool_calls[0].function
108
+ print(f"Function called: {tool_call.name}")
109
+ print(f"Arguments: {tool_call.arguments}")
110
+ print(f"Result: {get_weather(**json.loads(tool_call.arguments))}")
111
+ ```
112
+
113
+ **Output Example:**
114
+ ```
115
+ Function called: get_weather
116
+ Arguments: {"location": "San Francisco, CA", "unit": "celsius"}
117
+ Result: Getting the weather for San Francisco, CA in celsius...
118
+ ```
119
+
120
+ ### Manual Parsing of Model Output
121
+
122
+ If you cannot use vLLM's built-in parser, or need to use other inference frameworks (such as transformers, TGI, etc.), you can use the following method to manually parse the model's raw output. This method requires you to parse the XML tag format of the model output yourself.
123
+
124
+ #### Using Transformers Example
125
+
126
+ The following is a complete example using the transformers library:
127
+
128
+ ```python
129
+ from transformers import AutoTokenizer
130
+
131
+ def get_default_tools():
132
+ return [
133
+ {
134
+ "name": "get_current_weather",
135
+ "description": "Get the latest weather for a location",
136
+ "parameters": {
137
+ "type": "object",
138
+ "properties": {
139
+ "location": {
140
+ "type": "string",
141
+ "description": "A certain city, such as Beijing, Shanghai"
142
+ }
143
+ },
144
+ }
145
+ "required": ["location"],
146
+ "type": "object"
147
+ }
148
+ ]
149
+
150
+ # Load model and tokenizer
151
+ tokenizer = AutoTokenizer.from_pretrained(model_id)
152
+ prompt = "What's the weather like in Shanghai today?"
153
+ messages = [
154
+ {"role": "system", "content": [{"type": "text", "text": "You are a helpful assistant created by Minimax based on MiniMax-M1 model."}]},
155
+ {"role": "user", "content": [{"type": "text", "text": prompt}]},
156
+ ]
157
+
158
+ # Enable function call tools
159
+ tools = get_default_tools()
160
+
161
+ # Apply chat template and add tool definitions
162
+ text = tokenizer.apply_chat_template(
163
+ messages,
164
+ tokenize=False,
165
+ add_generation_prompt=True,
166
+ tools=tools
167
+ )
168
+
169
+ # Send request (using any inference service here)
170
+ import requests
171
+ payload = {
172
+ "model": "MiniMaxAI/MiniMax-M1-40k",
173
+ "prompt": text,
174
+ "max_tokens": 4000
175
+ }
176
+ response = requests.post(
177
+ "http://localhost:8000/v1/completions",
178
+ headers={"Content-Type": "application/json"},
179
+ json=payload,
180
+ stream=False,
181
+ )
182
+
183
+ # Model output needs manual parsing
184
+ raw_output = response.json()["choices"][0]["text"]
185
+ print("Raw output:", raw_output)
186
+
187
+ # Use the parsing function below to process the output
188
+ function_calls = parse_function_calls(raw_output)
189
+ ```
190
+
191
+ ## 🛠️ Function Call Definition
192
+
193
+ ### Function Structure
194
+
195
+ Function calls need to be defined in the `tools` field of the request body. Each function consists of the following components:
196
+
197
+ ```json
198
+ {
199
+ "tools": [
200
+ {
201
+ "name": "search_web",
202
+ "description": "Search function.",
203
+ "parameters": {
204
+ "properties": {
205
+ "query_list": {
206
+ "description": "Keywords for search, with list element count of 1.",
207
+ "items": { "type": "string" },
208
+ "type": "array"
209
+ },
210
+ "query_tag": {
211
+ "description": "Classification of the query",
212
+ "items": { "type": "string" },
213
+ "type": "array"
214
+ }
215
+ },
216
+ "required": [ "query_list", "query_tag" ],
217
+ "type": "object"
218
+ }
219
+ }
220
+ ]
221
+ }
222
+ ```
223
+
224
+ **Field Descriptions:**
225
+ - `name`: Function name
226
+ - `description`: Function description
227
+ - `parameters`: Function parameter definition
228
+ - `properties`: Parameter property definitions, where key is the parameter name and value contains detailed parameter description
229
+ - `required`: List of required parameters
230
+ - `type`: Parameter type (usually "object")
231
+
232
+ ### Internal Model Processing Format
233
+
234
+ When processed internally by the model, function definitions are converted to a special format and concatenated to the input text:
235
+
236
+ ```
237
+ <begin_of_document><beginning_of_sentence>system ai_setting=MiniMax AI
238
+ MiniMax AI是由上海稀宇科技有限公司(MiniMax)自主研发的AI助理。<end_of_sentence>
239
+ <beginning_of_sentence>system tool_setting=tools
240
+ You are provided with these tools:
241
+ <tools>
242
+ {"name": "search_web", "description": "搜索函数。", "parameters": {"properties": {"query_list": {"description": "进行搜索的关键词,列表元素个数为1。", "items": {"type": "string"}, "type": "array"}, "query_tag": {"description": "query的分类", "items": {"type": "string"}, "type": "array"}}, "required": ["query_list", "query_tag"], "type": "object"}}
243
+ </tools>
244
+ If you need to call tools, please respond with <tool_calls></tool_calls> XML tags, and provide tool-name and json-object of arguments, following the format below:
245
+ <tool_calls>
246
+ {"name": <tool-name>, "arguments": <args-json-object>}
247
+ ...
248
+ </tool_calls><end_of_sentence>
249
+ <beginning_of_sentence>user name=用户
250
+ OpenAI 和 Gemini 的最近一次发布会都是什么时候?<end_of_sentence>
251
+ <beginning_of_sentence>ai name=MiniMax AI
252
+ ```
253
+
254
+ ### Model Output Format
255
+
256
+ The model outputs function calls in the following format:
257
+
258
+ ```xml
259
+ <think>
260
+ Okay, I will search for the OpenAI and Gemini latest release.
261
+ </think>
262
+ <tool_calls>
263
+ {"name": "search_web", "arguments": {"query_tag": ["technology", "events"], "query_list": ["\"OpenAI\" \"latest\" \"release\""]}}
264
+ {"name": "search_web", "arguments": {"query_tag": ["technology", "events"], "query_list": ["\"Gemini\" \"latest\" \"release\""]}}
265
+ </tool_calls>
266
+ ```
267
+
268
+ ## 📥 Manual Parsing of Function Call Results
269
+
270
+ ### Parsing Function Calls
271
+
272
+ When manual parsing is required, you need to parse the XML tag format of the model output:
273
+
274
+ ```python
275
+ import re
276
+ import json
277
+ def parse_function_calls(content: str):
278
+ """
279
+ Parse function calls from model output
280
+ """
281
+ function_calls = []
282
+
283
+ # Match content within <tool_calls> tags
284
+ tool_calls_pattern = r"<tool_calls>(.*?)</tool_calls>"
285
+ tool_calls_match = re.search(tool_calls_pattern, content, re.DOTALL)
286
+
287
+ if not tool_calls_match:
288
+ return function_calls
289
+
290
+ tool_calls_content = tool_calls_match.group(1).strip()
291
+
292
+ # Parse each function call (one JSON object per line)
293
+ for line in tool_calls_content.split('\n'):
294
+ line = line.strip()
295
+ if not line:
296
+ continue
297
+
298
+ try:
299
+ # Parse JSON format function call
300
+ call_data = json.loads(line)
301
+ function_name = call_data.get("name")
302
+ arguments = call_data.get("arguments", {})
303
+
304
+ function_calls.append({
305
+ "name": function_name,
306
+ "arguments": arguments
307
+ })
308
+
309
+ print(f"Function call: {function_name}, Arguments: {arguments}")
310
+
311
+ except json.JSONDecodeError as e:
312
+ print(f"Parameter parsing failed: {line}, Error: {e}")
313
+
314
+ return function_calls
315
+
316
+ # Example: Handle weather query function
317
+ def execute_function_call(function_name: str, arguments: dict):
318
+ """
319
+ Execute function call and return result
320
+ """
321
+ if function_name == "get_current_weather":
322
+ location = arguments.get("location", "Unknown location")
323
+ # Build function execution result
324
+ return {
325
+ "role": "tool",
326
+ "content": [
327
+ {
328
+ "name": function_name,
329
+ "type": "text",
330
+ "text": json.dumps({
331
+ "location": location,
332
+ "temperature": "25",
333
+ "unit": "celsius",
334
+ "weather": "Sunny"
335
+ }, ensure_ascii=False)
336
+ }
337
+ ]
338
+ }
339
+ elif function_name == "search_web":
340
+ query_list = arguments.get("query_list", [])
341
+ query_tag = arguments.get("query_tag", [])
342
+ # Simulate search results
343
+ return {
344
+ "role": "tool",
345
+ "content": [
346
+ {
347
+ "name": function_name,
348
+ "type": "text",
349
+ "text": f"Search keywords: {query_list}, Categories: {query_tag}\nSearch results: Relevant information found"
350
+ }
351
+ ]
352
+ }
353
+
354
+ return None
355
+ ```
356
+
357
+ ### Returning Function Execution Results to the Model
358
+
359
+ After successfully parsing function calls, you should add the function execution results to the conversation history so that the model can access and utilize this information in subsequent interactions.
360
+
361
+ #### Single Result
362
+
363
+ If the model calls the `search_web` function, you can refer to the following format to add execution results, with the `name` field being the specific function name.
364
+
365
+ ```json
366
+ {
367
+ "role": "tool",
368
+ "content": [
369
+ {
370
+ "name": "search_web",
371
+ "type": "text",
372
+ "text": "test_result"
373
+ }
374
+ ]
375
+ }
376
+ ```
377
+
378
+ Corresponding model input format:
379
+ ```
380
+ <beginning_of_sentence>tool name=tools
381
+ tool name: search_web
382
+ tool result: test_result
383
+ <end_of_sentence>
384
+ ```
385
+
386
+ #### Multiple Results
387
+
388
+ If the model calls both `search_web` and `get_current_weather` functions simultaneously, you can refer to the following format to add execution results, with `content` containing multiple results.
389
+
390
+ ```json
391
+ {
392
+ "role": "tool",
393
+ "content": [
394
+ {
395
+ "name": "search_web",
396
+ "type": "text",
397
+ "text": "test_result1"
398
+ },
399
+ {
400
+ "name": "get_current_weather",
401
+ "type": "text",
402
+ "text": "test_result2"
403
+ }
404
+ ]
405
+ }
406
+ ```
407
+
408
+ Corresponding model input format:
409
+ ```
410
+ <beginning_of_sentence>tool name=tools
411
+ tool name: search_web
412
+ tool result: test_result1
413
+ tool name: get_current_weather
414
+ tool result: test_result2<end_of_sentence>
415
+ ```
416
+
417
+ While we recommend following the above formats, as long as the input returned to the model is easy to understand, the specific content of `name` and `text` is entirely up to you.
418
+
419
+ ## 📚 References
420
+
421
+ - [MiniMax-M1 Model Repository](https://github.com/MiniMaxAI/MiniMax-M1)
422
+ - [vLLM Project Homepage](https://github.com/vllm-project/vllm)
423
+ - [vLLM Function Calling PR](https://github.com/vllm-project/vllm/pull/20297)
424
+ - [OpenAI Python SDK](https://github.com/openai/openai-python)
docs/function_call_guide_cn.md ADDED
@@ -0,0 +1,422 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # MiniMax-M1 函数调用(Function Call)功能指南
2
+
3
+ ## 📖 简介
4
+
5
+ MiniMax-M1 模型支持函数调用功能,使模型能够识别何时需要调用外部函数,并以结构化格式输出函数调用参数。本文档详细介绍了如何使用 MiniMax-M1 的函数调用功能。
6
+
7
+ ## 🚀 快速开始
8
+
9
+ ### 使用 vLLM 进行 Function Calls(推荐)
10
+
11
+ 在实际部署过程中,为了支持类似 OpenAI API 的原生 Function Calling(工具调用)能力,MiniMax-M1 模型集成了专属 `tool_call_parser=minimax` 解析器,从而避免对模型输出结果进行额外的正则解析处理。
12
+
13
+ #### 环境准备与重新编译 vLLM
14
+
15
+ 由于该功能尚未正式发布在 PyPI 版本中,需基于源码进行编译。以下为基于 vLLM 官方 Docker 镜像 `vllm/vllm-openai:v0.8.3` 的示例流程:
16
+
17
+ ```bash
18
+ IMAGE=vllm/vllm-openai:v0.8.3
19
+ DOCKER_RUN_CMD="--network=host --privileged --ipc=host --ulimit memlock=-1 --shm-size=32gb --rm --gpus all --ulimit stack=67108864"
20
+
21
+ # 运行 docker
22
+ sudo docker run -it -v $MODEL_DIR:$MODEL_DIR \
23
+ -v $CODE_DIR:$CODE_DIR \
24
+ --name vllm_function_call \
25
+ $DOCKER_RUN_CMD \
26
+ --entrypoint /bin/bash \
27
+ $IMAGE
28
+ ```
29
+
30
+ #### 编译 vLLM 源码
31
+
32
+ 进入容器后,执行以下命令以获取源码并重新安装:
33
+
34
+ ```bash
35
+ cd $CODE_DIR
36
+ git clone https://github.com/vllm-project/vllm.git
37
+ cd vllm
38
+ pip install -e .
39
+ ```
40
+
41
+ #### 启动 vLLM API 服务
42
+
43
+ ```bash
44
+ export SAFETENSORS_FAST_GPU=1
45
+ export VLLM_USE_V1=0
46
+
47
+ python3 -m vllm.entrypoints.openai.api_server \
48
+ --model MiniMax-M1-80k \
49
+ --tensor-parallel-size 8 \
50
+ --trust-remote-code \
51
+ --quantization experts_int8 \
52
+ --enable-auto-tool-choice \
53
+ --tool-call-parser minimax \
54
+ --chat-template vllm/examples/tool_chat_template_minimax_m1.jinja \
55
+ --max_model_len 4096 \
56
+ --dtype bfloat16 \
57
+ --gpu-memory-utilization 0.85
58
+ ```
59
+
60
+ **⚠️ 注意:**
61
+ - `--tool-call-parser minimax` 为关键参数,用于启用 MiniMax-M1 自定义解析器
62
+ - `--enable-auto-tool-choice` 启用自动工具选择
63
+ - `--chat-template` 模板文件需要适配 tool calling 格式
64
+
65
+ #### Function Call 测试脚本示例
66
+
67
+ 以下 Python 脚本基于 OpenAI SDK 实现了一个天气查询函数的调用示例:
68
+
69
+ ```python
70
+ from openai import OpenAI
71
+ import json
72
+
73
+ client = OpenAI(base_url="http://localhost:8000/v1", api_key="dummy")
74
+
75
+ def get_weather(location: str, unit: str):
76
+ return f"Getting the weather for {location} in {unit}..."
77
+
78
+ tool_functions = {"get_weather": get_weather}
79
+
80
+ tools = [{
81
+ "type": "function",
82
+ "function": {
83
+ "name": "get_weather",
84
+ "description": "Get the current weather in a given location",
85
+ "parameters": {
86
+ "type": "object",
87
+ "properties": {
88
+ "location": {"type": "string", "description": "City and state, e.g., 'San Francisco, CA'"},
89
+ "unit": {"type": "string", "enum": ["celsius", "fahrenheit"]}
90
+ },
91
+ "required": ["location", "unit"]
92
+ }
93
+ }
94
+ }]
95
+
96
+ response = client.chat.completions.create(
97
+ model=client.models.list().data[0].id,
98
+ messages=[{"role": "user", "content": "What's the weather like in San Francisco? use celsius."}],
99
+ tools=tools,
100
+ tool_choice="auto"
101
+ )
102
+
103
+ print(response)
104
+
105
+ tool_call = response.choices[0].message.tool_calls[0].function
106
+ print(f"Function called: {tool_call.name}")
107
+ print(f"Arguments: {tool_call.arguments}")
108
+ print(f"Result: {get_weather(**json.loads(tool_call.arguments))}")
109
+ ```
110
+
111
+ **输出示例:**
112
+ ```
113
+ Function called: get_weather
114
+ Arguments: {"location": "San Francisco, CA", "unit": "celsius"}
115
+ Result: Getting the weather for San Francisco, CA in celsius...
116
+ ```
117
+
118
+ ### 手动解析模型输出
119
+
120
+ 如果您无法使用 vLLM 的内置解析器,或者需要使用其他推理框架(如 transformers、TGI 等),可以使用以下方法手动解析模型的原始输出。这种方法需要您自己解析模型输出的 XML 标签格式。
121
+
122
+ #### 使用 Transformers 的示例
123
+
124
+ 以下是使用 transformers 库的完整示例:
125
+
126
+ ```python
127
+ from transformers import AutoTokenizer
128
+
129
+ def get_default_tools():
130
+ return [
131
+ {
132
+ "name": "get_current_weather",
133
+ "description": "Get the latest weather for a location",
134
+ "parameters": {
135
+ "type": "object",
136
+ "properties": {
137
+ "location": {
138
+ "type": "string",
139
+ "description": "A certain city, such as Beijing, Shanghai"
140
+ }
141
+ },
142
+ }
143
+ "required": ["location"],
144
+ "type": "object"
145
+ }
146
+ ]
147
+
148
+ # 加载模型和分词器
149
+ tokenizer = AutoTokenizer.from_pretrained(model_id)
150
+ prompt = "What's the weather like in Shanghai today?"
151
+ messages = [
152
+ {"role": "system", "content": [{"type": "text", "text": "You are a helpful assistant created by Minimax based on MiniMax-M1 model."}]},
153
+ {"role": "user", "content": [{"type": "text", "text": prompt}]},
154
+ ]
155
+
156
+ # 启用函数调用工具
157
+ tools = get_default_tools()
158
+
159
+ # 应用聊天模板,并加入工具定义
160
+ text = tokenizer.apply_chat_template(
161
+ messages,
162
+ tokenize=False,
163
+ add_generation_prompt=True,
164
+ tools=tools
165
+ )
166
+
167
+ # 发送请求(这里使用任何推理服务)
168
+ import requests
169
+ payload = {
170
+ "model": "MiniMaxAI/MiniMax-M1-40k",
171
+ "prompt": text,
172
+ "max_tokens": 4000
173
+ }
174
+ response = requests.post(
175
+ "http://localhost:8000/v1/completions",
176
+ headers={"Content-Type": "application/json"},
177
+ json=payload,
178
+ stream=False,
179
+ )
180
+
181
+ # 模型输出需要手动解析
182
+ raw_output = response.json()["choices"][0]["text"]
183
+ print("原始输出:", raw_output)
184
+
185
+ # 使用下面的解析函数处理输出
186
+ function_calls = parse_function_calls(raw_output)
187
+ ```
188
+
189
+ ## 🛠️ 函数调用的定义
190
+
191
+ ### 函数结构体
192
+
193
+ 函数调用需要在请求体中定义 `tools` 字段,每个函数由以下部分组成:
194
+
195
+ ```json
196
+ {
197
+ "tools": [
198
+ {
199
+ "name": "search_web",
200
+ "description": "搜索函数。",
201
+ "parameters": {
202
+ "properties": {
203
+ "query_list": {
204
+ "description": "进行搜索的关键词,列表元素个数为1。",
205
+ "items": { "type": "string" },
206
+ "type": "array"
207
+ },
208
+ "query_tag": {
209
+ "description": "query的分类",
210
+ "items": { "type": "string" },
211
+ "type": "array"
212
+ }
213
+ },
214
+ "required": [ "query_list", "query_tag" ],
215
+ "type": "object"
216
+ }
217
+ }
218
+ ]
219
+ }
220
+ ```
221
+
222
+ **字段说明:**
223
+ - `name`: 函数名称
224
+ - `description`: 函数功能描述
225
+ - `parameters`: 函数参数定义
226
+ - `properties`: 参数属性定义,key 是参数名,value 包含参数的详细描述
227
+ - `required`: 必填参数列表
228
+ - `type`: 参数类型(通常为 "object")
229
+
230
+ ### 模型内部处理格式
231
+
232
+ 在模型内部处理时,函数定义会被转换为特殊格式并拼接到输入文本中:
233
+
234
+ ```
235
+ <begin_of_document><beginning_of_sentence>system ai_setting=MiniMax AI
236
+ MiniMax AI是由上海稀宇科技有限公司(MiniMax)自主研发的AI助理。<end_of_sentence>
237
+ <beginning_of_sentence>system tool_setting=tools
238
+ You are provided with these tools:
239
+ <tools>
240
+ {"name": "search_web", "description": "搜索函数。", "parameters": {"properties": {"query_list": {"description": "进行搜索的关键词,列表元素个数为1。", "items": {"type": "string"}, "type": "array"}, "query_tag": {"description": "query的分类", "items": {"type": "string"}, "type": "array"}}, "required": ["query_list", "query_tag"], "type": "object"}}
241
+ </tools>
242
+ If you need to call tools, please respond with <tool_calls></tool_calls> XML tags, and provide tool-name and json-object of arguments, following the format below:
243
+ <tool_calls>
244
+ {"name": <tool-name>, "arguments": <args-json-object>}
245
+ ...
246
+ </tool_calls><end_of_sentence>
247
+ <beginning_of_sentence>user name=用户
248
+ OpenAI 和 Gemini 的最近一次发布会都是什么时候?<end_of_sentence>
249
+ <beginning_of_sentence>ai name=MiniMax AI
250
+ ```
251
+
252
+ ### 模型输出格式
253
+
254
+ 模型会以以下格式输出函数调用:
255
+
256
+ ```xml
257
+ <think>
258
+ Okay, I will search for the OpenAI and Gemini latest release.
259
+ </think>
260
+ <tool_calls>
261
+ {"name": "search_web", "arguments": {"query_tag": ["technology", "events"], "query_list": ["\"OpenAI\" \"latest\" \"release\""]}}
262
+ {"name": "search_web", "arguments": {"query_tag": ["technology", "events"], "query_list": ["\"Gemini\" \"latest\" \"release\""]}}
263
+ </tool_calls>
264
+ ```
265
+
266
+ ## 📥 手动解析函数调用结果
267
+
268
+ ### 解析函数调用
269
+
270
+ 当需要手动解析时,您需要解析模型输出的 XML 标签格式:
271
+
272
+ ```python
273
+ import re
274
+ import json
275
+ def parse_function_calls(content: str):
276
+ """
277
+ 解析模型输出中的函数调用
278
+ """
279
+ function_calls = []
280
+
281
+ # 匹配 <tool_calls> 标签内的内容
282
+ tool_calls_pattern = r"<tool_calls>(.*?)</tool_calls>"
283
+ tool_calls_match = re.search(tool_calls_pattern, content, re.DOTALL)
284
+
285
+ if not tool_calls_match:
286
+ return function_calls
287
+
288
+ tool_calls_content = tool_calls_match.group(1).strip()
289
+
290
+ # 解析每个函数调用(每行一个JSON对象)
291
+ for line in tool_calls_content.split('\n'):
292
+ line = line.strip()
293
+ if not line:
294
+ continue
295
+
296
+ try:
297
+ # 解析JSON格式的函数调用
298
+ call_data = json.loads(line)
299
+ function_name = call_data.get("name")
300
+ arguments = call_data.get("arguments", {})
301
+
302
+ function_calls.append({
303
+ "name": function_name,
304
+ "arguments": arguments
305
+ })
306
+
307
+ print(f"调用函数: {function_name}, 参数: {arguments}")
308
+
309
+ except json.JSONDecodeError as e:
310
+ print(f"参数解析失败: {line}, 错误: {e}")
311
+
312
+ return function_calls
313
+
314
+ # 示例:处理天气查询函数
315
+ def execute_function_call(function_name: str, arguments: dict):
316
+ """
317
+ 执行函数调用并返回结果
318
+ """
319
+ if function_name == "get_current_weather":
320
+ location = arguments.get("location", "未知位置")
321
+ # 构建函数执行结果
322
+ return {
323
+ "role": "tool",
324
+ "content": [
325
+ {
326
+ "name": function_name,
327
+ "type": "text",
328
+ "text": json.dumps({
329
+ "location": location,
330
+ "temperature": "25",
331
+ "unit": "celsius",
332
+ "weather": "晴朗"
333
+ }, ensure_ascii=False)
334
+ }
335
+ ]
336
+ }
337
+ elif function_name == "search_web":
338
+ query_list = arguments.get("query_list", [])
339
+ query_tag = arguments.get("query_tag", [])
340
+ # 模拟搜索结果
341
+ return {
342
+ "role": "tool",
343
+ "content": [
344
+ {
345
+ "name": function_name,
346
+ "type": "text",
347
+ "text": f"搜索关键词: {query_list}, 分类: {query_tag}\n搜索结果: 相关信息已找到"
348
+ }
349
+ ]
350
+ }
351
+
352
+ return None
353
+ ```
354
+
355
+ ### 将函数执行结果返回给模型
356
+
357
+ 成功解析函数调用后,您应将函数执行结果添加到对话历史中,以便模型在后续交互中能够访问和利用这些信息。
358
+
359
+ #### 单个结果
360
+
361
+ 假如模型调用了 `search_web` 函数,您可以参考如下格式添加执行结果,`name` 字段为具体的函数名称。
362
+
363
+ ```json
364
+ {
365
+ "role": "tool",
366
+ "content": [
367
+ {
368
+ "name": "search_web",
369
+ "type": "text",
370
+ "text": "test_result"
371
+ }
372
+ ]
373
+ }
374
+ ```
375
+
376
+ 对应如下的模型输入格式:
377
+ ```
378
+ <beginning_of_sentence>tool name=tools
379
+ tool name: search_web
380
+ tool result: test_result
381
+ <end_of_sentence>
382
+ ```
383
+
384
+ #### 多个结果
385
+
386
+ 假如模型同时调用了 `search_web` 和 `get_current_weather` 函数,您可以参考如下格式添加执行结果,`content`包含多个结果。
387
+
388
+ ```json
389
+ {
390
+ "role": "tool",
391
+ "content": [
392
+ {
393
+ "name": "search_web",
394
+ "type": "text",
395
+ "text": "test_result1"
396
+ },
397
+ {
398
+ "name": "get_current_weather",
399
+ "type": "text",
400
+ "text": "test_result2"
401
+ }
402
+ ]
403
+ }
404
+ ```
405
+
406
+ 对应如下的模型输入格式:
407
+ ```
408
+ <beginning_of_sentence>tool name=tools
409
+ tool name: search_web
410
+ tool result: test_result1
411
+ tool name: get_current_weather
412
+ tool result: test_result2<end_of_sentence>
413
+ ```
414
+
415
+ 虽然我们建议您参考以上格式,但只要返回给模型的输入易于理解,`name` 和 `text` 的具体内容完全由您自主决定。
416
+
417
+ ## 📚 参考资料
418
+
419
+ - [MiniMax-M1 模型仓库](https://github.com/MiniMaxAI/MiniMax-M1)
420
+ - [vLLM 项目主页](https://github.com/vllm-project/vllm)
421
+ - [vLLM Function Calling PR](https://github.com/vllm-project/vllm/pull/20297)
422
+ - [OpenAI Python SDK](https://github.com/openai/openai-python)
docs/transformers_deployment_guide.md ADDED
@@ -0,0 +1,97 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # 🚀 MiniMax Model Transformers Deployment Guide
2
+
3
+ [Transformers中文版部署指南](./transformers_deployment_guide_cn.md)
4
+
5
+ ## 📖 Introduction
6
+
7
+ This guide will help you deploy the MiniMax-M1 model using the [Transformers](https://huggingface.co/docs/transformers/index) library. Transformers is a widely used deep learning library that provides a rich collection of pre-trained models and flexible model operation interfaces.
8
+
9
+ ## 🛠️ Environment Setup
10
+
11
+ ### Installing Transformers
12
+
13
+ ```bash
14
+ pip install transformers torch accelerate
15
+ ```
16
+
17
+ ## 📋 Basic Usage Example
18
+
19
+ The pre-trained model can be used as follows:
20
+
21
+ ```python
22
+ from transformers import AutoModelForCausalLM, AutoTokenizer, GenerationConfig
23
+
24
+ MODEL_PATH = "{MODEL_PATH}"
25
+ model = AutoModelForCausalLM.from_pretrained(MODEL_PATH, device_map="auto", trust_remote_code=True)
26
+ tokenizer = AutoTokenizer.from_pretrained(MODEL_PATH, trust_remote_code=True)
27
+
28
+ messages = [
29
+ {"role": "user", "content": [{"type": "text", "text": "What is your favourite condiment?"}]},
30
+ {"role": "assistant", "content": [{"type": "text", "text": "Well, I'm quite partial to a good squeeze of fresh lemon juice. It adds just the right amount of zesty flavour to whatever I'm cooking up in the kitchen!"}]},
31
+ {"role": "user", "content": [{"type": "text", "text": "Do you have mayonnaise recipes?"}]}
32
+ ]
33
+
34
+ text = tokenizer.apply_chat_template(
35
+ messages,
36
+ tokenize=False,
37
+ add_generation_prompt=True
38
+ )
39
+
40
+ model_inputs = tokenizer(text, return_tensors="pt").to(model.device)
41
+
42
+ generation_config = GenerationConfig(
43
+ max_new_tokens=20,
44
+ eos_token_id=tokenizer.eos_token_id,
45
+ use_cache=True,
46
+ )
47
+
48
+ generated_ids = model.generate(**model_inputs, generation_config=generation_config)
49
+
50
+ generated_ids = [
51
+ output_ids[len(input_ids):] for input_ids, output_ids in zip(model_inputs.input_ids, generated_ids)
52
+ ]
53
+
54
+ response = tokenizer.batch_decode(generated_ids, skip_special_tokens=True)[0]
55
+ print(response)
56
+ ```
57
+
58
+ ## ⚡ Performance Optimization
59
+
60
+ ### Speeding up with Flash Attention
61
+
62
+ The code snippet above showcases inference without any optimization tricks. However, one can drastically speed up the model by leveraging [Flash Attention](../perf_train_gpu_one#flash-attention-2), which is a faster implementation of the attention mechanism used inside the model.
63
+
64
+ First, make sure to install the latest version of Flash Attention 2:
65
+
66
+ ```bash
67
+ pip install -U flash-attn --no-build-isolation
68
+ ```
69
+
70
+ Also make sure that you have hardware that is compatible with Flash-Attention 2. Read more about it in the official documentation of the [Flash Attention repository](https://github.com/Dao-AILab/flash-attention). Additionally, ensure you load your model in half-precision (e.g. `torch.float16`).
71
+
72
+ To load and run a model using Flash Attention-2, refer to the snippet below:
73
+
74
+ ```python
75
+ import torch
76
+ from transformers import AutoModelForCausalLM, AutoTokenizer
77
+
78
+ MODEL_PATH = "{MODEL_PATH}"
79
+ model = AutoModelForCausalLM.from_pretrained(MODEL_PATH, trust_remote_code=True, torch_dtype=torch.float16, attn_implementation="flash_attention_2", device_map="auto")
80
+ tokenizer = AutoTokenizer.from_pretrained(MODEL_PATH, trust_remote_code=True)
81
+
82
+ prompt = "My favourite condiment is"
83
+
84
+ model_inputs = tokenizer([prompt], return_tensors="pt").to("cuda")
85
+ generated_ids = model.generate(**model_inputs, max_new_tokens=100, do_sample=True)
86
+ response = tokenizer.batch_decode(generated_ids)[0]
87
+ print(response)
88
+ ```
89
+
90
+ ## 📮 Getting Support
91
+
92
+ If you encounter any issues while deploying the MiniMax-M1 model:
93
+ - Please check our official documentation
94
+ - Contact our technical support team through official channels
95
+ - Submit an Issue on our GitHub repository
96
+
97
+ We continuously optimize the deployment experience on Transformers and welcome your feedback!
docs/transformers_deployment_guide_cn.md ADDED
@@ -0,0 +1,95 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # 🚀 MiniMax 模型 Transformers 部署指南
2
+
3
+ ## 📖 简介
4
+
5
+ 本指南将帮助您使用 [Transformers](https://huggingface.co/docs/transformers/index) 库部署 MiniMax-M1 模型。Transformers 是一个广泛使用的深度学习库,提供了丰富的预训练模型和灵活的模型操作接口。
6
+
7
+ ## 🛠️ 环境准备
8
+
9
+ ### 安装 Transformers
10
+
11
+ ```bash
12
+ pip install transformers torch accelerate
13
+ ```
14
+
15
+ ## 📋 基本使用示例
16
+
17
+ 预训练模型可以按照以下方式使用:
18
+
19
+ ```python
20
+ from transformers import AutoModelForCausalLM, AutoTokenizer, GenerationConfig
21
+
22
+ MODEL_PATH = "{MODEL_PATH}"
23
+ model = AutoModelForCausalLM.from_pretrained(MODEL_PATH, device_map="auto", trust_remote_code=True)
24
+ tokenizer = AutoTokenizer.from_pretrained(MODEL_PATH, trust_remote_code=True)
25
+
26
+ messages = [
27
+ {"role": "user", "content": [{"type": "text", "text": "What is your favourite condiment?"}]},
28
+ {"role": "assistant", "content": [{"type": "text", "text": "Well, I'm quite partial to a good squeeze of fresh lemon juice. It adds just the right amount of zesty flavour to whatever I'm cooking up in the kitchen!"}]},
29
+ {"role": "user", "content": [{"type": "text", "text": "Do you have mayonnaise recipes?"}]}
30
+ ]
31
+
32
+ text = tokenizer.apply_chat_template(
33
+ messages,
34
+ tokenize=False,
35
+ add_generation_prompt=True
36
+ )
37
+
38
+ model_inputs = tokenizer(text, return_tensors="pt").to(model.device)
39
+
40
+ generation_config = GenerationConfig(
41
+ max_new_tokens=20,
42
+ eos_token_id=tokenizer.eos_token_id,
43
+ use_cache=True,
44
+ )
45
+
46
+ generated_ids = model.generate(**model_inputs, generation_config=generation_config)
47
+
48
+ generated_ids = [
49
+ output_ids[len(input_ids):] for input_ids, output_ids in zip(model_inputs.input_ids, generated_ids)
50
+ ]
51
+
52
+ response = tokenizer.batch_decode(generated_ids, skip_special_tokens=True)[0]
53
+ print(response)
54
+ ```
55
+
56
+ ## ⚡ 性能优化
57
+
58
+ ### 使用 Flash Attention 加速
59
+
60
+ 上面的代码片段展示了不使用任何优化技巧的推理过程。但通过利用 [Flash Attention](../perf_train_gpu_one#flash-attention-2),可以大幅加速模型,因为它提供了模型内部使用的注意力机制的更快实现。
61
+
62
+ 首先,确保安装最新版本的 Flash Attention 2:
63
+
64
+ ```bash
65
+ pip install -U flash-attn --no-build-isolation
66
+ ```
67
+
68
+ 还要确保您拥有与 Flash-Attention 2 兼容的硬件。在[Flash Attention 官方仓库](https://github.com/Dao-AILab/flash-attention)的官方文档中了解更多信息。此外,请确保以半精度(例如 `torch.float16`)加载模型。
69
+
70
+ 要使用 Flash Attention-2 加载和运行模型,请参考以下代码片段:
71
+
72
+ ```python
73
+ import torch
74
+ from transformers import AutoModelForCausalLM, AutoTokenizer
75
+
76
+ MODEL_PATH = "{MODEL_PATH}"
77
+ model = AutoModelForCausalLM.from_pretrained(MODEL_PATH, trust_remote_code=True, torch_dtype=torch.float16, attn_implementation="flash_attention_2", device_map="auto")
78
+ tokenizer = AutoTokenizer.from_pretrained(MODEL_PATH, trust_remote_code=True)
79
+
80
+ prompt = "My favourite condiment is"
81
+
82
+ model_inputs = tokenizer([prompt], return_tensors="pt").to("cuda")
83
+ generated_ids = model.generate(**model_inputs, max_new_tokens=100, do_sample=True)
84
+ response = tokenizer.batch_decode(generated_ids)[0]
85
+ print(response)
86
+ ```
87
+
88
+ ## 📮 获取支持
89
+
90
+ 如果您在部署 MiniMax-M1 模型过程中遇到任何问题:
91
+ - 请查看我们的官方文档
92
+ - 通过官方渠道联系我们的技术支持团队
93
+ - 在我们的 GitHub 仓库提交 Issue
94
+
95
+ 我们会持续优化 Transformers 上的部署体验,欢迎您的反馈!
docs/vllm_deployment_guide.md ADDED
@@ -0,0 +1,161 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # 🚀 MiniMax Models vLLM Deployment Guide
2
+
3
+ [vLLM中文版部署指南](./vllm_deployment_guide_cn.md)
4
+
5
+ ## 📖 Introduction
6
+
7
+ We recommend using [vLLM](https://docs.vllm.ai/en/latest/) to deploy [MiniMax-M1](https://huggingface.co/MiniMaxAI/MiniMax-M1-40k) model. Based on our testing, vLLM performs excellently when deploying this model, with the following features:
8
+
9
+ - 🔥 Outstanding service throughput performance
10
+ - ⚡ Efficient and intelligent memory management
11
+ - 📦 Powerful batch request processing capability
12
+ - ⚙️ Deeply optimized underlying performance
13
+
14
+ The MiniMax-M1 model can run efficiently on a single server equipped with 8 H800 or 8 H20 GPUs. In terms of hardware configuration, a server with 8 H800 GPUs can process context inputs up to 2 million tokens, while a server equipped with 8 H20 GPUs can support ultra-long context processing capabilities of up to 5 million tokens.
15
+
16
+ ## 💾 Obtaining MiniMax Models
17
+
18
+ ### MiniMax-M1 Model Obtaining
19
+
20
+ You can download the model from our official HuggingFace repository: [MiniMax-M1-40k](https://huggingface.co/MiniMaxAI/MiniMax-M1-40k), [MiniMax-M1-80k](https://huggingface.co/MiniMaxAI/MiniMax-M1-80k)
21
+
22
+ Download command:
23
+ ```
24
+ pip install -U huggingface-hub
25
+ huggingface-cli download MiniMaxAI/MiniMax-M1-40k
26
+ # huggingface-cli download MiniMaxAI/MiniMax-M1-80k
27
+
28
+ # If you encounter network issues, you can set a proxy
29
+ export HF_ENDPOINT=https://hf-mirror.com
30
+ ```
31
+
32
+ Or download using git:
33
+
34
+ ```bash
35
+ git lfs install
36
+ git clone https://huggingface.co/MiniMaxAI/MiniMax-M1-40k
37
+ git clone https://huggingface.co/MiniMaxAI/MiniMax-M1-80k
38
+ ```
39
+
40
+ ⚠️ **Important Note**: Please ensure that [Git LFS](https://git-lfs.github.com/) is installed on your system, which is necessary for completely downloading the model weight files.
41
+
42
+ ## 🛠️ Deployment Options
43
+
44
+ ### Option: Deploy Using Docker (Recommended)
45
+
46
+ To ensure consistency and stability of the deployment environment, we recommend using Docker for deployment.
47
+
48
+ ⚠️ **Version Requirements**:
49
+ - MiniMax-M1 model requires vLLM version 0.9.2 or later for full support
50
+ - Special Note: Using vLLM versions below 0.9.2 may result in incompatibility or incorrect precision for the model:
51
+ - For details, see: [Fix minimax model cache & lm_head precision #19592](https://github.com/vllm-project/vllm/pull/19592)
52
+
53
+ 1. Get the container image:
54
+
55
+ Currently, the official vLLM Docker image for version v0.9.2 has not been released yet.
56
+ As an example, we will demonstrate how to manually build vLLM using version v0.8.3.
57
+ ```bash
58
+ docker pull vllm/vllm-openai:v0.8.3
59
+ ```
60
+
61
+ 2. Run the container:
62
+ ```bash
63
+ # Set environment variables
64
+ IMAGE=vllm/vllm-openai:v0.8.3
65
+ MODEL_DIR=<model storage path>
66
+ CODE_DIR=<code path>
67
+ NAME=MiniMaxImage
68
+
69
+ # Docker run configuration
70
+ DOCKER_RUN_CMD="--network=host --privileged --ipc=host --ulimit memlock=-1 --shm-size=2gb --rm --gpus all --ulimit stack=67108864"
71
+
72
+ # Start the container
73
+ sudo docker run -it \
74
+ -v $MODEL_DIR:$MODEL_DIR \
75
+ -v $CODE_DIR:$CODE_DIR \
76
+ --name $NAME \
77
+ $DOCKER_RUN_CMD \
78
+ $IMAGE /bin/bash
79
+
80
+ # install vLLM
81
+ cd $CODE_DIR
82
+ git clone https://github.com/vllm-project/vllm.git
83
+ cd vllm
84
+ pip install -e .
85
+ ```
86
+
87
+ 💡 If you are using other environment configurations, please refer to the [vLLM Installation Guide](https://docs.vllm.ai/en/latest/getting_started/installation.html)
88
+
89
+ ## 🚀 Starting the Service
90
+
91
+ ### Launch MiniMax-M1 Service
92
+
93
+ ```bash
94
+ export SAFETENSORS_FAST_GPU=1
95
+ export VLLM_USE_V1=0
96
+ python3 -m vllm.entrypoints.openai.api_server \
97
+ --model <model storage path> \
98
+ --tensor-parallel-size 8 \
99
+ --trust-remote-code \
100
+ --quantization experts_int8 \
101
+ --max_model_len 4096 \
102
+ --dtype bfloat16
103
+ ```
104
+
105
+ ### API Call Example
106
+
107
+ ```bash
108
+ curl http://localhost:8000/v1/chat/completions \
109
+ -H "Content-Type: application/json" \
110
+ -d '{
111
+ "model": "MiniMaxAI/MiniMax-M1",
112
+ "messages": [
113
+ {"role": "system", "content": [{"type": "text", "text": "You are a helpful assistant."}]},
114
+ {"role": "user", "content": [{"type": "text", "text": "Who won the world series in 2020?"}]}
115
+ ]
116
+ }'
117
+ ```
118
+
119
+ ## ❗ Common Issues
120
+
121
+ ### Module Loading Problems
122
+ If you encounter the following error:
123
+ ```
124
+ import vllm._C # noqa
125
+ ModuleNotFoundError: No module named 'vllm._C'
126
+ ```
127
+
128
+ Or
129
+
130
+ ```
131
+ MiniMax-M1 model is not currently supported
132
+ ```
133
+
134
+ We provide two solutions:
135
+
136
+ #### Solution 1: Copy Dependency Files
137
+ ```bash
138
+ cd <working directory>
139
+ git clone https://github.com/vllm-project/vllm.git
140
+ cd vllm
141
+ cp /usr/local/lib/python3.12/dist-packages/vllm/*.so vllm
142
+ cp -r /usr/local/lib/python3.12/dist-packages/vllm/vllm_flash_attn/* vllm/vllm_flash_attn
143
+ ```
144
+
145
+ #### Solution 2: Install from Source
146
+ ```bash
147
+ cd <working directory>
148
+ git clone https://github.com/vllm-project/vllm.git
149
+
150
+ cd vllm/
151
+ pip install -e .
152
+ ```
153
+
154
+ ## 📮 Getting Support
155
+
156
+ If you encounter any issues while deploying MiniMax-M1 model:
157
+ - Please check our official documentation
158
+ - Contact our technical support team through official channels
159
+ - Submit an [Issue](https://github.com/MiniMax-AI/MiniMax-M1/issues) on our GitHub repository
160
+
161
+ We will continuously optimize the deployment experience of this model and welcome your feedback!
docs/vllm_deployment_guide_cn.md ADDED
@@ -0,0 +1,158 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # 🚀 MiniMax 模型 vLLM 部署指南
2
+
3
+ ## 📖 简介
4
+
5
+ 我们推荐使用 [vLLM](https://docs.vllm.ai/en/latest/) 来部署 [MiniMax-M1](https://huggingface.co/MiniMaxAI/MiniMax-M1-40k) 模型。经过我们的测试,vLLM 在部署这个模型时表现出色,具有以下特点:
6
+
7
+ - 🔥 卓越的服务吞吐量性能
8
+ - ⚡ 高效智能的内存管理机制
9
+ - 📦 强大的批量请求处理能力
10
+ - ⚙️ 深度优化的底层性能
11
+
12
+ MiniMax-M1 模型可在单台配备8个H800或8个H20 GPU的服务器上高效运行。在硬件配置方面,搭载8个H800 GPU的服务器可处理长达200万token的上下文输入,而配备8个H20 GPU的服务器则能够支持高达500万token的超长上下文处理能力。
13
+
14
+ ## 💾 获取 MiniMax 模型
15
+
16
+ ### MiniMax-M1 模型获取
17
+
18
+ 您可以从我们的官方 HuggingFace 仓库下载模型:[MiniMax-M1-40k](https://huggingface.co/MiniMaxAI/MiniMax-M1-40k)、[MiniMax-M1-80k](https://huggingface.co/MiniMaxAI/MiniMax-M1-80k)
19
+
20
+ 下载命令:
21
+ ```
22
+ pip install -U huggingface-hub
23
+ huggingface-cli download MiniMaxAI/MiniMax-M1-40k
24
+ # huggingface-cli download MiniMaxAI/MiniMax-M1-80k
25
+
26
+ # 如果遇到网络问题,可以设置代理
27
+ export HF_ENDPOINT=https://hf-mirror.com
28
+ ```
29
+
30
+ 或者使用 git 下载:
31
+
32
+ ```bash
33
+ git lfs install
34
+ git clone https://huggingface.co/MiniMaxAI/MiniMax-M1-40k
35
+ git clone https://huggingface.co/MiniMaxAI/MiniMax-M1-80k
36
+ ```
37
+
38
+ ⚠️ **重要提示**:请确保系统已安装 [Git LFS](https://git-lfs.github.com/),这对于完整下载模型权重文件是必需的。
39
+
40
+ ## 🛠️ 部署方案
41
+
42
+ ### 方案:使用 Docker 部署(推荐)
43
+
44
+ 为确保部署环境的一致性和稳定性,我们推荐使用 Docker 进行部署。
45
+
46
+ ⚠️ **版本要求**:
47
+ - 基础要求:vLLM 版本必须 ≥ 0.9.2,以确保对 MiniMax-M1 模型的完整支持
48
+ - 特殊说明:如果使用低于 0.9.2 的 vLLM 版本,会遇见无法支持该模型或者精度不正确的情况:
49
+ - 详情见:[Fix minimax model cache & lm_head precision #19592](https://github.com/vllm-project/vllm/pull/19592)
50
+
51
+ 1. 获取容器镜像:
52
+
53
+ 目前 vLLM 官方还未推出v0.9.2版本 docker,我们以 v0.8.3 为例子进行手动编译 vLLM:
54
+ ```bash
55
+ docker pull vllm/vllm-openai:v0.8.3
56
+ ```
57
+
58
+ 2. 运行容器:
59
+ ```bash
60
+ # 设置环境变量
61
+ IMAGE=vllm/vllm-openai:v0.8.3
62
+ MODEL_DIR=<模型存放路径>
63
+ CODE_DIR=<代码路径>
64
+ NAME=MiniMaxImage
65
+
66
+ # Docker运行配置
67
+ DOCKER_RUN_CMD="--network=host --privileged --ipc=host --ulimit memlock=-1 --shm-size=2gb --rm --gpus all --ulimit stack=67108864"
68
+
69
+ # 启动容器
70
+ sudo docker run -it \
71
+ -v $MODEL_DIR:$MODEL_DIR \
72
+ -v $CODE_DIR:$CODE_DIR \
73
+ --name $NAME \
74
+ $DOCKER_RUN_CMD \
75
+ $IMAGE /bin/bash
76
+
77
+ # 编译 vLLM
78
+ cd $CODE_DIR
79
+ git clone https://github.com/vllm-project/vllm.git
80
+ cd vllm
81
+ pip install -e .
82
+ ```
83
+
84
+ 💡 如果您使用其他环境配置,请参考 [vLLM 安装指南](https://docs.vllm.ai/en/latest/getting_started/installation.html)
85
+
86
+ ## 🚀 启动服务
87
+
88
+ ### 启动 MiniMax-M1 服务
89
+
90
+ ```bash
91
+ export SAFETENSORS_FAST_GPU=1
92
+ export VLLM_USE_V1=0
93
+ python3 -m vllm.entrypoints.openai.api_server \
94
+ --model <模型存放路径> \
95
+ --tensor-parallel-size 8 \
96
+ --trust-remote-code \
97
+ --quantization experts_int8 \
98
+ --max_model_len 4096 \
99
+ --dtype bfloat16
100
+ ```
101
+
102
+ ### API 调用示例
103
+
104
+ ```bash
105
+ curl http://localhost:8000/v1/chat/completions \
106
+ -H "Content-Type: application/json" \
107
+ -d '{
108
+ "model": "MiniMaxAI/MiniMax-M1",
109
+ "messages": [
110
+ {"role": "system", "content": [{"type": "text", "text": "You are a helpful assistant."}]},
111
+ {"role": "user", "content": [{"type": "text", "text": "Who won the world series in 2020?"}]}
112
+ ]
113
+ }'
114
+ ```
115
+
116
+ ## ❗ 常见问题
117
+
118
+ ### 模块加载问题
119
+ 如果遇到以下错误:
120
+ ```
121
+ import vllm._C # noqa
122
+ ModuleNotFoundError: No module named 'vllm._C'
123
+ ```
124
+
125
+
126
+
127
+ ```
128
+ 当前并不支持 MiniMax-M1 模型
129
+ ```
130
+
131
+ 我们提供两种解决方案:
132
+
133
+ #### 解决方案一:复制依赖文件
134
+ ```bash
135
+ cd <工作目录>
136
+ git clone https://github.com/vllm-project/vllm.git
137
+ cd vllm
138
+ cp /usr/local/lib/python3.12/dist-packages/vllm/*.so vllm
139
+ cp -r /usr/local/lib/python3.12/dist-packages/vllm/vllm_flash_attn/* vllm/vllm_flash_attn
140
+ ```
141
+
142
+ #### 解决方案二:从源码安装
143
+ ```bash
144
+ cd <工作目录>
145
+ git clone https://github.com/vllm-project/vllm.git
146
+
147
+ cd vllm/
148
+ pip install -e .
149
+ ```
150
+
151
+ ## 📮 获取支持
152
+
153
+ 如果您在部署 MiniMax-M1 模型过程中遇到任何问题:
154
+ - 请查看我们的官方文档
155
+ - 通过官方渠道联系我们的技术支持团队
156
+ - 在我们的 GitHub 仓库提交 [Issue](https://github.com/MiniMax-AI/MiniMax-M1/issues)
157
+
158
+ 我们会持续优化模型的部署体验,欢迎您的反馈!
figures/TextBench.png ADDED
main.py ADDED
@@ -0,0 +1,106 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from transformers import AutoModelForCausalLM, AutoTokenizer, AutoConfig, QuantoConfig, GenerationConfig
2
+ import torch
3
+ import argparse
4
+
5
+ """
6
+ usage:
7
+ export SAFETENSORS_FAST_GPU=1
8
+ python main.py --quant_type int8 --world_size 8 --model_id <model_path>
9
+ """
10
+
11
+ def generate_quanto_config(hf_config: AutoConfig, quant_type: str):
12
+ QUANT_TYPE_MAP = {
13
+ "default": None,
14
+ "int8": QuantoConfig(
15
+ weights="int8",
16
+ modules_to_not_convert=[
17
+ "lm_head",
18
+ "embed_tokens",
19
+ ] + [f"model.layers.{i}.coefficient" for i in range(hf_config.num_hidden_layers)]
20
+ + [f"model.layers.{i}.block_sparse_moe.gate" for i in range(hf_config.num_hidden_layers)]
21
+ ),
22
+ }
23
+ return QUANT_TYPE_MAP[quant_type]
24
+
25
+
26
+ def parse_args():
27
+ parser = argparse.ArgumentParser()
28
+ parser.add_argument("--quant_type", type=str, default="default", choices=["default", "int8"])
29
+ parser.add_argument("--model_id", type=str, required=True)
30
+ parser.add_argument("--world_size", type=int, required=True)
31
+ return parser.parse_args()
32
+
33
+
34
+ def check_params(args, hf_config: AutoConfig):
35
+ if args.quant_type == "int8":
36
+ assert args.world_size >= 8, "int8 weight-only quantization requires at least 8 GPUs"
37
+
38
+ assert hf_config.num_hidden_layers % args.world_size == 0, f"num_hidden_layers({hf_config.num_hidden_layers}) must be divisible by world_size({args.world_size})"
39
+
40
+
41
+ @torch.no_grad()
42
+ def main():
43
+ args = parse_args()
44
+ print("\n=============== Argument ===============")
45
+ for key in vars(args):
46
+ print(f"{key}: {vars(args)[key]}")
47
+ print("========================================")
48
+
49
+ model_id = args.model_id
50
+
51
+ hf_config = AutoConfig.from_pretrained(model_id, trust_remote_code=True)
52
+ check_params(args, hf_config)
53
+ quantization_config = generate_quanto_config(hf_config, args.quant_type)
54
+
55
+ device_map = {
56
+ 'model.embed_tokens': 'cuda:0',
57
+ 'model.norm': f'cuda:{args.world_size - 1}',
58
+ 'lm_head': f'cuda:{args.world_size - 1}'
59
+ }
60
+ layers_per_device = hf_config.num_hidden_layers // args.world_size
61
+ for i in range(args.world_size):
62
+ for j in range(layers_per_device):
63
+ device_map[f'model.layers.{i * layers_per_device + j}'] = f'cuda:{i}'
64
+
65
+ tokenizer = AutoTokenizer.from_pretrained(model_id)
66
+ message = [
67
+ {"role": "system", "content": [{"type": "text", "text": "You are a helpful assistant."}]},
68
+ {"role": "user", "content": [{"type": "text", "text": "Hello, what is the weather today?"}]}
69
+ ]
70
+ tools = [
71
+ {"name": "get_location", "description": "Get the location of the user.", "parameters": {"type": "object", "properties": {}}},
72
+ {"name": "get_weather", "description": "Get the weather of a city.", "parameters": {"type": "object", "properties": {"city": {"type": "string", "description": "The name of the city"}}}},
73
+ {"name": "get_news", "description": "Get the news.", "parameters": {"type": "object", "properties": {"domain": {"type": "string", "description": "The domain of the news"}}}}
74
+ ]
75
+ text = tokenizer.apply_chat_template(
76
+ message,
77
+ tools,
78
+ tokenize=False,
79
+ add_generation_prompt=True
80
+ )
81
+ model_inputs = tokenizer(text, return_tensors="pt").to("cuda")
82
+ quantized_model = AutoModelForCausalLM.from_pretrained(
83
+ model_id,
84
+ torch_dtype="bfloat16",
85
+ device_map=device_map,
86
+ quantization_config=quantization_config,
87
+ trust_remote_code=True,
88
+ offload_buffers=True,
89
+ )
90
+ generation_config = GenerationConfig(
91
+ max_new_tokens=20,
92
+ eos_token_id=200020,
93
+ use_cache=True,
94
+ )
95
+ generated_ids = quantized_model.generate(**model_inputs, generation_config=generation_config)
96
+ print(f"generated_ids: {generated_ids}")
97
+ generated_ids = [
98
+ output_ids[len(input_ids):] for input_ids, output_ids in zip(model_inputs.input_ids, generated_ids)
99
+ ]
100
+ response = tokenizer.batch_decode(generated_ids, skip_special_tokens=True)[0]
101
+ print(response)
102
+
103
+ if __name__ == "__main__":
104
+ main()
105
+
106
+
merges.txt ADDED
The diff for this file is too large to render. See raw diff
 
model-00000-of-00414.safetensors ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:74b96f1448f8825f0b7c31870adbe1fe090807f59178022e824c19d2c511785c
3
+ size 2458386576
model-00001-of-00414.safetensors ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:b30db96050a9b8ae6669005d624689b3634ae2cabb883df7e0bf304ca8523869
3
+ size 2191113152
model-00002-of-00414.safetensors ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:ab8ed124800f1fb8115d365dba53faca2efa9f4eeb5c1b1eb0d1f37ac6692685
3
+ size 2330307784
model-00003-of-00414.safetensors ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:4ecb8662e5aac41824c025a234deef1839d2aac1b53639b86c2cb0f0c3ee1a37
3
+ size 2254810656
model-00004-of-00414.safetensors ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:9b773c0cbd9214be1e4d3d469902535ac475b1a44709f80964357c3ae0df87c2
3
+ size 2116402376
model-00005-of-00414.safetensors ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:0d5276a2085fa85d1ddacff0c95366e91ca146c42bacfaa94b0b6e3260a114da
3
+ size 2103016184
model-00006-of-00414.safetensors ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:73511eca7a83fe6694cad1e45fc0d3b64169013c3d409bcd5988e80940230c22
3
+ size 2254810688
model-00007-of-00414.safetensors ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:dd0cc621259942b80b61090966e26441c5ab48aca712bd6165290b048af0e186
3
+ size 2116402392
model-00008-of-00414.safetensors ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:c3c272227843028ead0bd4475b32551813e75024cccdb974c14ff7df8bd500d7
3
+ size 2202839784
model-00009-of-00414.safetensors ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:154b2fb0d51782a9203bd9f0320ecac3a56af3567091c9cf933065f1dfd2eb60
3
+ size 2151680440
model-00010-of-00414.safetensors ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:a82f461e80e393d2aaea194233f93702c2779ed187f21d4deae6a3bdaa666229
3
+ size 2264926800
model-00011-of-00414.safetensors ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:cbfb5c69c93008c4b9b010befbc2bec270843fdfb6b1513735d419db8e689a08
3
+ size 2151680448
model-00012-of-00414.safetensors ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:815a96e6720e8731df8cf277240b6684acfa9e22d22c9da90c1d0fb10e2769a4
3
+ size 2264926776
model-00013-of-00414.safetensors ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:85013f07e163cf71baed3ad21a904339acac533b4c2becf8ff47519d418c2330
3
+ size 2151680456
model-00014-of-00414.safetensors ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:9c4be2df2339396c768344fc3e73ff6215782c1cd069ce81e1ee9a2f04bb4aa9
3
+ size 2264926792
model-00015-of-00414.safetensors ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:c0f7015e30ad5a37a881f38465164ffd642e83e9200993e099df72e5e96d50cb
3
+ size 2151680440
model-00016-of-00414.safetensors ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:e06d43c22e5302ae0160a744d587e02d6af318da14897da9a5651a83022f7307
3
+ size 2264926792
model-00017-of-00414.safetensors ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:743a170b52f9a4b4691961dbb755586c8b24b9ea4d21bc65f1843d8a8d618251
3
+ size 2151680456
model-00018-of-00414.safetensors ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:7d4a5722a4e38d7e33d6851e381a96fa0c39fbf31ec339840a9d391b23b91f97
3
+ size 2264926776
model-00019-of-00414.safetensors ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:7ea16941a5c9abc8142b8b7417e48c99a971e2f48e531ce7c405e676e1a81040
3
+ size 2151680456
model-00020-of-00414.safetensors ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:1c64ed89c8a2464654157cdd2fd26f5a7321c8e2eed81047449a2e65e303c52e
3
+ size 2264926792
model-00021-of-00414.safetensors ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:8225ded83e7edccc710a532dea7fa5aba94548b5c33ffeae383ece3fb3ed1115
3
+ size 2151680440
model-00022-of-00414.safetensors ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:00609011d89fb1e16b954fd27185f1f1ed8c0301ce1fa6ad60acbfebd8702c09
3
+ size 2264926792
model-00023-of-00414.safetensors ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:ce61598e2d6945d011a4eee1a8fd162849610ead1ce6c5a2df31e7012808cb13
3
+ size 2151680456
model-00024-of-00414.safetensors ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:b18e828e1e6bf1fb205f74536eb5b67c106f6faae71324da0c4ae6847b22f723
3
+ size 2264926776
model-00025-of-00414.safetensors ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:677abfff6d5e7a595a5ba9488dbbf3205dc3562552688e6307701056384b5649
3
+ size 2151680456
model-00026-of-00414.safetensors ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:31a756bcd95acd5fe94d0d7fd144ecff85ea9d6ad10404f2c96009d016fadf78
3
+ size 2264926800
model-00027-of-00414.safetensors ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:31bb76a7def5d2875fe04ca5062a6f492925965e245ee516beec0086637724a3
3
+ size 2151680440
model-00028-of-00414.safetensors ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:3ae51678271a3d01447cc9f16f680416441e5c04c7c41b32025b6d372c1565d1
3
+ size 2264926792
model-00029-of-00414.safetensors ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:40da9e32fca4f03d6b499b5fb59c1814892e035239f8d11f8dfb0ffb84453776
3
+ size 2151680456
model-00030-of-00414.safetensors ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:3c2754dfc8893d9c9f499e74e63647996631b4170429d2919b276ffa17f5a575
3
+ size 2264926776
model-00031-of-00414.safetensors ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:9c360b35fe49968444ab8622561493fb34dbc6eb40359878c2a9354df8fdf9ed
3
+ size 2151680448
model-00032-of-00414.safetensors ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:6e3c7c7f02cba7ba76ea20d93551b3b2ee322cfdffb90ed8f4067be74afa406b
3
+ size 2264926800
model-00033-of-00414.safetensors ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:e0811283abe2f87f88e02cf150917a3d2b8c6cb4a526a1d943233fa5db941920
3
+ size 2151680440
model-00034-of-00414.safetensors ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:7d8b1e023ed43f0bb29d4129b0a76d77fc8a69974cf1034749714748abf8aa26
3
+ size 2264926784