You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The cleanup method in NVFBenchmark class calls self._timer.cleanup(), but the TorchProfileTimer and FusionProfileTimer classes do not have a cleanup method defined. This could lead to a NotImplementedError or unexpected behavior.
The set_fd method in NVFBenchmark class asserts that self._timer is an instance of FusionProfileTimer. This assumption might not hold if other timer classes are introduced in the future, leading to potential runtime errors.
The new Timer, TorchProfileTimer, and FusionProfileTimer classes lack detailed docstrings explaining their purpose, methods, and usage. This could make it difficult for other developers to understand and use these classes effectively.
# Base class for all timers used by pytest-benchmark.classTimer:
def__init__(self):
self.current_time=0.0def_increment_global_time(self, elapsed_time: float) ->None:
self.current_time+=elapsed_timedef__call__(self):
raiseNotImplementedError("Subclass must implement this method")
defcleanup(self):
passclassTorchProfileTimer(Timer):
def__init__(self):
super().__init__()
self.prof=profile(activities=[ProfilerActivity.CUDA])
def_get_kernel_time(
self, prof_averages: torch.autograd.profiler_util.EventList
) ->float:
""" Arguments: prof_averages: Output of self.prof.key_averages() Returns: time_value: Elapsed CUDA time in seconds. """elapsed_cuda_time=0has_cuda_event=Falseforeventinprof_averages:
ifevent.device_type!=DeviceType.CUDA:
continuehas_cuda_event=True# Re: torch profiler API changes in https://github.com/pytorch/pytorch/pull/123247elapsed_cuda_time= (
elapsed_cuda_time+event.self_device_time_totalifhasattr(event, "self_device_time_total")
elseevent.self_cuda_time_total
)
asserthas_cuda_event, "No CUDA events found"returnelapsed_cuda_time/1e6def__call__(self):
""" Custom torchprofiler-based timer used by pytest-benchmark. At every timer call, the profiler is stopped to compute the elapsed CUDA time and the global clock is incremented. The profiler is restarted before returning to continue tracing. Returns: self.current_time: Global monotonic clock variable """try:
self.prof.stop()
exceptAssertionError:
self.prof.start()
returnself.current_timeprof_averages=self.prof.key_averages()
elapsed_cuda_time=self._get_kernel_time(prof_averages)
self._increment_global_time(elapsed_cuda_time)
# Clear the internal profiler object to avoid accumulating function events and then restart the profiler# See PR: https://github.com/pytorch/pytorch/pull/125510self.prof.profiler=Nonereturnself.current_timedefcleanup(self):
""" Stops a running torchprofiler instance if found. """try:
self.prof.stop()
exceptAssertionError:
passclassFusionProfileTimer(Timer):
def__init__(self):
super().__init__()
self.fd=None# Specifies if the timer in host measurement is called at the start/finish of execution.# Timings are measured at the end of execution.self.execution_start=Truedefset_fd(self, fd):
self.fd=fddef__call__(self):
ifnotself.execution_start:
profile=self.fd.profile()
elapsed_host_time=profile.host_time_ms/1e3self._increment_global_time(elapsed_host_time)
self.execution_start=notself.execution_startreturnself.current_time
This file contains hidden or 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
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
The motivation is to use them in Thunder.