Skip to content

Simplify model initialization for kws streaming tests - #3706

Merged
phoenix-meadowlark merged 2 commits into
iree-org:mainfrom
phoenix-meadowlark:kws-internal-sync
Nov 4, 2020
Merged

phoenix-meadowlark merged 2 commits into
iree-org:mainfrom
phoenix-meadowlark:kws-internal-sync

Conversation

@phoenix-meadowlark

Copy link
Copy Markdown
Contributor

Also generalizes the input shape specification to allow external streaming to be easily enabled after a keras bug is fixed.

@phoenix-meadowlark phoenix-meadowlark added integrations/tensorflow TensorFlow model import and conversion integrations Relating to high-level frontend integrations labels Nov 3, 2020
@google-cla google-cla Bot added the cla: yes label Nov 3, 2020
@GMNGeoffrey

Copy link
Copy Markdown
Member

You'll need to import this into a CL. Also in the future it would be better to separate "unbreak the build" changes from functional changes like this :-)

@phoenix-meadowlark

Copy link
Copy Markdown
Contributor Author

You'll need to import this into a CL. Also in the future it would be better to separate "unbreak the build" changes from functional changes like this :-)

Oh, darn! And hmm, even though the reason the build was broken in order to make the functional changes?

@GMNGeoffrey

GMNGeoffrey commented Nov 3, 2020 •

Copy link
Copy Markdown
Member

You'll need to import this into a CL. Also in the future it would be better to separate "unbreak the build" changes from functional changes like this :-)

Oh, darn! And hmm, even though the reason the build was broken in order to make the functional changes?

Yes :-) Well basically you don't want there to be contention on the review. Other options would've been asking for review of the functional stuff before submitting the build-breaking thing (to ensure there wouldn't be contention) or including the functional changes in the original google3 CL (assuming they're testable there).

@phoenix-meadowlark
phoenix-meadowlark marked this pull request as draft November 4, 2020 00:56
@phoenix-meadowlark
phoenix-meadowlark changed the base branch from google to main November 4, 2020 18:12
@phoenix-meadowlark
phoenix-meadowlark marked this pull request as ready for review November 4, 2020 18:13

@GMNGeoffrey GMNGeoffrey left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Hmmm maybe someone with more TF Python experience could review here? It looks to me like you're modifying class properties in a few places in weird ways to me. Like are you modifying the name of the class itself?? And then as part of creating a module through a classmethod, modifying the class state. This all seems a bit wonky, as opposed to something more like

class KeywordSpottingModule(tf.Module):
  def __init__(self, model):
    self.m = model
    self.input_shapes = [tensor.shape for tensor in model.inputs]
    self.name = model

Also please update the PR description.

@phoenix-meadowlark phoenix-meadowlark changed the title Update commit for kws_streaming and use new model initialization Simplify model initialization for kws streaming tests Nov 4, 2020
@phoenix-meadowlark

Copy link
Copy Markdown
Contributor Author

Also please update the PR description.

Ugh github didn't like me changing the name and the base branch at the same time, I guess. Thanks for catching that.

It looks to me like you're modifying class properties in a few places in weird ways to me. Like are you modifying the name of the class itself?? And then as part of creating a module through a classmethod, modifying the class state. This all seems a bit wonky, as opposed to something more like

This isn't actually TensorFlow specific, and .input_shapes is not an attribute that tf.Module provides. In general we can only know the input shapes after model initialization for models with external streaming. We need to be able to access this information from within the trace function to generate the data, however a list is not a valid exported name.

We can get around this by either creating a variable _global_input_shapes that we define outside of KeywordSpottingModule, update in KeywordSpottingModule.__init__ and use in predict, or by placing the input_shapes on the KeywordSpottingModule cls and then extracting it after initialization. A third option would be to redundantly recreate and then convert the module into its streaming mode after compiling it to each backend in order to get the input shapes. e.g.

self._modules = tf_test_utils.compile_tf_module(KeywordSpottingModule, exported_names=['predict'])
model = utils.get_model_with_default_params(FLAGS.model, MODE_ENUM_TO_MODE[FLAGS.mode])
self._input_shapes = [tensor.shape for tensor in model.inputs]

That would slow down the tests, however. A fourth option would be for someone to dig into the python bindings to add non-function exported names and then propagate that change up through each of the tf_utils.CompiledModule subclasses and their serializations, but I don't actually think there's much benefit to doing that for a single test.

My vote is with either a global variable or an attribute on the class. What do you think?

@GMNGeoffrey GMNGeoffrey left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Ok I still don't love this, but I don't really have better suggestions :-D

@phoenix-meadowlark
phoenix-meadowlark merged commit 3e59369 into iree-org:main Nov 4, 2020
@hanhanW hanhanW mentioned this pull request Nov 5, 2020
hanhanW pushed a commit to hanhanW/iree that referenced this pull request Nov 5, 2020
Also generalizes the input shape specification to allow external streaming to be easily enabled after a keras bug is fixed.
@hanhanW hanhanW mentioned this pull request Nov 5, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

integrations/tensorflow TensorFlow model import and conversion integrations Relating to high-level frontend integrations

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants