-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Summary: Add Proton profiler support. The profiler will instrument into the `run()` function to instrument the benchmark process. Pull Request resolved: #102 Test Plan: ``` $ python run.py --op softmax --num-inputs 3 --metrics proton Entering scope x_val_[4096, 256] Exiting scope x_val_[4096, 256] Entering scope x_val_[4096, 384] Exiting scope x_val_[4096, 384] Entering scope x_val_[4096, 512] Exiting scope x_val_[4096, 512] x_val naive_softmax-proton triton_softmax-proton ----------- ---------------------- ----------------------- [4096, 256] [4096, 384] [4096, 512] ``` ``` $ proton-viewer proton.hatchet -m time ``` <img width="1548" alt="image" src="https://github.com/user-attachments/assets/eb450119-08bc-48cb-b148-e84127f9c7b1"> Reviewed By: adamomainz Differential Revision: D66909978 Pulled By: xuzhao9 fbshipit-source-id: 3f5226c7abb3732c86dc9f908f7ce9dfdd529d29
- Loading branch information
1 parent
62d311e
commit 87dffcc
Showing
6 changed files
with
111 additions
and
25 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -16,3 +16,5 @@ __pycache__/ | |
*.egg-info/ | ||
torch_compile_debug/ | ||
build/ | ||
/*.csv | ||
*.hatchet |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
from .run import do_bench_wrapper |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
import torch | ||
import triton | ||
|
||
|
||
def do_bench_wrapper( | ||
fn, | ||
warmup, | ||
rep, | ||
grad_to_none, | ||
use_cuda_graphs: bool = False, | ||
bypass_fail: bool = False, | ||
): | ||
"""Wrapper to triton's do_bench to gain latency.""" | ||
if use_cuda_graphs: | ||
with torch.cuda.stream(torch.cuda.Stream()): | ||
return triton.testing.do_bench_cudagraph( | ||
fn, | ||
rep=rep, | ||
return_mode="median", | ||
grad_to_none=grad_to_none, | ||
) | ||
else: | ||
try: | ||
return triton.testing.do_bench( | ||
fn, | ||
warmup=warmup, | ||
rep=rep, | ||
return_mode="median", | ||
grad_to_none=grad_to_none, | ||
) | ||
except Exception as e: | ||
if not bypass_fail: | ||
raise e | ||
return None |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
from .trace import proton_trace |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
from typing import Callable, Optional | ||
|
||
import triton.profiler as proton | ||
|
||
|
||
def proton_trace( | ||
session_id: int, | ||
scope_name: str, | ||
fn: Callable, | ||
warmup: int, | ||
flops: Optional[int] = None, | ||
bytes: Optional[int] = None, | ||
): | ||
# warmup | ||
for _ in range(warmup): | ||
fn() | ||
metrics_dict = {} | ||
if flops: | ||
metrics_dict["flops"] = flops | ||
if bytes: | ||
metrics_dict["bytes"] = bytes | ||
proton.activate(session_id) | ||
with proton.scope(scope_name, metrics=metrics_dict): | ||
fn() | ||
proton.deactivate(session_id) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters