Skip to content

Improve single chunk array handling in svd #6612

Closed

Description

@eric-czech

The current SVD implementation has very unintuitive performance characteristics for small arrays:

import dask.array as da
# Create short-fat (small) single-chunk array
x = da.random.random((100, 100000), chunks=(-1, -1))
x.nbytes # 80000000 = 80MB

# Despite x being 80MB, this uses ~80 **GB** of RAM and
# I have no idea how long it would take to run (at least more than 5 minutes)
da.linalg.svd(x)[0].mean().compute()

# This on the other hand runs almost instantly and barely uses any memory
da.linalg.svd(x.T)[2].T.mean().compute() # the U array is V.T when given x.T

With #6591 in place, it would make sense to identify single chunk arrays and transpose them first to avoid this. That still wouldn't stop a user from providing an array with weird chunking, but I think a special case for single-chunk arrays is appropriate.

Activity

  1. mrocklin commented on Sep 9, 2020

    @mrocklin
    Member

    That is bizarre.

    With #6591 in place, it would make sense to identify single chunk arrays and transpose them first to avoid this.

    +1 from me

    That still wouldn't stop a user from providing an array with weird chunking, but I think a special case for single-chunk arrays is appropriate.

    More generally, I think that there is a tension between doing what the user tells us, and making some decisions for them behind the scenes. Historically we've chosen to do what the user tells us, even if it's suboptimal, just to avoid magical behavior.

    I think that we've made some decisions over the last couple of years that reverse this policy and gotten no push-back. Personally I'd be in favor of doing a lot more automated decision making. Transposing sounds great. We could go even further and do automatic rechunking and such.

    If you're interested in making SVD performance more robust then I'm entirely in favor.

  2. eric-czech commented on Sep 9, 2020

    @eric-czech
    ContributorAuthor

    I think that we've made some decisions over the last couple of years that reverse this policy and gotten no push-back. Personally I'd be in favor of doing a lot more automated decision making. Transposing sounds great. We could go even further and do automatic rechunking and such.

    Makes sense, thanks @mrocklin. I can't say I'd feel very confident in trying to add much more magical behavior beyond the easy single-chunk case yet, but I'll certainly try to report any useful info I find as we test tsqr more (for things other than SVD too).

    On a related note, at some point I wanted to compare dask svd/tsqr to numpy/scipy svd on unchunked arrays and see if there's a big enough difference in performance that it would make sense to have some switch in our code for it. Do you know if that's already been done before?

  3. mrocklin commented on Sep 9, 2020

    @mrocklin
    Member
  4. changed the title [-]Transpose single chunk arrays in svd[/-] [+]Improve single chunk array handling in svd[/+] on Sep 10, 2020
  5. eric-czech commented on Sep 11, 2020

    @eric-czech
    ContributorAuthor

    Fixed by #6616 (and partially #6623)

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