diff --git a/assets/methods/xdit_method.png b/assets/methods/xdit_method.png index a92e8c1c..0c6f4cb3 100644 Binary files a/assets/methods/xdit_method.png and b/assets/methods/xdit_method.png differ diff --git a/xfuser/core/__init__.py b/xfuser/core/__init__.py index 85308338..51fe2c73 100644 --- a/xfuser/core/__init__.py +++ b/xfuser/core/__init__.py @@ -4,10 +4,12 @@ xFuserJointLongContextAttention, xFuserFluxLongContextAttention, ) +from .utils import gpu_timer_decorator __all__ = [ "CacheManager", "xFuserLongContextAttention", "xFuserJointLongContextAttention", "xFuserFluxLongContextAttention", + "gpu_timer_decorator", ] diff --git a/xfuser/core/utils/__init__.py b/xfuser/core/utils/__init__.py new file mode 100644 index 00000000..f0713958 --- /dev/null +++ b/xfuser/core/utils/__init__.py @@ -0,0 +1 @@ +from .timer import gpu_timer_decorator diff --git a/xfuser/core/utils/timer.py b/xfuser/core/utils/timer.py new file mode 100644 index 00000000..376adf3b --- /dev/null +++ b/xfuser/core/utils/timer.py @@ -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