[inductor] fix test_dynamo_timed on Windows. (#159981)

Fixed `test_dynamo_timed `:
<img width="1030" height="389" alt="image" src="https://github.com/user-attachments/assets/02d84dd8-6a65-4f91-8d4c-48ba0a81fac1" />

Pull Request resolved: https://github.com/pytorch/pytorch/pull/159981
Approved by: https://github.com/angelayi
This commit is contained in:
Xu Han
2025-08-07 16:37:52 +00:00
committed by PyTorch MergeBot
parent f3a4d742ec
commit 06824f3c72

View File

@ -12,6 +12,9 @@ from torch._dynamo import utils
from torch._inductor.test_case import TestCase
_IS_WINDOWS = sys.platform == "win32"
class TestUtils(TestCase):
def test_nan(self):
a = torch.Tensor([float("nan")])
@ -283,6 +286,37 @@ class TestDynamoTimed(TestCase):
self.assertExpectedInline(
pprint.pformat(utils.compilation_time_metrics),
"""\
{'GraphLowering.codegen': [0.0, 0.0],
'GraphLowering.compile_to_fn': [0.0, 0.0],
'GraphLowering.compile_to_module': [0.0, 0.0],
'GraphLowering.run': [0.0, 0.0],
'OutputGraph.call_user_compiler': [0.0],
'PyCodeCache.load_by_key_path': [0.0, 0.0],
'PythonWrapperCodegen.generate': [0.0, 0.0],
'Scheduler.__init__': [0.0, 0.0],
'Scheduler.codegen': [0.0, 0.0],
'Scheduler.fused_nodes': [0.0, 0.0],
'_compile.compile_inner': [0.0],
'_recursive_joint_graph_passes': [0.0],
'_recursive_post_grad_passes': [0.0, 0.0],
'_recursive_pre_grad_passes': [0.0],
'additional_fake_tensor_prop': [0.0, 0.0],
'aot_collect_metadata': [0.0],
'aot_trace_joint_graph': [0.0],
'backward._backward_impl': [0.0],
'build_guards': [0.0],
'bytecode_tracing': [0.0],
'compile_attempt_0': [0.0],
'compile_file': [0.0, 0.0],
'compile_fx.<locals>.bw_compiler': [0.0],
'compile_fx.<locals>.fw_compiler_base': [0.0],
'compile_fx_inner': [0.0, 0.0],
'create_aot_dispatcher_function': [0.0],
'fx_codegen_and_compile': [0.0, 0.0],
'gc': [0.0],
'min_cut_rematerialization_partition': [0.0]}"""
if _IS_WINDOWS
else """\
{'GraphLowering.codegen': [0.0, 0.0],
'GraphLowering.compile_to_fn': [0.0, 0.0],
'GraphLowering.compile_to_module': [0.0, 0.0],
@ -321,6 +355,18 @@ class TestDynamoTimed(TestCase):
self.assertExpectedInline(
pprint.pformat(time_spent),
"""\
{'_recursive_joint_graph_passes': 0.0,
'_recursive_post_grad_passes': 0.0,
'_recursive_pre_grad_passes': 0.0,
'backend_compile': 0.0,
'code_gen': 0.0,
'entire_backward_compile': 0.0,
'entire_frame_compile': 0.0,
'gc': 0.0,
'inductor_compile': 0.0,
'total_wall_time': 0.0}"""
if _IS_WINDOWS
else """\
{'_recursive_joint_graph_passes': 0.0,
'_recursive_post_grad_passes': 0.0,
'_recursive_pre_grad_passes': 0.0,
@ -364,6 +410,87 @@ class TestDynamoTimed(TestCase):
self.assertExpectedInline(
pprint.pformat(raw),
"""\
{'accumulated_cache_size': 0,
'aot_autograd_cumulative_compile_time_us': 0,
'backend_compile_time_s': 0.0,
'backward_cumulative_compile_time_us': None,
'cache_size': 0,
'co_filename': None,
'co_firstlineno': None,
'co_name': 'forward',
'code_gen_time_s': 0.0,
'compile_id': '1/0',
'compile_time_autotune_time_us': None,
'compliant_custom_ops': set(),
'config_inline_inbuilt_nn_modules': False,
'config_suppress_errors': False,
'cuda_version': None,
'cudagraph_skip_reason': None,
'distributed_ephemeral_timeout_us': None,
'duration_us': 0,
'dynamo_compile_time_before_restart_us': 0,
'dynamo_config': None,
'dynamo_cumulative_compile_time_us': 0,
'dynamo_time_before_restart_s': 0.0,
'end_time_us': 100,
'entire_frame_compile_time_s': 0.0,
'fail_reason': None,
'fail_type': None,
'fail_user_frame_filename': None,
'fail_user_frame_lineno': None,
'frame_key': '1',
'gc_time_us': 0,
'graph_input_count': 1,
'graph_node_count': 3,
'graph_op_count': 1,
'guard_count': 9,
'has_guarded_code': True,
'inductor_code_gen_cumulative_compile_time_us': 0,
'inductor_compile_time_s': 0.0,
'inductor_config': None,
'inductor_cumulative_compile_time_us': 0,
'inductor_fx_remote_cache_backend_type': None,
'inductor_fx_remote_cache_hit_count': None,
'inductor_fx_remote_cache_hit_keys': None,
'inductor_fx_remote_cache_miss_count': None,
'inductor_fx_remote_cache_miss_keys': None,
'is_forward': True,
'is_runtime': False,
'joint_graph_pass_time_us': 0,
'log_format_version': 3,
'non_compliant_ops': set(),
'num_graph_breaks': 0,
'num_triton_bundles': None,
'pgo_get_remote_code_state_time_us': None,
'pgo_put_remote_code_state_time_us': None,
'post_grad_pass_time_us': 0,
'pre_grad_pass_time_us': 0,
'python_version': None,
'recompile_reason': None,
'recompile_user_contexts': None,
'remote_cache_time_saved_s': None,
'remote_cache_version': None,
'remote_fx_graph_cache_get_time_ms': None,
'remote_fx_graph_cache_get_time_us': None,
'remote_fx_graph_cache_put_time_ms': None,
'remote_fx_graph_cache_put_time_us': None,
'restart_reasons': set(),
'runtime_cudagraphify_time_us': None,
'runtime_triton_autotune_time_us': None,
'shape_env_guard_count': 0,
'specialize_float': False,
'start_time': 0.0001,
'start_time_us': 100,
'structured_logging_overhead_s': 0.0,
'structured_logging_overhead_us': 0,
'tensorify_float_attempt': None,
'tensorify_float_failure': None,
'tensorify_float_success': None,
'triton_compile_time_us': None,
'triton_kernel_compile_times_us': None,
'triton_version': None}"""
if _IS_WINDOWS
else """\
{'accumulated_cache_size': 0,
'aot_autograd_cumulative_compile_time_us': 0,
'backend_compile_time_s': 0.0,
@ -456,6 +583,87 @@ class TestDynamoTimed(TestCase):
self.assertExpectedInline(
pprint.pformat(raw),
"""\
{'accumulated_cache_size': None,
'aot_autograd_cumulative_compile_time_us': None,
'backend_compile_time_s': None,
'backward_cumulative_compile_time_us': 0,
'cache_size': None,
'co_filename': None,
'co_firstlineno': None,
'co_name': None,
'code_gen_time_s': 0.0,
'compile_id': '1/0',
'compile_time_autotune_time_us': None,
'compliant_custom_ops': None,
'config_inline_inbuilt_nn_modules': False,
'config_suppress_errors': False,
'cuda_version': None,
'cudagraph_skip_reason': None,
'distributed_ephemeral_timeout_us': None,
'duration_us': 0,
'dynamo_compile_time_before_restart_us': None,
'dynamo_config': None,
'dynamo_cumulative_compile_time_us': None,
'dynamo_time_before_restart_s': None,
'end_time_us': 100,
'entire_frame_compile_time_s': None,
'fail_reason': None,
'fail_type': None,
'fail_user_frame_filename': None,
'fail_user_frame_lineno': None,
'frame_key': None,
'gc_time_us': None,
'graph_input_count': None,
'graph_node_count': None,
'graph_op_count': None,
'guard_count': None,
'has_guarded_code': None,
'inductor_code_gen_cumulative_compile_time_us': 0,
'inductor_compile_time_s': 0.0,
'inductor_config': None,
'inductor_cumulative_compile_time_us': 0,
'inductor_fx_remote_cache_backend_type': None,
'inductor_fx_remote_cache_hit_count': None,
'inductor_fx_remote_cache_hit_keys': None,
'inductor_fx_remote_cache_miss_count': None,
'inductor_fx_remote_cache_miss_keys': None,
'is_forward': False,
'is_runtime': False,
'joint_graph_pass_time_us': None,
'log_format_version': 3,
'non_compliant_ops': None,
'num_graph_breaks': 0,
'num_triton_bundles': None,
'pgo_get_remote_code_state_time_us': None,
'pgo_put_remote_code_state_time_us': None,
'post_grad_pass_time_us': 0,
'pre_grad_pass_time_us': None,
'python_version': None,
'recompile_reason': None,
'recompile_user_contexts': None,
'remote_cache_time_saved_s': None,
'remote_cache_version': None,
'remote_fx_graph_cache_get_time_ms': None,
'remote_fx_graph_cache_get_time_us': None,
'remote_fx_graph_cache_put_time_ms': None,
'remote_fx_graph_cache_put_time_us': None,
'restart_reasons': None,
'runtime_cudagraphify_time_us': None,
'runtime_triton_autotune_time_us': None,
'shape_env_guard_count': None,
'specialize_float': None,
'start_time': 0.0001,
'start_time_us': 100,
'structured_logging_overhead_s': 0.0,
'structured_logging_overhead_us': 0,
'tensorify_float_attempt': None,
'tensorify_float_failure': None,
'tensorify_float_success': None,
'triton_compile_time_us': None,
'triton_kernel_compile_times_us': None,
'triton_version': None}"""
if _IS_WINDOWS
else """\
{'accumulated_cache_size': None,
'aot_autograd_cumulative_compile_time_us': None,
'backend_compile_time_s': None,