MDMM hardware-aware metrics (FPGA + PACA), tests and docs#46
Open
ArghyaRanjanDas wants to merge 3 commits into
Open
MDMM hardware-aware metrics (FPGA + PACA), tests and docs#46ArghyaRanjanDas wants to merge 3 commits into
ArghyaRanjanDas wants to merge 3 commits into
Conversation
Add the two hardware-aware sparsity metrics for MDMM to both the Keras and Torch backends, on dev's per-backend layout: - FPGAAwareSparsityMetric: fraction of zero DSP/BRAM weight groups, modelling FPGA resource packing (rf / precision / bram_width). - PACAPatternMetric: drives conv kernels onto a small set of dominant binary patterns. Pattern selection stays on-graph (keras.ops bit-pack + bincount / native torch.unique, no NumPy round-trip of the weight) and exposes a projection mask applied during fine-tuning through a generic, metric-agnostic hook in MDMM. Data model (MDMMPruningModel): - New metric_type values + flat Optional fields (precision, target_resource, bram_width, num_patterns_to_keep, beta, distance_metric) validated by Pydantic (ge/le + Literal); a model_validator forces PACA -> Equality / target 0. - Fix the reported Pydantic serialization warnings (constraint_type 'Equality' and the discriminated pruning_parameters union): enum fields now default to enum members instead of bare strings, which Pydantic does not coerce on defaults. Also: distance/layout/resource constants centralised in core/constants.py, the get_layer_sparsity float/int dtype fix on the TF backend, and config_mdmm_fpga.yaml + config_mdmm_paca.yaml with mdmm_fpga_config() / mdmm_paca_config() helpers.
- test_mdmm.py / test_mdmm_metrics.py: Keras MDMM, FPGA DSP/BRAM math, PACA pattern selection + projection masking, full phase cycles, Pydantic validation, and a regression test that MDMM configs serialize without Pydantic warnings. - test_torch_mdmm.py: native-torch MDMM + metrics. - run_tests.sh: run the new files under both tensorflow and torch backends.
- reference.md: MDMM metric-type overview + FPGAAwareSparsity and PACAPatternSparsity parameter tables. - getting_started.md: constraint-based MDMM usage with the hardware-aware configs.
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.
Summary
FPGAAwareSparsityandPACAPatternMDMM metrics to both the Keras and Torch backends, ported onto dev's per-backend layout. Supersedes MDMM tests and hardware-aware metric functions #37, which was built on the old singlepruning_methods/tree and targetedmain.constraint_typeenum and the discriminatedpruning_parametersunion). Root cause: the MDMM enum fields defaulted to bare strings, and Pydantic does not validate/coerce defaults, so the runtime value stayed astr. They now default to enum members.MDMMPruningModel(ge/le+Literal) and drop the per-metric asserts. PACA auto-forces Equality/target 0 via a model_validator, so the MDMM layer stays metric-agnostic.torch.unique, no NumPy round-trip of the weight); centralise distance/layout/resource constants incore/constants.py; fix theget_layer_sparsityfloat/int dtype bug on the TF backend.config_mdmm_fpga.yaml,config_mdmm_paca.yaml, themdmm_fpga_config()/mdmm_paca_config()helpers, and document the new metric types inreference.mdandgetting_started.md.Test plan
cd tests && pytest test_mdmm.py test_mdmm_metrics.py(Keras / TensorFlow)cd tests && KERAS_BACKEND=torch pytest test_mdmm.py test_mdmm_metrics.py(Keras / Torch)cd tests && KERAS_BACKEND=torch pytest test_torch_mdmm.py(native Torch)config_mdmm_fpga.yamlandconfig_mdmm_paca.yaml, callmodel_dump(), confirm noPydanticSerializationUnexpectedValuewarnings.pytest test_pdp.py test_ap.py.Notes for review
metric_typeis read off the config and resolved via the metric registry, and theMetricType/ConstraintTypeenums already exist. This PR keeps that flat-params + registry approach rather than nested metric models.patterns.pyno-opOIHW->OIHWpermute is replaced with real per-backend layout handling (Keras kernels are HWIO, Torch OIHW), and theconvert_to_numpypattern step is gone.