From 62d5609c3dfeab59a907286d6eb2b4adad3e0425 Mon Sep 17 00:00:00 2001 From: Kunbo Ding Date: Thu, 11 Apr 2024 19:05:31 +0800 Subject: [PATCH] Fix timer for NPU&XPU (#8261) * Fix timer for NPU&XPU * Fix NPU/XPU timer --- paddlenlp/trainer/plugins/timer.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/paddlenlp/trainer/plugins/timer.py b/paddlenlp/trainer/plugins/timer.py index dc2cf1245800..6413a16eb1b4 100644 --- a/paddlenlp/trainer/plugins/timer.py +++ b/paddlenlp/trainer/plugins/timer.py @@ -32,7 +32,7 @@ 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 @@ -40,7 +40,7 @@ def start(self): 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