freenode
AI & ML

PyTorch Dynamo silently drops closure mutations in local class methods

Compiled functions under fullgraph mode lost in-place list and dict updates performed by methods on classes defined inside the region.

PyTorch Dynamo has been discarding in-place mutations to lists and dictionaries captured by closures when those mutations run inside methods of a class that is defined and instantiated within a torch.compile region.

The failure shows up with fullgraph=True and no graph break. Instances created inside the compiled function do not carry the provenance Dynamo needs for their methods. Closure cells for the captured containers are therefore treated as brand-new values, and the mutations never appear in the generated bytecode. Context managers constructed the same way hit the identical gap on enter and exit.

A contributor traced the lost method sources and prepared a fix that keeps class-level provenance available even when the instance itself is sourceless, so side effects on existing captured containers are recorded instead of dropped.