Skip to content

Fix deserialization of legacy .nir files - #143

Merged
Jegp merged 3 commits into
mainfrom
fix_reset_deserialize
Jun 16, 2025
Merged

Jegp merged 3 commits into
mainfrom
fix_reset_deserialize

Conversation

@benkroehs

Copy link
Copy Markdown
Collaborator

This PR fixes the broken import of .nir files which were created before #129, mentioned in #142.

@Jegp Jegp left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

I like the addition, and this should most definitely be merged. It worries me a little we didn't catch this before. Could we set up a unit test that tests that we can read legacy .nir files? We could just use the old ones from the paper or something similar.

@fabio-innatera

Copy link
Copy Markdown
Collaborator

I am not sure if making reset_v a default parameter wouldn't be a better solution.

There was quite a bit of discussion about that in the original PR: #129
The original PR even had backwards compatibility at the start (for both the API and the file format), but was then changed later on to be a breaking change.

Is it worth breaking literally the whole ecosystem for this by making this a mandatory parameter? Especially if there is still discussion ongoing on how exactly to model this mechanism.

SNNTorch:
https://github.com/jeshraghian/snntorch/blob/8eed194a72d35668bbf30ce900691b20a5220e5a/snntorch/export_nir.py#L108

Norse:
https://github.com/norse/norse/blob/a66f465806b50c93ce860b42bdc73d94d470434d/norse/torch/utils/export_nir.py#L45

SPYX:
https://github.com/kmheckel/spyx/blob/876926bf3aecc49dbfeeee196d2df8be81c543b7/spyx/nir.py#L419

And I guess rockpool, sinabs etc. will also be affected.

@benkroehs

benkroehs commented Jun 12, 2025 •

Copy link
Copy Markdown
Collaborator Author

@Jegp I’ve now added a small test to verify that the .nir files from the paper can be read. While it's a very shallow test, I believe it should suffice for now. What do you think?
I had to exclude two .nir files because type checking failed for them, but I’m not sure how you’d like to proceed with that.
I was also confused when this error came up because I assumed the original changes would maintain backward compatibility for (de)serialization. However, it turns out that the read_node function I modified is not actually used during read operations — that was my oversight. With the new deserialization test in place, though, this issue shouldn’t recur.

@fabio-innatera I think the concerns you're raising are very valid and made me revisit the approach. First of all, I think the implementation which is suggested by Jens in #138 seems like a solid long-term solution.
In my eyes, two things are still holding that back:

  1. A broader discussion (which is still pending)
  2. The end-of-life of Python 3.9 (since we want to support 3.9 until then as I understood)

In the meantime I thought the introduction of v_reset might be a reasonable solution, even if it is a breaking change. But since the long-term solution would not be breaking, maybe this just introduces unnecessary troubles.
Additionally software frameworks can still use NIR versions before the v_reset commit if they want to as well as adapt to the change, right? I think this is a very flexible solution.

@fabio-innatera

Copy link
Copy Markdown
Collaborator

This solution certainly works for my use-case.

Reflecting a bit on this, I believe having a (relatively) stable file format is much more important than a stable API. At least right now, when the NIR library is still changing regularly, being too cautious with breaking changes might limit innovation and figuring out actual great solutions to specific problems.

Comment thread tests/test_readwrite.py Resolved
Comment thread tests/test_readwrite.py Resolved
@benkroehs
benkroehs force-pushed the fix_reset_deserialize branch 3 times, most recently from a145864 to 28d8106 Compare June 13, 2025 13:21
@benkroehs

Copy link
Copy Markdown
Collaborator Author

What do you think now @fabio-innatera and @Jegp? I think this looks mergable now.

(made some mistakes and had to force push several times.... 🙈)

Comment thread tests/test_readwrite.py Resolved
@fabio-innatera

Copy link
Copy Markdown
Collaborator

Small nitpick, otherwise looking good 👍

@benkroehs
benkroehs force-pushed the fix_reset_deserialize branch from 28d8106 to de2c637 Compare June 13, 2025 15:51

@Jegp Jegp left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

This looks great, thank you @benkroehs.

I agree that a stable file format is absolutely critical. And, as you point out, Ben, this is an improvement compared to status quo. Let's merge this and continue the discussions on what to do with platform-specific parameters and default parameters/composability.

LGTM!

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants