Skip to content

add TORCH_FORCE_SYNCHRONOUS_COLLECTIVES to force functional collectives to be synchronous - #128331

Closed
bdhirsh wants to merge 11 commits into
gh/bdhirsh/578/basefrom
gh/bdhirsh/578/head
Closed

bdhirsh wants to merge 11 commits into
gh/bdhirsh/578/basefrom
gh/bdhirsh/578/head

Conversation

@bdhirsh

@bdhirsh bdhirsh commented Jun 10, 2024 •

Copy link
Copy Markdown
Collaborator

One way that OOM's can show up with using torch.compile with distributed code is if our compile fails to issue a wait_tensor properly on a functional collective.

This PR adds an env var that forces all functional collectives to be synchronous at runtime (making issuing wait_tensor at runtime a no-op, so if we fail to issue wait_tensors properly at runtime then we will not leak memory).

If we see a mem leak / OOM when using compile with distributed code, this flag should at least quickly tell us if the mem leak is coming from not waiting on a collective, vs. something else entirely.

cc @XilunWu @H-Huang @awgu @kwen2501 @wanchaol @fegin @fduwjj @wz337 @wconstab @d4l3k @c-p-i-o @yifuwang / @wconstab, wdyt of this env var?

Stack from ghstack (oldest at bottom):

cc @mrshenli @pritamdamania87 @zhaojuanmao @satgera @gqchen @aazzolini @osalpekar @jiayisuse @H-Huang @kwen2501 @awgu @penguinwu @fegin @XilunWu @wanchaol @fduwjj @wz337 @tianyu-l @wconstab @yf225 @chauhang @d4l3k

@pytorch-bot

pytorch-bot Bot commented Jun 10, 2024 •

Copy link
Copy Markdown

🔗 Helpful Links

🧪 See artifacts and rendered test results at hud.pytorch.org/pr/128331

Note: Links to docs will display an error until the docs builds have been completed.

❗ 1 Active SEVs

There are 1 currently active SEVs. If your PR is affected, please view them below:

✅ No Failures

As of commit 2b4a770 with merge base 81df076 (image):
💚 Looks good so far! There are no failures yet. 💚

This comment was automatically generated by Dr. CI and updates every 15 minutes.

@ezyang

ezyang commented Jun 10, 2024

Copy link
Copy Markdown
Contributor

Doesn't have to be in this PR, but you should think about where this should be doc'ed and how people who need to know about it can find out about it.

@bdhirsh

bdhirsh commented Jun 10, 2024

Copy link
Copy Markdown
Collaborator Author

yep, very fair (@drisspg - per that BE project you were looking into, do we have a nice way for users to find TORCH_* env vars already? Otherwise maybe if/once we agree that this env var is reasonable, I can look for a place in the docs to mention it)

// Useful for debugging memory leaks with compile that surface
// due to compile not properly waiting on functional collectives.
bool force_synchronous_functional_collectives() {
static char const* temp = getenv("TORCH_FORCE_SYNCHRONOUS_COLLECTIVES");

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Use std::getenv. Also what if the user wants to explicitly disable it?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

@wconstab

Copy link
Copy Markdown
Contributor

I like the idea of adding the env, but not sure how to name it.

most of the distributed envs are named TORCH_NCCL_* and @shuqiang recently doc'd them all in this page, you should probably add an entry there and also in compile docs?

The 2 confusing points regarding naming and behavior are

  • its not NCCL specific, so probably TORCH_ is better
  • the env only affects functional collectives, which might confuse users of non-functional collectives

TORCH_FUNCOL_SYNC?

@bdhirsh

bdhirsh commented Jun 10, 2024

Copy link
Copy Markdown
Collaborator Author

The 2 confusing points regarding naming and behavior are

@wconstab thanks for the feedback. The point about most env vars including NCCL in their name but this not being nccl-specific is fair. TORCH_FUNCOL_SYNC sounds reasonable to me, I can change it to that.

bdhirsh added 2 commits June 12, 2024 07:22
…l collectives to be synchronous"

One way that OOM's can show up with using torch.compile with distributed code is if our compile fails to issue a `wait_tensor` properly on a functional collective.

This PR adds an env var that forces all functional collectives to be synchronous at runtime (making issuing wait_tensor at runtime a no-op, so if we fail to issue wait_tensors properly at runtime then we will not leak memory).

If we see a mem leak / OOM when using compile with distributed code, this flag should at least quickly tell us if the mem leak is coming from not waiting on a collective, vs. something else entirely.

cc yifuwang / wconstab, wdyt of this env var?




cc mrshenli pritamdamania87 zhaojuanmao satgera gqchen aazzolini osalpekar jiayisuse H-Huang kwen2501 awgu penguinwu fegin XilunWu wanchaol fduwjj wz337 tianyu-l wconstab yf225 chauhang d4l3k

[ghstack-poisoned]
…l collectives to be synchronous"

One way that OOM's can show up with using torch.compile with distributed code is if our compile fails to issue a `wait_tensor` properly on a functional collective.

This PR adds an env var that forces all functional collectives to be synchronous at runtime (making issuing wait_tensor at runtime a no-op, so if we fail to issue wait_tensors properly at runtime then we will not leak memory).

If we see a mem leak / OOM when using compile with distributed code, this flag should at least quickly tell us if the mem leak is coming from not waiting on a collective, vs. something else entirely.

cc yifuwang / wconstab, wdyt of this env var?




cc mrshenli pritamdamania87 zhaojuanmao satgera gqchen aazzolini osalpekar jiayisuse H-Huang kwen2501 awgu penguinwu fegin XilunWu wanchaol fduwjj wz337 tianyu-l wconstab yf225 chauhang d4l3k

[ghstack-poisoned]
@yifuwang

Copy link
Copy Markdown
Collaborator

This looks great! Thanks for adding it.

Curious what are the most common sources of unwaited collectives based on your observation. It is more due to graph break boundary handling, or users calling the _c10d_functional ops without calling wait? For the latter, we can add a pass to lint/fix the program.

bdhirsh added 2 commits June 13, 2024 14:52
…l collectives to be synchronous"

One way that OOM's can show up with using torch.compile with distributed code is if our compile fails to issue a `wait_tensor` properly on a functional collective.

This PR adds an env var that forces all functional collectives to be synchronous at runtime (making issuing wait_tensor at runtime a no-op, so if we fail to issue wait_tensors properly at runtime then we will not leak memory).

If we see a mem leak / OOM when using compile with distributed code, this flag should at least quickly tell us if the mem leak is coming from not waiting on a collective, vs. something else entirely.

cc yifuwang / wconstab, wdyt of this env var?




cc mrshenli pritamdamania87 zhaojuanmao satgera gqchen aazzolini osalpekar jiayisuse H-Huang kwen2501 awgu penguinwu fegin XilunWu wanchaol fduwjj wz337 tianyu-l wconstab yf225 chauhang d4l3k

[ghstack-poisoned]
…l collectives to be synchronous"

One way that OOM's can show up with using torch.compile with distributed code is if our compile fails to issue a `wait_tensor` properly on a functional collective.

This PR adds an env var that forces all functional collectives to be synchronous at runtime (making issuing wait_tensor at runtime a no-op, so if we fail to issue wait_tensors properly at runtime then we will not leak memory).

If we see a mem leak / OOM when using compile with distributed code, this flag should at least quickly tell us if the mem leak is coming from not waiting on a collective, vs. something else entirely.

cc yifuwang / wconstab, wdyt of this env var?




cc mrshenli pritamdamania87 zhaojuanmao satgera gqchen aazzolini osalpekar jiayisuse H-Huang kwen2501 awgu penguinwu fegin XilunWu wanchaol fduwjj wz337 tianyu-l wconstab yf225 chauhang d4l3k

[ghstack-poisoned]
…l collectives to be synchronous"

One way that OOM's can show up with using torch.compile with distributed code is if our compile fails to issue a `wait_tensor` properly on a functional collective.

This PR adds an env var that forces all functional collectives to be synchronous at runtime (making issuing wait_tensor at runtime a no-op, so if we fail to issue wait_tensors properly at runtime then we will not leak memory).

If we see a mem leak / OOM when using compile with distributed code, this flag should at least quickly tell us if the mem leak is coming from not waiting on a collective, vs. something else entirely.

cc yifuwang / wconstab, wdyt of this env var?




cc mrshenli pritamdamania87 zhaojuanmao satgera gqchen aazzolini osalpekar jiayisuse H-Huang kwen2501 awgu penguinwu fegin XilunWu wanchaol fduwjj wz337 tianyu-l wconstab yf225 chauhang d4l3k

[ghstack-poisoned]
bdhirsh added a commit that referenced this pull request Jun 18, 2024
…es to be synchronous

ghstack-source-id: 8ccdf3e
Pull Request resolved: #128331
…l collectives to be synchronous"

One way that OOM's can show up with using torch.compile with distributed code is if our compile fails to issue a `wait_tensor` properly on a functional collective.

This PR adds an env var that forces all functional collectives to be synchronous at runtime (making issuing wait_tensor at runtime a no-op, so if we fail to issue wait_tensors properly at runtime then we will not leak memory).

If we see a mem leak / OOM when using compile with distributed code, this flag should at least quickly tell us if the mem leak is coming from not waiting on a collective, vs. something else entirely.

cc yifuwang / wconstab, wdyt of this env var?




cc mrshenli pritamdamania87 zhaojuanmao satgera gqchen aazzolini osalpekar jiayisuse H-Huang kwen2501 awgu penguinwu fegin XilunWu wanchaol fduwjj wz337 tianyu-l wconstab yf225 chauhang d4l3k

[ghstack-poisoned]
bdhirsh added a commit that referenced this pull request Jun 27, 2024
…es to be synchronous

ghstack-source-id: 05cb6a2
Pull Request resolved: #128331
…l collectives to be synchronous"

One way that OOM's can show up with using torch.compile with distributed code is if our compile fails to issue a `wait_tensor` properly on a functional collective.

This PR adds an env var that forces all functional collectives to be synchronous at runtime (making issuing wait_tensor at runtime a no-op, so if we fail to issue wait_tensors properly at runtime then we will not leak memory).

If we see a mem leak / OOM when using compile with distributed code, this flag should at least quickly tell us if the mem leak is coming from not waiting on a collective, vs. something else entirely.

cc yifuwang / wconstab, wdyt of this env var?




cc mrshenli pritamdamania87 zhaojuanmao satgera gqchen aazzolini osalpekar jiayisuse H-Huang kwen2501 awgu penguinwu fegin XilunWu wanchaol fduwjj wz337 tianyu-l wconstab yf225 chauhang d4l3k

[ghstack-poisoned]
bdhirsh added a commit that referenced this pull request Jun 28, 2024
…es to be synchronous

ghstack-source-id: 3989292
Pull Request resolved: #128331
…l collectives to be synchronous"

One way that OOM's can show up with using torch.compile with distributed code is if our compile fails to issue a `wait_tensor` properly on a functional collective.

This PR adds an env var that forces all functional collectives to be synchronous at runtime (making issuing wait_tensor at runtime a no-op, so if we fail to issue wait_tensors properly at runtime then we will not leak memory).

If we see a mem leak / OOM when using compile with distributed code, this flag should at least quickly tell us if the mem leak is coming from not waiting on a collective, vs. something else entirely.

cc yifuwang / wconstab, wdyt of this env var?




cc mrshenli pritamdamania87 zhaojuanmao satgera gqchen aazzolini osalpekar jiayisuse H-Huang kwen2501 awgu penguinwu fegin XilunWu wanchaol fduwjj wz337 tianyu-l wconstab yf225 chauhang d4l3k

[ghstack-poisoned]
bdhirsh added a commit that referenced this pull request Jul 9, 2024
…es to be synchronous

ghstack-source-id: 02eb260
Pull Request resolved: #128331
@albanD
albanD removed their request for review July 9, 2024 19:14
…l collectives to be synchronous"

One way that OOM's can show up with using torch.compile with distributed code is if our compile fails to issue a `wait_tensor` properly on a functional collective.

This PR adds an env var that forces all functional collectives to be synchronous at runtime (making issuing wait_tensor at runtime a no-op, so if we fail to issue wait_tensors properly at runtime then we will not leak memory).

If we see a mem leak / OOM when using compile with distributed code, this flag should at least quickly tell us if the mem leak is coming from not waiting on a collective, vs. something else entirely.

cc yifuwang / wconstab, wdyt of this env var?




cc mrshenli pritamdamania87 zhaojuanmao satgera gqchen aazzolini osalpekar jiayisuse H-Huang kwen2501 awgu penguinwu fegin XilunWu wanchaol fduwjj wz337 tianyu-l wconstab yf225 chauhang d4l3k

[ghstack-poisoned]
bdhirsh added a commit that referenced this pull request Jul 9, 2024
…es to be synchronous

ghstack-source-id: b1478de
Pull Request resolved: #128331
…l collectives to be synchronous"

One way that OOM's can show up with using torch.compile with distributed code is if our compile fails to issue a `wait_tensor` properly on a functional collective.

This PR adds an env var that forces all functional collectives to be synchronous at runtime (making issuing wait_tensor at runtime a no-op, so if we fail to issue wait_tensors properly at runtime then we will not leak memory).

If we see a mem leak / OOM when using compile with distributed code, this flag should at least quickly tell us if the mem leak is coming from not waiting on a collective, vs. something else entirely.

cc yifuwang / wconstab, wdyt of this env var?




cc mrshenli pritamdamania87 zhaojuanmao satgera gqchen aazzolini osalpekar jiayisuse H-Huang kwen2501 awgu penguinwu fegin XilunWu wanchaol fduwjj wz337 tianyu-l wconstab yf225 chauhang d4l3k

[ghstack-poisoned]
bdhirsh added a commit that referenced this pull request Jul 10, 2024
…es to be synchronous

ghstack-source-id: 3d87fe8
Pull Request resolved: #128331
@github-actions

github-actions Bot commented Sep 8, 2024

Copy link
Copy Markdown
Contributor

Looks like this PR hasn't been updated in a while so we're going to go ahead and mark this as Stale.
Feel free to remove the Stale label if you feel this was a mistake.
If you are unable to remove the Stale label please contact a maintainer in order to do so.
If you want the bot to never mark this PR stale again, add the no-stale label.
Stale pull requests will automatically be closed after 30 days of inactivity.

@github-actions github-actions Bot added the Stale label Sep 8, 2024
@github-actions github-actions Bot closed this Oct 8, 2024
@github-actions
github-actions Bot deleted the gh/bdhirsh/578/head branch November 8, 2024 02:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

oncall: distributed Add this issue/PR to distributed oncall triage queue release notes: distributed (c10d) release notes category Stale

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants