Skip to content

Enable Intel GPU #753

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
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 17 additions & 4 deletions torchao/_models/llama/generate.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@
def device_sync(device):
if "cuda" in device:
torch.cuda.synchronize(device)
elif "xpu" in device:
torch.xpu.synchronize(device)
elif ("cpu" in device) or ("mps" in device):
pass
else:
Expand Down Expand Up @@ -288,7 +290,10 @@ def main(

for i in range(start, num_samples):
if i==0:
torch.cuda.reset_peak_memory_stats()
if "cuda" in device:
Copy link
Contributor

Choose a reason for hiding this comment

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

Same as below, can you please check that torch.cuda.reset_peak_memory_stats does not need to be applied to hip

torch.cuda.reset_peak_memory_stats()
elif "xpu" in device:
torch.xpu.reset_peak_memory_stats()
device_sync(device=device) # MKG
if i >= 0 and interactive:
prompt = input("What is your prompt? ")
Expand Down Expand Up @@ -318,8 +323,15 @@ def callback(x):
if (i != num_samples - 1 or not profile):
prof = contextlib.nullcontext()
else:
torch.profiler._utils._init_for_cuda_graphs()
prof = torch.profiler.profile()
if "cuda" in device:
Comment on lines 325 to +326
Copy link
Contributor

Choose a reason for hiding this comment

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

Please dismantle the pyramid of doom and use elif "cuda" in device" rather than else:\n\tif "cuda" in device:"
And see my comment below again about "hip"

torch.profiler._utils._init_for_cuda_graphs()
prof = torch.profiler.profile()
elif "xpu" in device:
prof = torch.profiler.profile(
activities=[
torch.profiler.ProfilerActivity.CPU,
torch.profiler.ProfilerActivity.XPU],
)
with prof:
y = generate(
model,
Expand Down Expand Up @@ -369,7 +381,8 @@ def callback(x):

tokpersec = torch.mean(torch.tensor(aggregate_metrics['tokens_per_sec'])).item()
bandwidth = model_size * tokpersec
mem = torch.cuda.max_memory_reserved() /1e9
max_memory_reserved = torch.cuda.max_memory_reserved() if "cuda" in device else torch.xpu.max_memory_reserved()
Copy link
Contributor

Choose a reason for hiding this comment

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

This feels wrong, as it will dispatch to xpu for HIP devices as well, wouldn't it?

mem = max_memory_reserved / 1e9
print(f"Average tokens/sec: {tokpersec:.2f}")
print(f"Average Bandwidth: {bandwidth:.02f} GB/s")
print(f"Peak Memory Usage: {mem:.02f} GB")
Expand Down