Commit 277d325
Refactor sparse optimization code following DRY and single responsibility principles
- Split pack_bitmasks into modular functions with single responsibilities:
- _validate_bitmask_shape(): Input validation
- _pack_bits_torch(): Core PyTorch packing logic
- _pack_bits_numpy_fallback(): NumPy fallback
- Refactored get_24_bytemasks with helper functions:
- _validate_24_sparsity_tensor(): Tensor validation
- _get_topk_mask(): Isolated mask generation algorithm
- Improved error messages with actual tensor dimensions
- Reduced test suite from 222 to 182 lines by removing redundancy
- Organized tests into focused classes by functionality
- All optimizations preserved, code is now more maintainable
🤖 Generated with [Claude Code](https://claude.ai/code)
Co-Authored-By: Claude <noreply@anthropic.com>1 parent 893e189 commit 277d325
File tree
3 files changed
+182
-142
lines changed- src/compressed_tensors
- compressors/sparse_compressors
- utils
- tests
3 files changed
+182
-142
lines changedLines changed: 47 additions & 13 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
206 | 206 | | |
207 | 207 | | |
208 | 208 | | |
209 | | - | |
| 209 | + | |
| 210 | + | |
| 211 | + | |
| 212 | + | |
| 213 | + | |
| 214 | + | |
| 215 | + | |
| 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 | + | |
210 | 241 | | |
211 | 242 | | |
212 | 243 | | |
| |||
222 | 253 | | |
223 | 254 | | |
224 | 255 | | |
| 256 | + | |
| 257 | + | |
| 258 | + | |
225 | 259 | | |
| 260 | + | |
| 261 | + | |
| 262 | + | |
226 | 263 | | |
227 | 264 | | |
228 | | - | |
229 | | - | |
230 | | - | |
231 | | - | |
232 | | - | |
233 | | - | |
| 265 | + | |
| 266 | + | |
234 | 267 | | |
235 | | - | |
236 | | - | |
237 | | - | |
238 | | - | |
| 268 | + | |
| 269 | + | |
| 270 | + | |
239 | 271 | | |
240 | | - | |
| 272 | + | |
| 273 | + | |
| 274 | + | |
241 | 275 | | |
242 | | - | |
| 276 | + | |
243 | 277 | | |
| 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 | + | |
296 | 344 | | |
297 | 345 | | |
298 | 346 | | |
299 | | - | |
| 347 | + | |
| 348 | + | |
| 349 | + | |
300 | 350 | | |
301 | | - | |
302 | | - | |
| 351 | + | |
| 352 | + | |
| 353 | + | |
303 | 354 | | |
| 355 | + | |
| 356 | + | |
| 357 | + | |
304 | 358 | | |
305 | 359 | | |
306 | 360 | | |
307 | 361 | | |
| 362 | + | |
308 | 363 | | |
309 | 364 | | |
310 | 365 | | |
311 | 366 | | |
312 | | - | |
313 | | - | |
314 | 367 | | |
315 | | - | |
316 | 368 | | |
317 | | - | |
318 | | - | |
319 | | - | |
320 | | - | |
321 | | - | |
| 369 | + | |
| 370 | + | |
322 | 371 | | |
323 | 372 | | |
324 | | - | |
325 | | - | |
326 | | - | |
327 | | - | |
328 | | - | |
| 373 | + | |
| 374 | + | |
329 | 375 | | |
330 | 376 | | |
331 | 377 | | |
| |||
0 commit comments