Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Weight quantization #88

Open
wants to merge 8 commits into
base: master
Choose a base branch
from
Open

Weight quantization #88

wants to merge 8 commits into from

Conversation

neworderofjamie
Copy link
Contributor

@neworderofjamie neworderofjamie commented Feb 28, 2024

I am going to add support to the e-prop and inference compilers before I merge this but thought I'd open a PR for a sanity check. Basic design is:

Quantisation helpers

Take some percentile (99% of un-quantised weight distribution) and fit a fixed point format to it

Quantisation callbacks

Pulls weights, calculates quantised version using helper and pushes

Event prop compiler

  • Uses standard g variable for quantised version of the weight so, when checkpoints are loaded into inference compiler, quantised weights these will be used
  • Adds second gBack to trainable weights to hold unquantised weight which gradients get applied to
  • At beginning of each batch, quantisation callback is applied to
  • Untrained weights are quantised in place, either with a callback at the start of training if they are initialised using GeNN or by calling the helper directly if raw values are provided.

This does assume each synapse group (in GeNN speak) has its own scaling factor - will need to confirm whether this is the case on Loihi.
Training with Eventprop, 8-bit weights don't cause any problems with MNIST SHD example goes from XXX to 63.9% accuracy.

Quantised weight distribution (note quantisation artefacts in long tails):

Figure_1

@neworderofjamie neworderofjamie added the enhancement New feature or request label Feb 28, 2024
@codecov-commenter
Copy link

Codecov Report

Attention: Patch coverage is 37.81513% with 74 lines in your changes are missing coverage. Please review.

Project coverage is 61.48%. Comparing base (8822f90) to head (ab24e11).

Files Patch % Lines
ml_genn/ml_genn/compilers/event_prop_compiler.py 10.34% 26 Missing ⚠️
ml_genn/ml_genn/utils/quantisation.py 21.21% 26 Missing ⚠️
ml_genn/ml_genn/compilers/weight_quantisation.py 50.00% 13 Missing ⚠️
ml_genn/ml_genn/compilers/inference_compiler.py 70.96% 9 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master      #88      +/-   ##
==========================================
- Coverage   62.19%   61.48%   -0.72%     
==========================================
  Files         100      102       +2     
  Lines        3896     4011     +115     
==========================================
+ Hits         2423     2466      +43     
- Misses       1473     1545      +72     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

* moved checkpointing functionality down into CompiledModel
* added option to either quantise per-population or connection
* when quantising per-population quantise multiple weights together
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants