Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bug fixes: nir.Output type inference & CubaLIF.w_in read/write #71

Merged
merged 3 commits into from
Oct 19, 2023

Conversation

stevenabreu7
Copy link
Collaborator

@stevenabreu7 stevenabreu7 commented Oct 19, 2023

Right now, the type inference goes through but it doesn't actually change the NIR graph. This PR fixes that.

Update: this PR fixes a weird edge case where the input_type of a nir.Output node is inferred. This currently fails because it will not update the output_type for the nir.Output node and this is used when writing the graph to a file. (hence, when writing to a file and reading again, the shape inference is essentially discarded).

Update update: I've also added an urgent fix that adds w_in to the read and write method of the CubaLIF node. This should have always been there..

Right now, the type inference goes through but it doesn't actually change the NIR graph. This PR fixes that.
@matjobst
Copy link
Collaborator

matjobst commented Oct 19, 2023

For me the inference changed the graph already without your modifications. Did you observe the nodes not changing in a specific instance?
The dataclasses are mutable unless set to frozen. That is why it is not necessary to actively write the nodes back into the graph.

@stevenabreu7
Copy link
Collaborator Author

yep I just wrote tests to check that this works, but the problem was something else. I will update the PR in a moment - sorry about the confusion

@stevenabreu7 stevenabreu7 changed the title Fix type inference Fix type inference at output node Oct 19, 2023
@stevenabreu7 stevenabreu7 changed the title Fix type inference at output node Fix type inference for nir.Output nodes Oct 19, 2023
@stevenabreu7 stevenabreu7 changed the title Fix type inference for nir.Output nodes Bug fixes: nir.Output type inference & CubaLIF.w_in read/write Oct 19, 2023
Copy link
Collaborator

@Jegp Jegp left a comment

Choose a reason for hiding this comment

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

Hacky, but functional! LGTM 💰

@@ -261,6 +261,12 @@ def _forward_type_inference(self, debug=True):
k.replace('output', 'input'): v for k, v in pre_node.output_type.items()
}

# make sure that output nodes have output_type = input_type
if isinstance(post_node, Output):
post_node.output_type = {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Hmmmm this looks like a hack

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

it feels hacky, but the output node is the only node whose input_type field is irrelevant - so it's just a special case where we just have to set the output_type as well. a cleaner solution would be that Input and Output only have a type - but that would complicate many other things..

@@ -72,6 +72,7 @@ def read_node(node: typing.Any) -> nir.NIRNode:
r=node["r"][()],
v_leak=node["v_leak"][()],
v_threshold=node["v_threshold"][()],
w_in=node["w_in"][()],
Copy link
Collaborator

Choose a reason for hiding this comment

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

☠️

@stevenabreu7 stevenabreu7 merged commit 21c111f into main Oct 19, 2023
5 checks passed
stevenabreu7 added a commit that referenced this pull request Oct 19, 2023
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