Model Details
This model is a mixed gguf q2ks format of zai-org/GLM-4.5 generated by intel/auto-round algorithm. Embedding layer and lm-head layer are fallback to 8 bits and non expert layers are fallback to 4 bits. Please refer to Section Generate the model
for more details.
Please follow the license of the original model.
How To Use
Llamacpp inference
/llama-cli -hf Intel/GLM-4.5-gguf-q2ks-mixed-AutoRound
> Write a quick sort algorithm.
Of course! Here's a quick sort algorithm written in Python. Quick sort is a highly efficient sorting algorithm and is a divide-and-conquer algorithm.
### The Algorithm
The algorithm picks a 'pivot' element from the array and partitions the other elements into two sub-arrays: those less than the pivot and those greater than the pivot. The process is then repeated recursively for the sub-arrays until the entire list is sorted.
### Python Implementation
```python
def quick_sort(arr):
"""
Sorts an array in ascending order using the Quick Sort algorithm.
This is an in-place sort using the Lomuto partition scheme.
"""
# Helper function to perform the partitioning
def _partition(low, high):
# We'll use the last element as the pivot
pivot = arr[high]
i = low - 1 # Index of smaller element
for j in range(low, high):
# If current element is smaller than or equal to pivot
if arr[j] <= pivot:
i += 1
arr[i], arr[j] = arr[j], arr[i] # Swap
# Place the pivot in its correct position
arr[i + 1], arr[high] = arr[high], arr[i + 1]
return i + 1 # Return the pivot index
# Main recursive function
def _sort(low, high):
if low < high:
# pi is the partitioning index, arr[pi] is now at its correct place
pi = _partition(low, high)
# Recursively sort elements before and after the partition
_sort(low, pi - 1)
_sort(pi + 1, high)
# Start the sorting process
_sort(0, len(arr) - 1)
return arr
# Example usage:
my_list = [10, 7, 8, 9, 1, 5]
print(f"Original list: {my_list}")
sorted_list = quick_sort(my_list)
print(f"Sorted list: {sorted_list}")
# Output:
# Original list: [10, 7, 8, 9, 1, 5]
# Sorted list: [1, 5, 7, 8, 9, 10]
```
### Explanation:
1. **`quick_sort(arr)`**: This is the main function that users call. It sets up the recursive sorting process.
2. **`_partition(low, high)`**: This is a helper function that does the core work of the algorithm.
* **Pivot Selection**: It selects the last element of the current sub-array (`arr[high]`) as the pivot.
* **Partitioning**: It iterates through the sub-array (from `low` to `high-1`). Any element found that is less than or equal to the pivot is swapped to the left side of the sub-array. The index `i` keeps track of the boundary between elements less than the pivot and elements greater than the pivot.
* **Final Swap**: After the loop, the pivot itself is swapped into its final, correct position (at index `i + 1`), and this new index is returned.
3. **`_sort(low, high)`**: This is the recursive helper function.
* **Base Case**: The recursion stops when `low >= high`, meaning the sub-array has 0 or 1 element and is already considered sorted.
* **Recursive Step**: It first calls `_partition` to get the pivot's correct position (`pi`). Then, it makes two recursive calls to sort the elements to the left of the pivot (`_sort(low, pi - 1)`) and the elements to the right of the pivot (`_sort(pi + 1, high)`).
### Key Points:
* **Time Complexity**:
* **Best and Average Case**: O(n log n). This occurs when the pivot consistently divides the array into roughly equal halves.
* **Worst Case**: O(n²). This can happen if the pivot is consistently the smallest or largest element (e.g., if the array is already sorted and you always pick the last element as the pivot). This can be mitigated by choosing a better pivot strategy (e.g., "median-of-three").
* **Space Complexity**: O(log n) on average for the recursion stack depth. O(n) in the worst case.
* **In-Place**: This implementation is an "in-place" sort, meaning it modifies the original array directly and does not require significant extra memory for creating new arrays (unlike, for example, a naive merge sort implementation). This makes it very memory-efficient.
I can provide an implementation in another language (like JavaScript, C++, or Java) or explain a different partitioning scheme (like Hoare's) if you'd like!
Generate the model
Here is the sample command to reproduce the model
import torch
from transformers import AutoModelForCausalLM, AutoTokenizer
from auto_round import AutoRound
model_name = "zai-org/GLM-4.5"
model = AutoModelForCausalLM.from_pretrained(model_name,
device_map="cpu", torch_dtype="auto")
tokenizer = AutoTokenizer.from_pretrained(model_name)
layer_config = {}
for n, m in model.named_modules():
if n == "lm_head" or isinstance(m,torch.nn.Embedding):
layer_config[n] = {"bits": 8}
elif isinstance(m, torch.nn.Linear) and (not "expert" in n or "shared_experts" in n) and n != "lm_head":
layer_config[n] = {"bits": 4}
autoround = AutoRound(model, tokenizer, iters=0, layer_config=layer_config, nsamples=512)
autoround.quantize_and_save("tmp_autoround", format="gguf:q2_k_s")
Ethical Considerations and Limitations
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.
Therefore, before deploying any applications of the model, developers should perform safety testing.
Caveats and Recommendations
Users (both direct and downstream) should be made aware of the risks, biases and limitations of the model.
Here are a couple of useful links to learn more about Intel's AI software:
- Intel Neural Compressor link
Disclaimer
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.
Cite
@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} }
- Downloads last month
- 1,644
2-bit
Model tree for Intel/GLM-4.5-gguf-q2ks-mixed-AutoRound
Base model
zai-org/GLM-4.5