A weight matrix is stored densely in fp16 (2 bytes per number). To store an unstructured-pruned copy in CSR (compressed sparse row) format you keep, for each non-zero, its fp16 value (2 bytes) and its column index (int32, 4 bytes), plus one int32 row pointer per row plus one. How many bytes does the sparse copy use at 80% and 95% sparsity, and at what sparsity does it break even with the dense copy?
ML systems and evaluation, Model compression
Level L2 Elementary. Length Medium. Nature Mat Mathematical.
What's being asked
Whether you can count the real memory cost of sparse storage, including index overhead, and see why moderate unstructured sparsity saves less than it seems.
Key idea
Every non-zero in CSR costs a value plus an index, here bytes, three times the 2 bytes of one dense fp16 entry. So CSR beats dense only when the fraction of non-zeros is below , that is, above about 67% sparsity.
Steps
- Start with the concept question `unstructured-vs-structured-pruning`; this is its numerical side. Dense size: bytes.
- At 80% sparsity the number of non-zeros is . Values and column indices cost bytes. Row pointers cost bytes. Total bytes, about 60% of the dense size.
- At 95% sparsity there are non-zeros: bytes plus gives bytes, about 15% of the dense size.
- Break-even: with density (fraction of non-zeros), sparse size and dense size . Setting them equal gives , so sparsity . At 50% sparsity CSR needs about bytes, more than the dense copy.
- Speed is a separate matter. Saving memory does not make a GPU faster, since irregular index lookups prevent the dense matrix-multiply hardware from being used well. Hardware-friendly patterns such as 2:4 sparsity (keep 2 of every 4 values) store 2 values plus small 2-bit position codes, about bytes per 4 weights against 8 bytes dense, with a regular layout the hardware can use.
Common mistakes
- Saying 80% sparsity means 80% less memory. The index data cost as much as twice the value data, so here the saving is about 40%.
- Forgetting the index bytes altogether, or the small row-pointer array.
- Assuming memory saved means time saved. Sparse kernels often run slower than dense ones at moderate sparsity.
How long your answer should be
Half a page; about 3 minutes, with the three byte counts and the break-even.
Read this
Previous in ML systems and evaluation: How do you monitor a deployed ML (machine learning) model when ground-truth labels arrive weeks late or never arrive at all?
Next in ML systems and evaluation: How do accuracy, F1 score and ROC-AUC compare as evaluation metrics for a binary classifier, and when is each appropriate, considering threshold dependence, class imbalance and whether each measures ranking quality or decision quality (use a small confusion-matrix example)?