Skip to content

Commit

Permalink
add gpu timer decorator (#207)
Browse files Browse the repository at this point in the history
  • Loading branch information
feifeibear authored Aug 20, 2024
1 parent 68d6211 commit a8212ca
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 0 deletions.
Binary file modified assets/methods/xdit_method.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 2 additions & 0 deletions xfuser/core/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,12 @@
xFuserJointLongContextAttention,
xFuserFluxLongContextAttention,
)
from .utils import gpu_timer_decorator

__all__ = [
"CacheManager",
"xFuserLongContextAttention",
"xFuserJointLongContextAttention",
"xFuserFluxLongContextAttention",
"gpu_timer_decorator",
]
1 change: 1 addition & 0 deletions xfuser/core/utils/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from .timer import gpu_timer_decorator
19 changes: 19 additions & 0 deletions xfuser/core/utils/timer.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import torch
import time


def gpu_timer_decorator(func):
def wrapper(*args, **kwargs):
torch.cuda.synchronize()
start_time = time.time()
result = func(*args, **kwargs)
torch.cuda.synchronize()
end_time = time.time()

if torch.distributed.get_rank() == 0:
print(
f"{func.__name__} took {end_time - start_time} seconds to run on GPU."
)
return result

return wrapper

0 comments on commit a8212ca

Please sign in to comment.