pytorch - 💡(How to fix) Fix DISABLED test_trace_return_dataclass_nested (__main__.TestFX) [2 comments, 1 participants]

Official PRs (…)
ON THIS PAGE

Recommended Tools

×6

Utilities matched from this issue’s tags and category — try them while you read without losing context.

GitHub issue graph ai analysis

Paste a GitHub issue URL. We fetch that issue, discover linked issues from bodies/comments/timeline, collect linked pull requests, and produce a structured English report.

The report is written in English Markdown for sharing and archival.

Helpful · Quick feedback

Loading…
GitHub stats
pytorch/pytorch#181322Fetched 2026-04-24 10:35:58
View on GitHub
Comments
2
Participants
1
Timeline
30
Reactions
0
Participants
Timeline (top)
mentioned ×12subscribed ×12labeled ×4commented ×2

Error Message

Traceback (most recent call last): File "/__w/pytorch/pytorch/test/test_fx.py", line 2885, in test_trace_return_dataclass_nested class MyOutput: File "/__w/pytorch/pytorch/test/test_fx.py", line 2884, in torch_dynamo_resume_in_test_trace_return_dataclass_nested_at_2885 @dataclass ^^^^^^^^^ File "/opt/conda/envs/py_3.14/lib/python3.14t/dataclasses.py", line 1442, in dataclass return wrap(cls) File "/opt/conda/envs/py_3.14/lib/python3.14t/dataclasses.py", line 1432, in wrap return _process_class(cls, init, repr, eq, order, unsafe_hash, frozen, match_args, kw_only, slots, weakref_slot) File "/opt/conda/envs/py_3.14/lib/python3.14t/dataclasses.py", line 1130, in _process_class func_builder = _FuncBuilder(globals) File "/opt/conda/envs/py_3.14/lib/python3.14t/site-packages/torch/_dynamo/convert_frame.py", line 2480, in call result = self._torchdynamo_orig_backend( frame, cache_entry, self.hooks, frame_state, skip=1 ) File "/opt/conda/envs/py_3.14/lib/python3.14t/site-packages/torch/_dynamo/convert_frame.py", line 2198, in call result = self._inner_convert( frame, cache_entry, hooks, frame_state, skip=skip + 1 ) File "/opt/conda/envs/py_3.14/lib/python3.14t/site-packages/torch/_dynamo/convert_frame.py", line 758, in call result = _compile( frame.f_code, ...<16 lines>... convert_frame_box=self._box, ) File "/opt/conda/envs/py_3.14/lib/python3.14t/site-packages/torch/_dynamo/convert_frame.py", line 2048, in _compile raise InternalTorchDynamoError( f"{type(e).qualname}: {str(e)}" ).with_traceback(e.traceback) from None File "/opt/conda/envs/py_3.14/lib/python3.14t/site-packages/torch/_dynamo/convert_frame.py", line 1983, in _compile guarded_code, tracer_output = compile_inner(code, one_graph, hooks) ~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^ File "/opt/conda/envs/py_3.14/lib/python3.14t/site-packages/torch/_utils_internal.py", line 96, in wrapper_function return function(*args, **kwargs) File "/opt/conda/envs/py_3.14/lib/python3.14t/site-packages/torch/_dynamo/convert_frame.py", line 1593, in compile_inner result = _compile_inner(code, one_graph, hooks) File "/opt/conda/envs/py_3.14/lib/python3.14t/site-packages/torch/_dynamo/convert_frame.py", line 1652, in _compile_inner dynamo_output = compile_frame( code, ...<11 lines>... package=package, ) File "/opt/conda/envs/py_3.14/lib/python3.14t/site-packages/torch/_dynamo/convert_frame.py", line 1500, in compile_frame bytecode, tracer_output = transform_code_object(code, transform) ~~~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^ File "/opt/conda/envs/py_3.14/lib/python3.14t/site-packages/torch/_dynamo/bytecode_transformation.py", line 1626, in transform_code_object tracer_output = transformations(instructions, code_options) File "/opt/conda/envs/py_3.14/lib/python3.14t/site-packages/torch/_dynamo/convert_frame.py", line 1472, in transform tracer_output = trace_frame( code, ...<14 lines>... package=package, ) File "/opt/conda/envs/py_3.14/lib/python3.14t/site-packages/torch/_dynamo/convert_frame.py", line 365, in _fn return fn(*args, **kwargs) File "/opt/conda/envs/py_3.14/lib/python3.14t/site-packages/torch/_dynamo/convert_frame.py", line 933, in trace_frame run_tracer() ~~~~~~~~~~^^ File "/opt/conda/envs/py_3.14/lib/python3.14t/site-packages/torch/_dynamo/convert_frame.py", line 914, in run_tracer tracer.run() ~~~~~~~~~~^^ File "/opt/conda/envs/py_3.14/lib/python3.14t/site-packages/torch/_dynamo/symbolic_convert.py", line 1839, in run while self.step(): ~~~~~~~~~^^ File "/opt/conda/envs/py_3.14/lib/python3.14t/site-packages/torch/_dynamo/symbolic_convert.py", line 1506, in step self.dispatch_table[inst.opcode](self, inst) ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^ File "/opt/conda/envs/py_3.14/lib/python3.14t/site-packages/torch/_dynamo/symbolic_convert.py", line 1043, in wrapper return inner_fn(self, inst) File "/opt/conda/envs/py_3.14/lib/python3.14t/site-packages/torch/_dynamo/symbolic_convert.py", line 2974, in STORE_ATTR VariableTracker.build(self, setattr).call_function( ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^ self, # type: ignore[arg-type] ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ [obj, VariableTracker.build(self, inst.argval), val], ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ {}, ^^^ ) ^ File "/opt/conda/envs/py_3.14/lib/python3.14t/site-packages/torch/_dynamo/variables/builtin.py", line 1519, in call_function return handler(tx, args, kwargs) # type: ignore[return-value] File "/opt/conda/envs/py_3.14/lib/python3.14t/site-packages/torch/_dynamo/variables/builtin.py", line 1078, in <lambda> tx, [v.realize() for v in args], kwargs ~~~~~~~~~^^ File "/opt/conda/envs/py_3.14/lib/python3.14t/site-packages/torch/_dynamo/variables/lazy.py", line 107, in realize self._cache.realize() ~~~~~~~~~~~~~~~~~~~^^ File "/opt/conda/envs/py_3.14/lib/python3.14t/site-packages/torch/_dynamo/variables/lazy.py", line 44, in realize self.vt = builder.VariableBuilder( ~~~~~~~~~~~~~~~~~~~~~~~~ tx, self.source, allow_lazy_constant=False ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ )(self.value) ~^^^^^^^^^^^^ File "/opt/conda/envs/py_3.14/lib/python3.14t/site-packages/torch/_dynamo/variables/builder.py", line 488, in call return self._call_impl(value) ~~~~~~~~~~~~~~~^^^^^^^ File "/opt/conda/envs/py_3.14/lib/python3.14t/site-packages/torch/_dynamo/variables/builder.py", line 525, in _call_impl vt = self._wrap(value) File "/opt/conda/envs/py_3.14/lib/python3.14t/site-packages/torch/_dynamo/variables/builder.py", line 878, in _wrap result = dict( build_key_value(i, k, v) for i, k, v in enumerate_items_with_dict_position(value) ) File "/opt/conda/envs/py_3.14/lib/python3.14t/site-packages/torch/_dynamo/variables/builder.py", line 880, in <genexpr> for i, k, v in enumerate_items_with_dict_position(value) ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^^^^^^^ File "/opt/conda/envs/py_3.14/lib/python3.14t/site-packages/torch/_dynamo/utils.py", line 2944, in <genexpr> return ((i, k, v) for i, (k, v) in enumerate(items)) ~~~~~~~~~^^^^^^^ torch._dynamo.exc.InternalTorchDynamoError: RuntimeError: dictionary changed size during iteration

from user code: File "/opt/conda/envs/py_3.14/lib/python3.14t/dataclasses.py", line 440, in init self.globals = globals

Set TORCHDYNAMO_VERBOSE=1 for the internal stack trace (please do this especially if you're reporting a bug to PyTorch). For even more developer context, set TORCH_LOGS="+dynamo"

To execute this test, run the following from the base repo dir: PYTORCH_TEST_WITH_DYNAMO=1 python test/test_fx.py TestFX.test_trace_return_dataclass_nested

This message can be suppressed by setting PYTORCH_PRINT_REPRO_ON_FAILURE=0

Root Cause

This test was disabled because it is failing in CI. See recent examples and the most recent trunk workflow logs.

Fix Action

Fix / Workaround

Traceback (most recent call last):
  File "/__w/pytorch/pytorch/test/test_fx.py", line 2885, in test_trace_return_dataclass_nested
    class MyOutput:
  File "/__w/pytorch/pytorch/test/test_fx.py", line 2884, in torch_dynamo_resume_in_test_trace_return_dataclass_nested_at_2885
    @dataclass
     ^^^^^^^^^
  File "/opt/conda/envs/py_3.14/lib/python3.14t/dataclasses.py", line 1442, in dataclass
    return wrap(cls)
  File "/opt/conda/envs/py_3.14/lib/python3.14t/dataclasses.py", line 1432, in wrap
    return _process_class(cls, init, repr, eq, order, unsafe_hash,
                          frozen, match_args, kw_only, slots,
                          weakref_slot)
  File "/opt/conda/envs/py_3.14/lib/python3.14t/dataclasses.py", line 1130, in _process_class
    func_builder = _FuncBuilder(globals)
  File "/opt/conda/envs/py_3.14/lib/python3.14t/site-packages/torch/_dynamo/convert_frame.py", line 2480, in __call__
    result = self._torchdynamo_orig_backend(
        frame, cache_entry, self.hooks, frame_state, skip=1
    )
  File "/opt/conda/envs/py_3.14/lib/python3.14t/site-packages/torch/_dynamo/convert_frame.py", line 2198, in __call__
    result = self._inner_convert(
        frame, cache_entry, hooks, frame_state, skip=skip + 1
    )
  File "/opt/conda/envs/py_3.14/lib/python3.14t/site-packages/torch/_dynamo/convert_frame.py", line 758, in __call__
    result = _compile(
        frame.f_code,
    ...<16 lines>...
        convert_frame_box=self._box,
    )
  File "/opt/conda/envs/py_3.14/lib/python3.14t/site-packages/torch/_dynamo/convert_frame.py", line 2048, in _compile
    raise InternalTorchDynamoError(
        f"{type(e).__qualname__}: {str(e)}"
    ).with_traceback(e.__traceback__) from None
  File "/opt/conda/envs/py_3.14/lib/python3.14t/site-packages/torch/_dynamo/convert_frame.py", line 1983, in _compile
    guarded_code, tracer_output = compile_inner(code, one_graph, hooks)
                                  ~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/conda/envs/py_3.14/lib/python3.14t/site-packages/torch/_utils_internal.py", line 96, in wrapper_function
    return function(*args, **kwargs)
  File "/opt/conda/envs/py_3.14/lib/python3.14t/site-packages/torch/_dynamo/convert_frame.py", line 1593, in compile_inner
    result = _compile_inner(code, one_graph, hooks)
  File "/opt/conda/envs/py_3.14/lib/python3.14t/site-packages/torch/_dynamo/convert_frame.py", line 1652, in _compile_inner
    dynamo_output = compile_frame(
        code,
    ...<11 lines>...
        package=package,
    )
  File "/opt/conda/envs/py_3.14/lib/python3.14t/site-packages/torch/_dynamo/convert_frame.py", line 1500, in compile_frame
    bytecode, tracer_output = transform_code_object(code, transform)
                              ~~~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^
  File "/opt/conda/envs/py_3.14/lib/python3.14t/site-packages/torch/_dynamo/bytecode_transformation.py", line 1626, in transform_code_object
    tracer_output = transformations(instructions, code_options)
  File "/opt/conda/envs/py_3.14/lib/python3.14t/site-packages/torch/_dynamo/convert_frame.py", line 1472, in transform
    tracer_output = trace_frame(
        code,
    ...<14 lines>...
        package=package,
    )
  File "/opt/conda/envs/py_3.14/lib/python3.14t/site-packages/torch/_dynamo/convert_frame.py", line 365, in _fn
    return fn(*args, **kwargs)
  File "/opt/conda/envs/py_3.14/lib/python3.14t/site-packages/torch/_dynamo/convert_frame.py", line 933, in trace_frame
    run_tracer()
    ~~~~~~~~~~^^
  File "/opt/conda/envs/py_3.14/lib/python3.14t/site-packages/torch/_dynamo/convert_frame.py", line 914, in run_tracer
    tracer.run()
    ~~~~~~~~~~^^
  File "/opt/conda/envs/py_3.14/lib/python3.14t/site-packages/torch/_dynamo/symbolic_convert.py", line 1839, in run
    while self.step():
          ~~~~~~~~~^^
  File "/opt/conda/envs/py_3.14/lib/python3.14t/site-packages/torch/_dynamo/symbolic_convert.py", line 1506, in step
    self.dispatch_table[inst.opcode](self, inst)
    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^
  File "/opt/conda/envs/py_3.14/lib/python3.14t/site-packages/torch/_dynamo/symbolic_convert.py", line 1043, in wrapper
    return inner_fn(self, inst)
  File "/opt/conda/envs/py_3.14/lib/python3.14t/site-packages/torch/_dynamo/symbolic_convert.py", line 2974, in STORE_ATTR
    VariableTracker.build(self, setattr).call_function(
    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^
        self,  # type: ignore[arg-type]
        ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
        [obj, VariableTracker.build(self, inst.argval), val],
        ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
        {},
        ^^^
    )
    ^
  File "/opt/conda/envs/py_3.14/lib/python3.14t/site-packages/torch/_dynamo/variables/builtin.py", line 1519, in call_function
    return handler(tx, args, kwargs)  # type: ignore[return-value]
  File "/opt/conda/envs/py_3.14/lib/python3.14t/site-packages/torch/_dynamo/variables/builtin.py", line 1078, in <lambda>
    tx, [v.realize() for v in args], kwargs
         ~~~~~~~~~^^
  File "/opt/conda/envs/py_3.14/lib/python3.14t/site-packages/torch/_dynamo/variables/lazy.py", line 107, in realize
    self._cache.realize()
    ~~~~~~~~~~~~~~~~~~~^^
  File "/opt/conda/envs/py_3.14/lib/python3.14t/site-packages/torch/_dynamo/variables/lazy.py", line 44, in realize
    self.vt = builder.VariableBuilder(
              ~~~~~~~~~~~~~~~~~~~~~~~~
        tx, self.source, allow_lazy_constant=False
        ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    )(self.value)
    ~^^^^^^^^^^^^
  File "/opt/conda/envs/py_3.14/lib/python3.14t/site-packages/torch/_dynamo/variables/builder.py", line 488, in __call__
    return self._call_impl(value)
           ~~~~~~~~~~~~~~~^^^^^^^
  File "/opt/conda/envs/py_3.14/lib/python3.14t/site-packages/torch/_dynamo/variables/builder.py", line 525, in _call_impl
    vt = self._wrap(value)
  File "/opt/conda/envs/py_3.14/lib/python3.14t/site-packages/torch/_dynamo/variables/builder.py", line 878, in _wrap
    result = dict(
        build_key_value(i, k, v)
        for i, k, v in enumerate_items_with_dict_position(value)
    )
  File "/opt/conda/envs/py_3.14/lib/python3.14t/site-packages/torch/_dynamo/variables/builder.py", line 880, in <genexpr>
    for i, k, v in enumerate_items_with_dict_position(value)
                   ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^^^^^^^
  File "/opt/conda/envs/py_3.14/lib/python3.14t/site-packages/torch/_dynamo/utils.py", line 2944, in <genexpr>
    return ((i, k, v) for i, (k, v) in enumerate(items))
                                       ~~~~~~~~~^^^^^^^
torch._dynamo.exc.InternalTorchDynamoError: RuntimeError: dictionary changed size during iteration

Code Example

Traceback (most recent call last):
  File "/__w/pytorch/pytorch/test/test_fx.py", line 2885, in test_trace_return_dataclass_nested
    class MyOutput:
  File "/__w/pytorch/pytorch/test/test_fx.py", line 2884, in torch_dynamo_resume_in_test_trace_return_dataclass_nested_at_2885
    @dataclass
     ^^^^^^^^^
  File "/opt/conda/envs/py_3.14/lib/python3.14t/dataclasses.py", line 1442, in dataclass
    return wrap(cls)
  File "/opt/conda/envs/py_3.14/lib/python3.14t/dataclasses.py", line 1432, in wrap
    return _process_class(cls, init, repr, eq, order, unsafe_hash,
                          frozen, match_args, kw_only, slots,
                          weakref_slot)
  File "/opt/conda/envs/py_3.14/lib/python3.14t/dataclasses.py", line 1130, in _process_class
    func_builder = _FuncBuilder(globals)
  File "/opt/conda/envs/py_3.14/lib/python3.14t/site-packages/torch/_dynamo/convert_frame.py", line 2480, in __call__
    result = self._torchdynamo_orig_backend(
        frame, cache_entry, self.hooks, frame_state, skip=1
    )
  File "/opt/conda/envs/py_3.14/lib/python3.14t/site-packages/torch/_dynamo/convert_frame.py", line 2198, in __call__
    result = self._inner_convert(
        frame, cache_entry, hooks, frame_state, skip=skip + 1
    )
  File "/opt/conda/envs/py_3.14/lib/python3.14t/site-packages/torch/_dynamo/convert_frame.py", line 758, in __call__
    result = _compile(
        frame.f_code,
    ...<16 lines>...
        convert_frame_box=self._box,
    )
  File "/opt/conda/envs/py_3.14/lib/python3.14t/site-packages/torch/_dynamo/convert_frame.py", line 2048, in _compile
    raise InternalTorchDynamoError(
        f"{type(e).__qualname__}: {str(e)}"
    ).with_traceback(e.__traceback__) from None
  File "/opt/conda/envs/py_3.14/lib/python3.14t/site-packages/torch/_dynamo/convert_frame.py", line 1983, in _compile
    guarded_code, tracer_output = compile_inner(code, one_graph, hooks)
                                  ~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/conda/envs/py_3.14/lib/python3.14t/site-packages/torch/_utils_internal.py", line 96, in wrapper_function
    return function(*args, **kwargs)
  File "/opt/conda/envs/py_3.14/lib/python3.14t/site-packages/torch/_dynamo/convert_frame.py", line 1593, in compile_inner
    result = _compile_inner(code, one_graph, hooks)
  File "/opt/conda/envs/py_3.14/lib/python3.14t/site-packages/torch/_dynamo/convert_frame.py", line 1652, in _compile_inner
    dynamo_output = compile_frame(
        code,
    ...<11 lines>...
        package=package,
    )
  File "/opt/conda/envs/py_3.14/lib/python3.14t/site-packages/torch/_dynamo/convert_frame.py", line 1500, in compile_frame
    bytecode, tracer_output = transform_code_object(code, transform)
                              ~~~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^
  File "/opt/conda/envs/py_3.14/lib/python3.14t/site-packages/torch/_dynamo/bytecode_transformation.py", line 1626, in transform_code_object
    tracer_output = transformations(instructions, code_options)
  File "/opt/conda/envs/py_3.14/lib/python3.14t/site-packages/torch/_dynamo/convert_frame.py", line 1472, in transform
    tracer_output = trace_frame(
        code,
    ...<14 lines>...
        package=package,
    )
  File "/opt/conda/envs/py_3.14/lib/python3.14t/site-packages/torch/_dynamo/convert_frame.py", line 365, in _fn
    return fn(*args, **kwargs)
  File "/opt/conda/envs/py_3.14/lib/python3.14t/site-packages/torch/_dynamo/convert_frame.py", line 933, in trace_frame
    run_tracer()
    ~~~~~~~~~~^^
  File "/opt/conda/envs/py_3.14/lib/python3.14t/site-packages/torch/_dynamo/convert_frame.py", line 914, in run_tracer
    tracer.run()
    ~~~~~~~~~~^^
  File "/opt/conda/envs/py_3.14/lib/python3.14t/site-packages/torch/_dynamo/symbolic_convert.py", line 1839, in run
    while self.step():
          ~~~~~~~~~^^
  File "/opt/conda/envs/py_3.14/lib/python3.14t/site-packages/torch/_dynamo/symbolic_convert.py", line 1506, in step
    self.dispatch_table[inst.opcode](self, inst)
    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^
  File "/opt/conda/envs/py_3.14/lib/python3.14t/site-packages/torch/_dynamo/symbolic_convert.py", line 1043, in wrapper
    return inner_fn(self, inst)
  File "/opt/conda/envs/py_3.14/lib/python3.14t/site-packages/torch/_dynamo/symbolic_convert.py", line 2974, in STORE_ATTR
    VariableTracker.build(self, setattr).call_function(
    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^
        self,  # type: ignore[arg-type]
        ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
        [obj, VariableTracker.build(self, inst.argval), val],
        ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
        {},
        ^^^
    )
    ^
  File "/opt/conda/envs/py_3.14/lib/python3.14t/site-packages/torch/_dynamo/variables/builtin.py", line 1519, in call_function
    return handler(tx, args, kwargs)  # type: ignore[return-value]
  File "/opt/conda/envs/py_3.14/lib/python3.14t/site-packages/torch/_dynamo/variables/builtin.py", line 1078, in <lambda>
    tx, [v.realize() for v in args], kwargs
         ~~~~~~~~~^^
  File "/opt/conda/envs/py_3.14/lib/python3.14t/site-packages/torch/_dynamo/variables/lazy.py", line 107, in realize
    self._cache.realize()
    ~~~~~~~~~~~~~~~~~~~^^
  File "/opt/conda/envs/py_3.14/lib/python3.14t/site-packages/torch/_dynamo/variables/lazy.py", line 44, in realize
    self.vt = builder.VariableBuilder(
              ~~~~~~~~~~~~~~~~~~~~~~~~
        tx, self.source, allow_lazy_constant=False
        ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    )(self.value)
    ~^^^^^^^^^^^^
  File "/opt/conda/envs/py_3.14/lib/python3.14t/site-packages/torch/_dynamo/variables/builder.py", line 488, in __call__
    return self._call_impl(value)
           ~~~~~~~~~~~~~~~^^^^^^^
  File "/opt/conda/envs/py_3.14/lib/python3.14t/site-packages/torch/_dynamo/variables/builder.py", line 525, in _call_impl
    vt = self._wrap(value)
  File "/opt/conda/envs/py_3.14/lib/python3.14t/site-packages/torch/_dynamo/variables/builder.py", line 878, in _wrap
    result = dict(
        build_key_value(i, k, v)
        for i, k, v in enumerate_items_with_dict_position(value)
    )
  File "/opt/conda/envs/py_3.14/lib/python3.14t/site-packages/torch/_dynamo/variables/builder.py", line 880, in <genexpr>
    for i, k, v in enumerate_items_with_dict_position(value)
                   ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^^^^^^^
  File "/opt/conda/envs/py_3.14/lib/python3.14t/site-packages/torch/_dynamo/utils.py", line 2944, in <genexpr>
    return ((i, k, v) for i, (k, v) in enumerate(items))
                                       ~~~~~~~~~^^^^^^^
torch._dynamo.exc.InternalTorchDynamoError: RuntimeError: dictionary changed size during iteration

from user code:
   File "/opt/conda/envs/py_3.14/lib/python3.14t/dataclasses.py", line 440, in __init__
    self.globals = globals

Set TORCHDYNAMO_VERBOSE=1 for the internal stack trace (please do this especially if you're reporting a bug to PyTorch). For even more developer context, set TORCH_LOGS="+dynamo"


To execute this test, run the following from the base repo dir:
    PYTORCH_TEST_WITH_DYNAMO=1 python test/test_fx.py TestFX.test_trace_return_dataclass_nested

This message can be suppressed by setting PYTORCH_PRINT_REPRO_ON_FAILURE=0
RAW_BUFFERClick to expand / collapse

Platforms: dynamo

This test was disabled because it is failing in CI. See recent examples and the most recent trunk workflow logs.

Over the past 6 hours, it has been determined flaky in 4 workflow(s) with 4 failures and 4 successes.

Debugging instructions (after clicking on the recent samples link): DO NOT ASSUME THINGS ARE OKAY IF THE CI IS GREEN. We now shield flaky tests from developers so CI will thus be green but it will be harder to parse the logs. To find relevant log snippets:

  1. Click on the workflow logs linked above
  2. Click on the Test step of the job so that it is expanded. Otherwise, the grepping will not work.
  3. Grep for test_trace_return_dataclass_nested
  4. There should be several instances run (as flaky tests are rerun in CI) from which you can study the logs.
<details><summary>Sample error message</summary>
Traceback (most recent call last):
  File "/__w/pytorch/pytorch/test/test_fx.py", line 2885, in test_trace_return_dataclass_nested
    class MyOutput:
  File "/__w/pytorch/pytorch/test/test_fx.py", line 2884, in torch_dynamo_resume_in_test_trace_return_dataclass_nested_at_2885
    @dataclass
     ^^^^^^^^^
  File "/opt/conda/envs/py_3.14/lib/python3.14t/dataclasses.py", line 1442, in dataclass
    return wrap(cls)
  File "/opt/conda/envs/py_3.14/lib/python3.14t/dataclasses.py", line 1432, in wrap
    return _process_class(cls, init, repr, eq, order, unsafe_hash,
                          frozen, match_args, kw_only, slots,
                          weakref_slot)
  File "/opt/conda/envs/py_3.14/lib/python3.14t/dataclasses.py", line 1130, in _process_class
    func_builder = _FuncBuilder(globals)
  File "/opt/conda/envs/py_3.14/lib/python3.14t/site-packages/torch/_dynamo/convert_frame.py", line 2480, in __call__
    result = self._torchdynamo_orig_backend(
        frame, cache_entry, self.hooks, frame_state, skip=1
    )
  File "/opt/conda/envs/py_3.14/lib/python3.14t/site-packages/torch/_dynamo/convert_frame.py", line 2198, in __call__
    result = self._inner_convert(
        frame, cache_entry, hooks, frame_state, skip=skip + 1
    )
  File "/opt/conda/envs/py_3.14/lib/python3.14t/site-packages/torch/_dynamo/convert_frame.py", line 758, in __call__
    result = _compile(
        frame.f_code,
    ...<16 lines>...
        convert_frame_box=self._box,
    )
  File "/opt/conda/envs/py_3.14/lib/python3.14t/site-packages/torch/_dynamo/convert_frame.py", line 2048, in _compile
    raise InternalTorchDynamoError(
        f"{type(e).__qualname__}: {str(e)}"
    ).with_traceback(e.__traceback__) from None
  File "/opt/conda/envs/py_3.14/lib/python3.14t/site-packages/torch/_dynamo/convert_frame.py", line 1983, in _compile
    guarded_code, tracer_output = compile_inner(code, one_graph, hooks)
                                  ~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/conda/envs/py_3.14/lib/python3.14t/site-packages/torch/_utils_internal.py", line 96, in wrapper_function
    return function(*args, **kwargs)
  File "/opt/conda/envs/py_3.14/lib/python3.14t/site-packages/torch/_dynamo/convert_frame.py", line 1593, in compile_inner
    result = _compile_inner(code, one_graph, hooks)
  File "/opt/conda/envs/py_3.14/lib/python3.14t/site-packages/torch/_dynamo/convert_frame.py", line 1652, in _compile_inner
    dynamo_output = compile_frame(
        code,
    ...<11 lines>...
        package=package,
    )
  File "/opt/conda/envs/py_3.14/lib/python3.14t/site-packages/torch/_dynamo/convert_frame.py", line 1500, in compile_frame
    bytecode, tracer_output = transform_code_object(code, transform)
                              ~~~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^
  File "/opt/conda/envs/py_3.14/lib/python3.14t/site-packages/torch/_dynamo/bytecode_transformation.py", line 1626, in transform_code_object
    tracer_output = transformations(instructions, code_options)
  File "/opt/conda/envs/py_3.14/lib/python3.14t/site-packages/torch/_dynamo/convert_frame.py", line 1472, in transform
    tracer_output = trace_frame(
        code,
    ...<14 lines>...
        package=package,
    )
  File "/opt/conda/envs/py_3.14/lib/python3.14t/site-packages/torch/_dynamo/convert_frame.py", line 365, in _fn
    return fn(*args, **kwargs)
  File "/opt/conda/envs/py_3.14/lib/python3.14t/site-packages/torch/_dynamo/convert_frame.py", line 933, in trace_frame
    run_tracer()
    ~~~~~~~~~~^^
  File "/opt/conda/envs/py_3.14/lib/python3.14t/site-packages/torch/_dynamo/convert_frame.py", line 914, in run_tracer
    tracer.run()
    ~~~~~~~~~~^^
  File "/opt/conda/envs/py_3.14/lib/python3.14t/site-packages/torch/_dynamo/symbolic_convert.py", line 1839, in run
    while self.step():
          ~~~~~~~~~^^
  File "/opt/conda/envs/py_3.14/lib/python3.14t/site-packages/torch/_dynamo/symbolic_convert.py", line 1506, in step
    self.dispatch_table[inst.opcode](self, inst)
    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^
  File "/opt/conda/envs/py_3.14/lib/python3.14t/site-packages/torch/_dynamo/symbolic_convert.py", line 1043, in wrapper
    return inner_fn(self, inst)
  File "/opt/conda/envs/py_3.14/lib/python3.14t/site-packages/torch/_dynamo/symbolic_convert.py", line 2974, in STORE_ATTR
    VariableTracker.build(self, setattr).call_function(
    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^
        self,  # type: ignore[arg-type]
        ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
        [obj, VariableTracker.build(self, inst.argval), val],
        ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
        {},
        ^^^
    )
    ^
  File "/opt/conda/envs/py_3.14/lib/python3.14t/site-packages/torch/_dynamo/variables/builtin.py", line 1519, in call_function
    return handler(tx, args, kwargs)  # type: ignore[return-value]
  File "/opt/conda/envs/py_3.14/lib/python3.14t/site-packages/torch/_dynamo/variables/builtin.py", line 1078, in <lambda>
    tx, [v.realize() for v in args], kwargs
         ~~~~~~~~~^^
  File "/opt/conda/envs/py_3.14/lib/python3.14t/site-packages/torch/_dynamo/variables/lazy.py", line 107, in realize
    self._cache.realize()
    ~~~~~~~~~~~~~~~~~~~^^
  File "/opt/conda/envs/py_3.14/lib/python3.14t/site-packages/torch/_dynamo/variables/lazy.py", line 44, in realize
    self.vt = builder.VariableBuilder(
              ~~~~~~~~~~~~~~~~~~~~~~~~
        tx, self.source, allow_lazy_constant=False
        ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    )(self.value)
    ~^^^^^^^^^^^^
  File "/opt/conda/envs/py_3.14/lib/python3.14t/site-packages/torch/_dynamo/variables/builder.py", line 488, in __call__
    return self._call_impl(value)
           ~~~~~~~~~~~~~~~^^^^^^^
  File "/opt/conda/envs/py_3.14/lib/python3.14t/site-packages/torch/_dynamo/variables/builder.py", line 525, in _call_impl
    vt = self._wrap(value)
  File "/opt/conda/envs/py_3.14/lib/python3.14t/site-packages/torch/_dynamo/variables/builder.py", line 878, in _wrap
    result = dict(
        build_key_value(i, k, v)
        for i, k, v in enumerate_items_with_dict_position(value)
    )
  File "/opt/conda/envs/py_3.14/lib/python3.14t/site-packages/torch/_dynamo/variables/builder.py", line 880, in <genexpr>
    for i, k, v in enumerate_items_with_dict_position(value)
                   ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^^^^^^^
  File "/opt/conda/envs/py_3.14/lib/python3.14t/site-packages/torch/_dynamo/utils.py", line 2944, in <genexpr>
    return ((i, k, v) for i, (k, v) in enumerate(items))
                                       ~~~~~~~~~^^^^^^^
torch._dynamo.exc.InternalTorchDynamoError: RuntimeError: dictionary changed size during iteration

from user code:
   File "/opt/conda/envs/py_3.14/lib/python3.14t/dataclasses.py", line 440, in __init__
    self.globals = globals

Set TORCHDYNAMO_VERBOSE=1 for the internal stack trace (please do this especially if you're reporting a bug to PyTorch). For even more developer context, set TORCH_LOGS="+dynamo"


To execute this test, run the following from the base repo dir:
    PYTORCH_TEST_WITH_DYNAMO=1 python test/test_fx.py TestFX.test_trace_return_dataclass_nested

This message can be suppressed by setting PYTORCH_PRINT_REPRO_ON_FAILURE=0
</details>

Test file path: test_fx.py

For all disabled tests (by GitHub issue), see https://hud.pytorch.org/disabled.

cc @ezyang @EikanWang @jgong5 @wenzhe-nrv @chauhang @penguinwu

extent analysis

TL;DR

The test test_trace_return_dataclass_nested is failing due to an InternalTorchDynamoError caused by a RuntimeError: dictionary changed size during iteration, suggesting an issue with the dynamic compilation of PyTorch code.

Guidance

  1. Investigate the stacktrace: The error occurs in the torch/_dynamo/variables/builder.py file, specifically in the _wrap function, which is trying to build a dictionary from an iterable. This suggests that the issue might be related to the way the dictionary is being constructed or modified.
  2. Check the test code: The test test_trace_return_dataclass_nested is using the @dataclass decorator, which might be interacting with the dynamic compilation in an unexpected way. Review the test code to see if there are any potential issues with the way the dataclass is being defined or used.
  3. Run the test with verbose logging: Set TORCHDYNAMO_VERBOSE=1 to get a more detailed internal stack trace, which might provide more insight into the issue.
  4. Check for similar issues: Look for similar errors or issues in the PyTorch repository or documentation, as this might be a known problem with a existing solution.

Notes

The issue seems to be related to the interaction between PyTorch's dynamic compilation and the @dataclass decorator. Without more information or a minimal reproducible example, it's difficult to provide a more specific solution.

Recommendation

Apply a workaround by modifying the test code to avoid using the @dataclass decorator or by using a different approach to define the dataclass, until a more permanent solution can be found.

Vote matrix · Quick signals

Works
Did the solution work? Tap to confirm.
Easy Fix
Was it a quick fix?
Time Saver
Did it save you time?
Blocking
Was it severely blocking?
Common Issue
Are others likely hitting this too?
Flaky / Intermittent
Is it intermittent?
Verified / Reproducible
Can you reproduce it reliably?
Loading…

Still need to ship something?

×6

Another batch ranked right after the header list — different links, same matching logic.

Back to top recommendations

TRENDING

pytorch - 💡(How to fix) Fix DISABLED test_trace_return_dataclass_nested (__main__.TestFX) [2 comments, 1 participants]