Skip to content

Implement pipeline-aware shard estimator and turn it on by default for prefetch pipeline #1924

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

Closed
wants to merge 1 commit into from

Conversation

levythu
Copy link
Contributor

@levythu levythu commented Apr 24, 2024

Summary:
Lots of rank load imbalance comes from underestimation of sparse, which is not only a function of parameter, but the HBM usage during input and output. This is especially bad if we have multi-stage pipeline, which keeps multiple copies of input for each table.

Prefetched embedding has the worst performance. By heuristically analyzing the current memory snapshot, we noticed 4~7x of extra input.

This diff use a new formulas to calculate HBM usage:

  • Multiple input are considered depending on the pipeline
  • Output and input are added using max, since output tensor is not occupying extra HBM before a2a communication, at that time input is no longer used

For backward compatibility, we haven't roll out the change to ally user as it may incur extra failure of jobs. Instead, we set up different pipeline-awareness mode:

  • None: Use old formulas regardless
  • Prefetch-Only (default): Use new formulas if prefetch pipeline is on
  • All: Use new formulas.

Differential Revision: D56444328

@facebook-github-bot facebook-github-bot added the CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. label Apr 24, 2024
@facebook-github-bot
Copy link
Contributor

This pull request was exported from Phabricator. Differential Revision: D56444328

…r prefetch pipeline (pytorch#1924)

Summary:

Lots of rank load imbalance comes from underestimation of sparse, which is not only a function of parameter, but the HBM usage during input and output. This is especially bad if we have multi-stage pipeline, which keeps multiple copies of input for each table.

Prefetched embedding has the worst performance. By heuristically analyzing the current memory snapshot, we noticed 4~7x of extra input. 

This diff use a new formulas to calculate HBM usage:
- Multiple input are considered depending on the pipeline
- Output and input are added using max, since output tensor is not occupying extra HBM before a2a communication, at that time input is no longer used

For backward compatibility, we haven't roll out the change to ally user as it may incur extra failure of jobs. Instead, we set up different pipeline-awareness mode:
- None: Use old formulas regardless
- Prefetch-Only (default): Use new formulas if prefetch pipeline is on
- All: Use new formulas.

Differential Revision: D56444328
@facebook-github-bot
Copy link
Contributor

This pull request was exported from Phabricator. Differential Revision: D56444328

levythu added a commit to levythu/torchrec that referenced this pull request Apr 24, 2024
…r prefetch pipeline (pytorch#1924)

Summary:

Lots of rank load imbalance comes from underestimation of sparse, which is not only a function of parameter, but the HBM usage during input and output. This is especially bad if we have multi-stage pipeline, which keeps multiple copies of input for each table.

Prefetched embedding has the worst performance. By heuristically analyzing the current memory snapshot, we noticed 4~7x of extra input. 

This diff use a new formulas to calculate HBM usage:
- Multiple input are considered depending on the pipeline
- Output and input are added using max, since output tensor is not occupying extra HBM before a2a communication, at that time input is no longer used

For backward compatibility, we haven't roll out the change to ally user as it may incur extra failure of jobs. Instead, we set up different pipeline-awareness mode:
- None: Use old formulas regardless
- Prefetch-Only (default): Use new formulas if prefetch pipeline is on
- All: Use new formulas.

Differential Revision: D56444328
levythu added a commit to levythu/torchrec that referenced this pull request Apr 24, 2024
… than HBM-only

Summary: Checked pytorch#1924 for context. Basically, under some specific case, a table could use even more hbm when offloaded and prefetched. in this case, we'd rather not offload them.

Differential Revision: D56505315
facebook-github-bot pushed a commit that referenced this pull request Apr 25, 2024
… than HBM-only

Summary: Check #1924 for context. Basically, under some specific case, a table could use even more hbm when offloaded and prefetched. in this case, we'd rather not offload them.

Reviewed By: henrylhtsang

Differential Revision: D56505315

fbshipit-source-id: f8cdf03568f79ad7e2ef842b8939280de9ec9c84
levythu added a commit to levythu/torchrec that referenced this pull request Sep 12, 2024
Summary:
Prior context: pytorch#1924 or D56444328.

From the in-depth analysis, the output of embedding didn't really contribute to the peak memory. Instead, they're quite ephemeral and deallocated right after output-dist. (See the analysis of original PR/diff for more details).

Therefore, this diff remove output out of the memory accounting for an embedding shard. This behavior is not always safe though: in rare case, e.g. a rank contain only sparse , or for some reason sparse forward/backward happens when HBM usage hits peak, output size will contribute to peak memory instead -- the change leave the open interface to still count in output size and caller will set it as needed.

For backward compatibility, this change only applies to any estimation using "new formula" (the pipeline aware formula). The old formula will keep untouched and always include output.

{F1862246115}

Differential Revision: D62540207
facebook-github-bot pushed a commit that referenced this pull request Sep 12, 2024
Summary:
Pull Request resolved: #2382

Prior context: #1924 or D56444328.

From the in-depth analysis, the output of embedding didn't really contribute to the peak memory. Instead, they're quite ephemeral and deallocated right after output-dist. (See the analysis of original PR/diff for more details).

Therefore, this diff remove output out of the memory accounting for an embedding shard. This behavior is not always safe though: in rare case, e.g. a rank contain only sparse , or for some reason sparse forward/backward happens when HBM usage hits peak, output size will contribute to peak memory instead -- the change leave the open interface to still count in output size and caller will set it as needed.

For backward compatibility, this change only applies to any estimation using "new formula" (the pipeline aware formula). The old formula will keep untouched and always include output.

{F1862246115}

Reviewed By: sarckk

Differential Revision: D62540207

fbshipit-source-id: 0af679817ab61b508b5ce06fec4e0136e7a63dea
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. fb-exported
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants