Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Avoid h2d - d2h roundtrip when using unflatten #861

Merged

Conversation

danieldk
Copy link
Collaborator

Description

unflatten converts its lengths argument to a NumPy array, because CuPy's split function requires lengths to be in CPU memory. However, in various places in Thinc, we copy the lengths array to GPU memory when CupyOps is used. This results in an unnecessary roundtrip of the lengths array (host to device -> device to host). One of these roundtrips (array list2array) showed up in profiles of the biaffine parser.

This change fixes some length array allocations to avoid the round trip.

Types of change

Performance improvement

Checklist

  • I confirm that I have the right to submit this contribution under the project's MIT license.
  • I ran the tests, and all new and existing tests passed.
  • My changes don't require a change to the documentation, or if they do, I've added all required information.

`unflatten` converts its `lengths` argument to a NumPy array, because
CuPy's `split` function requires lengths to be in CPU memory. However,
in various places in Thinc, we copy the lengths array to GPU memory when
CupyOps is used. This results in an unnecessary roundtrip of the lengths
array (host to device -> device to host). One of these roundtrips
(array `list2array`) showed up in profiles of the biaffine parser.

This change fixes some length array allocations to avoid the round trip.
@netlify
Copy link

netlify bot commented Mar 13, 2023

👷 Deploy request for thinc-ai pending review.

Visit the deploys page to approve it

Name Link
🔨 Latest commit 0f12a2f

@danieldk danieldk added performance Speed and memory use feat / layers Weights layers, transforms, combinators, wrappers labels Mar 13, 2023
Copy link
Member

@svlandeg svlandeg left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice find!

@svlandeg svlandeg merged commit 388df13 into explosion:master Mar 16, 2023
@danieldk danieldk deleted the chore/avoid-device-roundtrip-unflatten branch March 16, 2023 19:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feat / layers Weights layers, transforms, combinators, wrappers performance Speed and memory use
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants