mirror of
https://github.com/zebrajr/pytorch.git
synced 2025-12-07 12:21:27 +01:00
Summary: As of https://github.com/pytorch/pytorch/pull/103192, dynamo supports code that creates OrderedDict instances using kwargs for the key-value pairs rather than passing a dict literal. But custom dicts (for example subclasses of OrderedDict) follow a different codepath so that we can check for conditions such as a custom `__init__` that need to force a graph break. This commit allows kwargs for custom dict constructors - if the args are empty and the class is not also a dataclass (which is the case that, for example, a `transformers.modeling_outputs.ModelOutput` instance will wind up hitting) then treat the kwargs as the key-value pairs. NOTE: For this to behave 100% correctly, we are relying on the fact that python dicts behave like ordered dicts so that they preserve the kwargs' ordering. Technically it is not guaranteed that future versions of Python will respect this; if that behavior changes we would need to ensure that dynamo uses OrderedDict for kwargs all the way down in order to handle special cases like OrderedDict where the kwargs' ordering does matter. Test Plan: ``` pytest test/dynamo/test_functions.py ``` I also verified that the new test fails without the changes to `dicts.py`. Reviewers: yanboliang Pull Request resolved: https://github.com/pytorch/pytorch/pull/112513 Approved by: https://github.com/yanboliang |
||
|---|---|---|
| .. | ||
| __init__.py | ||
| base.py | ||
| builder.py | ||
| builtin.py | ||
| constant.py | ||
| ctx_manager.py | ||
| dicts.py | ||
| distributed.py | ||
| functions.py | ||
| higher_order_ops.py | ||
| lists.py | ||
| misc.py | ||
| nn_module.py | ||
| optimizer.py | ||
| tensor.py | ||
| torch_function.py | ||
| torch.py | ||
| user_defined.py | ||