add utility to compute analytical bits per weight - #67
Open
pkmandke wants to merge 18 commits into
Open
Conversation
Signed-off-by: Prathamesh Mandke <46148373+pkmandke@users.noreply.github.com>
Signed-off-by: Prathamesh Mandke <46148373+pkmandke@users.noreply.github.com>
Signed-off-by: Prathamesh Mandke <46148373+pkmandke@users.noreply.github.com>
pkmandke
marked this pull request as ready for review
August 17, 2026 20:59
guru-desh
reviewed
Aug 18, 2026
Signed-off-by: Prathamesh Mandke <46148373+pkmandke@users.noreply.github.com>
Signed-off-by: Prathamesh Mandke <46148373+pkmandke@users.noreply.github.com>
Signed-off-by: Prathamesh Mandke <46148373+pkmandke@users.noreply.github.com>
u-simha
reviewed
Aug 19, 2026
u-simha
left a comment
Contributor
There was a problem hiding this comment.
Have left some comments; my main suggestion would be to have a documentation page (even if it is brief) rather than the doc string at the top of the file
| # Use of this source code is governed by a BSD-3-Clause license that can | ||
| # be found in the LICENSE file or at https://opensource.org/licenses/BSD-3-Clause | ||
|
|
||
| """Compute the average bits-per-weight (bpw) of a prepared ``coreai-opt`` model. |
Contributor
There was a problem hiding this comment.
My suggestion would be to have a doc page explaining the usage of this tool; doc strings in the headings of the file isn't often read, compared to the documentation.
Member
Add utility to compute the average bits-per-weight (bpw) of a prepared
coreai-optmodel in eager mode quantization and palettization.Public API
Imported from
coreai_opt.inspection:Usage:
Supported: eager-mode integer weight quantization (int8/int4/int2 and unsigned variants, symmetric or asymmetric, any granularity, sub-byte payloads packed at
n_bits), and palettization at any spec-supportedn_bitsincluding a quantized LUT.Raises
NotImplementedErrorfor: graph-mode /torch.fx.GraphModulemodels, floating-point (FP8/FP4) weight quantization, and parametrizations that store multiple original tensors (weight_norm,spectral_norm).Note: This is an analytical estimate, not a measurement. It is meant for prepared models, not finalized ones.
Testing
tests/inspection/test_bits_per_weight.py: unit tests against hand-derived golden bit counts across quantization dtypes, qschemes, and granularities, plus palettizationn_bitsx granularity combinations. Also covers persistent and non-persistent buffers, tied weights, per-module attribution, and the unsupported-config errors.tests/export/test_bpw_export_size.py: cross-checkstotal_bits / 8against the measured payload of an actualCore AIexport. The prediction must be a lower bound and land within a 2.5 percent structural-metadata budget.tests/export/export_utils.py: addscoreai_export_size_byteshelper.tests/models/simple.py: addsLinearBatchNormModelfixture (buffer coverage) and optionalbiasto two existing fixtures.TODO: