-
Notifications
You must be signed in to change notification settings - Fork 74k
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
Partial function specified through keyword on first position in tf.function #26602
Comments
Can we isolate this issue to misbehavior of getfullargspec instead of tf.function? I ask because as far as tf.function is concerned nothing breaks if we just wrap the partial call into a lambda *args, **kwds: partial_call(*args, **kwds) so we should probably just do that at intake time if the user passes a functools.partial function. |
I am not actually sure that this is a misbehavior of getfullargspec. Currently we are using ArgSpec to be able to bind arguments to (partial or normal) function later. We want to represent partial function fully with ArgSpec, but this is not possible with Python2.x: it is not possible to have arguments with defaults before arguments without defaults. I would consider this more an integration issue. For example, do we really need to represent partial function using getfullargspec on the inner function (the one with more arguments)? Could we somehow forget about the inner partial and work with the outer only? I haven't tried it myself. |
I think we should do the latter and forget about the inner partial.
Or we should not rely on argspec for this at all and instead look at the
arguments as they're presented at calling time (which I much prefer).
…On Thu, Mar 14, 2019 at 7:30 AM Vojtech Bardiovsky ***@***.***> wrote:
I am not actually sure that this is a misbehavior of getfullargspec.
Currently we are using ArgSpec to be able to bind arguments to (partial or
normal) function later. We want to represent partial function fully with
ArgSpec, but this is not possible with Python2.x: it is not possible to
have arguments with defaults before arguments without defaults.
I would consider this more an integration issue. For example, do we really
need to represent partial function using getfullargspec on the inner
function (the one with more arguments)? Could we somehow forget about the
inner partial and work with the outer only? I haven't tried it myself.
—
You are receiving this because you commented.
Reply to this email directly, view it on GitHub
<#26602 (comment)>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/AAATxWfus7xJCyx0oit5DEAcSXFRFacdks5vWl0OgaJpZM4bqjiP>
.
--
- Alex
|
@vbardiovskyg I think you're working on this, right? |
#26602 -> this will not be fixed, because as I learned during this refactoring, it is a limitation of functools.partial. PiperOrigin-RevId: 242826003
Since we are now depending on partial to do the argument binding, this becomes infeasible (i.e. we don't want to provide more functionality than partial already does). |
@vbardiovskyg Please see comments in the following code (TF 2.2.0rc2). Why does the first case succeed and second fail? Is this a bug? Thanks. import tensorflow as tf
import functools
def f(x, y):
return x + y
bind_x = functools.partial(f, x=1)
bind_y = functools.partial(f, y=1)
dataset = tf.data.Dataset.range(1)
print(next(iter(dataset.map(bind_y)))) # This works
print(next(iter(dataset.map(bind_x)))) # TypeError: tf__f() got multiple values for argument 'x' |
Hi @mmilosav, this is due to how partial works. See the following snippet using partial outside of TensorFlow context:
|
Wrapping in tf.function a partial with first argument specified:
This does not work in Python2.x, because tf_inspect.getfullargspec cannot represent such construct using Argspec.
Unfortunately this also does not work in Python3, where Argspecs are already capable of representing this:
The text was updated successfully, but these errors were encountered: