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

Support accessing the module reference for the process group #96

Merged
merged 4 commits into from Apr 4, 2024

Conversation

carmocca
Copy link
Member

@carmocca carmocca commented Mar 28, 2024

What does this PR do?

Works around #121 to support:

import os
import thunder
import torch
import torch.distributed as torch_dist
from thunder import ThunderModule

world_size = int(os.environ.get("WORLD_SIZE", 1))
local_rank = int(os.environ.get("LOCAL_RANK", 0))
global_rank = int(os.environ.get("RANK", 0))
if world_size > 1:
    torch_dist.init_process_group(backend="nccl")
    pg = torch_dist.distributed_c10d._get_default_group()
device = torch.device("cuda", local_rank)
torch.cuda.set_device(device)

model = torch.nn.Linear(5, 10, bias=False, device=device)
x = torch.randn(2, 5, device=device)

def fwd_loss(m, x):
    return m(x).sum()

fwd_loss = thunder.jit(fwd_loss)
model = thunder.distributed.ddp(model)

# notice how we cannot do `model.no_sync()` because it's not a ThunderModule
with ThunderModule.no_sync(model):
    out = fwd_loss(model, x)

@carmocca carmocca self-assigned this Mar 28, 2024
Copy link
Collaborator

@t-vi t-vi left a comment

Choose a reason for hiding this comment

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

I would like to have a more general fix (see #122) but I think this is good for now.

Thank you @carmocca

@t-vi t-vi enabled auto-merge (squash) April 3, 2024 17:20
@t-vi t-vi merged commit c915335 into main Apr 4, 2024
40 checks passed
@t-vi t-vi deleted the carmocca/sync-grads-compiled-fn branch April 4, 2024 00:44
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.

None yet

3 participants