snntorch icon indicating copy to clipboard operation
snntorch copied to clipboard

export/import_nir__Adding-Conv2D_and_AvgPool2d

Open SirineArfa opened this issue 1 year ago • 1 comments

  • fixes #304
  • Adding support for the following torch.nn modules [Conv2d, AvgPool2d and Flatten] to export_nir.py and import_nir.py
  • Create example notebook in examples/tutorial_snntorch_to_nir.ipynb for snntorch model with layers [Conv2d, AvgPool2d,LIF, Linear,LIF] and export/import it to NIR
  • Include this model's tests in tests/test_nir.py

SirineArfa avatar Mar 25 '24 00:03 SirineArfa

  • The pip version of NIR is not automatically updated and is currently version 1.0.1 from Dec 25. Hence, it does not contain AvgPool2d yet.

  • To try this feature you must build NIR from source: - git clone https://github.com/neuromorphs/NIR.git - cd NIR - pip install .

SirineArfa avatar Apr 10 '24 15:04 SirineArfa

Yep, this would be really practical to have (pls review) :)

asti205 avatar Jul 14 '24 04:07 asti205

There are a couple of conflicts in snntorch/functional/loss.py.

  • Line 100: arguments are different; population coding is missing.
  • Line 114: weights are now an instance variable; I'm not totally sure if these are inherited properly.

jeshraghian avatar Jul 15 '24 16:07 jeshraghian

Conflicts in snntorch/functional/loss.py were resolved by merging the changes from master branch to Adding-Conv2D_and_Pooling branch because the original changes for export/import_nir__Adding-Conv2D_and_AvgPool2d were not not intended to affect the loss function logic.

SirineArfa avatar Jul 16 '24 08:07 SirineArfa

The tests haven't passed as there is now a dependency on sinabs.layers. I don't think we should add dependencies on external libraries to enable NIR exports to function correctly. How easy would it be to remove that requirement?

jeshraghian avatar Jul 16 '24 16:07 jeshraghian

The sinabs.layers dependencies for sumpooling layers were easily removed, as this feature was used for a custom model conversion to NIR and indeed shouldn't be added to the snntorch NIR functions.

SirineArfa avatar Jul 17 '24 08:07 SirineArfa

Thank you! I ran the tests and it oddly worked with 3.9/3.10, but it didn't work on Python 3.8. One of the tests throws module 'nir' has no attribute 'AvgPool2d'.

I'm not totally sure why this wouldn't be compatible with 3.8...

@stevenabreu7 : have you observed anything like this among the other libraries?

I would rather not eliminate compatibility with 3.8 over this, but a non-ideal option is to modify the test if we're not sure why this error persists.

jeshraghian avatar Jul 17 '24 16:07 jeshraghian

I checked the NIR repo and in the pyproject.toml file it indicates in line 35 requires-python = ">=3.9" and I think that's why the tests in snntorch for python 3.8 fails, so I guess if it is the case, then the snntorch compatibility with 3.8 should be eliminated.

SirineArfa avatar Jul 18 '24 14:07 SirineArfa

thanks for checking that. Yep, let's remove Python 3.8 from the test matrix. I tried to commit to your fork but I don't have the necessary permissions. All that needs to be changed are the following files:

  • .github/workflows/build-tag.yml
  • CONTRIBUTING.rst
  • setup.py

If you update those, the tests should pass and I'll merge the PR.

jeshraghian avatar Jul 18 '24 15:07 jeshraghian

I removed python 3.8 dependencies from the appointed files.

SirineArfa avatar Jul 18 '24 15:07 SirineArfa