Conversation
- relable inp to args and Tout to output_types - add arguments kwargs and output_shapes - allow args/kwargs/output_types/output_shapes to be a nested structure
|
Can one of the admins verify this patch? |
|
ping @alextp |
|
|
||
|
|
||
| """ | ||
| from tensorflow.python.framework import tensor_shape |
There was a problem hiding this comment.
Imports should go at the top of the file
There was a problem hiding this comment.
I will move it to the top in the next commit.
|
|
||
|
|
||
| def py_func(func, inp, Tout, stateful=True, name=None): | ||
| def py_func(func, args=(), kwargs={}, output_types=None, output_shapes=None, |
There was a problem hiding this comment.
This change from imp to args, kwargs can break existing code, breaking our API compatibility guidelines we've had since tf 1.0.
So we need to find a way of doing what you want while not changing the signature of py_func.
There was a problem hiding this comment.
When my suggestion does not move to contrib or 3-party and it is necessary to keep the API, my suggestion is (I do not know the rules for deprecated arguments in tf, I saw only some examples):
def py_func(func, inp, Tout=None, stateful=True, name=None, kwargs={}, Sout=None)
What I want with the changed signature is to allow keyword arguments and automatic set_shape like in tf.data.Dataset.from_generator.
Since in python it is common to use func(*args, **kwargs) I used that names. output_types and shape came from tf.data.Dataset.from_generator.
| # If callable, assume same signature and call with tensors and get the shapes | ||
| output_shapes = output_shapes(*args, **kwargs) | ||
|
|
||
| flat_output_types = nest.flatten(output_types) |
There was a problem hiding this comment.
So my understanding is that the main change here is you call nest.flatten and nest.pack_sequence_as around the user code in a py_func. Everything else is debugging / diagnostics, right?
If so, I think this can live in utility code instead of in the tensorflow library proper. Maybe you want to add a contrib.py_func with this API or add this py func wrapper in a third-party library somewhere?
There was a problem hiding this comment.
You are right. The main changed are allow kwargs as input and arbitrary returns with shapes (earlier only list/scalar without shape).
Another (not so important) point is to allow shape/type inference from the input.(Useful for decorators)
If you prefer contrib.py_func I can move the code to contrib.
If you prefer a third-party library, I will keep the code in a private repo.
When you need a use case inside of tf for this modification, look in tf.data.Dataset.from_generator.
The code there was the starting point.
There was a problem hiding this comment.
I agree the dataset API for py_func is friendlier to use and I like exposing it. We could consider either tf.py_func_v2, or contrib.
@martinwicke for API review as to whether we prefer _v2 or contrib
|
I'd say contrib to start, so we can fix things if we find something wrong with the initial version. |
|
Where should the code be? I do not know how contrib is organized. |
|
contrib.framework seems to be the least-inappropriate existing package. Just move this definition to a file there and it should work I think |
|
ok, I moved now the code to |
alextp
left a comment
There was a problem hiding this comment.
You also need to import the symbol from contrib/framework/init.py or it won't show up in the public package
|
sorry that I forgot the import, I fixed that. |
|
Jenkins, test this please. |
|
Let's see if the tests catch those.
…On Mon, Dec 11, 2017 at 4:14 PM, Christoph Boeddeker < ***@***.***> wrote:
sorry that I forgot the import, I fixed that.
There are maybe some more such bugs because I have not figured out how to
install tensorflow from binary with git in editable mode.
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#15121 (comment)>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/AAATxdQHql0ysoJKd93tNISiQwOd918Kks5s_VTcgaJpZM4Q2CO2>
.
--
- Alex
|
|
@tensorflow-jenkins test this please |
|
@boeddeker do you mind fix the lint errors and test failures? |
|
@yifeif Where do I find the lint errors and test failures? |
|
Incidentally you should write a test, then.
…On Thu, Dec 21, 2017 at 1:46 AM, Christoph Boeddeker < ***@***.***> wrote:
@yifeif <https://github.com/yifeif> Where do I find the lint errors and
test failures?
Since I did not write a test, how could a test fail, that is related to
this PR?
I only found one lint error.
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#15121 (comment)>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/AAATxbxk3jbO5J7-pdn8ClBY_MIth8MWks5tCijxgaJpZM4Q2CO2>
.
--
- Alex
|
| from tensorflow.python.framework import tensor_shape | ||
| from tensorflow.python.util import nest | ||
|
|
||
| from tensorflow.python.ops.script_ops import py_func as _py_func |
There was a problem hiding this comment.
Please use the hidden ops for that.
There was a problem hiding this comment.
What do you mean with hidden ops? I used a renaming because of the name collision.
There was a problem hiding this comment.
@drpngx this is fine -- it's a contrib-only extension of py_func, py_func still exists as a public symbol, so we don't need hidden_ops.
|
This appears to make a lot of tests fail. Could you check? |
|
I am not familiar with the import machinery in tensorflow, can someone explain, why the import does not work? I will start to write tests, when the source code is formally correct for tensorflow. |
|
The Otherwise I think this should work. |
|
@martinwicke Right, contrib, good point. |
|
@boeddeker you're probably missing some dependency. |
|
@tensorflow-jenkins test this please |
|
Do I have to add the new file to |
|
Jenkins, test this please. |
|
Sorry, but I have no bazel and did not know that I have to add dependencies. |
|
@tensorflow-jenkins test this please |
See #14448
Improved
py_functo accept nested structures as input and as output like intf.data.Dataset.form_generatorOpen questions: