Performance Improvements - #775
Merged
Merged
Conversation
- test_connections.py: drop __init__ constructors so pytest actually collects the classes (0 tests ran before); fix test_transfer to move the connection to the device before asserting placement; rename the argument-taking test_weights to check_weights (manual matrix check, driven from __main__); make the __main__ MCC list self-discovering. - topology.py: densify sparse feature values ([1, src, tgt] from prime_feature) into [src, tgt] fold factors — Probability(sparse=True) crashed with "expand is unsupported for Sparse tensors"; restore empty-pipeline fan-in behavior; skip None factors from sub-features; gate sparse_compute per device (CUDA needs >= 4e6 synapses to amortize the nonzero() sync; on CPU the gather helps even at small sizes). - topology_features.py: sub-features return None (identity in the fold) instead of int 1. - MCC_learning.py: key the cached MSTDP decay factors on (dt, device) so changing network.dt or moving devices recomputes them instead of silently reusing stale values. - _bench_common.py: repo root is three levels up, not two — the benchmarks were unimportable without an installed bindsnet. - New regression tests: sparse Probability (dense + gather paths), empty pipeline, sub-feature identity, MSTDP dt change, CUDA gate equality. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
- topology.py: cache the folded (a_eff, b_sum) whenever every pipeline feature is static (is_static flag; Probability, MeanField, adaptation features, and sub-features are dynamic). Invalidated on learning updates, normalize, reset, and device/dtype moves. Weight*Mask* Intensity at 100x20000: 4506 -> 66 us/step CPU, 321 -> 58 us GPU. - topology_features.py: Weight's per-time-step normalization is deferred by the connection until after the fold consumes the pre-norm value, removing the full-matrix clone every step. Fix the reduction assertion (isinstance(x, callable) raised TypeError for any custom reduction). - MCC_learning.py: MSTDP with the default batch reductions applies the reward-weighted eligibility as two rank-1 addmm_ updates instead of materializing [batch, src, tgt] every step (5077 -> 899 us CPU, 834 -> 332 us GPU at 100x20000; exact same numbers, verified to 1e-7). Dense path kept for averaging buffers, custom reductions, and sparse weights. Skip the decay multiply when decay is the no-op 1.0. Give MSTDPET the same (dt, device)-keyed decay/learning-rate cache as MSTDP (was 3 exp() + 2 host-to-device copies per step). - New tests: rank-1 MSTDP == dense eligibility (batch 1/4, tensor rewards), fold-cache storage + invalidation, deferred time-step norm. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Collaborator
|
Thank you @C-Earl for the performance gain! much appreciated |
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.
Various performance improvements:
Weight, an operation likeW @ vwould be executed for a feature-matrixWand pre-synaptic spike vectorv. If activity invis sparse, many of the multiplication operations would result in 0's, wasting computational time. The event-based computation removes columns adjacent to entries invwhich are 0's to prevent this.MultiCompartmentConnectionand validity of all the aboveAlso added a new stress-test model at
examples/stress_test/example_network.pyand benchmark scripts atexamples/benchmark/sparse_computation and foldable pipeline. The model contains 20,000 excitatory + 2,000 inhibitory neurons, and MSTDP learning rules with sparsely populated multicompartment connections.The model itself produces no meaningful behavior, but tests a general case of a large model with medium-activity and sparse connections. Benchmark scripts tell us the performance improvements that come with this model:
(Times reported are median run times per-
computecall)