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

Converter improvements #137

Merged
merged 1 commit into from
Mar 27, 2020
Merged

Converter improvements #137

merged 1 commit into from
Mar 27, 2020

Conversation

hunse
Copy link
Collaborator

@hunse hunse commented Mar 4, 2020

Some improvements to get the Keras converter working with my network.

  • Do not sort source_tensor list. This is no longer required, and is problematic for models that have an output that is used other places in the model (since the sorting puts all outputs at the end).
  • Use a single bias connection in inference_only mode. We don't need to worry about proper bias sharing since we're not training them. It's much faster to use one connection to do all the biases in this case.

TODO:

  • Add a test of a network that has a middle layer as an output

@drasmuss
Copy link
Member

drasmuss commented Mar 4, 2020

Just a heads up, you might want to start from this branch #134, as it has some of the changes you're adding already. It also has a more efficient convolutional bias implementation (I forgot that wasn't in master yet), which would be good to benchmark against the inference_only version to see if there is still an advantage.

@hunse hunse force-pushed the converter-hunse branch from 4c11b80 to 698bd49 Compare March 5, 2020 16:07
@hunse
Copy link
Collaborator Author

hunse commented Mar 5, 2020

I did a quick check of the new bias code in #130 on my network, and it appears to be as fast. I've put my old work in https://github.com/nengo/nengo-dl/tree/converter-hunse-inf-only-bias just in case we want it later, and rebased this onto #134.

@hunse hunse force-pushed the converter-hunse branch 2 times, most recently from 94ec5e0 to e3aa159 Compare March 19, 2020 14:48
Copy link
Member

@drasmuss drasmuss left a comment

Choose a reason for hiding this comment

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

Added some fixups.

With respect to the "Better error for unconverted input tensor", my thinking was that since this isn't an error that users should ever be running into, we don't really need to provide extra code for a pretty error message. So I changed it so that it just directly raises the relevant error (a KeyError if node_id doesn't exist) at the appropriate line in the code, which should make that easier to debug (rather than getting that pre=None error), without adding any new logic/parameters/tests.

The other change is just simplifying the test somewhat for the sorting fix.

If those look good to you, will merge!

return None
else:
raise ValueError("Input tensor %s has not been converted" % (tensor))
return self.converter.layer_map[input_layer][input_node_id][input_tensor_id]
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 was my impression that sometimes this function needed to be called on nodes that aren't in the layer map, and return None in that case to indicate that. But if that's not necessary, this is certainly much simpler!

Copy link
Member

Choose a reason for hiding this comment

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

That only happens in one case, in ConvertInputs, so I just changed it to directly handle that case in that function, rather than handling it in this generic method.

# if this input layer has an input obj, that means it is a passthrough
# (so we just return the input)
output = self.get_input_obj(node_id)
except KeyError:
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Ahh, I see, this is the one place we needed that, so then we just catch the error. Works for me, as long as there's not any risk with catching some other KeyError by mistake.

Copy link
Collaborator Author

@hunse hunse left a comment

Choose a reason for hiding this comment

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

LGTM

This is no longer required, and is problematic for models that
have an output that is used other places in the model (since
the sorting puts all outputs at the end).

Also ensure a better error for unconverted input tensor
@drasmuss drasmuss merged commit b8394f6 into master Mar 27, 2020
@drasmuss drasmuss deleted the converter-hunse branch March 27, 2020 14:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

2 participants