Skip to content

Commit a1645ea

Browse files
author
ascend-robot
committed
[fix] fix race condition for modifying torch num_threads
Co-authored-by: 0oshowero0<o0shower0o@outlook.com> # message auto-generated for no-merge-commit merge: !5 merge fix_race_condition into main [fix] fix race condition for modifying torch num_threads Created-by: hanzhenyu8 Commit-by: 0oshowero0 Merged-by: ascend-robot Description: fix race condition for modifying torch num_threads See merge request: Ascend/TransferQueue!5
1 parent 55913b8 commit a1645ea

2 files changed

Lines changed: 5 additions & 3 deletions

File tree

transfer_queue/utils/perf_utils.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828
handler.setFormatter(logging.Formatter("%(asctime)s - %(levelname)s - %(name)s - %(message)s"))
2929
logger.addHandler(handler)
3030

31-
TQ_PERF_LOG_FLUSH_INTERVAL = float(os.environ.get("TQ_PERF_LOG_FLUSH_INTERVAL", 10)) # in seconds
31+
TQ_PERF_LOG_FLUSH_INTERVAL = float(os.environ.get("TQ_PERF_LOG_FLUSH_INTERVAL", 300)) # in seconds
3232

3333

3434
class IntervalPerfMonitor:

transfer_queue/utils/utils.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,8 @@
2626
logger = logging.getLogger(__name__)
2727
logger.setLevel(os.getenv("TQ_LOGGING_LEVEL", logging.WARNING))
2828

29+
DEFAULT_TORCH_NUM_THREADS = torch.get_num_threads()
30+
2931
# Ensure logger has a handler
3032
if not logger.hasHandlers():
3133
handler = logging.StreamHandler()
@@ -141,10 +143,10 @@ def limit_pytorch_auto_parallel_threads(target_num_threads: Optional[int] = None
141143
yield
142144
finally:
143145
# Restore the original number of threads
144-
torch.set_num_threads(pytorch_current_num_threads)
146+
torch.set_num_threads(DEFAULT_TORCH_NUM_THREADS)
145147
logger.debug(
146148
f"{info} (pid={pid}): torch.get_num_threads() is {torch.get_num_threads()}, "
147-
f"restoring to {pytorch_current_num_threads}."
149+
f"restoring to {DEFAULT_TORCH_NUM_THREADS}."
148150
)
149151

150152

0 commit comments

Comments
 (0)