@@ -105,6 +105,7 @@ def optimize(job, save_fn, model):
105
105
last_update = 0
106
106
m = float ("inf" )
107
107
p = float ("inf" )
108
+ c = weight_budget
108
109
for i in range (anneal_stages * anneal_samples ):
109
110
if time .time () - last_update > 1 or i == anneal_samples - 1 :
110
111
print (f" -- Optimizing: { i + 1 :4} /{ anneal_stages * anneal_samples :4} " )
@@ -125,27 +126,41 @@ def optimize(job, save_fn, model):
125
126
else :
126
127
norm = bestnorm
127
128
128
- s_ , si_ , p_ , c_ , m_ = ext_c .sim_anneal (slots ,
129
- weight_budget ,
130
- anneal_temp_max ,
131
- anneal_cooling_factor ,
132
- anneal_temp_min ,
133
- anneal_iter ,
134
- norm )
129
+ s_ , si_ , p_ , c_ , m_ = ext_c .sim_anneal (
130
+ slots ,
131
+ weight_budget ,
132
+ anneal_temp_max ,
133
+ anneal_cooling_factor ,
134
+ anneal_temp_min ,
135
+ anneal_iter ,
136
+ norm
137
+ )
135
138
136
139
if i < anneal_samples * 2 :
137
140
if m_ < m :
138
141
m = m_
139
142
bestnorm = norm
140
143
else :
141
144
if p_ < p :
142
- s , si , p , m = s_ , si_ , p_ , m_
145
+ s , si , p , c , m = s_ , si_ , p_ , c_ , m_
146
+
147
+ # Tweak solution in case there is some budget left over
148
+
149
+ while True :
150
+ repeat = False
151
+ for i in range (len (si )):
152
+ if si [i ] < len (slots [i ]) - 1 :
153
+ delta_c = slots [i ][si [i ] + 1 ][0 ] - slots [i ][si [i ]][0 ]
154
+ if c + delta_c <= weight_budget :
155
+ c += delta_c
156
+ si [i ] = si [i ] + 1
157
+ repeat = True
158
+ if not repeat : break
143
159
144
160
solution_idx = si
145
161
print (f" -- max(err): { m :.6f} " )
146
162
print (f" -- error_norm: { bestnorm :.6f} " )
147
163
148
-
149
164
# Save strategy
150
165
151
166
print (" -- Quantization strategy:" )
0 commit comments