Add initial support for joint sparsity pipeline - #80
Draft
u-simha wants to merge 3 commits into
Draft
Conversation
Adds a hidden, settable-but-not-public `_sparsity` field to QuantizationSpec and PalettizationSpec: weights are pre-sparsified before fake-quant/palettize, and finalize() inserts sparse_to_dense (plus lut_to_dense for palettization) in the correct op order. Validation of unsupported combinations (asymmetric quant, unsigned/FP4 dtypes, quantized LUTs, per-channel scale, non-per-tensor granularity) now happens at spec-construction time via pydantic.
Moves the [0, 1] range check for _sparsity into the existing _validate_sparsity(_zero_preserving) methods so each spec has a single validation entrypoint, and shortens a couple of over-long comments.
Resolves conflicts from main's graph-mode rewrite (qspec reconciliation pipeline, ensure_initialized-based palettization clustering, factory/import renames) and threads the sparsity plumbing through the new code paths: - _KMeansFakePalettize.__init__ now takes sparsity explicitly and forwards it to the base class, since upstream removed the old **kwargs passthrough. - The graph-mode qspec reconciliation pipeline (_qspec_types.py, _provisional_qspec_generation.py, _qspec_constraints.py, _qspec_resolution.py) rebuilds a fresh QuantizationSpec from reconciled fields; added a SPARSITY field so the private _sparsity value round-trips through that rebuild instead of silently reverting to None. Verified: tests/export/test_joint_sparsity.py (4/4), tests/quantization/ + tests/palettization/ (2059/2059, excluding slow), tests/export/ full suite (all passing, excluding slow).
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What:
How:
_sparsityfield to theQuantizationSpecandPalettizationSpecto sparsity the weights before the fake quantization & fake palettization is appliedprepare_for_exportfor both quantization & palettization to insert thesparse_to_denseops in the correct orderConstraints:
prepare()call)Example quant + sparsity config:
Example palett + sparsity config: