Skip to content

Provide default mapping function for trivial pytorch functions from torch.nn #25

Open

Description

@bvogginger

Description

Currently, the conversion to/from nir of the following pytorch function is handled individually in each pytorch-based framework:

  • torch.nn.Conv2d
  • torch.nn.Linear

In the future this might apply to other functions like:

  • torch.nn.Conv1d and other convolution operations
  • torch.nn.AvgPool2d and other average pooling operations
  • torch.nn.MaxPool2d and other max pooling operations

This is related to this issue in snntorch: jeshraghian/snntorch#304

Suggestion

To reduce the amount of redundant code, we could implement default mapper functions for these pytorch native operations. This default mapper function could be applied to a nn.Module ore nir.node when the framework specific mapper function does not supply the operation.

Changes for conversion from pytorch to NIR

The suggestion is to implement a default mapper function like _extract_default_model
and call it if there is no NIRNode found by the framework dependent model_map function provided: https://github.com/neuromorphs/NIRTorch/blob/main/nirtorch/to_nir.py#L70

Changes for conversion from NIR to pytorch

Extend function _switch_default_models in https://github.com/neuromorphs/NIRTorch/blob/main/nirtorch/from_nir.py#L188

Activity

  1. bvogginger commented on Mar 27, 2024

    @bvogginger
    CollaboratorAuthor

    I'm working on this issue.

  2. self-assigned this
    on Mar 28, 2024
  3. Jegp commented on Feb 18, 2025

    @Jegp
    Collaborator

    After porting to torch.fx there's a need to revisit this; we need default mappings from NIR to Torch (https://github.com/neuromorphs/NIRTorch/blob/main/nirtorch/nir_interpreter.py#L60) and from Torch to NIR (https://github.com/neuromorphs/NIRTorch/blob/main/nirtorch/torch_tracer.py#L63)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions