{"action":"created","issue":{"url":"https://api.github.com/repos/tensorflow/tensorflow/issues/19717","repository_url":"https://api.github.com/repos/tensorflow/tensorflow","labels_url":"https://api.github.com/repos/tensorflow/tensorflow/issues/19717/labels{/name}","comments_url":"https://api.github.com/repos/tensorflow/tensorflow/issues/19717/comments","events_url":"https://api.github.com/repos/tensorflow/tensorflow/issues/19717/events","html_url":"https://github.com/tensorflow/tensorflow/issues/19717","id":328807755,"node_id":"MDU6SXNzdWUzMjg4MDc3NTU=","number":19717,"title":"`ScipyOptimizerInterface` fails with `scatter_add` and `scatter_update`","user":{"login":"david-cortes","id":11860098,"node_id":"MDQ6VXNlcjExODYwMDk4","avatar_url":"https://avatars0.githubusercontent.com/u/11860098?v=4","gravatar_id":"","url":"https://api.github.com/users/david-cortes","html_url":"https://github.com/david-cortes","followers_url":"https://api.github.com/users/david-cortes/followers","following_url":"https://api.github.com/users/david-cortes/following{/other_user}","gists_url":"https://api.github.com/users/david-cortes/gists{/gist_id}","starred_url":"https://api.github.com/users/david-cortes/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/david-cortes/subscriptions","organizations_url":"https://api.github.com/users/david-cortes/orgs","repos_url":"https://api.github.com/users/david-cortes/repos","events_url":"https://api.github.com/users/david-cortes/events{/privacy}","received_events_url":"https://api.github.com/users/david-cortes/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":{"login":"aselle","id":326106,"node_id":"MDQ6VXNlcjMyNjEwNg==","avatar_url":"https://avatars1.githubusercontent.com/u/326106?v=4","gravatar_id":"","url":"https://api.github.com/users/aselle","html_url":"https://github.com/aselle","followers_url":"https://api.github.com/users/aselle/followers","following_url":"https://api.github.com/users/aselle/following{/other_user}","gists_url":"https://api.github.com/users/aselle/gists{/gist_id}","starred_url":"https://api.github.com/users/aselle/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/aselle/subscriptions","organizations_url":"https://api.github.com/users/aselle/orgs","repos_url":"https://api.github.com/users/aselle/repos","events_url":"https://api.github.com/users/aselle/events{/privacy}","received_events_url":"https://api.github.com/users/aselle/received_events","type":"User","site_admin":false},"assignees":[{"login":"aselle","id":326106,"node_id":"MDQ6VXNlcjMyNjEwNg==","avatar_url":"https://avatars1.githubusercontent.com/u/326106?v=4","gravatar_id":"","url":"https://api.github.com/users/aselle","html_url":"https://github.com/aselle","followers_url":"https://api.github.com/users/aselle/followers","following_url":"https://api.github.com/users/aselle/following{/other_user}","gists_url":"https://api.github.com/users/aselle/gists{/gist_id}","starred_url":"https://api.github.com/users/aselle/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/aselle/subscriptions","organizations_url":"https://api.github.com/users/aselle/orgs","repos_url":"https://api.github.com/users/aselle/repos","events_url":"https://api.github.com/users/aselle/events{/privacy}","received_events_url":"https://api.github.com/users/aselle/received_events","type":"User","site_admin":false}],"milestone":null,"comments":2,"created_at":"2018-06-03T07:45:46Z","updated_at":"2018-06-19T18:44:06Z","closed_at":null,"author_association":"NONE","body":"If I try to build some loss function which in its calculations includes an `scatter_add` or `scatter_update` and optimize it using `ScipyOptimizerInterface`, TensorFlow will fail in calculating the gradient.\r\n\r\nHere's an example with a variant of low-rank matrix factorization in which I add an extra variable, which adds to some of the rows of one of the matrices in the low-rank factorization:\r\n\r\n```python\r\nimport numpy as np, tensorflow as tf\r\n\r\nnrow = 20\r\nncol = 30\r\nk = 15\r\nnrow_add = 10\r\nncol_mult_add = 5\r\nregularization = 1e-6\r\n\r\nnp.random.seed(1)\r\nX = np.random.normal(size = (nrow, ncol)).astype('float32')\r\nX2 = np.random.normal(size = (nrow_add, ncol_mult_add)).astype('float32')\r\nix_row_add = np.random.choice(np.arange(nrow), replace=False, size=nrow_add).astype('int32')\r\n\r\nA = tf.Variable(tf.random_normal([nrow, k]))\r\nB = tf.Variable(tf.random_normal([ncol, k]))\r\nA2 = tf.Variable(tf.random_normal([ncol_mult_add, k]))\r\n\r\nXtf = tf.placeholder(tf.float32)\r\nX2tf = tf.placeholder(tf.float32)\r\n\r\nA_added = tf.scatter_add(A, ix_row_add, tf.matmul(X2, A2))\r\npred_x = tf.matmul(A_added, B, transpose_b=True)\r\nloss = tf.losses.mean_squared_error(Xtf, pred_x)\r\nloss += regularization * (tf.nn.l2_loss(A) + tf.nn.l2_loss(A2) + tf.nn.l2_loss(B))\r\n\r\noptimizer = tf.contrib.opt.ScipyOptimizerInterface(loss, method='L-BFGS-B')\r\nmodel = tf.global_variables_initializer()\r\nsess=tf.Session()\r\nsess.run(model)\r\nwith sess:\r\n    sess.run(model)\r\n    optimizer.minimize(sess, feed_dict={Xtf:X, X2tf:X2})\r\n    Aopt = A.eval(session=sess)\r\n    A2opt = A2.eval(session=sess)\r\n    Bopt = B.eval(session=sess)\r\n``` \r\n\r\nThrows:\r\n```\r\nInvalidArgumentError: Input 0 of node ScatterAdd was passed float from _arg_Variable_0_2:0 incompatible with expected float_ref.\r\n```\r\n\r\nInformation about my system:\r\n* Have I written custom code: No\r\n* OS Platform and Distribution: Debian buster/sid 64-bit\r\n* TensorFlow installed from: binary (PyPI)\r\n* TensorFlow version: 1.7.0\r\n* Python version: 3.6.3\r\n* Bazel version: N/A\r\n* GCC/Compiler version: N/A\r\n* CUDA/cuDNN version: N/A\r\n* GPU model and memory: N/A\r\n* Exact command to reproduce: N/A"},"comment":{"url":"https://api.github.com/repos/tensorflow/tensorflow/issues/comments/398504096","html_url":"https://github.com/tensorflow/tensorflow/issues/19717#issuecomment-398504096","issue_url":"https://api.github.com/repos/tensorflow/tensorflow/issues/19717","id":398504096,"node_id":"MDEyOklzc3VlQ29tbWVudDM5ODUwNDA5Ng==","user":{"login":"tensorflowbutler","id":28546240,"node_id":"MDQ6VXNlcjI4NTQ2MjQw","avatar_url":"https://avatars2.githubusercontent.com/u/28546240?v=4","gravatar_id":"","url":"https://api.github.com/users/tensorflowbutler","html_url":"https://github.com/tensorflowbutler","followers_url":"https://api.github.com/users/tensorflowbutler/followers","following_url":"https://api.github.com/users/tensorflowbutler/following{/other_user}","gists_url":"https://api.github.com/users/tensorflowbutler/gists{/gist_id}","starred_url":"https://api.github.com/users/tensorflowbutler/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/tensorflowbutler/subscriptions","organizations_url":"https://api.github.com/users/tensorflowbutler/orgs","repos_url":"https://api.github.com/users/tensorflowbutler/repos","events_url":"https://api.github.com/users/tensorflowbutler/events{/privacy}","received_events_url":"https://api.github.com/users/tensorflowbutler/received_events","type":"User","site_admin":false},"created_at":"2018-06-19T18:44:06Z","updated_at":"2018-06-19T18:44:06Z","author_association":"MEMBER","body":"Nagging Assignee @aselle: It has been 15 days with no activity and this issue has an assignee. Please update the label and/or status accordingly."}}
{"actor":{"display_login":"tensorflowbutler"}}