Skip to content

Commit

Permalink
Renamed surrogate gradient. Added Identity (#114)
Browse files Browse the repository at this point in the history
  • Loading branch information
Jegp authored Sep 21, 2024
1 parent e232117 commit 6c9775f
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 1 deletion.
2 changes: 1 addition & 1 deletion nir/ir/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
from .linear import Affine, Linear, Scale
from .neuron import IF, LI, LIF, CubaLIF, I
from .pooling import AvgPool2d, SumPool2d
from .surrogate_gradient import Threshold
from .threshold import Threshold
from .typing import NIRNode

# NIRNodes that can be (de)serialized
Expand Down
20 changes: 20 additions & 0 deletions nir/ir/graph.py
Original file line number Diff line number Diff line change
Expand Up @@ -496,3 +496,23 @@ def from_dict(cls, node: Dict[str, Any]) -> "NIRNode":
node["output_type"] = {"output": node["shape"]}
del node["shape"]
return super().from_dict(node)

@dataclass(eq=False)
class Identity(NIRNode):
"""Identity Node.
This is a virtual node, which allows for the identity operation.
"""
input_type: Types

def __post_init__(self):
self.output_type = self.input_type

def to_dict(self) -> Dict[str, Any]:
ret = super().to_dict()
ret["shape"] = self.output_type["output"]
return ret

@classmethod
def from_dict(cls, node: Dict[str, Any]) -> "NIRNode":
return super().from_dict(node)
File renamed without changes.

0 comments on commit 6c9775f

Please sign in to comment.