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

Fix: add event sync in fsdp tutorial #3166

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

zzb610
Copy link

@zzb610 zzb610 commented Nov 20, 2024

Fixes #ISSUE_NUMBER

Description

The event should be synchronized before calling elapsed_time to ensure that the corresponding event has completed. This change is necessary to avoid runtime errors related to incomplete events.

For more details, refer to the relevant code in the PyTorch repository:

Example Code

import torch
def case():
    torch.cuda.set_device(0)

    init_start_event = torch.cuda.Event(enable_timing=True)
    init_end_event = torch.cuda.Event(enable_timing=True)

    init_start_event.record()
    for i in range(100):
        a = torch.randn(size=(1024, 1024), device="cuda")
        b = torch.randn(size=(1024, 1024), device="cuda")
        out = torch.add(a, b)
        out = torch.matmul(a, b)
        out = torch.matmul(a, b)
        out = torch.matmul(a, b)
        out = torch.matmul(a, b)
    init_end_event.record()

    # print("init_end_event.query(): ", init_end_event.query()) # False
    # # RuntimeError: CUDA error: device not ready
    # print(
    #     f"CUDA event elapsed time: {init_start_event.elapsed_time(init_end_event) / 1000}sec"
    # )

    # OK
    init_end_event.synchronize()
    print("init_end_event.query(): ", init_end_event.query())
    print(
        f"CUDA event elapsed time: {init_start_event.elapsed_time(init_end_event) / 1000}sec"
    )

cc @wconstab @osalpekar @H-Huang @kwen2501

Copy link

pytorch-bot bot commented Nov 20, 2024

🔗 Helpful Links

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

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:

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

@zzb610
Copy link
Author

zzb610 commented Nov 25, 2024

@HamidShojanazeri Could you please take a look at this PR when you have a moment? Thanks a lot!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants