[BE][PYFMT] migrate PYFMT for torch.{distributed,distributions} to ruff format (#144547)

Pull Request resolved: https://github.com/pytorch/pytorch/pull/144547
Approved by: https://github.com/kwen2501
This commit is contained in:
Xuehai Pan
2025-02-28 11:10:58 +08:00
committed by PyTorch MergeBot
parent 4e160d5fd9
commit 995df34b19
143 changed files with 920 additions and 774 deletions

View File

@ -165,9 +165,11 @@ def to_map(
Example:
::
to_map(Std.OUT, local_world_size=2) # returns: {0: Std.OUT, 1: Std.OUT}
to_map({1: Std.OUT}, local_world_size=2) # returns: {0: Std.NONE, 1: Std.OUT}
to_map({0: Std.OUT, 1: Std.OUT}, local_world_size=2) # returns: {0: Std.OUT, 1: Std.OUT}
to_map(Std.OUT, local_world_size=2) # returns: {0: Std.OUT, 1: Std.OUT}
to_map({1: Std.OUT}, local_world_size=2) # returns: {0: Std.NONE, 1: Std.OUT}
to_map(
{0: Std.OUT, 1: Std.OUT}, local_world_size=2
) # returns: {0: Std.OUT, 1: Std.OUT}
"""
if isinstance(val_or_map, Std):
return dict.fromkeys(range(local_world_size), val_or_map)
@ -304,7 +306,9 @@ class DefaultLogsSpecs(LogsSpecs):
if not self._run_log_dir:
self._run_log_dir = self._make_log_dir(self._root_log_dir, run_id)
attempt_log_dir = os.path.join(self._run_log_dir, f"attempt_{restart_count}") # type: ignore[call-overload]
attempt_log_dir = os.path.join(
self._run_log_dir, f"attempt_{restart_count}"
) # type: ignore[call-overload]
shutil.rmtree(attempt_log_dir, ignore_errors=True)
os.makedirs(attempt_log_dir)
@ -868,9 +872,7 @@ class SubprocessContext(PContext):
if result.is_failed():
first_failure = min(result.failures.values(), key=lambda f: f.timestamp)
logger.error(
"failed (exitcode: %s)"
" local_rank: %s (pid: %s)"
" of binary: %s",
"failed (exitcode: %s) local_rank: %s (pid: %s) of binary: %s",
first_failure.exitcode,
first_failure.local_rank,
first_failure.pid,