Skip to content

Commit

Permalink
Fix timer for NPU&XPU (#8261)
Browse files Browse the repository at this point in the history
* Fix timer for NPU&XPU

* Fix NPU/XPU timer
  • Loading branch information
KB-Ding authored Apr 11, 2024
1 parent 84615ea commit 62d5609
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions paddlenlp/trainer/plugins/timer.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,15 +32,15 @@ def __init__(self, name):
def start(self):
"""Start the timer."""
assert not self.started_, f"{self.name} timer has already started"
if "gpu" in paddle.device.get_device():
if "cpu" not in paddle.device.get_device():
paddle.device.synchronize()
self.start_time = time.time()
self.started_ = True

def stop(self):
"""Stop the timers."""
assert self.started_, f"{self.name} timer is not started."
if "gpu" in paddle.device.get_device():
if "cpu" not in paddle.device.get_device():
paddle.device.synchronize()
self.elapsed_ += time.time() - self.start_time
self.started_ = False
Expand Down

0 comments on commit 62d5609

Please sign in to comment.