n1ck-guo commited on
Commit
6c769b9
·
verified ·
1 Parent(s): 0a20864

Create README.md

Browse files
Files changed (1) hide show
  1. README.md +299 -0
README.md ADDED
@@ -0,0 +1,299 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ---
2
+ base_model:
3
+ - openai/gpt-oss-20b
4
+ ---
5
+
6
+ ## Model Details
7
+
8
+ This model is a gguf q4ks format of [openai/gpt-oss-120b](https://huggingface.co/openai/gpt-oss-120b) generated by [intel/auto-round](https://github.com/intel/auto-round) algorithm.
9
+
10
+ Please follow the license of the original model.
11
+
12
+ ## How To Use
13
+
14
+ Llamacpp inference
15
+
16
+ ~~~bash
17
+ llama-cli -hf Intel/gpt-oss-120b-gguf-q4ks-AutoRound
18
+ ~~~
19
+
20
+ ~~~bash
21
+ > Write a quick sort algorithm.
22
+ <|channel|>analysis<|message|>The user: "Write a quick sort algorithm." Likely they want code in some language. I should provide a quicksort implementation, possibly multiple languages, explain. I can give Python example. Also discuss partition scheme. Provide code.
23
+
24
+ I'll respond with an example in Python, plus explanation. Also could include C++ version. Provide generic.<|start|>assistant<|channel|>final<|message|>Below is a complete, ready‑to‑run implementation of the Quick‑Sort algorithm together with a short explanation of how it works.
25
+ You’ll find versions in **Python**, **C++**, and **JavaScript** so you can pick the one that best fits your project.
26
+
27
+ ---
28
+
29
+ ## 1. Quick‑Sort Overview
30
+
31
+ Quick‑Sort is a divide‑and‑conquer sorting algorithm that works in three steps:
32
+
33
+ 1. **Choose a pivot** element from the array (any element works, but a good choice reduces the chance of worst‑case O(n²) behavior).
34
+ 2. **Partition** the array into two sub‑arrays:
35
+ * Elements **≤ pivot** go to the left side.
36
+ * Elements **> pivot** go to the right side.
37
+ 3. **Recursively** apply Quick‑Sort to the left and right sub‑arrays.
38
+
39
+ The algorithm runs in **average O(n log n)** time and **O(log n)** extra space (the recursion stack). The in‑place version shown below uses the **Lomuto partition scheme**, which is easy to understand and implement.
40
+
41
+ ---
42
+
43
+ ## 2. Python Implementation (In‑Place)
44
+
45
+ ```python
46
+ def quicksort(arr, low=0, high=None):
47
+ """
48
+ In‑place quicksort.
49
+ Parameters
50
+ ----------
51
+ arr : list
52
+ The list to be sorted.
53
+ low : int, optional
54
+ Starting index of the sub‑list to sort (default 0).
55
+ high : int, optional
56
+ End index (inclusive) of the sub‑list to sort.
57
+ If None, the whole list is sorted.
58
+ """
59
+ if high is None:
60
+ high = len(arr) - 1
61
+
62
+ # Base case: a segment of length 0 or 1 is already sorted
63
+ if low < high:
64
+ # Partition the segment and get the pivot's final index
65
+ p = _partition(arr, low, high)
66
+
67
+ # Recursively sort the two halves
68
+ quicksort(arr, low, p - 1)
69
+ quicksort(arr, p + 1, high)
70
+
71
+
72
+ def _partition(arr, low, high):
73
+ """
74
+ Lomuto partition scheme.
75
+ Returns the final index of the pivot.
76
+ """
77
+ pivot = arr[high] # Choose the rightmost element as pivot
78
+ i = low - 1 # Index of the smaller element
79
+
80
+ for j in range(low, high):
81
+ if arr[j] <= pivot: # If current element <= pivot
82
+ i += 1
83
+ arr[i], arr[j] = arr[j], arr[i] # Swap it to the front
84
+
85
+ # Place the pivot after the last smaller element
86
+ arr[i + 1], arr[high] = arr[high], arr[i + 1]
87
+ return i + 1 # Return the pivot's final position
88
+
89
+
90
+ # -----------------------------
91
+ # Example usage
92
+ if __name__ == "__main__":
93
+ data = [33, 10, 55, 71, 29, 3, 90, 42]
94
+ print("Before:", data)
95
+ quicksort(data)
96
+ print("After :", data)
97
+ ```
98
+
99
+ **What the code does**
100
+
101
+ * `quicksort` is the public entry point. It accepts a mutable list and sorts it in place.
102
+ * `_partition` rearranges the elements around a pivot (chosen as the last element). After partitioning, every element left of the returned index is ≤ pivot, and everything right is > pivot.
103
+ * The recursion depth is bounded by `O(log n)` on average, but in the worst case (already sorted input with the naive pivot choice) it can degrade to `O(n)`. To avoid that, you can:
104
+ * Randomly shuffle the array before sorting, **or**
105
+ * Use a **median‑of‑three** or **random pivot** selection inside `_partition`.
106
+
107
+ ---
108
+
109
+ ## 3. C++ Implementation (In‑Place)
110
+
111
+ ```cpp
112
+ #include <iostream>
113
+ #include <vector>
114
+ #include <cstdlib> // std::rand, std::srand
115
+ #include <ctime> // std::time
116
+
117
+ // Lomuto partition
118
+ int partition(std::vector<int>& a, int low, int high) {
119
+ int pivot = a[high]; // Choose rightmost element as pivot
120
+ int i = low - 1; // Index of smaller element
121
+
122
+ for (int j = low; j < high; ++j) {
123
+ if (a[j] <= pivot) {
124
+ ++i;
125
+ std::swap(a[i], a[j]);
126
+ }
127
+ }
128
+ std::swap(a[i + 1], a[high]); // Place pivot in its final spot
129
+ return i + 1; // Return pivot index
130
+ }
131
+
132
+ // Recursive quicksort
133
+ void quicksort(std::vector<int>& a, int low, int high) {
134
+ if (low < high) {
135
+ int p = partition(a, low, high);
136
+ quicksort(a, low, p - 1);
137
+ quicksort(a, p + 1, high);
138
+ }
139
+ }
140
+
141
+ // Helper that sorts the whole vector
142
+ void quicksort(std::vector<int>& a) {
143
+ quicksort(a, 0, static_cast<int>(a.size()) - 1);
144
+ }
145
+
146
+ // -------------------------------------------------
147
+ int main() {
148
+ std::srand(static_cast<unsigned>(std::time(nullptr))); // optional random seed
149
+
150
+ std::vector<int> data = {33, 10, 55, 71, 29, 3, 90, 42};
151
+
152
+ std::cout << "Before: ";
153
+ for (int x : data) std::cout << x << ' ';
154
+ std::cout << '\n';
155
+
156
+ quicksort(data);
157
+
158
+ std::cout << "After : ";
159
+ for (int x : data) std::cout << x << ' ';
160
+ std::cout << '\n';
161
+ }
162
+ ```
163
+
164
+ **Notes**
165
+
166
+ * The algorithm is identical to the Python version, just expressed with C++ syntax.
167
+ * `std::swap` does the element exchange.
168
+ * If you want a *random pivot* to improve average performance, replace the line `int pivot = a[high];` with:
169
+
170
+ ```cpp
171
+ int randIdx = low + std::rand() % (high - low + 1);
172
+ std::swap(a[randIdx], a[high]); // move random element to the end
173
+ int pivot = a[high];
174
+ ```
175
+
176
+ ---
177
+
178
+ ## 4. JavaScript Implementation (In‑Place)
179
+
180
+ ```js
181
+ /**
182
+ * In‑place quicksort for an array of numbers.
183
+ * @param {Array<number>} arr - The array to sort.
184
+ * @param {number} low - Starting index (default 0).
185
+ * @param {number} high - Ending index (default arr.length‑1).
186
+ */
187
+ function quicksort(arr, low = 0, high = arr.length - 1) {
188
+ if (low < high) {
189
+ const p = partition(arr, low, high);
190
+ quicksort(arr, low, p - 1);
191
+ quicksort(arr, p + 1, high);
192
+ }
193
+ }
194
+
195
+ /**
196
+ * Lomuto partition scheme.
197
+ * @returns {number} Final index of the pivot.
198
+ */
199
+ function partition(arr, low, high) {
200
+ const pivot = arr[high]; // rightmost element as pivot
201
+ let i = low - 1;
202
+
203
+ for (let j = low; j < high; ++j) {
204
+ if (arr[j] <= pivot) {
205
+ ++i;
206
+ [arr[i], arr[j]] = [arr[j], arr[i]]; // swap via destructuring
207
+ }
208
+ }
209
+ // place pivot after the last smaller element
210
+ [arr[i + 1], arr[high]] = [arr[high], arr[i + 1]];
211
+ return i + 1;
212
+ }
213
+
214
+ // ---------------------------
215
+ // Example usage
216
+ const data = [33, 10, 55, 71, 29, 3, 90, 42];
217
+ console.log('Before:', data);
218
+ quicksort(data);
219
+ console.log('After :', data);
220
+ ```
221
+
222
+ ---
223
+
224
+ ## 5. Quick‑Sort Variants & Tips
225
+
226
+ | Variant | When to use it | Key idea |
227
+ |---------|----------------|----------|
228
+ | **Random pivot** | When you can’t guarantee input order | Randomly pick a pivot to make worst‑case probability negligible |
229
+ | **Median‑of‑three** | Small overhead, good practical performance | Choose pivot as median of first, middle, last elements |
230
+ | **Three‑way (Dutch‑national‑flag) partition** | When the array contains many duplicate keys | Split into `< pivot`, `= pivot`, `> pivot` to avoid O(n²) on many equal elements |
231
+ | **Iterative Quick‑Sort** | When recursion depth may overflow (very large arrays) | Use an explicit stack (or tail‑call optimisation) instead of recursion |
232
+
233
+ ---
234
+
235
+ ## 6. Complexity Recap
236
+
237
+ | Metric | Average case | Worst case | Space (auxiliary) |
238
+ |--------|--------------|-----------|-------------------|
239
+ | Time | **O(n log n)** | **O(n²)** (e.g., already sorted with naive pivot) | **O(log n)** recursion depth (in‑place) |
240
+ | Stability | **No** (elements with equal keys may be reordered) | – | – |
241
+
242
+ If you need a **stable** sort, consider Merge‑Sort or TimSort (the algorithm used by Python’s built‑in `list.sort()`).
243
+
244
+ ---
245
+
246
+ ### TL;DR – Quick‑Sort in a nutshell
247
+
248
+ ```python
249
+ def quicksort(arr):
250
+ if len(arr) <= 1:
251
+ return arr
252
+ pivot = arr[-1]
253
+ left = [x for x in arr[:-1] if x <= pivot]
254
+ right = [x for x in arr[:-1] if x > pivot]
255
+ return quicksort(left) + [pivot] + quicksort(right)
256
+ ```
257
+
258
+ The one‑liner above is a **functional** (non‑in‑place) version that is easy to understand but uses O(n) extra memory for each recursive call.
259
+
260
+ Pick the version that fits your constraints, and you’ll have a fast, reliable sorting routine ready to go!
261
+
262
+ ~~~
263
+
264
+ ### Generate the model
265
+
266
+ #### Requirement
267
+ pip install git+https://github.com/intel/auto-round.git@hengguo/gguf_update_0806
268
+
269
+ Here is the sample command to reproduce the model
270
+
271
+ ```bash
272
+ auto_round --format gguf:q4_k_s --iters 0 --nsamples 512 --model openai/gpt-oss-120b --output_dir tmp_autoround
273
+ ```
274
+
275
+
276
+
277
+ ## Ethical Considerations and Limitations
278
+
279
+ The model can produce factually incorrect output, and should not be relied on to produce factually accurate information. Because of the limitations of the pretrained model and the finetuning datasets, it is possible that this model could generate lewd, biased or otherwise offensive outputs.
280
+
281
+ Therefore, before deploying any applications of the model, developers should perform safety testing.
282
+
283
+ ## Caveats and Recommendations
284
+
285
+ Users (both direct and downstream) should be made aware of the risks, biases and limitations of the model.
286
+
287
+ Here are a couple of useful links to learn more about Intel's AI software:
288
+
289
+ - Intel Neural Compressor [link](https://github.com/intel/neural-compressor)
290
+
291
+ ## Disclaimer
292
+
293
+ The license on this model does not constitute legal advice. We are not responsible for the actions of third parties who use this model. Please consult an attorney before using this model for commercial purposes.
294
+
295
+ ## Cite
296
+
297
+ @article{cheng2023optimize, title={Optimize weight rounding via signed gradient descent for the quantization of llms}, author={Cheng, Wenhua and Zhang, Weiwei and Shen, Haihao and Cai, Yiyang and He, Xin and Lv, Kaokao and Liu, Yi}, journal={arXiv preprint arXiv:2309.05516}, year={2023} }
298
+
299
+ [arxiv](https://arxiv.org/abs/2309.05516) [github](https://github.com/intel/auto-round)