Skip to content

Gradients with TensorArray fail after scatter of 0 size #12

@taerimmkim

Description

@taerimmkim

system information

  • Have I written custom code (as opposed to using a stock example script provided in TensorFlow): yes

  • OS Platform and Distribution (e.g., Linux Ubuntu 16.04): Linux Ubuntu 16.04

  • TensorFlow installed from (source or binary): binary

Describe the problem

아래에서 오류가 발생:

import tensorflow as tf

x_orig = tf.zeros([3], tf.float32)

ta = tf.TensorArray(tf.float32, size=1, element_shape=[3])
ta = ta.write(0, x_orig)
ta = ta.scatter(tf.range(0, 0), ta.gather(tf.range(0, 0)))
x = ta.read(0)
g, = tf.gradients(tf.reduce_sum(x), [x_orig])

sess = tf.Session()
print sess.run(g)

다음과 같은 에러메세지 발생:

tensorflow.python.framework.errors_impl.UnimplementedError: TensorArray has size zero, but element shape <unknown> is not fully defined. Currently only static shapes are supported when packing zero-size TensorArrays.
         [[Node: gradients/TensorArrayScatter/TensorArrayScatterV3_grad/TensorArrayGatherV3 = TensorArrayGatherV3[dtype=DT_FLOAT, element_shape=<unknown>, _device="/job:localhost/replica:0/task:0/cpu:0"](gradients/TensorArrayScatter/TensorArrayScatterV3_grad/TensorArrayGrad/TensorArrayGradV3, range, gradients/TensorArrayScatter/TensorArrayScatterV3_grad/TensorArrayGrad/gradient_flow)]]

ta = ta.scatter(tf.range(0, 0), ta.gather(tf.range(0, 0))) 코드가 수행되면 ''''ta'''' 가 제거된다.
원인은 _TensorArrayScatterGrad.scatter가 호출될 때 TensorArrayelement_size만큼 복제하지 못하기 때문인 것 같다.

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