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

Three Factor Learning #400

Merged
merged 104 commits into from
Oct 27, 2022
Merged

Conversation

bala-git9
Copy link
Contributor

@bala-git9 bala-git9 commented Oct 7, 2022

Issue Number:

Objective of pull request:
Implements the necessary changes to LAVA to support three factor learning rules. Contains a tutorial that implements a reward-modulated STDP learning rule. This PR also proposes structural changes to the Dense and LIF process and process models to include base classes specific to learning.

Pull request checklist

Your PR fulfills the following requirements:

  • Issue created that explains the change and why it's needed
  • Tests are part of the PR (for bug fixes / features)
  • Docs reviewed and added / updated if needed (for bug fixes / features)
  • PR conforms to Coding Conventions
  • PR applys BSD 3-clause or LGPL2.1+ Licenses to all code files
  • Lint (flakeheaven lint src/lava tests/) and (bandit -r src/lava/.) pass locally
  • Build tests (pytest) passes locally

Pull request type

Please check your PR type:

  • Bugfix
  • Feature
  • Code style update (formatting, renaming)
  • Refactoring (no functional changes, no api changes)
  • Build related changes
  • Documentation changes
  • Other (please describe):

What is the current behavior?

What is the new behavior?

Does this introduce a breaking change?

  • Yes
  • No

Supplemental information

@mathisrichter mathisrichter added this to the Release 0.5.1 milestone Oct 25, 2022
@tim-shea tim-shea self-requested a review October 25, 2022 16:50
Copy link
Contributor

@tim-shea tim-shea left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Changing comment to approve. Previous suggestions could be addressed in a second iteration in v0.6.

Copy link
Contributor

@awintel awintel left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks better but still there are a couple of "cosmetic" things you should improve:
(Will approve nonetheless to not hold up the merge once you've addressed these)

  • Please check all your headlines again. There are still several examples with random lower/upper case spelling like: "Initialize Network Processes", "Connect network Processes", "Tag Dynamics for Post-synaptic Neurons", "Reward Trace for Post-synaptic Neurons"
  • "...how the improved Lava learning API..." -> "improved" is out of context. "Improved" over what?
  • There is no hyphen between Loihi and 2. Sometimes you also say Loihi2 without white space.
  • The intro paragraph doesn't seem accurate or maybe is outdated with the code: "... first define interface for RSTDP". I don't see an interface definition. You only instantiate a pre-build rule and build a network to use it. Only in the very end you define a custom rule.
  • I would pull the note about Loihi 2 unavailability into an emphasis box. This way it's clearer that this is temporary and also reduces the chance that we forget to update the text once the code changes.
  • Wrong string before the definition of your post neurons: "# Pre-synaptic neuron parameters"
  • Although I now understand why there are two post neurons based on our discussion. The reader of this tutorial has no idea at this point of the tutorial why you chose two. Please motivate why there are two not just state that there are two. It's because you want to demonstrate something specific in the end.
  • Could you align the x axis of the spike and trace plots?
  • As pointed out in my last review, I feel the tutorial would benefit from at least a minimal explanation/discussion of the final results. You show one figure after the other but what should the reader take note of?
  • Is this correct: "Frémaux"? Looks messed up.
  • Is there now way around exposing the name LoihiUCLearningRule at the user level that should be agnostic of HW details? This is unfortunate...

Copy link
Contributor

@gkarray gkarray left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good overall.
Left comments on minor things, but will approve nonetheless to not hold up the release. If these can be addressed now, good, otherwise, they can be left for a future release.

One final comment :

  • I think the folder src/lava/proc/learning_rules shouldn't go in the proc library at all. It does not contain any Process definition. This folder should probably instead be moved to src/lava/magma/core/learning/learning_rules

src/lava/proc/learning_rules/r_stdp_learning_rule.py Outdated Show resolved Hide resolved
src/lava/magma/core/model/py/connection.py Outdated Show resolved Hide resolved
src/lava/proc/dense/models.py Outdated Show resolved Hide resolved
src/lava/proc/dense/models.py Outdated Show resolved Hide resolved
@weidel-p
Copy link
Contributor

In the latest changes I addressed some of the comments above:

  • renamed UC/HC learning rules to 2F resp. 3F. I think this sounds better
  • renamed the run_spk function of the connection base class to recv_traces to avoid confusion.
  • added a for a 3F learning rule
  • added test for float_to_literal
  • added docstrings where I found them missing

@weidel-p
Copy link
Contributor

Regarding the correct place for the high level learning rules such as STDP. Strictly speaking, @gkarray is correct, they are not Processes, so they should be somewhere else. But in my opinion, they should stay in the process library as this is the place where a user is looking for commonly used models such as LIF. Our high level implementations of learning rules serve the same purpose. Additionally, I would like to avoid imports from deep inside lava for common use-cases.

@weidel-p weidel-p merged commit ee2a6cf into lava-nc:main Oct 27, 2022
monkin77 pushed a commit to monkin77/thesis-lava that referenced this pull request Jul 12, 2024
* inheritance from base class

* inheritance from base connection

* floating point model

* minor cleanup

* added neuron base class

* separate models from process files

* rm init file

* inherit from Neuron and Connection

* merged LearningDense into Dense

* release candidate 0.5

* beginning last clean

* clean in progress

* updated tutorial

* changes according to checklist made. missing use of np.where refactor

* changed evaluate_trace to use boolean indexing instead of np.where

* removed BITS_

* lint and poetry update

* moved tutorial to in_depth

* Licenses

* lint tests

* poetry update

* docstrings for connection and learning rule

* fixing typo

* minor optimization for floating point model

* added learning related unit tests

* added other learning related unit tests

* refactored docstrings

* merged Loihi1 and 2 LearningRules and added seed for RNGs

* added neuon base class and three fac learning rule

* minor changes

* Adding R-STDP wrapper and tutorial skeleton

* Adding decay to tag

* adding LearningLIF process and update tutorial

* adding LearningLIF process model

* Modifying reward trace based on graded input

* Update LearningLIF to include graded input spikes

* Updated tutorial

* Updating unit tests

* Fixing errors

* Editing tutorial text

* modified tutorial and fixing dangling ports

* adding tutorial_helper func

* adding some plots to tutorial

* Merge origin/main to origin/dev/learning_three_factor

* added graded in ports to LearningDense and fixing tutorial plots

* changes structure

* added minor changes to stdo tutorials

* fixing np.logical_and/or problems

* tutorial polishing

* weights plot fixed

* fixing graded input ports in Dense

* fixing lint errors

* fixing LearningLIF run_spk

* tutorial text changes

* fixing lint errors

* lint issues

* annoying white spaces fixed

* removing enable_learning flag

* adding plot explanations

* fixing rstdp wrapper

* fix the stdp tests. minor update to structure

* minor change

* Saving tutorial text updates to new file. Avoiding merge conflict.

* add y1 ports and major changes to the learning rules

* minor changes

* changing plastic to learning and wrapper name

* fixed bugs and inconsistencies, moved RSTDP LIF to tutorial

* including float to literal str

* fixing lint errors

* modifying tutorial

* fixing lif tests

* removing LearningLIF test

* fixing tutorial image

* changing tutorial name

* moving image to lava-docs

* fixing some of the comments from AW

* renames run_spk in connection, HCand UC to 2F resp 3F, docstrings ands tests

* fetch pyproject and lock from main

* fixing tutorials plots, changing docstrings

* adding tutorial text

Co-authored-by: Philipp <philipp.weidel@intel.com>
Co-authored-by: gkarray <ghassen.karray@intel.ch>
Co-authored-by: drager-intel <danielle.rager@intel.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
1-feature New feature request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants