Skip to content

tf.variable with initial value does not work in eager mode #155

Closed

Description

@rnett

As the title says, tf.variable with an initial value does not work in eager mode. I'm not sure if it is supposed to, as tf.Variable does in the python api but apparently didn't at first. Interestingly, it's not the variable op that fails, it's the assign:

cannot compute Assign as input #0(zero-based) was expected to be a int32_ref tensor but is a int32 tensor
org.tensorflow.exceptions.TFInvalidArgumentException: cannot compute Assign as input #0(zero-based) was expected to be a int32_ref tensor but is a int32 tensor
	at org.tensorflow.internal.c_api.AbstractTF_Status.throwExceptionIfNotOK(AbstractTF_Status.java:87)
	at org.tensorflow.EagerOperationBuilder.execute(EagerOperationBuilder.java:273)
	at org.tensorflow.EagerOperationBuilder.build(EagerOperationBuilder.java:66)
	at org.tensorflow.EagerOperationBuilder.build(EagerOperationBuilder.java:55)
	at org.tensorflow.op.core.Assign.create(Assign.java:97)
	at org.tensorflow.op.core.Helpers.createVariableWithInit(Helpers.java:51)
	at org.tensorflow.op.Ops.variable(Ops.java:7520)

Activity

  1. Craigacp commented on Nov 21, 2020

    @Craigacp
    Collaborator

    Yeah, that's documented in the javadoc:

    * Only supported on Graph sessions as the {@link org.tensorflow.op.core.Assign} op

    I couldn't figure out an alternative at the time and needed it for the optimizers work. We should at minimum fix it so it throws a sensible looking exception.

  2. rnett commented on Nov 21, 2020

    @rnett
    ContributorAuthor

    Could be done easily enough as part of #154, that's what I was originally going to suggest before I realized it was supported in python eager mode.

    I assume the codegen doesn't support custom javadocs on the ops methods (for putting the warning on tf.variable)?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions