pytorch/torch/_dynamo/variables
Simon Fan 07c4c2a792 [dynamo][be] hide warnings without invalidating warnings cache (#158520)
I feel uneasy about touching `__warningregistry__` since it is undocumented and private surface. The only public API hook that doesn't increment warnings version seems to be https://docs.python.org/3/library/warnings.html#warnings.showwarning.

So we could wack a mole all the warnings muters in compile to just not display warnings, and we wouldn't invalidate warnings cache. This PR adds it for torch/_dynamo, and I didn't find any warnings versioning mutation from torch/_inductor.

There is a behavior change if someone calls a compiled graph with simplefilter("error"):
```python
# e.g. test/dynamo_expected_failures/TestAutogradFallback.test_no_autograd_kernel_inplace_mode_nothing
with warnings.catch_warnings():
    warnings.simplefilter("error")  # turns all warnings into errors
    compiled_fn()  # will throw if any of the muted warnings fire
```

FIXES https://github.com/pytorch/pytorch/issues/128427

A note for the future: The warnings module doesn't offer a thread safe way of using it. Even regular filters have this problem, directly editing `__warningregistry__` would be very bad, and this PR would mute all threads. Someone will need to build a thread safe warnings interface.

Pull Request resolved: https://github.com/pytorch/pytorch/pull/158520
Approved by: https://github.com/anijain2305, https://github.com/zou3519
2025-07-18 22:02:31 +00:00
..
__init__.py [Dynamo] [SetSubclass] Add support for user defined sets (#153553) 2025-07-04 00:45:25 +00:00
base.py [dynamo] update base variable call_method hint with note on comprehensions (#156769) 2025-06-25 21:55:55 +00:00
builder.py [dynamo][be] hide warnings without invalidating warnings cache (#158520) 2025-07-18 22:02:31 +00:00
builtin.py [dict] Allow Dynamo to trace through explicit dict dunder method call (#154794) 2025-07-10 22:50:39 +00:00
constant.py Fixes for CPython int/float tests (#155978) 2025-07-02 15:04:00 +00:00
ctx_manager.py [hop] support torch.func.functional_call in hop subgraph (#155886) 2025-06-28 23:47:46 +00:00
dicts.py [dict] Implement dict.__eq__ and dict.__ne__ (#154942) 2025-07-10 22:50:39 +00:00
distributed.py [BE][4/16] fix typos in torch/ (torch/_dynamo/) (#156314) 2025-06-23 02:57:19 +00:00
functions.py [dynamo] do not issue lru_cache warning for functions in the top-level torch namespace (#157598) 2025-07-04 08:17:50 +00:00
higher_order_ops.py [while_loop] fix constant tensor used as carried inputs (#158381) 2025-07-18 07:08:11 +00:00
iter.py [dynamo] updating gb_type names for uniqueness (#154452) 2025-05-28 16:54:10 +00:00
lazy.py [dynamo] Avoid recompiling over unused objects (#156891) 2025-07-09 20:14:34 +00:00
lists.py [iter] exhaust ListIterator when unpack_var_sequence is called (#156370) 2025-07-18 16:48:27 +00:00
misc.py [Dynamo] [FrozensetSubclass] Add support for user defined frozensets (#154263) 2025-07-04 00:46:05 +00:00
nn_module.py [BE][4/16] fix typos in torch/ (torch/_dynamo/) (#156314) 2025-06-23 02:57:19 +00:00
optimizer.py [dynamo] Guard serialization for NAME_MATCH (#152332) 2025-04-29 20:16:00 +00:00
script_object.py Document dynamo (#146736) 2025-02-13 00:02:21 +00:00
sdpa.py [Dynamo][Misc] Apply typing hints for codegen (#150289) 2025-04-04 14:26:22 +00:00
tensor.py [dynamo][tensor] Skip HASATTR attribute on tensor guards (#158215) 2025-07-15 20:10:47 +00:00
torch_function.py [BE][4/16] fix typos in torch/ (torch/_dynamo/) (#156314) 2025-06-23 02:57:19 +00:00
torch.py [dynamo] Constant fold torch.autograd._profiler_enabled (#158482) 2025-07-17 01:07:42 +00:00
user_defined.py [Dynamo] Use proper sources for constructing dataclass defaults (#157993) 2025-07-18 21:51:40 +00:00