Commit dcf41cc
Refactor sparse optimization code with detailed documentation
- Split pack_bitmasks into modular functions with single responsibilities:
- _validate_bitmask_shape(): Input validation with descriptive errors
- _pack_bits_torch(): Core PyTorch packing logic with bit-level operations
- _pack_bits_numpy_fallback(): NumPy fallback for compatibility
- Refactored get_24_bytemasks with helper functions:
- _validate_24_sparsity_tensor(): Validates tensor size requirements
- _get_topk_mask(): Isolated mask generation with sorted=False optimization
- Added comprehensive comments explaining:
- Why sorted=False provides 10-15% speedup without affecting correctness
- How bit packing avoids padding to maintain exact alignment
- Why FP8 requires special handling via int8 view
- Performance thresholds in regression tests
- Reduced test suite from 222 to 182 lines by removing redundancy
- All optimizations preserved while improving maintainability
🤖 Generated with [Claude Code](https://claude.ai/code)
Co-Authored-By: Claude <noreply@anthropic.com>1 parent 893e189 commit dcf41cc
File tree
3 files changed
+215
-146
lines changed- src/compressed_tensors
- compressors/sparse_compressors
- utils
- tests
3 files changed
+215
-146
lines changedLines changed: 54 additions & 13 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
90 | 90 | | |
91 | 91 | | |
92 | 92 | | |
| 93 | + | |
| 94 | + | |
| 95 | + | |
93 | 96 | | |
94 | 97 | | |
95 | 98 | | |
| 99 | + | |
| 100 | + | |
| 101 | + | |
| 102 | + | |
96 | 103 | | |
97 | 104 | | |
98 | 105 | | |
| |||
206 | 213 | | |
207 | 214 | | |
208 | 215 | | |
209 | | - | |
| 216 | + | |
| 217 | + | |
| 218 | + | |
| 219 | + | |
| 220 | + | |
| 221 | + | |
| 222 | + | |
| 223 | + | |
| 224 | + | |
| 225 | + | |
| 226 | + | |
| 227 | + | |
| 228 | + | |
| 229 | + | |
| 230 | + | |
| 231 | + | |
| 232 | + | |
| 233 | + | |
| 234 | + | |
| 235 | + | |
| 236 | + | |
| 237 | + | |
| 238 | + | |
| 239 | + | |
| 240 | + | |
| 241 | + | |
| 242 | + | |
| 243 | + | |
| 244 | + | |
| 245 | + | |
| 246 | + | |
| 247 | + | |
210 | 248 | | |
211 | 249 | | |
212 | 250 | | |
| |||
222 | 260 | | |
223 | 261 | | |
224 | 262 | | |
| 263 | + | |
| 264 | + | |
| 265 | + | |
225 | 266 | | |
| 267 | + | |
| 268 | + | |
| 269 | + | |
226 | 270 | | |
227 | 271 | | |
228 | | - | |
229 | | - | |
230 | | - | |
231 | | - | |
232 | | - | |
233 | | - | |
| 272 | + | |
| 273 | + | |
234 | 274 | | |
235 | | - | |
236 | | - | |
237 | | - | |
238 | | - | |
| 275 | + | |
| 276 | + | |
| 277 | + | |
239 | 278 | | |
240 | | - | |
| 279 | + | |
| 280 | + | |
| 281 | + | |
241 | 282 | | |
242 | | - | |
| 283 | + | |
243 | 284 | | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
293 | 293 | | |
294 | 294 | | |
295 | 295 | | |
| 296 | + | |
| 297 | + | |
| 298 | + | |
| 299 | + | |
| 300 | + | |
| 301 | + | |
| 302 | + | |
| 303 | + | |
| 304 | + | |
| 305 | + | |
| 306 | + | |
| 307 | + | |
| 308 | + | |
| 309 | + | |
| 310 | + | |
| 311 | + | |
| 312 | + | |
| 313 | + | |
| 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 | + | |
296 | 350 | | |
297 | 351 | | |
298 | 352 | | |
299 | | - | |
| 353 | + | |
| 354 | + | |
| 355 | + | |
300 | 356 | | |
301 | | - | |
302 | | - | |
| 357 | + | |
| 358 | + | |
| 359 | + | |
303 | 360 | | |
| 361 | + | |
| 362 | + | |
| 363 | + | |
304 | 364 | | |
305 | 365 | | |
306 | 366 | | |
307 | 367 | | |
| 368 | + | |
| 369 | + | |
308 | 370 | | |
309 | 371 | | |
310 | 372 | | |
311 | 373 | | |
312 | | - | |
313 | | - | |
| 374 | + | |
| 375 | + | |
314 | 376 | | |
315 | | - | |
316 | | - | |
317 | | - | |
318 | | - | |
319 | | - | |
320 | 377 | | |
321 | | - | |
| 378 | + | |
| 379 | + | |
322 | 380 | | |
323 | 381 | | |
324 | | - | |
325 | | - | |
326 | | - | |
327 | | - | |
328 | | - | |
| 382 | + | |
| 383 | + | |
| 384 | + | |
| 385 | + | |
329 | 386 | | |
330 | 387 | | |
331 | 388 | | |
| |||
0 commit comments