Commit 1ec8bb6
fix match_modules_set to work with MoE (#524)
* fix match_modules_set to work with MoE
Summary:
match_modules_set isn't currently as useful as it could be because it
lacks the ability to match multiple results for each set like in the
case of a moe model where you have 128 experts.
```
[`layers.32.mlp.experts.0.gate_up_proj`, ..., `layers.32.mlp.experts.127.gate_up_proj`]
```
In order to make is so this can still work for matching simple cases and
moe cases we use the following approach.
1) match modules until we have at least 1 match per target
2) when we have 1 match per target, our set is 'full' and we calculate
the common parent context
3) continue matching and for each match, check if parent context would change given the
new match
4) if we find a match that changes the parent context, this is the first
element of the next set. yield the existing matched set and then
reset, using the current match as the first element of the new set.
To facilitate this algorithm i also added get_lowest_common_module_name
which basically copies a similar function in llm-compressor though
significantly simpler.
Signed-off-by: HDCharles <[email protected]>
* Update src/compressed_tensors/utils/match.py
Co-authored-by: Kyle Sayers <[email protected]>
Signed-off-by: HDCharles <[email protected]>
* Update src/compressed_tensors/utils/match.py
Co-authored-by: Kyle Sayers <[email protected]>
Signed-off-by: HDCharles <[email protected]>
* Update src/compressed_tensors/utils/match.py
Co-authored-by: Kyle Sayers <[email protected]>
Signed-off-by: HDCharles <[email protected]>
* Update src/compressed_tensors/utils/match.py
Co-authored-by: Kyle Sayers <[email protected]>
Signed-off-by: HDCharles <[email protected]>
* format fixes and bug fixes
Summary
Signed-off-by: HDCharles <[email protected]>
* formatting and fixes
Summary
Signed-off-by: HDCharles <[email protected]>
* formatting
Summary
Signed-off-by: HDCharles <[email protected]>
* formatting the formatting of format
Summary
Signed-off-by: HDCharles <[email protected]>
* making it look nice
Summary
Signed-off-by: HDCharles <[email protected]>
* improve name to lowest_common_ancestor
Summary
Signed-off-by: HDCharles <[email protected]>
* check for multiple matches, formatting, List typehint
Summary
Signed-off-by: HDCharles <[email protected]>
* error instead of warn
Summary
Signed-off-by: HDCharles <[email protected]>
* fix
Summary
Signed-off-by: HDCharles <[email protected]>
---------
Signed-off-by: HDCharles <[email protected]>
Signed-off-by: HDCharles <[email protected]>
Co-authored-by: Kyle Sayers <[email protected]>
Co-authored-by: Fynn Schmitt-Ulms <[email protected]>1 parent 73c2cf9 commit 1ec8bb6
File tree
2 files changed
+317
-47
lines changed- src/compressed_tensors/utils
- tests/test_utils
2 files changed
+317
-47
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
13 | 13 | | |
14 | 14 | | |
15 | 15 | | |
| 16 | + | |
16 | 17 | | |
| 18 | + | |
17 | 19 | | |
18 | 20 | | |
19 | 21 | | |
| |||
29 | 31 | | |
30 | 32 | | |
31 | 33 | | |
| 34 | + | |
32 | 35 | | |
33 | 36 | | |
34 | 37 | | |
| |||
157 | 160 | | |
158 | 161 | | |
159 | 162 | | |
| 163 | + | |
| 164 | + | |
| 165 | + | |
| 166 | + | |
| 167 | + | |
| 168 | + | |
| 169 | + | |
| 170 | + | |
| 171 | + | |
| 172 | + | |
| 173 | + | |
| 174 | + | |
| 175 | + | |
| 176 | + | |
| 177 | + | |
| 178 | + | |
| 179 | + | |
| 180 | + | |
| 181 | + | |
| 182 | + | |
| 183 | + | |
| 184 | + | |
| 185 | + | |
| 186 | + | |
| 187 | + | |
| 188 | + | |
160 | 189 | | |
161 | 190 | | |
162 | 191 | | |
163 | 192 | | |
164 | | - | |
| 193 | + | |
| 194 | + | |
165 | 195 | | |
166 | | - | |
167 | | - | |
| 196 | + | |
| 197 | + | |
| 198 | + | |
| 199 | + | |
| 200 | + | |
| 201 | + | |
| 202 | + | |
| 203 | + | |
168 | 204 | | |
169 | | - | |
| 205 | + | |
| 206 | + | |
| 207 | + | |
| 208 | + | |
| 209 | + | |
| 210 | + | |
| 211 | + | |
170 | 212 | | |
171 | 213 | | |
172 | | - | |
173 | | - | |
174 | | - | |
175 | | - | |
176 | | - | |
177 | | - | |
178 | | - | |
179 | | - | |
180 | | - | |
181 | | - | |
| 214 | + | |
| 215 | + | |
| 216 | + | |
| 217 | + | |
| 218 | + | |
| 219 | + | |
| 220 | + | |
| 221 | + | |
| 222 | + | |
| 223 | + | |
182 | 224 | | |
183 | | - | |
184 | | - | |
185 | | - | |
186 | | - | |
187 | | - | |
188 | 225 | | |
189 | 226 | | |
190 | 227 | | |
191 | 228 | | |
192 | 229 | | |
193 | 230 | | |
194 | 231 | | |
195 | | - | |
| 232 | + | |
| 233 | + | |
| 234 | + | |
| 235 | + | |
| 236 | + | |
| 237 | + | |
| 238 | + | |
| 239 | + | |
| 240 | + | |
| 241 | + | |
| 242 | + | |
| 243 | + | |
| 244 | + | |
| 245 | + | |
| 246 | + | |
| 247 | + | |
| 248 | + | |
| 249 | + | |
| 250 | + | |
| 251 | + | |
| 252 | + | |
| 253 | + | |
| 254 | + | |
| 255 | + | |
| 256 | + | |
| 257 | + | |
| 258 | + | |
| 259 | + | |
| 260 | + | |
| 261 | + | |
| 262 | + | |
| 263 | + | |
| 264 | + | |
| 265 | + | |
| 266 | + | |
| 267 | + | |
| 268 | + | |
| 269 | + | |
| 270 | + | |
| 271 | + | |
| 272 | + | |
| 273 | + | |
| 274 | + | |
| 275 | + | |
196 | 276 | | |
197 | 277 | | |
198 | 278 | | |
199 | 279 | | |
| 280 | + | |
| 281 | + | |
200 | 282 | | |
201 | 283 | | |
202 | 284 | | |
203 | 285 | | |
204 | | - | |
| 286 | + | |
| 287 | + | |
| 288 | + | |
| 289 | + | |
| 290 | + | |
| 291 | + | |
| 292 | + | |
| 293 | + | |
| 294 | + | |
| 295 | + | |
| 296 | + | |
| 297 | + | |
| 298 | + | |
| 299 | + | |
| 300 | + | |
| 301 | + | |
| 302 | + | |
| 303 | + | |
| 304 | + | |
| 305 | + | |
| 306 | + | |
| 307 | + | |
| 308 | + | |
| 309 | + | |
205 | 310 | | |
206 | | - | |
| 311 | + | |
207 | 312 | | |
208 | 313 | | |
209 | | - | |
210 | | - | |
211 | | - | |
212 | | - | |
213 | | - | |
214 | | - | |
215 | | - | |
216 | | - | |
217 | | - | |
218 | | - | |
219 | | - | |
220 | | - | |
221 | | - | |
| 314 | + | |
| 315 | + | |
| 316 | + | |
| 317 | + | |
| 318 | + | |
| 319 | + | |
| 320 | + | |
| 321 | + | |
| 322 | + | |
| 323 | + | |
| 324 | + | |
| 325 | + | |
| 326 | + | |
| 327 | + | |
| 328 | + | |
| 329 | + | |
| 330 | + | |
| 331 | + | |
| 332 | + | |
| 333 | + | |
| 334 | + | |
| 335 | + | |
| 336 | + | |
| 337 | + | |
| 338 | + | |
| 339 | + | |
| 340 | + | |
| 341 | + | |
| 342 | + | |
| 343 | + | |
| 344 | + | |
| 345 | + | |
| 346 | + | |
| 347 | + | |
| 348 | + | |
| 349 | + | |
| 350 | + | |
222 | 351 | | |
223 | 352 | | |
224 | 353 | | |
| |||
0 commit comments