Skip to content

Commit 6ae7c8e

Browse files
Essozclaude
andcommitted
fix: suppress warnings during torch module instrumentation
Importing torch.distributed and other submodules during the two-pass instrumentation scan fires deprecation UserWarnings (e.g. reduce_op). Wrap both passes in warnings.catch_warnings(simplefilter=ignore) so these don't leak to the user's terminal. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
1 parent a2be746 commit 6ae7c8e

1 file changed

Lines changed: 16 additions & 10 deletions

File tree

traincheck/instrumentor/tracer.py

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -627,6 +627,8 @@ def __init__(
627627
)
628628

629629
def instrument(self) -> int:
630+
import warnings
631+
630632
if not self.instrumenting:
631633
return 0
632634

@@ -639,9 +641,11 @@ def instrument(self) -> int:
639641
"First pass: Recursive scan of the module"
640642
)
641643
assert isinstance(self.target, (types.ModuleType, type)), "Invalid target"
642-
first_pass_instrumented_count += self._instrument_module(
643-
self.target, visited_file_paths, True, 0
644-
)
644+
with warnings.catch_warnings():
645+
warnings.simplefilter("ignore")
646+
first_pass_instrumented_count += self._instrument_module(
647+
self.target, visited_file_paths, True, 0
648+
)
645649
get_instrumentation_logger_for_process().info(
646650
"Files scanned %s", "\n".join(sorted(visited_file_paths))
647651
)
@@ -665,13 +669,15 @@ def instrument(self) -> int:
665669
f"Instrumenting module {module_path}"
666670
)
667671

668-
pymodule = importlib.import_module(module_path)
669-
second_pass_instrumented_count += self._instrument_module(
670-
pymodule,
671-
visited_file_paths,
672-
False,
673-
0,
674-
)
672+
with warnings.catch_warnings():
673+
warnings.simplefilter("ignore")
674+
pymodule = importlib.import_module(module_path)
675+
second_pass_instrumented_count += self._instrument_module(
676+
pymodule,
677+
visited_file_paths,
678+
False,
679+
0,
680+
)
675681
get_instrumentation_logger_for_process().info(
676682
"Second pass instrumented %d functions", second_pass_instrumented_count
677683
)

0 commit comments

Comments
 (0)