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

Vectorize local shard retrieval #5826

Merged
merged 2 commits into from
Dec 1, 2023
Merged

Conversation

jonb377
Copy link
Collaborator

@jonb377 jonb377 commented Nov 20, 2023

To capitalize on the improvements in #5824 and #5825, moving tensor shards to CPU should be batched. This change does the following:

  • Make _get_local_shards and _get_local_shard_replica_and_indices operate on lists of tensors instead of individual tensors.
  • Updates _sharded_cpu_state_dict to use the batched method across all sharded tensors in the state_dict.

With all three changes applied, the amount of time spent transferring the state_dict to CPU for a 2B parameter model decreases from >10s to 3.4s, which unblocks training much more quickly.

@jonb377 jonb377 requested a review from yeounoh November 20, 2023 09:18
@jonb377 jonb377 self-assigned this Nov 20, 2023
@jonb377 jonb377 force-pushed the jonbolin/vectorize-local-shards branch from 8d0b5bf to bad9356 Compare November 20, 2023 12:07
XLATensorPtr xtensor = bridge::GetXlaTensor(input);
m.def(
"_get_local_shard_replica_and_indices",
[](const std::vector<at::Tensor>& input)
Copy link
Contributor

Choose a reason for hiding this comment

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

nit. rename input to inputs or input_tensors

Copy link
Contributor

@yeounoh yeounoh left a comment

Choose a reason for hiding this comment

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

LGTM

@jonb377 jonb377 force-pushed the jonbolin/vectorize-local-shards branch from bad9356 to 7ecc38d Compare November 29, 2023 21:59
@jonb377 jonb377 force-pushed the jonbolin/vectorize-local-shards branch from 7ecc38d to 48e9943 Compare November 30, 2023 23:21
Base automatically changed from jonbolin/copy-pool to master December 1, 2023 01:55
@jonb377 jonb377 force-pushed the jonbolin/vectorize-local-shards branch from 48e9943 to b673c07 Compare December 1, 2023 01:57
@jonb377 jonb377 merged commit c919973 into master Dec 1, 2023
19 checks passed
@jonb377 jonb377 deleted the jonbolin/vectorize-local-shards branch December 1, 2023 18:22
ManfeiBai pushed a commit to ManfeiBai/PyTorchXLA that referenced this pull request Dec 1, 2023
chunnienc pushed a commit to chunnienc/xla that referenced this pull request Dec 14, 2023
bhavya01 pushed a commit that referenced this pull request Apr 22, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants