From 23491519d288dedb2a54cfad5fef7fcb2ad8eade Mon Sep 17 00:00:00 2001 From: Guilherme Leobas Date: Mon, 30 Jun 2025 12:03:34 -0300 Subject: [PATCH] Fixes for CPython int/float tests (#155978) Pull Request resolved: https://github.com/pytorch/pytorch/pull/155978 Approved by: https://github.com/zou3519 --- test/dynamo/cpython/3_13/test_int.diff | 16 +++++++++++---- test/dynamo/cpython/3_13/test_int.py | 3 ++- ...lex-ComplexTest.test_truediv_zero_division | 0 ...ManagerTestCase.test_contextmanager_except | 0 ...anagerTestCase.test_contextmanager_finally | 0 ...tManagerTestCase.test_contextmanager_plain | 0 ...xtlib-ContextManagerTestCase.test_keywords | 0 ...TestContextDecorator.test_contextdecorator | 0 ...Decorator.test_contextmanager_as_decorator | 0 ...extlib-TestContextDecorator.test_decorator | 0 ...tTest.test_empty_presized_dict_in_freelist | 0 ...tTest.test_reverse_iterator_for_empty_dict | 0 ...ons-ExceptionTests.test_generator_leaking3 | 0 ...ons-ExceptionTests.test_raise_in_generator | 0 ...st_float-GeneralFloatCases.test_float_ceil | 0 ...t_float-GeneralFloatCases.test_float_floor | 0 ...est_float-GeneralFloatCases.test_float_mod | 0 ...est_float-GeneralFloatCases.test_float_pow | 0 ...13-test_float-InfNanTest.test_inf_from_str | 0 ...13-test_float-InfNanTest.test_nan_from_str | 0 ...n313-test_float-RoundTestCase.test_inf_nan | 0 ...313-test_float-RoundTestCase.test_overflow | 0 ...hrowTest.test_exception_context_with_yield | 0 ...est.test_exception_context_with_yield_from | 0 ...eption_context_with_yield_inside_generator | 0 ...IntStrDigitLimitsTests.test_max_str_digits | 0 ...LimitsTests.test_max_str_digits_edge_cases | 0 ...tStrDigitLimitsTests.test_sign_not_counted | 0 ...rDigitLimitsTests.test_underscores_ignored | 0 ...Python313-test_int-IntTestCases.test_basic | 0 ...test_int-IntTestCases.test_int_base_limits | 0 ...3-test_int-IntTestCases.test_invalid_signs | 0 ...13-test_int-IntTestCases.test_string_float | 0 ...t-PyLongModuleTests.test_pylong_str_to_int | 0 ...-test_iter-TestCase.test_iter_independence | 0 ...er-TestCase.test_nested_comprehensions_for | 0 ...r-TestCase.test_nested_comprehensions_iter | 0 ...est_iter-TestCase.test_sinkstate_enumerate | 0 ...13-test_iter-TestCase.test_sinkstate_yield | 0 .../CPython313-test_list-ListTest.test_basic | 0 ...hon313-test_list-ListTest.test_empty_slice | 0 ...Python313-test_list-ListTest.test_getslice | 0 .../CPython313-test_list-ListTest.test_slice | 0 ...t_list-ListTest.test_slice_assign_iterator | 0 ...n313-test_list-ListTest.test_step_overflow | 0 ...t-ListTest.test_tier2_invalidates_iterator | 0 .../CPython313-test_math-MathTests.test_ulp | 0 ...dict-CPythonBuiltinDictTests.test_reinsert | 0 ..._dict-CPythonBuiltinDictTests.test_setitem | 0 ...eredDictSubclassTests.test_iterators_empty | 0 ...thonOrderedDictSubclassTests.test_reinsert | 0 ...ythonOrderedDictSubclassTests.test_setitem | 0 ...dict-CPythonOrderedDictTests.test_fromkeys | 0 ...ythonOrderedDictTests.test_iterators_empty | 0 ...dict-CPythonOrderedDictTests.test_reinsert | 0 ..._dict-CPythonOrderedDictTests.test_setitem | 0 ...raise-TestContext.test_c_exception_context | 0 ...3-test_raise-TestContext.test_cycle_broken | 0 ...-test_raise-TestContext.test_raise_finally | 0 ...set-TestSet.test_remove_keyerror_unpacking | 0 ...-TestSet.test_set_literal_evaluation_order | 0 ...Subclass.test_set_literal_evaluation_order | 0 ...rateSortUndecorate.test_key_with_exception | 0 ...-TestOptimizedCompares.test_none_in_tuples | 0 ...eExceptionTests.test_exc_info_no_exception | 0 ...test_sys-SysModuleTest.test_implementation | 0 ...thon313-test_tuple-TupleTest.test_getslice | 0 .../CPython313-test_tuple-TupleTest.test_iadd | 0 .../CPython313-test_tuple-TupleTest.test_imul | 0 ...3-test_tuple-TupleTest.test_tupleresizebug | 0 ...t_fallback_warns_when_warnings_are_enabled | 0 test/functorch/test_vmap.py | 1 + torch/_dynamo/exc.py | 2 +- torch/_dynamo/polyfills/__init__.py | 9 +++++++++ torch/_dynamo/polyfills/sys.py | 5 +++++ torch/_dynamo/test_case.py | 5 +++-- torch/_dynamo/variables/builtin.py | 7 ++++++- torch/_dynamo/variables/constant.py | 20 +++++++++++++++---- 78 files changed, 55 insertions(+), 13 deletions(-) delete mode 100644 test/dynamo_expected_failures/CPython313-test_complex-ComplexTest.test_truediv_zero_division delete mode 100644 test/dynamo_expected_failures/CPython313-test_contextlib-ContextManagerTestCase.test_contextmanager_except delete mode 100644 test/dynamo_expected_failures/CPython313-test_contextlib-ContextManagerTestCase.test_contextmanager_finally delete mode 100644 test/dynamo_expected_failures/CPython313-test_contextlib-ContextManagerTestCase.test_contextmanager_plain delete mode 100644 test/dynamo_expected_failures/CPython313-test_contextlib-ContextManagerTestCase.test_keywords delete mode 100644 test/dynamo_expected_failures/CPython313-test_contextlib-TestContextDecorator.test_contextdecorator delete mode 100644 test/dynamo_expected_failures/CPython313-test_contextlib-TestContextDecorator.test_contextmanager_as_decorator delete mode 100644 test/dynamo_expected_failures/CPython313-test_contextlib-TestContextDecorator.test_decorator delete mode 100644 test/dynamo_expected_failures/CPython313-test_dict-DictTest.test_empty_presized_dict_in_freelist delete mode 100644 test/dynamo_expected_failures/CPython313-test_dict-DictTest.test_reverse_iterator_for_empty_dict delete mode 100644 test/dynamo_expected_failures/CPython313-test_exceptions-ExceptionTests.test_generator_leaking3 delete mode 100644 test/dynamo_expected_failures/CPython313-test_exceptions-ExceptionTests.test_raise_in_generator delete mode 100644 test/dynamo_expected_failures/CPython313-test_float-GeneralFloatCases.test_float_ceil delete mode 100644 test/dynamo_expected_failures/CPython313-test_float-GeneralFloatCases.test_float_floor delete mode 100644 test/dynamo_expected_failures/CPython313-test_float-GeneralFloatCases.test_float_mod delete mode 100644 test/dynamo_expected_failures/CPython313-test_float-GeneralFloatCases.test_float_pow delete mode 100644 test/dynamo_expected_failures/CPython313-test_float-InfNanTest.test_inf_from_str delete mode 100644 test/dynamo_expected_failures/CPython313-test_float-InfNanTest.test_nan_from_str delete mode 100644 test/dynamo_expected_failures/CPython313-test_float-RoundTestCase.test_inf_nan delete mode 100644 test/dynamo_expected_failures/CPython313-test_float-RoundTestCase.test_overflow delete mode 100644 test/dynamo_expected_failures/CPython313-test_generators-GeneratorThrowTest.test_exception_context_with_yield delete mode 100644 test/dynamo_expected_failures/CPython313-test_generators-GeneratorThrowTest.test_exception_context_with_yield_from delete mode 100644 test/dynamo_expected_failures/CPython313-test_generators-GeneratorThrowTest.test_exception_context_with_yield_inside_generator delete mode 100644 test/dynamo_expected_failures/CPython313-test_int-IntStrDigitLimitsTests.test_max_str_digits delete mode 100644 test/dynamo_expected_failures/CPython313-test_int-IntStrDigitLimitsTests.test_max_str_digits_edge_cases delete mode 100644 test/dynamo_expected_failures/CPython313-test_int-IntStrDigitLimitsTests.test_sign_not_counted delete mode 100644 test/dynamo_expected_failures/CPython313-test_int-IntStrDigitLimitsTests.test_underscores_ignored delete mode 100644 test/dynamo_expected_failures/CPython313-test_int-IntTestCases.test_basic delete mode 100644 test/dynamo_expected_failures/CPython313-test_int-IntTestCases.test_int_base_limits delete mode 100644 test/dynamo_expected_failures/CPython313-test_int-IntTestCases.test_invalid_signs delete mode 100644 test/dynamo_expected_failures/CPython313-test_int-IntTestCases.test_string_float delete mode 100644 test/dynamo_expected_failures/CPython313-test_int-PyLongModuleTests.test_pylong_str_to_int delete mode 100644 test/dynamo_expected_failures/CPython313-test_iter-TestCase.test_iter_independence delete mode 100644 test/dynamo_expected_failures/CPython313-test_iter-TestCase.test_nested_comprehensions_for delete mode 100644 test/dynamo_expected_failures/CPython313-test_iter-TestCase.test_nested_comprehensions_iter delete mode 100644 test/dynamo_expected_failures/CPython313-test_iter-TestCase.test_sinkstate_enumerate delete mode 100644 test/dynamo_expected_failures/CPython313-test_iter-TestCase.test_sinkstate_yield delete mode 100644 test/dynamo_expected_failures/CPython313-test_list-ListTest.test_basic delete mode 100644 test/dynamo_expected_failures/CPython313-test_list-ListTest.test_empty_slice delete mode 100644 test/dynamo_expected_failures/CPython313-test_list-ListTest.test_getslice delete mode 100644 test/dynamo_expected_failures/CPython313-test_list-ListTest.test_slice delete mode 100644 test/dynamo_expected_failures/CPython313-test_list-ListTest.test_slice_assign_iterator delete mode 100644 test/dynamo_expected_failures/CPython313-test_list-ListTest.test_step_overflow delete mode 100644 test/dynamo_expected_failures/CPython313-test_list-ListTest.test_tier2_invalidates_iterator delete mode 100644 test/dynamo_expected_failures/CPython313-test_math-MathTests.test_ulp delete mode 100644 test/dynamo_expected_failures/CPython313-test_ordered_dict-CPythonBuiltinDictTests.test_reinsert delete mode 100644 test/dynamo_expected_failures/CPython313-test_ordered_dict-CPythonBuiltinDictTests.test_setitem delete mode 100644 test/dynamo_expected_failures/CPython313-test_ordered_dict-CPythonOrderedDictSubclassTests.test_iterators_empty delete mode 100644 test/dynamo_expected_failures/CPython313-test_ordered_dict-CPythonOrderedDictSubclassTests.test_reinsert delete mode 100644 test/dynamo_expected_failures/CPython313-test_ordered_dict-CPythonOrderedDictSubclassTests.test_setitem delete mode 100644 test/dynamo_expected_failures/CPython313-test_ordered_dict-CPythonOrderedDictTests.test_fromkeys delete mode 100644 test/dynamo_expected_failures/CPython313-test_ordered_dict-CPythonOrderedDictTests.test_iterators_empty delete mode 100644 test/dynamo_expected_failures/CPython313-test_ordered_dict-CPythonOrderedDictTests.test_reinsert delete mode 100644 test/dynamo_expected_failures/CPython313-test_ordered_dict-CPythonOrderedDictTests.test_setitem delete mode 100644 test/dynamo_expected_failures/CPython313-test_raise-TestContext.test_c_exception_context delete mode 100644 test/dynamo_expected_failures/CPython313-test_raise-TestContext.test_cycle_broken delete mode 100644 test/dynamo_expected_failures/CPython313-test_raise-TestContext.test_raise_finally delete mode 100644 test/dynamo_expected_failures/CPython313-test_set-TestSet.test_remove_keyerror_unpacking delete mode 100644 test/dynamo_expected_failures/CPython313-test_set-TestSet.test_set_literal_evaluation_order delete mode 100644 test/dynamo_expected_failures/CPython313-test_set-TestSetSubclass.test_set_literal_evaluation_order delete mode 100644 test/dynamo_expected_failures/CPython313-test_sort-TestDecorateSortUndecorate.test_key_with_exception delete mode 100644 test/dynamo_expected_failures/CPython313-test_sort-TestOptimizedCompares.test_none_in_tuples delete mode 100644 test/dynamo_expected_failures/CPython313-test_sys-ActiveExceptionTests.test_exc_info_no_exception delete mode 100644 test/dynamo_expected_failures/CPython313-test_sys-SysModuleTest.test_implementation delete mode 100644 test/dynamo_expected_failures/CPython313-test_tuple-TupleTest.test_getslice delete mode 100644 test/dynamo_expected_failures/CPython313-test_tuple-TupleTest.test_iadd delete mode 100644 test/dynamo_expected_failures/CPython313-test_tuple-TupleTest.test_imul delete mode 100644 test/dynamo_expected_failures/CPython313-test_tuple-TupleTest.test_tupleresizebug delete mode 100644 test/dynamo_expected_failures/TestVmapAPI.test_fallback_warns_when_warnings_are_enabled diff --git a/test/dynamo/cpython/3_13/test_int.diff b/test/dynamo/cpython/3_13/test_int.diff index a9e4880015e5..257cbbd37686 100644 --- a/test/dynamo/cpython/3_13/test_int.diff +++ b/test/dynamo/cpython/3_13/test_int.diff @@ -1,5 +1,5 @@ diff --git a/test/dynamo/cpython/3_13/test_int.py b/test/dynamo/cpython/3_13/test_int.py -index 48825f46911..ac7aeacbc01 100644 +index 48825f46911..4ab200372ea 100644 --- a/test/dynamo/cpython/3_13/test_int.py +++ b/test/dynamo/cpython/3_13/test_int.py @@ -1,13 +1,137 @@ @@ -153,7 +153,15 @@ index 48825f46911..ac7aeacbc01 100644 def test_basic(self): self.assertEqual(int(314), 314) -@@ -607,7 +731,7 @@ class IntTestCases(unittest.TestCase): +@@ -566,6 +690,7 @@ class IntTestCases(unittest.TestCase): + self.assertEqual(n, 1) + self.assertIs(type(n), IntSubclass) + ++ @skipIfTorchDynamo("flaky under dynamo") + def test_error_message(self): + def check(s, base=None): + with self.assertRaises(ValueError, +@@ -607,7 +732,7 @@ class IntTestCases(unittest.TestCase): self.assertEqual(int('1_2_3_4_5_6_7', 32), 1144132807) @@ -162,7 +170,7 @@ index 48825f46911..ac7aeacbc01 100644 int_class = int # Override this in subclasses to reuse the suite. -@@ -818,7 +942,7 @@ class IntSubclassStrDigitLimitsTests(IntStrDigitLimitsTests): +@@ -818,7 +943,7 @@ class IntSubclassStrDigitLimitsTests(IntStrDigitLimitsTests): int_class = IntSubclass @@ -171,7 +179,7 @@ index 48825f46911..ac7aeacbc01 100644 # Tests of the functions in _pylong.py. Those get used when the # number of digits in the input values are large enough. -@@ -922,4 +1046,4 @@ class PyLongModuleTests(unittest.TestCase): +@@ -922,4 +1047,4 @@ class PyLongModuleTests(unittest.TestCase): bits <<= 1 if __name__ == "__main__": diff --git a/test/dynamo/cpython/3_13/test_int.py b/test/dynamo/cpython/3_13/test_int.py index 072c591e073a..4ab200372ea2 100644 --- a/test/dynamo/cpython/3_13/test_int.py +++ b/test/dynamo/cpython/3_13/test_int.py @@ -9,7 +9,7 @@ import torch import torch._dynamo.test_case import unittest from torch._dynamo.test_case import CPythonTestCase -from torch.testing._internal.common_utils import run_tests +from torch.testing._internal.common_utils import run_tests, skipIfTorchDynamo __TestCase = CPythonTestCase @@ -690,6 +690,7 @@ class IntTestCases(__TestCase): self.assertEqual(n, 1) self.assertIs(type(n), IntSubclass) + @skipIfTorchDynamo("flaky under dynamo") def test_error_message(self): def check(s, base=None): with self.assertRaises(ValueError, diff --git a/test/dynamo_expected_failures/CPython313-test_complex-ComplexTest.test_truediv_zero_division b/test/dynamo_expected_failures/CPython313-test_complex-ComplexTest.test_truediv_zero_division deleted file mode 100644 index e69de29bb2d1..000000000000 diff --git a/test/dynamo_expected_failures/CPython313-test_contextlib-ContextManagerTestCase.test_contextmanager_except b/test/dynamo_expected_failures/CPython313-test_contextlib-ContextManagerTestCase.test_contextmanager_except deleted file mode 100644 index e69de29bb2d1..000000000000 diff --git a/test/dynamo_expected_failures/CPython313-test_contextlib-ContextManagerTestCase.test_contextmanager_finally b/test/dynamo_expected_failures/CPython313-test_contextlib-ContextManagerTestCase.test_contextmanager_finally deleted file mode 100644 index e69de29bb2d1..000000000000 diff --git a/test/dynamo_expected_failures/CPython313-test_contextlib-ContextManagerTestCase.test_contextmanager_plain b/test/dynamo_expected_failures/CPython313-test_contextlib-ContextManagerTestCase.test_contextmanager_plain deleted file mode 100644 index e69de29bb2d1..000000000000 diff --git a/test/dynamo_expected_failures/CPython313-test_contextlib-ContextManagerTestCase.test_keywords b/test/dynamo_expected_failures/CPython313-test_contextlib-ContextManagerTestCase.test_keywords deleted file mode 100644 index e69de29bb2d1..000000000000 diff --git a/test/dynamo_expected_failures/CPython313-test_contextlib-TestContextDecorator.test_contextdecorator b/test/dynamo_expected_failures/CPython313-test_contextlib-TestContextDecorator.test_contextdecorator deleted file mode 100644 index e69de29bb2d1..000000000000 diff --git a/test/dynamo_expected_failures/CPython313-test_contextlib-TestContextDecorator.test_contextmanager_as_decorator b/test/dynamo_expected_failures/CPython313-test_contextlib-TestContextDecorator.test_contextmanager_as_decorator deleted file mode 100644 index e69de29bb2d1..000000000000 diff --git a/test/dynamo_expected_failures/CPython313-test_contextlib-TestContextDecorator.test_decorator b/test/dynamo_expected_failures/CPython313-test_contextlib-TestContextDecorator.test_decorator deleted file mode 100644 index e69de29bb2d1..000000000000 diff --git a/test/dynamo_expected_failures/CPython313-test_dict-DictTest.test_empty_presized_dict_in_freelist b/test/dynamo_expected_failures/CPython313-test_dict-DictTest.test_empty_presized_dict_in_freelist deleted file mode 100644 index e69de29bb2d1..000000000000 diff --git a/test/dynamo_expected_failures/CPython313-test_dict-DictTest.test_reverse_iterator_for_empty_dict b/test/dynamo_expected_failures/CPython313-test_dict-DictTest.test_reverse_iterator_for_empty_dict deleted file mode 100644 index e69de29bb2d1..000000000000 diff --git a/test/dynamo_expected_failures/CPython313-test_exceptions-ExceptionTests.test_generator_leaking3 b/test/dynamo_expected_failures/CPython313-test_exceptions-ExceptionTests.test_generator_leaking3 deleted file mode 100644 index e69de29bb2d1..000000000000 diff --git a/test/dynamo_expected_failures/CPython313-test_exceptions-ExceptionTests.test_raise_in_generator b/test/dynamo_expected_failures/CPython313-test_exceptions-ExceptionTests.test_raise_in_generator deleted file mode 100644 index e69de29bb2d1..000000000000 diff --git a/test/dynamo_expected_failures/CPython313-test_float-GeneralFloatCases.test_float_ceil b/test/dynamo_expected_failures/CPython313-test_float-GeneralFloatCases.test_float_ceil deleted file mode 100644 index e69de29bb2d1..000000000000 diff --git a/test/dynamo_expected_failures/CPython313-test_float-GeneralFloatCases.test_float_floor b/test/dynamo_expected_failures/CPython313-test_float-GeneralFloatCases.test_float_floor deleted file mode 100644 index e69de29bb2d1..000000000000 diff --git a/test/dynamo_expected_failures/CPython313-test_float-GeneralFloatCases.test_float_mod b/test/dynamo_expected_failures/CPython313-test_float-GeneralFloatCases.test_float_mod deleted file mode 100644 index e69de29bb2d1..000000000000 diff --git a/test/dynamo_expected_failures/CPython313-test_float-GeneralFloatCases.test_float_pow b/test/dynamo_expected_failures/CPython313-test_float-GeneralFloatCases.test_float_pow deleted file mode 100644 index e69de29bb2d1..000000000000 diff --git a/test/dynamo_expected_failures/CPython313-test_float-InfNanTest.test_inf_from_str b/test/dynamo_expected_failures/CPython313-test_float-InfNanTest.test_inf_from_str deleted file mode 100644 index e69de29bb2d1..000000000000 diff --git a/test/dynamo_expected_failures/CPython313-test_float-InfNanTest.test_nan_from_str b/test/dynamo_expected_failures/CPython313-test_float-InfNanTest.test_nan_from_str deleted file mode 100644 index e69de29bb2d1..000000000000 diff --git a/test/dynamo_expected_failures/CPython313-test_float-RoundTestCase.test_inf_nan b/test/dynamo_expected_failures/CPython313-test_float-RoundTestCase.test_inf_nan deleted file mode 100644 index e69de29bb2d1..000000000000 diff --git a/test/dynamo_expected_failures/CPython313-test_float-RoundTestCase.test_overflow b/test/dynamo_expected_failures/CPython313-test_float-RoundTestCase.test_overflow deleted file mode 100644 index e69de29bb2d1..000000000000 diff --git a/test/dynamo_expected_failures/CPython313-test_generators-GeneratorThrowTest.test_exception_context_with_yield b/test/dynamo_expected_failures/CPython313-test_generators-GeneratorThrowTest.test_exception_context_with_yield deleted file mode 100644 index e69de29bb2d1..000000000000 diff --git a/test/dynamo_expected_failures/CPython313-test_generators-GeneratorThrowTest.test_exception_context_with_yield_from b/test/dynamo_expected_failures/CPython313-test_generators-GeneratorThrowTest.test_exception_context_with_yield_from deleted file mode 100644 index e69de29bb2d1..000000000000 diff --git a/test/dynamo_expected_failures/CPython313-test_generators-GeneratorThrowTest.test_exception_context_with_yield_inside_generator b/test/dynamo_expected_failures/CPython313-test_generators-GeneratorThrowTest.test_exception_context_with_yield_inside_generator deleted file mode 100644 index e69de29bb2d1..000000000000 diff --git a/test/dynamo_expected_failures/CPython313-test_int-IntStrDigitLimitsTests.test_max_str_digits b/test/dynamo_expected_failures/CPython313-test_int-IntStrDigitLimitsTests.test_max_str_digits deleted file mode 100644 index e69de29bb2d1..000000000000 diff --git a/test/dynamo_expected_failures/CPython313-test_int-IntStrDigitLimitsTests.test_max_str_digits_edge_cases b/test/dynamo_expected_failures/CPython313-test_int-IntStrDigitLimitsTests.test_max_str_digits_edge_cases deleted file mode 100644 index e69de29bb2d1..000000000000 diff --git a/test/dynamo_expected_failures/CPython313-test_int-IntStrDigitLimitsTests.test_sign_not_counted b/test/dynamo_expected_failures/CPython313-test_int-IntStrDigitLimitsTests.test_sign_not_counted deleted file mode 100644 index e69de29bb2d1..000000000000 diff --git a/test/dynamo_expected_failures/CPython313-test_int-IntStrDigitLimitsTests.test_underscores_ignored b/test/dynamo_expected_failures/CPython313-test_int-IntStrDigitLimitsTests.test_underscores_ignored deleted file mode 100644 index e69de29bb2d1..000000000000 diff --git a/test/dynamo_expected_failures/CPython313-test_int-IntTestCases.test_basic b/test/dynamo_expected_failures/CPython313-test_int-IntTestCases.test_basic deleted file mode 100644 index e69de29bb2d1..000000000000 diff --git a/test/dynamo_expected_failures/CPython313-test_int-IntTestCases.test_int_base_limits b/test/dynamo_expected_failures/CPython313-test_int-IntTestCases.test_int_base_limits deleted file mode 100644 index e69de29bb2d1..000000000000 diff --git a/test/dynamo_expected_failures/CPython313-test_int-IntTestCases.test_invalid_signs b/test/dynamo_expected_failures/CPython313-test_int-IntTestCases.test_invalid_signs deleted file mode 100644 index e69de29bb2d1..000000000000 diff --git a/test/dynamo_expected_failures/CPython313-test_int-IntTestCases.test_string_float b/test/dynamo_expected_failures/CPython313-test_int-IntTestCases.test_string_float deleted file mode 100644 index e69de29bb2d1..000000000000 diff --git a/test/dynamo_expected_failures/CPython313-test_int-PyLongModuleTests.test_pylong_str_to_int b/test/dynamo_expected_failures/CPython313-test_int-PyLongModuleTests.test_pylong_str_to_int deleted file mode 100644 index e69de29bb2d1..000000000000 diff --git a/test/dynamo_expected_failures/CPython313-test_iter-TestCase.test_iter_independence b/test/dynamo_expected_failures/CPython313-test_iter-TestCase.test_iter_independence deleted file mode 100644 index e69de29bb2d1..000000000000 diff --git a/test/dynamo_expected_failures/CPython313-test_iter-TestCase.test_nested_comprehensions_for b/test/dynamo_expected_failures/CPython313-test_iter-TestCase.test_nested_comprehensions_for deleted file mode 100644 index e69de29bb2d1..000000000000 diff --git a/test/dynamo_expected_failures/CPython313-test_iter-TestCase.test_nested_comprehensions_iter b/test/dynamo_expected_failures/CPython313-test_iter-TestCase.test_nested_comprehensions_iter deleted file mode 100644 index e69de29bb2d1..000000000000 diff --git a/test/dynamo_expected_failures/CPython313-test_iter-TestCase.test_sinkstate_enumerate b/test/dynamo_expected_failures/CPython313-test_iter-TestCase.test_sinkstate_enumerate deleted file mode 100644 index e69de29bb2d1..000000000000 diff --git a/test/dynamo_expected_failures/CPython313-test_iter-TestCase.test_sinkstate_yield b/test/dynamo_expected_failures/CPython313-test_iter-TestCase.test_sinkstate_yield deleted file mode 100644 index e69de29bb2d1..000000000000 diff --git a/test/dynamo_expected_failures/CPython313-test_list-ListTest.test_basic b/test/dynamo_expected_failures/CPython313-test_list-ListTest.test_basic deleted file mode 100644 index e69de29bb2d1..000000000000 diff --git a/test/dynamo_expected_failures/CPython313-test_list-ListTest.test_empty_slice b/test/dynamo_expected_failures/CPython313-test_list-ListTest.test_empty_slice deleted file mode 100644 index e69de29bb2d1..000000000000 diff --git a/test/dynamo_expected_failures/CPython313-test_list-ListTest.test_getslice b/test/dynamo_expected_failures/CPython313-test_list-ListTest.test_getslice deleted file mode 100644 index e69de29bb2d1..000000000000 diff --git a/test/dynamo_expected_failures/CPython313-test_list-ListTest.test_slice b/test/dynamo_expected_failures/CPython313-test_list-ListTest.test_slice deleted file mode 100644 index e69de29bb2d1..000000000000 diff --git a/test/dynamo_expected_failures/CPython313-test_list-ListTest.test_slice_assign_iterator b/test/dynamo_expected_failures/CPython313-test_list-ListTest.test_slice_assign_iterator deleted file mode 100644 index e69de29bb2d1..000000000000 diff --git a/test/dynamo_expected_failures/CPython313-test_list-ListTest.test_step_overflow b/test/dynamo_expected_failures/CPython313-test_list-ListTest.test_step_overflow deleted file mode 100644 index e69de29bb2d1..000000000000 diff --git a/test/dynamo_expected_failures/CPython313-test_list-ListTest.test_tier2_invalidates_iterator b/test/dynamo_expected_failures/CPython313-test_list-ListTest.test_tier2_invalidates_iterator deleted file mode 100644 index e69de29bb2d1..000000000000 diff --git a/test/dynamo_expected_failures/CPython313-test_math-MathTests.test_ulp b/test/dynamo_expected_failures/CPython313-test_math-MathTests.test_ulp deleted file mode 100644 index e69de29bb2d1..000000000000 diff --git a/test/dynamo_expected_failures/CPython313-test_ordered_dict-CPythonBuiltinDictTests.test_reinsert b/test/dynamo_expected_failures/CPython313-test_ordered_dict-CPythonBuiltinDictTests.test_reinsert deleted file mode 100644 index e69de29bb2d1..000000000000 diff --git a/test/dynamo_expected_failures/CPython313-test_ordered_dict-CPythonBuiltinDictTests.test_setitem b/test/dynamo_expected_failures/CPython313-test_ordered_dict-CPythonBuiltinDictTests.test_setitem deleted file mode 100644 index e69de29bb2d1..000000000000 diff --git a/test/dynamo_expected_failures/CPython313-test_ordered_dict-CPythonOrderedDictSubclassTests.test_iterators_empty b/test/dynamo_expected_failures/CPython313-test_ordered_dict-CPythonOrderedDictSubclassTests.test_iterators_empty deleted file mode 100644 index e69de29bb2d1..000000000000 diff --git a/test/dynamo_expected_failures/CPython313-test_ordered_dict-CPythonOrderedDictSubclassTests.test_reinsert b/test/dynamo_expected_failures/CPython313-test_ordered_dict-CPythonOrderedDictSubclassTests.test_reinsert deleted file mode 100644 index e69de29bb2d1..000000000000 diff --git a/test/dynamo_expected_failures/CPython313-test_ordered_dict-CPythonOrderedDictSubclassTests.test_setitem b/test/dynamo_expected_failures/CPython313-test_ordered_dict-CPythonOrderedDictSubclassTests.test_setitem deleted file mode 100644 index e69de29bb2d1..000000000000 diff --git a/test/dynamo_expected_failures/CPython313-test_ordered_dict-CPythonOrderedDictTests.test_fromkeys b/test/dynamo_expected_failures/CPython313-test_ordered_dict-CPythonOrderedDictTests.test_fromkeys deleted file mode 100644 index e69de29bb2d1..000000000000 diff --git a/test/dynamo_expected_failures/CPython313-test_ordered_dict-CPythonOrderedDictTests.test_iterators_empty b/test/dynamo_expected_failures/CPython313-test_ordered_dict-CPythonOrderedDictTests.test_iterators_empty deleted file mode 100644 index e69de29bb2d1..000000000000 diff --git a/test/dynamo_expected_failures/CPython313-test_ordered_dict-CPythonOrderedDictTests.test_reinsert b/test/dynamo_expected_failures/CPython313-test_ordered_dict-CPythonOrderedDictTests.test_reinsert deleted file mode 100644 index e69de29bb2d1..000000000000 diff --git a/test/dynamo_expected_failures/CPython313-test_ordered_dict-CPythonOrderedDictTests.test_setitem b/test/dynamo_expected_failures/CPython313-test_ordered_dict-CPythonOrderedDictTests.test_setitem deleted file mode 100644 index e69de29bb2d1..000000000000 diff --git a/test/dynamo_expected_failures/CPython313-test_raise-TestContext.test_c_exception_context b/test/dynamo_expected_failures/CPython313-test_raise-TestContext.test_c_exception_context deleted file mode 100644 index e69de29bb2d1..000000000000 diff --git a/test/dynamo_expected_failures/CPython313-test_raise-TestContext.test_cycle_broken b/test/dynamo_expected_failures/CPython313-test_raise-TestContext.test_cycle_broken deleted file mode 100644 index e69de29bb2d1..000000000000 diff --git a/test/dynamo_expected_failures/CPython313-test_raise-TestContext.test_raise_finally b/test/dynamo_expected_failures/CPython313-test_raise-TestContext.test_raise_finally deleted file mode 100644 index e69de29bb2d1..000000000000 diff --git a/test/dynamo_expected_failures/CPython313-test_set-TestSet.test_remove_keyerror_unpacking b/test/dynamo_expected_failures/CPython313-test_set-TestSet.test_remove_keyerror_unpacking deleted file mode 100644 index e69de29bb2d1..000000000000 diff --git a/test/dynamo_expected_failures/CPython313-test_set-TestSet.test_set_literal_evaluation_order b/test/dynamo_expected_failures/CPython313-test_set-TestSet.test_set_literal_evaluation_order deleted file mode 100644 index e69de29bb2d1..000000000000 diff --git a/test/dynamo_expected_failures/CPython313-test_set-TestSetSubclass.test_set_literal_evaluation_order b/test/dynamo_expected_failures/CPython313-test_set-TestSetSubclass.test_set_literal_evaluation_order deleted file mode 100644 index e69de29bb2d1..000000000000 diff --git a/test/dynamo_expected_failures/CPython313-test_sort-TestDecorateSortUndecorate.test_key_with_exception b/test/dynamo_expected_failures/CPython313-test_sort-TestDecorateSortUndecorate.test_key_with_exception deleted file mode 100644 index e69de29bb2d1..000000000000 diff --git a/test/dynamo_expected_failures/CPython313-test_sort-TestOptimizedCompares.test_none_in_tuples b/test/dynamo_expected_failures/CPython313-test_sort-TestOptimizedCompares.test_none_in_tuples deleted file mode 100644 index e69de29bb2d1..000000000000 diff --git a/test/dynamo_expected_failures/CPython313-test_sys-ActiveExceptionTests.test_exc_info_no_exception b/test/dynamo_expected_failures/CPython313-test_sys-ActiveExceptionTests.test_exc_info_no_exception deleted file mode 100644 index e69de29bb2d1..000000000000 diff --git a/test/dynamo_expected_failures/CPython313-test_sys-SysModuleTest.test_implementation b/test/dynamo_expected_failures/CPython313-test_sys-SysModuleTest.test_implementation deleted file mode 100644 index e69de29bb2d1..000000000000 diff --git a/test/dynamo_expected_failures/CPython313-test_tuple-TupleTest.test_getslice b/test/dynamo_expected_failures/CPython313-test_tuple-TupleTest.test_getslice deleted file mode 100644 index e69de29bb2d1..000000000000 diff --git a/test/dynamo_expected_failures/CPython313-test_tuple-TupleTest.test_iadd b/test/dynamo_expected_failures/CPython313-test_tuple-TupleTest.test_iadd deleted file mode 100644 index e69de29bb2d1..000000000000 diff --git a/test/dynamo_expected_failures/CPython313-test_tuple-TupleTest.test_imul b/test/dynamo_expected_failures/CPython313-test_tuple-TupleTest.test_imul deleted file mode 100644 index e69de29bb2d1..000000000000 diff --git a/test/dynamo_expected_failures/CPython313-test_tuple-TupleTest.test_tupleresizebug b/test/dynamo_expected_failures/CPython313-test_tuple-TupleTest.test_tupleresizebug deleted file mode 100644 index e69de29bb2d1..000000000000 diff --git a/test/dynamo_expected_failures/TestVmapAPI.test_fallback_warns_when_warnings_are_enabled b/test/dynamo_expected_failures/TestVmapAPI.test_fallback_warns_when_warnings_are_enabled deleted file mode 100644 index e69de29bb2d1..000000000000 diff --git a/test/functorch/test_vmap.py b/test/functorch/test_vmap.py index 1222e8905978..1c2481499851 100644 --- a/test/functorch/test_vmap.py +++ b/test/functorch/test_vmap.py @@ -734,6 +734,7 @@ class TestVmapAPI(TestCase): # warning, not a warning from the vmap fallback path. self.assertEqual(len(wa), 1) + @skipIfTorchDynamo("Flaky test") @unittest.expectedFailure def test_fallback_warns_when_warnings_are_enabled(self): # NB: One day we will implement a batching rule for torch.atan2. diff --git a/torch/_dynamo/exc.py b/torch/_dynamo/exc.py index 6287ba85797d..84241eb16833 100644 --- a/torch/_dynamo/exc.py +++ b/torch/_dynamo/exc.py @@ -374,7 +374,7 @@ def raise_observed_exception( # stack and raise the exception. exception_vt = BuiltinVariable(exc_type).call_function(tx, args or [], kwargs or {}) # type: ignore[arg-type] tx.exn_vt_stack.set_current_exception(exception_vt) - raise observed_exception_map[exc_type] + raise get_dynamo_observed_exception(exc_type) def handle_observed_exception(tx: Any) -> None: diff --git a/torch/_dynamo/polyfills/__init__.py b/torch/_dynamo/polyfills/__init__.py index c0722999fbec..4b3d911e202b 100644 --- a/torch/_dynamo/polyfills/__init__.py +++ b/torch/_dynamo/polyfills/__init__.py @@ -186,6 +186,15 @@ def set_difference_update(set1, *others): set1.update(result) +def assert_multi_line_equal(self_, first, second, msg=None): + return self_.assertTrue(first == second, msg) + + +# The original impl. uses difflib +def assert_sequence_equal(self_, seq1, seq2, msg=None, seq_type=None): + return self_.assertTrue(seq1 == seq2, msg) + + def getattr_and_trace(*args, **kwargs): wrapper_obj = args[0] attr_name = args[1] diff --git a/torch/_dynamo/polyfills/sys.py b/torch/_dynamo/polyfills/sys.py index 2504d2b6fcab..b7f6b5eff3bb 100644 --- a/torch/_dynamo/polyfills/sys.py +++ b/torch/_dynamo/polyfills/sys.py @@ -23,3 +23,8 @@ def intern(string: str, /) -> str: @substitute_in_graph(sys.getrecursionlimit, can_constant_fold_through=True) def getrecursionlimit() -> int: return sys.getrecursionlimit() + + +@substitute_in_graph(sys.get_int_max_str_digits, can_constant_fold_through=True) +def get_int_max_str_digits() -> int: + return sys.get_int_max_str_digits() diff --git a/torch/_dynamo/test_case.py b/torch/_dynamo/test_case.py index 7cd5dbc90d6c..dc7a44684051 100644 --- a/torch/_dynamo/test_case.py +++ b/torch/_dynamo/test_case.py @@ -22,6 +22,7 @@ from typing import Union import torch import torch.testing +from torch._dynamo import polyfills from torch._logging._internal import trace_log from torch.testing._internal.common_utils import ( # type: ignore[attr-defined] IS_WINDOWS, @@ -136,8 +137,8 @@ class CPythonTestCase(TestCase): assertRegex = unittest.TestCase.assertRegex assertNotRegex = unittest.TestCase.assertNotRegex assertCountEqual = unittest.TestCase.assertCountEqual - assertMultiLineEqual = unittest.TestCase.assertMultiLineEqual - assertSequenceEqual = unittest.TestCase.assertSequenceEqual + assertMultiLineEqual = polyfills.assert_multi_line_equal + assertSequenceEqual = polyfills.assert_sequence_equal assertListEqual = unittest.TestCase.assertListEqual assertTupleEqual = unittest.TestCase.assertTupleEqual assertSetEqual = unittest.TestCase.assertSetEqual diff --git a/torch/_dynamo/variables/builtin.py b/torch/_dynamo/variables/builtin.py index 2b12f25dd725..67fc6dc25248 100644 --- a/torch/_dynamo/variables/builtin.py +++ b/torch/_dynamo/variables/builtin.py @@ -1277,6 +1277,12 @@ class BuiltinVariable(VariableTracker): if isinstance(args[0], ConstantVariable): return args[0].call_method(tx, name, args[1:], kwargs) + if self.fn is float and len(args) >= 1: + if isinstance(args[0], ConstantVariable): + return ConstantVariable.create( + getattr(float, name)(args[0].as_python_constant()) + ) + return super().call_method(tx, name, args, kwargs) def _call_int_float(self, tx: "InstructionTranslator", arg): @@ -2062,7 +2068,6 @@ class BuiltinVariable(VariableTracker): "assertNotWarns", "assertWarnsRegex", "assertDictEqual", - "assertSequenceEqual", "assertWarns", ) ): diff --git a/torch/_dynamo/variables/constant.py b/torch/_dynamo/variables/constant.py index 8f3bd9d3965e..ce375975bed4 100644 --- a/torch/_dynamo/variables/constant.py +++ b/torch/_dynamo/variables/constant.py @@ -173,7 +173,14 @@ its type to `common_constant_types`. raise_observed_exception(type(e), tx) elif isinstance(self.value, (float, int)): if not (args or kwargs): - return ConstantVariable.create(getattr(self.value, name)()) + try: + return ConstantVariable.create(getattr(self.value, name)()) + except (OverflowError, ValueError) as exc: + raise_observed_exception( + type(exc), + tx, + args=list(map(ConstantVariable.create, exc.args)), + ) if ( hasattr(operator, name) and len(args) == 1 @@ -203,9 +210,14 @@ its type to `common_constant_types`. if name == "__len__" and not (args or kwargs): return ConstantVariable.create(len(self.value)) elif name == "__round__" and len(args) == 1 and args[0].is_python_constant(): - return ConstantVariable.create( - round(self.value, args[0].as_python_constant()) - ) + try: + return ConstantVariable.create( + round(self.value, args[0].as_python_constant()) + ) + except Exception as e: + raise_observed_exception( + type(e), tx, args=list(map(ConstantVariable.create, e.args)) + ) elif name == "__contains__" and len(args) == 1 and args[0].is_python_constant(): assert not kwargs search = args[0].as_python_constant()