bdellabe commited on
Commit
805ad4a
·
verified ·
1 Parent(s): ecfc111

Update README.md

Browse files
Files changed (1) hide show
  1. README.md +177 -1
README.md CHANGED
@@ -8,6 +8,8 @@ library_name: transformers
8
 
9
  W4A16 version of https://huggingface.co/MiniMaxAI/MiniMax-M2.5
10
 
 
 
11
  Creation script:
12
  ```python
13
  from llmcompressor import model_free_ptq
@@ -34,4 +36,178 @@ model_free_ptq(
34
  ignore=["re:.*self_attn.*", "lm_head"],
35
  max_workers=8,
36
  )
37
- ```
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
8
 
9
  W4A16 version of https://huggingface.co/MiniMaxAI/MiniMax-M2.5
10
 
11
+ ## Creation
12
+
13
  Creation script:
14
  ```python
15
  from llmcompressor import model_free_ptq
 
36
  ignore=["re:.*self_attn.*", "lm_head"],
37
  max_workers=8,
38
  )
39
+ ```
40
+
41
+ ## Inference
42
+
43
+ ```python
44
+ from vllm import LLM, SamplingParams
45
+ from transformers import AutoTokenizer
46
+
47
+ MODEL_ID = "nm-testing/MiniMax-M2.5-W4A16"
48
+
49
+ messages = [
50
+ {
51
+ "role": "system",
52
+ "content": [{"type": "text", "text": "You are a helpful assistant."}],
53
+ },
54
+ {
55
+ "role": "user",
56
+ "content": [
57
+ {
58
+ "type": "text",
59
+ "text": "Write a python function that sorts a list of numbers in ascending order",
60
+ }
61
+ ],
62
+ },
63
+ ]
64
+
65
+ # Create a sampling params object for greedy sampling
66
+ sampling_params = SamplingParams(
67
+ temperature=1.0, top_p=0.95, top_k=64, max_tokens=1000, min_tokens=500
68
+ )
69
+ if __name__ == "__main__":
70
+ llm = LLM(
71
+ MODEL_ID,
72
+ tensor_parallel_size=2,
73
+ max_model_len=4096,
74
+ )
75
+ tokenizer = AutoTokenizer.from_pretrained(MODEL_ID)
76
+
77
+ prompt = tokenizer.apply_chat_template(
78
+ messages, tokenize=False, add_generation_prompt=True
79
+ )
80
+ output = llm.generate(prompt, sampling_params)
81
+ for out in output:
82
+ print(out.outputs[0].text)
83
+ ```
84
+
85
+ Outputs:
86
+ <details>
87
+
88
+ <summary>Sample Ouput</summary>
89
+
90
+ We have a request: Write a python function that sorts a list of numbers in ascending order.
91
+
92
+ We need to provide a code snippet, perhaps with docstring and explanation.
93
+
94
+ We need to follow policies. There's no disallowed content.
95
+
96
+ We need to output a function. Provide explanation. Possibly use built-in sorted or implement sorting algorithm like quicksort, mergesort, insertion sort, etc. Probably best to use built-in sorted for simplicity.
97
+
98
+ But the user request: "Write a python function that sorts a list of numbers in ascending order". That's straightforward. Provide function.
99
+
100
+ Maybe show also custom implementation if needed. Might show both simple approach and custom sort.
101
+
102
+ Potential user might need more details: maybe they want to understand algorithm.
103
+
104
+ We can also handle edge cases: empty list, single element, negative numbers, duplicates.
105
+
106
+ We can show examples.
107
+
108
+ We can implement both simple: return sorted(list) and maybe also selection sort.
109
+
110
+ Probably best to answer with both: using built-in sorted function (for O(n log n) performance), and also a simple algorithm like bubble sort.
111
+
112
+ We could also provide in-place sorting using list.sort.
113
+
114
+ We'll output code.
115
+
116
+ We can provide docstring, type hints.
117
+
118
+ Ok.
119
+
120
+ Now final answer: Provide code with explanation.
121
+
122
+ Will follow best practice: include "def sort_ascending(nums: list[float]) -> list[float]:".
123
+
124
+ We'll have simple implementation. We'll also optionally show an O(n log n) solution.
125
+
126
+ We might provide test cases.
127
+
128
+ Thus final answer: provide python function.
129
+
130
+ Will also mention that sorted returns new list, while list.sort sorts in-place.
131
+
132
+ Ok.
133
+
134
+ Now produce final output.
135
+ </think>
136
+
137
+ Here’s a simple, well‑documented Python function that returns a new list containing the numbers from the input list sorted in ascending order.
138
+ It uses Python’s built‑in `sorted` (which implements Timsort – an O(n log n) algorithm), but I’ve also included a tiny custom implementation (bubble sort) if you want to see a “manual” approach.
139
+
140
+ ```python
141
+ from typing import List
142
+
143
+ def sort_ascending(nums: List[float]) -> List[float]:
144
+ """
145
+ Return a new list containing the numbers from *nums* sorted
146
+ in ascending order.
147
+
148
+ Parameters
149
+ ----------
150
+ nums : List[float]
151
+ A list of numbers (ints, floats, or a mix). The list may be empty.
152
+
153
+ Returns
154
+ -------
155
+ List[float]
156
+ A new list with the same elements sorted from smallest to largest.
157
+ The original list is left unchanged.
158
+
159
+ Examples
160
+ --------
161
+ >>> sort_ascending([3, 1, 4, 1, 5, 9, 2, 6])
162
+ [1, 1, 2, 3, 4, 5, 6, 9]
163
+ >>> sort_ascending([])
164
+ []
165
+ """
166
+ # --- Approach 1: built‑in sorted (fast, idiomatic) --------------------
167
+ # This creates a shallow copy and sorts it.
168
+ return sorted(nums)
169
+
170
+ # ----------------------------------------------------------------------
171
+ # If you’d like to see a simple “manual” sort, comment out the line
172
+ # above and uncomment the following function call:
173
+ #
174
+ # return _bubble_sort_copy(nums)
175
+
176
+
177
+ def _bubble_sort_copy(arr: List[float]) -> List[float]:
178
+ """
179
+ Return a copy of *arr* sorted with the bubble‑sort algorithm.
180
+ This is only for illustration – it runs in O(n²) time.
181
+ """
182
+ # Make a shallow copy so we don’t mutate the original list.
183
+ result = list(arr)
184
+ n = len(result)
185
+ for i in range(n):
186
+ # After each outer iteration, the last i elements are already in place.
187
+ for j in range(0, n - i - 1):
188
+ if result[j] > result[j + 1]:
189
+ # Swap adjacent elements.
190
+ result[j], result[j + 1] = result[j + 1], result[j]
191
+ return result
192
+
193
+
194
+ # -------------------------------------------------------------------------
195
+ # Example usage
196
+ if __name__ == "__main__":
197
+ test_lists = [
198
+ [3, 1, 4, 1, 5, 9, 2, 6],
199
+ [],
200
+ [7],
201
+ [-2, 5, -1, 0, 3],
202
+ [4.4, 2.2, 1.1, 3.3]
203
+ ]
204
+
205
+ for lst in test_lists:
206
+ sorted_lst = sort_ascending(lst)
207
+ print(f"Original: {lst} → Sorted: {sorted_lst}")
208
+ ```
209
+
210
+ ### What the function does
211
+ 1. **Input validation** – Accepts any iterable of numbers (ints, floats, etc.).
212
+ 2. **Built‑in solution** – `sorted(nums)` creates a new list and sorts it using Timsort,
213
+ </details>