mirror of
https://github.com/saymrwulf/pytorch.git
synced 2026-05-14 20:57:59 +00:00
Prior to this patch, we are using `ConstantVariable.create` to create VT for frozenset objects, and intended yet failed to predicate that on all itmes being literals (see https://github.com/pytorch/pytorch/pull/140984#discussion_r1847393736). The code was from https://github.com/pytorch/torchdynamo/commit/7c03434 and the original goal was to help DBR quantization, but as the new test in this patch shows, it could lead to silent incorrectness. Upon a closer look, this exposes some subtleties in how Dynamo handles `ConstantVariable` and `LOAD_CONST`, so this patch both fixes the aforementioned issue and documents, enforces, and makes explicit the invariants around `ConstantVariable` and `LOAD_CONST` -- only immutable objects are supported. Specifically, this patch: 1. refine the checks for wrapping a `frozenset` object, document why we can't just wrap its items directly due to lack of `Sourcec` for set items, and use a safe workaround (`SourcelessBuilder`) to ensure soundness while keeping the DBR quantization support. 2. Adds more types to `common_constant_types`, thereby making `ConstantVariable.is_base_literal` more lenient, and strictly checks this property in the constructor of `ConstantVariable`. 3. Change relevant uses of `create_instruction("LOAD_CONST", ...)` to `create_load_const` which checks `is_safe_constant`, and makes developer overrides explicit by using `create_load_const_unchecked` when needed. 4. In a few places, use more specific `VariableTracker`, e.g., `TypingVariable` rather than `ConstantVariable`, and `FrozensetVariable` rather than `SetVariable`. (2) and (3) are mainly to future-proof Dynamo against bugs like (1). Pull Request resolved: https://github.com/pytorch/pytorch/pull/141504 Approved by: https://github.com/jansel |
||
|---|---|---|
| .. | ||
| mock_modules | ||
| __init__.py | ||
| mock_store_global_crossfile_inline.py | ||
| test_activation_checkpointing.py | ||
| test_after_aot.py | ||
| test_aot_autograd.py | ||
| test_aot_autograd_cache.py | ||
| test_autograd_function.py | ||
| test_backends.py | ||
| test_backward_higher_order_ops.py | ||
| test_base_output.py | ||
| test_bytecode_utils.py | ||
| test_compile.py | ||
| test_compiler_bisector.py | ||
| test_comptime.py | ||
| test_config.py | ||
| test_ctx_manager.py | ||
| test_cudagraphs.py | ||
| test_cudagraphs_expandable_segments.py | ||
| test_debug_utils.py | ||
| test_decorators.py | ||
| test_deviceguard.py | ||
| test_dynamic_shapes.py | ||
| test_exc.py | ||
| test_exceptions.py | ||
| test_export.py | ||
| test_export_mutations.py | ||
| test_frame_init.py | ||
| test_functions.py | ||
| test_fx_passes_pre_grad.py | ||
| test_global.py | ||
| test_guard_manager.py | ||
| test_higher_order_ops.py | ||
| test_hooks.py | ||
| test_inline_inbuilt_nn_modules.py | ||
| test_input_attr_tracking.py | ||
| test_interop.py | ||
| test_logging.py | ||
| test_metrics_context.py | ||
| test_minifier.py | ||
| test_misc.py | ||
| test_model_output.py | ||
| test_modes.py | ||
| test_modules.py | ||
| test_nops.py | ||
| test_optimizers.py | ||
| test_pgo.py | ||
| test_pre_dispatch.py | ||
| test_prim_hop_base.py | ||
| test_profiler.py | ||
| test_python_autograd.py | ||
| test_recompile_ux.py | ||
| test_recompiles.py | ||
| test_reconstruct.py | ||
| test_reorder_logs.py | ||
| test_repros.py | ||
| test_resume.py | ||
| test_sdpa.py | ||
| test_skip_guard_eval_unsafe.py | ||
| test_skip_non_tensor.py | ||
| test_sources.py | ||
| test_structured_trace.py | ||
| test_subclasses.py | ||
| test_subgraphs.py | ||
| test_torchrec.py | ||
| test_trace_rules.py | ||
| test_unspec.py | ||
| test_utils.py | ||
| test_verify_correctness.py | ||
| test_view.py | ||
| utils.py | ||