Make Inductor's accumulate_grad op take the current grad explicitly and return the updated grad, so functionalization and compiled autograd no longer rely on hidden Tensor.grad reads.
Remove the custom op output alias annotation and make the returned grad fresh: clone the current grad before accumulation, avoid aliasing new_grad on initialization, and keep the compiled-autograd grad write as the op side effect. Split the Dynamo polyfills so the three-arg op follows the no-alias contract while Tensor.backward(inputs=...) keeps eager-style in-place accumulation and preserves existing dense .grad object identity.
Fix Dynamo's two-arg accumulate_grad_ handler to realize lazy tensor arguments before .grad reads/writes and clear mutation metadata when storing the source-stripped grad. Apply the optional extraction review suggestion in the compiled-autograd C++ bridge.
Test Plan:
- python -m py_compile torch/_dynamo/variables/torch.py torch/_dynamo/polyfills/init.py test/dynamo/test_fwd_loss_bwd.py test/inductor/test_compiled_autograd.py
- git diff --check
- git diff --cached --check
- lintrunner -a
- LD_LIBRARY_PATH=/data/users/jansel/pytorch-issue-fixer-2/env/lib:$LD_LIBRARY_PATH PYTHONPATH=/data/users/jansel/pytorch-issue-fixer-2/pytorch python test/dynamo/test_fwd_loss_bwd.py TestForwardLossBackward.test_tensor_backward_duplicate_inputs TestForwardLossBackward.test_tensor_backward_accumulates_grads TestForwardLossBackward.test_tensor_backward_preserves_existing_grad_reference
- LD_LIBRARY_PATH=/data/users/jansel/pytorch-issue-fixer-2/env/lib:$LD_LIBRARY_PATH PYTHONPATH=/data/users/jansel/pytorch-issue-fixer-2/pytorch python test/inductor/test_compiled_autograd.py TestCompiledAutograd.test_inputs_aliasing_bytecode_attr_mutations TestCompiledAutograd.test_accumulate_grad_capture_lifts_current_grad TestCompiledAutograd.test_accumulate_grad_op_functional_contract TestCompiledAutograd.test_accumulate_grad_accuracy (functional contract skipped locally due old registered schema)
- LD_LIBRARY_PATH=/data/users/jansel/pytorch-issue-fixer-2/env/lib:$LD_LIBRARY_PATH PYTHONPATH=/data/users/jansel/pytorch-issue-fixer-2/pytorch python test/dynamo/test_activation_checkpointing.py RematerializeACNodesPassTests.test_chunked_loss_remat
- LD_LIBRARY_PATH=/data/users/jansel/pytorch-issue-fixer-2/env/lib:$LD_LIBRARY_PATH PYTHONPATH=/data/users/jansel/pytorch-issue-fixer-2/pytorch python test/inductor/test_compiled_autograd.py TestCompiledAutograd.test_accumulate_grad_polyfill_case_2_3_1 TestCompiledAutograd.test_accumulate_grad_polyfill_case_2_1 TestCompiledAutograd.test_accumulate_grad_polyfill_case_3_2
- LD_LIBRARY_PATH=/data/users/jansel/pytorch-issue-fixer-2/env/lib:$LD_LIBRARY_PATH PYTHONPATH=/data/users/jansel/pytorch-issue-fixer-2/pytorch python test/dynamo/test_backward_higher_order_ops.py BackwardHigherOrderOpTests.test_invoke_in_pt2_compiled_autograd BackwardHigherOrderOpTests.test_invoke_in_pt2_compiled_autograd_side_effect
Fixes
Approved by: https://github.com/xmfan
Community-Analysen & Experten-Meinungen 0
Verwandte Story-Cluster & Quellen (Vektor-KI)
Ähnliche Beiträge
Auch interessante Nachrichten trunk/9c77ff51b6b2a30dc0964289e54c55b3f1bcdf13: Fix functional accumulate_grad state modeling (#184082)
Thematisch verwandte Begriffe: trunk9c77ff51b6b2a30dc0964289e54c55b3f1bcdf13, functional, accumulategrad, state · 6 Treffer
Building Agentic RAG, Step by Step: From Static Retrieval to Reasoning Pipelines
Why Most Multi-Agent Systems Fail Even When Evaluation Passes
[webapps] Grav CMS 2.0.7 - RCE
Videos werden geladen ...
Beiträge werden geladen ...
Videos werden geladen ...
Beiträge werden geladen ...
Videos werden geladen ...
Beiträge werden geladen ...
Videos werden geladen ...
Beiträge werden geladen ...
Videos werden geladen ...
SOCIAL SHARE CARD GENERATOR