Repository navigation
Add reset potential for IF, LIF and CubaLIF - #129
Conversation
|
In principle this looks great. You're adding an attribute that's definitely reasonable for many of the models. Simultaneously, this deviates from the neuron models, which means that all the platforms using NIR will need to update their graphs. I'm not saying it's a bad thing, but I would like to get the opinion of at least a few others of the users. @stevenabreu7 @jeshraghian @DylanMuir @matjobst care to comment? An additional concern is that all old |
|
If I recall correctly, we had this discussion at some point. Our conclusion was that a threshold subtraction is more suitable for our continuous-time modeling approach. Of course, in continuous-time models, reset and threshold-subtraction are the same. In discrete-time simulations, there will be a mismatch. I'm not sure what your goal was for this @benkroehs, but perhaps a good (backward-compatible) compromise would be to introduce a |
|
Thank you for your interesting thoughts and concerns.
Yes @Jegp, this would change the neuron model. In my view, the current implementation sets the reset potential to zero. To solve this legacy issue, one could set the default value of the reset potential to zero.
That's a good point. As you say, using a default value here too is in my opinion a good way to maintain backward compatibility. @stevenabreu7 my main goal is to connect jaxsnn as well as hxtorch to NIR. In my current use case, I have to supply the reset potential in a separate conversion configuration for both software frameworks. Although I think the approach with the scaled threshold could work, it doesn't seem very inherent to me since all software frameworks I checked (Norse, snnTorch, jaxsnn, hxtorch) implement a reset potential. |
|
I think @stevenabreu7 brings up an excellent point which I totally overlooked. NIR is inherently continuous, and in a continuous setting the reset is instantaneous. From that perspective it might even be wrong to include this in the IR: what would continuous-time systems do with such a parameter? I don't mean to say we shouldn't have it, but that would be the purist approach. On the other hand, if the continuous-time systems can't use the parameter, what's the harm in including it? Worst case, it would "just" be a redundant detail. Another option would be to use the metadata to register this. So, any translation could read the metadata to read what the exact reset mechanism might be. Right now, the metadata is simply a dictionary, so if this is a reasonable approach, we could consider extending the metadata to be more rigorous/typed. Thoughts? |
|
So in my eyes, regarding that the reset would be instantaneous: Yes, but it also is in the current implementation when the threshold is subtracted from the membrane voltage, no? It only allows this difference to be variable. And I also do not agree that the reset potential is a redundant part in continuous software frameworks. It is only redundant if you always expect your reset potential to be zero, what is not true in general. And since the reset potential has the ability to change the neurons dynamics, storing this in the meta data would be incorrect. Also the NIR documentation states "no backend should rely on this metadata". So for me the question is how to implement a configurable reset potential. And I think the most inherent way of doing this is to add a parameter |
|
This is tricky. In continuous time, the two can be made to be the same — by using subtraction, and setting the desired reset value wrt to the threshold. In discrete time, there is a big difference between the two. Subtraction is computationally preferred, as it loses less information and is a more accurate simulation of the continuous-time model. But some libraries use a fixed reset. There are many subtle implementation differences between libraries. e.g. order of integration; whether multiple spikes are permitted per dt; which ODE solving approach is used. These shouldn't matter to NIR. IMO NIR should describe the most flexible general case (which is subtraction of a specified value, IMO), and let the libraries implement as they like. |
|
Again, IMO NIR should not implement any given neuron model. NIR's value is primarily as an Intermediate Representation. As an aside, I worked with a PhD student yesterday who had built and trained a model in snnTorch, then used NIR to transfer to Rockpool for deployment on Xylo. 12 months ago that would have been a nightmare! It's amazing what NIR is enabling :) |
|
Let me share my thoughts as well. I think we should separate the discussions: 1. About adding a configurable reset voltage/factor I fully agree with @benkroehs: The current definition of IF, LIF, CubaLIF does not allow to set the reset voltage. But many backends actually implement it. This PR adds flexibility and it does not hurt existing solutions, as the current behavior can be achieved by setting the reset voltage / factor accordingly. For backwards compatibility, see below. 2. subtraction vs. reset voltage in continuous time definition In my opinion, this is not about continuous-time vs. discrete time vs. implementation. We have to add this flexible reset in the continuous-time formulation. The question is HOW to formulate it: @benkroehs 's suggestions: @stevenabreu7 's suggestion Both are correct and allow to implement the same behavior. Personally, I prefer the first version, as Yet, the 2nd option would be more consistent with how we can build higher-order primitives (See Figure 2d of the NIR paper from simple primitives. I'm not sure if we can realize the first option (which is actually a short-circuit) by a combination of simple primitive. The second option definitely can be realized. 3. Operator versioning It will happen that we add new primitives and change existing ones. We should slowly start to think about this versioning and how to support backward compatibility. |
|
Thank you @bvogginger for this great summary. I see that there are different implementations (reset to value vs subtraction). I think that the parameter that is introduced is not necessarily connected to the discussion about reset vs subtraction: However, our main objective is to add a parameter representing the reset potential, independent of its final implementation. |
|
Hi everyone, I've now implemented the requested backward compatibility, as suggested by @Jegp. This ensures that "old" .nir files without an explicit reset potential parameter remain compatible. Let me know what you think – I'd really appreciate your feedback so we can move forward! |
bvogginger
left a comment
There was a problem hiding this comment.
Thank you @benkroehs for adding the backward capability.
Yet, I'd like to suggest a different approach to achieve that. Here's a quick summary of my comments:
- parameter
v_resetshould be treated like any other neuron parameter. In the PR it has a default initializer, which is e.g. not the case forv_thresh. And, in the__post__initmethod, it is rescaled to zeros... - I think, on the long run we should handle all parameters equally. Otherwise we will end up with spaghetti code. Let's keep it clean.
- Hence, I suggest to remove the special handling of
v_threshfrom the NIRNodes. - Instead, we achieve backward compatibility of old NIR models when loading them from hdf5 files. See my suggestion in
serialization.py. Ifv_resetis not present, we create zeros_like(v_thresh). - Note that this is a breaking change (new attribute added which requires to be passed when the NIRNode is created). Hence, the
export_to_nircode in the frameworks need to be updated. - But, changes are anyway needed in the frameworks, as it is quite useful to support this flexibility also when running
import_from_nir.
Of course, this is just a suggestion. The aim is to keep the code clean in future.
What do you think of it?
|
Thank you @bvogginger for the review! I agree with all of your points. The previous implementation wasn't very clean — I had treated I've applied all of your suggestions — should be good to go now. Do you think it's mergable? |
bvogginger
left a comment
There was a problem hiding this comment.
The changes look good to me!
Yet, I'd prefer that this is approved a 2nd person as this is a breaking change.
@Jegp or @stevenabreu7: Could you please give it a short look and let us know if the chosen approach seems appropriate?
|
Fantastic discussion here. Thanks everyone for mulling this over so carefully. And thank you for adding backwards compatible code @benkroehs! I like the separation of concerns you made, @bvogginger. Let me address them one by one.
I can see both sides of the coin, and I think it's our job to permit both possibilities: parameterizing the reset for discrete simulators that need the parameter, but also allow continuous-time systems to ignore the parameter. In that sense, I think it's important that we do not hinder either use cases.
Unfortunately, the implementation here is a little gnarly if we want to use a single parameter (as opposed to having an additional string/bool parameter that determines the type of reset).
Alternatively, we should include a separate parameter to capture this. Something like reset_value: np.array
reset_method: Literal["reset", "hard"]I prefer the string version over the bool because it's easier to read. To conclude, I think any implementation now is better than nothing, so I'm happy to merge this and move on. But I think it's a temporary solution and that we should open an issue to deal with the reset types. Otherwise, we're not faithful to the (discrete) integration. On a more general level, I think we should somehow separate digital parameters with analog parameters. I agree that we need to represent them somehow, but there's no reason for them to "pollute" the other space. One suggestion for this would be to prefix such parameters with
Summary I'm happy to merge this as-is, given that we can open an issue to further discuss (1) the integration choices and (2) the naming for digital/analog parameters. Which will be easier to navigate as implementors when we have opset versions in place. |
|
I created two issues (#137 and #138) where we can move on with the discussion for the both open questions. So for me, this can be merged. 👍 Maybe this could also be discussed in one of the Open Neuromorphic Hacking Hours, since I feel like we are going in circles a little bit because this discussion is so stretched over time and discussing this in a more synchronous way might help. What do you think? Or are the Hacking Hours the wring place for this? |
LGTM 💸
I'm happy to meet and chat in the hacking hours, although it may be a hard discussion for everyone to relate to. Let's plan a time between you, Dylan, Bernhard, I, and anyone else in the NIR group who wants to join. I'll post an invitation on Discord. |
With this change I want to propose a
v_resetattribute to theIF,LIFandCubaLIFnode since the reset potential is important for the neurons dynamics. Tell me if there is something missing or if you think things should be implemented in another way. :)