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

#25871 slows down non-CPU runs #25944

Closed
ydshieh opened this issue Sep 4, 2023 · 0 comments · Fixed by #25955
Closed

#25871 slows down non-CPU runs #25944

ydshieh opened this issue Sep 4, 2023 · 0 comments · Fixed by #25955
Assignees

Comments

@ydshieh
Copy link
Collaborator

ydshieh commented Sep 4, 2023

See #25871 (comment)

(copy paste)

Using repr here significantly slows down non-CPU runs (-33% on HPU, probably similar numbers on GPU). Which makes sense as repr copies data from the device to the host.
Could we rely on type(x) instead?

Here is a code snippet to measure it:

import time
import torch

cpu_tensor = torch.ones(512, 512, device="cpu")
gpu_tensor = torch.ones(512, 512, device="cuda")

n = 100

t0 = time.perf_counter()
for i in range(n):
    _ = repr(cpu_tensor)
t1 = time.perf_counter()
for i in range(n):
    _ = repr(gpu_tensor)
t2 = time.perf_counter()

print("CPU time:", t1-t0)
print("GPU time:", t2-t1)
@ydshieh ydshieh self-assigned this Sep 4, 2023
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 a pull request may close this issue.

1 participant