Enable mixing value tensors (eager tensors or numpy arrays) and Keras symbolic...
Enable mixing value tensors (eager tensors or numpy arrays) and Keras symbolic tensors when building Keras graphs-of-layers in an eager scope. In these cases, the value tensors are treated as symbolic constants. This enables the following pattern to work in the same way in both V1 and V2: ``` lstm = LSTM(2) inputs = keras.Input((None, 3)) outputs = lstm(inputs, initial_state=tf.ones(shape)) ``` (without this change, the above code works in V1 but fails in V2 with an artificial exception). Known issue: in case a random tensor is used, there is a (usually harmless) behavior discrepancy remaining between V1 and V2, which is that in V2 we'd be using the same random value every time, whereas in V1 we'd be drawing new random values (since the tensor would be treated as a random op and not as a constant). We think this is not a problem because in V2 users should have the mental model "tensors are values" and thus would be expecting a random tensor to behave like a constant value and not like a random generator. PiperOrigin-RevId: 224915621
Showing
想要评论请 注册 或 登录