Structured OBS
Structured OBS (Optimal Brain Surgeon) via BlockSpec/ScopeSpec.
Compensation modes: local, full, split, interleaved.
- sparsekit.pruners.obs.block_col_indices(block, num_cols, device=device(type='cpu'))[source]
Map each block to its original column indices.
- sparsekit.pruners.obs.block_param_rc(block, num_cols, device=device(type='cpu'))[source]
Map each block to
(param_row, param_col).Unlike
block_col_indices()this returns the full grid (including the row dimension) and both row and column indices.
- class sparsekit.pruners.obs.StructuredOBS(scope, hessian, damp=0.0001, inv_h=None)[source]
Bases:
objectStructured OBS pruner operating through ScopeSpec.
- Parameters:
- prune(nnz, block_size=2048, compensate='local', n_splits=1)[source]
Prune to nnz blocks per scope.
- Phase 1: enumerate all C(bs, num_prune) subsets per scope, pick
the best per (row, scope) using C = H^{-1} submatrices.
- Phase 2 (compensation):
‘local’: within-scope only (fast, independent scopes)
- ‘full’: sequential compensation to ALL K columns via C[P, :]
(slower but ~44% better than SparseGPT)
- ‘split’: like ‘full’ but recomputes C between column splits.
Use n_splits to control granularity (2 = one C update at the midpoint).
- ‘interleaved’: re-selects masks AND compensates at each split
using recomputed C. Single shared C (O(K²) memory).
- prune_true_obs(nnz, ng=64, chunk_size=16, order='left_to_right', scoring='independent', c_dtype=None, progress_fn=None)[source]
Per-row True OBS with Schur complement updates.
Each row maintains its own C = inv(H), updated via Schur complement after pruning. Processes
ngblocks simultaneously per batch.- Parameters:
nnz (int) – Blocks to keep per scope.
ng (int) – Number of scopes to process per batch.
chunk_size (int) – Rows to process simultaneously.
order (str) –
"left_to_right"or"largest_first".scoring (str) –
"joint"(enumerate subsets) or"independent"(per-element w^2/diag(C) + topk).c_dtype – Dtype for per-row C matrices. Default
Noneuses fp16 for tensor-core Schur updates.progress_fn – Optional
callable(str)for progress messages.
- Return type:
None