Skip to content

Warn when calling session.run() on a very large scatter #360

Closed

Description

@bdaskalov

Scatter ops output a ref to the whole tensor for easier chaining. The problem is if one executes the op directly in Session.run() the whole tensor is copied back as a numpy array. This can create very annoying and hard to find performance problems. I think you should consider adding a warning.

For example:
large_table = tf.Variable(... [1000000, 3])
set3_op = tf.scatter_update(large_table, 3, [1,2,3])

session.run([set3_op])

Here run() modifies just 3 elements of the table but returns the whole table as a numpy array that is then
ignored.

Activity

  1. vrv commented on Nov 26, 2015

    @vrv

    Sure, we'll take that into consideration.

    Most computational operations, when expressed in our python API, return a tf.Tensor object, and passing a Tensor object to session.run does indeed fetch the result back -- you can just run the operation by passing set3_op.op instead.

  2. changed the title [-]scatter_ops can cause one to accidentally copy a large tensor[/-] [+]Warn when calling session.run() on a very large tensor[/+] on Dec 13, 2015
  3. girving commented on Mar 8, 2016

    @girving
    Contributor

    I don't think it's practical to have a warning like this, unfortunately. Calling session.run() on large tensors seems like pretty standard behavior for machine learning.

  4. bdaskalov commented on Mar 9, 2016

    @bdaskalov
    Author

    @girving I was still learning Tensorflow at the time I filed this so I guess I didn't phrase it properly.

    The problem is that tf.scatter_update/add/sub() Ops return the whole tensor although they are typically used to update only a small part of it.

    For example:

    session.run([tf.scatter_update(large_table, 3, [1,2,3]))

    will return the whole value of "large_table" as a NumPy array although it updates a small part of it. This can cause a nasty hard-to-find performance problem. I think it is reasonable to have a warning when
    on of the fetch operations in session.run is scatter_*.

  5. changed the title [-]Warn when calling session.run() on a very large tensor[/-] [+]Warn when calling session.run() on a very large scatter[/+] on Mar 9, 2016
  6. girving commented on Mar 9, 2016

    @girving
    Contributor

    Fair enough, I was a bit misled by the title change. Reopening.

  7. reopened this on Mar 9, 2016
  8. added
    stat:contribution welcome
    on Mar 9, 2016
  9. girving commented on Mar 9, 2016

    @girving
    Contributor

    Incidentally, it would be better to fix the performance issue entirely. There are a couple possible ways to do that, though I'm not sure if any are practical:

    1. Automatically replace scatter with scatter.op in session.run.
    2. Same as (1), but on the C++ side somehow.
    3. Return views into the tensor rather than the whole thing.

    @michaelisard: Do any of these seem sane / practical?

  10. added
    type:feature
    and removed on Feb 9, 2017
  11. tensorflowbutler commented on Dec 22, 2017

    @tensorflowbutler
    Member

    It has been 14 days with no activity and this issue has an assignee.Please update the label and/or status accordingly.

  12. 1 remaining item

  13. tensorflowbutler commented on Jan 24, 2018

    @tensorflowbutler
    Member

    Please remove the assignee, as this issue is inviting external contributions. Otherwise, remove the contributions welcome label. Thank you.

  14. tensorflowbutler commented on Feb 8, 2018

    @tensorflowbutler
    Member

    Please remove the assignee, as this issue is inviting external contributions. Otherwise, remove the contributions welcome label. Thank you.

  15. removed their assignment
    on Feb 8, 2018
  16. bhack commented on Sep 8, 2020

    @bhack
    Contributor

    Is this still valid? Also tf.scatter_update is deprecated.

  17. self-assigned this
    on Sep 23, 2021
  18. added
    comp:ops
    and removed
    stat:contribution welcome
    on Sep 23, 2021
  19. mohantym commented on Sep 23, 2021

    @mohantym
    Contributor

    Hi @bdaskalov ,
    We are checking to see if you still need help on this issue. We recommend that you upgrade your code base to 2.x versions following migration document and let us know if the issue still persists in newer versions. Thanks!

  20. added
    stat:awaiting response
    on Sep 23, 2021
  21. bdaskalov commented on Sep 23, 2021

    @bdaskalov
    Author
  22. removed
    stat:awaiting response
    on Sep 24, 2021
  23. mohantym commented on Sep 24, 2021

    @mohantym
    Contributor

    @bdaskalov ,Thanks for confirming the same!

  24. mohantym commented on Feb 11, 2022

    @mohantym
    Contributor

    Are you satisfied with the resolution of your issue?
    Yes
    No

  25. added a commit that references this issue on May 15, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

comp:opstype:feature

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions