Skip to content
This repository was archived by the owner on Jun 3, 2025. It is now read-only.

Commit 8f33437

Browse files
author
Sara Adkins
committed
incorporate sparsity into size calculation
1 parent eb0d561 commit 8f33437

File tree

3 files changed

+10
-6
lines changed

3 files changed

+10
-6
lines changed

src/sparsezoo/analyze_v2/memory_access_analysis.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -165,7 +165,8 @@ def get_memory_access_bits(
165165
node_weight = get_node_weight(model_graph, node)
166166
precision = get_numpy_quantization_level(node_weight)
167167
counts = memory_access_counts["single"]["counts"]
168-
bits = counts * precision
168+
counts_sparse = memory_access_counts["single"]["counts_sparse"]
169+
bits = (counts - counts_sparse) * precision
169170
is_quantized = is_quantized_layer(model_graph, node)
170171

171172
return {

src/sparsezoo/analyze_v2/operation_analysis.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -167,9 +167,11 @@ def get_operation_bits(
167167
is_quantized_op = "32" not in str(precision)
168168

169169
single_counts = ops["single"]["counts"]
170-
single_bits = single_counts * precision
170+
single_counts_sparse = ops["single"]["counts_sparse"]
171+
single_bits = (single_counts - single_counts_sparse) * precision
171172
block4_counts = ops["block4"]["counts"]
172-
block4_bits = block4_counts * precision
173+
block4_counts_sparse = ops["block4"]["counts_sparse"]
174+
block4_bits = (block4_counts - block4_counts_sparse) * precision
173175
return {
174176
"tensor": {
175177
"counts": single_counts,

src/sparsezoo/analyze_v2/parameter_analysis.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -153,16 +153,17 @@ def get_parameter_bits(
153153
If the layer is quantized, assume all its elements in the ndarray
154154
are quantized
155155
"""
156-
num_weights, _, _ = get_node_param_counts(node, model_graph)
156+
num_weights, num_bias, num_sparse_weights = get_node_param_counts(node, model_graph)
157157
if num_weights > 0:
158158
precision = get_node_weight_precision(model_graph, node)
159159
is_quantized = is_quantized_layer(model_graph, node)
160+
num_non_sparse_weights = num_weights - num_sparse_weights + num_bias
160161
return {
161162
"tensor": {
162163
"counts": num_weights,
163164
"counts_quant": num_weights * is_quantized,
164-
"bits": num_weights * precision,
165-
"bits_quant": num_weights * precision * is_quantized,
165+
"bits": num_non_sparse_weights * precision,
166+
"bits_quant": num_non_sparse_weights * precision * is_quantized,
166167
},
167168
}
168169

0 commit comments

Comments
 (0)