Views
No views yet
vllm serve Intel/Qwen3-Coder-30B-A3B-Instruct-int4-AutoRound --tensor-parallel-size 4 --max-model-len 655361from transformers import AutoModelForCausalLM, AutoTokenizer
2
3model_name = "Intel/Qwen3-Coder-30B-A3B-Instruct-int4-AutoRound"
4# load the tokenizer and the model
5tokenizer = AutoTokenizer.from_pretrained(model_name)
6model = AutoModelForCausalLM.from_pretrained(
7 model_name,
8 torch_dtype="auto",
9 device_map="auto"
10)
11
12# prepare the model input
13prompt = "Write a quick sort algorithm."
14messages = [
15 {"role": "user", "content": prompt}
16]
17text = tokenizer.apply_chat_template(
18 messages,
19 tokenize=False,
20 add_generation_prompt=True,
21)
22model_inputs = tokenizer([text], return_tensors="pt").to(model.device)
23
24# conduct text completion
25generated_ids = model.generate(
26 **model_inputs,
27 max_new_tokens=65536
28)
29output_ids = generated_ids[0][len(model_inputs.input_ids[0]):].tolist()
30
31content = tokenizer.decode(output_ids, skip_special_tokens=True)
32print("content:", content)
33
34"""
35content: Here's a quicksort algorithm implementation in Python:
36
37```python
38def quicksort(arr):
39 '''
40 Sorts an array using the quicksort algorithm.
41
42 Args:
43 arr: List of comparable elements
44
45 Returns:
46 None (sorts in-place)
47 '''
48 if len(arr) <= 1:
49 return
50
51 def partition(low, high):
52 '''Partition function using the last element as pivot'''
53 pivot = arr[high]
54 i = low - 1 # Index of smaller element
55
56 for j in range(low, high):
57 if arr[j] <= pivot:
58 i += 1
59 arr[i], arr[j] = arr[j], arr[i] # Swap elements
60
61 arr[i + 1], arr[high] = arr[high], arr[i + 1] # Place pivot in correct position
62 return i + 1
63
64 def quicksort_helper(low, high):
65 '''Recursive helper function'''
66 if low < high:
67 # Partition the array and get pivot index
68 pi = partition(low, high)
69
70 # Recursively sort elements before and after partition
71 quicksort_helper(low, pi - 1)
72 quicksort_helper(pi + 1, high)
73
74 quicksort_helper(0, len(arr) - 1)
75
76# Example usage:
77if __name__ == "__main__":
78 # Test the algorithm
79 test_array = [64, 34, 25, 12, 22, 11, 90]
80 print("Original array:", test_array)
81
82 quicksort(test_array)
83 print("Sorted array:", test_array)
84
85 # Test with other examples
86 test_cases = [
87 [5, 2, 8, 1, 9],
88 [1],
89 [],
90 [3, 3, 3, 3],
91 [5, 4, 3, 2, 1]
92 ]
93
94 for i, case in enumerate(test_cases):
95 original = case.copy()
96 quicksort(case)
97 print(f"Test {i+1}: {original} → {case}")
98
99**How it works:**
100
1011. **Divide**: Choose a "pivot" element and partition the array so that elements smaller than the pivot are on the left, and larger elements are on the right.
102
1032. **Conquer**: Recursively apply quicksort to the sub-arrays on both sides of the pivot.
104
1053. **Combine**: Since we're sorting in-place, no additional combining step is needed.
106
107**Key features:**
108- **Time Complexity**: O(n log n) average case, O(n²) worst case
109- **Space Complexity**: O(log n) due to recursion stack
110- **In-place sorting**: Modifies the original array
111- **Not stable**: Relative order of equal elements may change
112
113**Alternative version with random pivot selection** (better average performance):
114
115```python
116import random
117
118def quicksort_random(arr):
119 '''Quicksort with random pivot selection for better average performance'''
120 def partition(low, high):
121 # Randomly select pivot and swap with last element
122 random_index = random.randint(low, high)
123 arr[random_index], arr[high] = arr[high], arr[random_index]
124
125 pivot = arr[high]
126 i = low - 1
127
128 for j in range(low, high):
129 if arr[j] <= pivot:
130 i += 1
131 arr[i], arr[j] = arr[j], arr[i]
132
133 arr[i + 1], arr[high] = arr[high], arr[i + 1]
134 return i + 1
135
136 def quicksort_helper(low, high):
137 if low < high:
138 pi = partition(low, high)
139 quicksort_helper(low, pi - 1)
140 quicksort_helper(pi + 1, high)
141
142 if len(arr) > 1:
143 quicksort_helper(0, len(arr) - 1)
144
145The algorithm efficiently sorts arrays by repeatedly dividing them into smaller subproblems, making it one of the most widely used sorting algorithms in practice.
146"""auto-round --model Qwen/Qwen3-Coder-30B-A3B-Instruct --output_dir "./tmp_autoround" --enable_torch_compile --nsamples 512 --fp_layers mlp.gate