Device-generalize more dynamo tests to run on accelerator backends - #87
Open
aws-alexk wants to merge 1 commit into
Open
Device-generalize more dynamo tests to run on accelerator backends#87aws-alexk wants to merge 1 commit into
aws-alexk wants to merge 1 commit into
Conversation
Follow-up to the earlier device-generalization pass. These test/dynamo tests
still hardcode CPU input tensors (no device= argument). torch.compile is
device-preserving, but accelerator backends that execute the compiled graph
on-device return device tensors, so autograd rejects the device mismatch on
backward, e.g.:
RuntimeError: Function CompiledFunctionBackward returned an invalid
gradient at index 0 - expected device cpu but got <accel>:0
or the compiled region raises a plain device mismatch when a CPU input meets an
on-device intermediate.
Create inputs on the current accelerator via the module-level device_type
(torch.accelerator.current_accelerator, falling back to "cpu"), adding
device=device_type to input tensor factories and .to(device_type) to nn.Module
instances in the affected tests. test_activation_checkpointing.py and
test_wrap_inductor_compiled_regions.py gain the module-level device_type
definition (the other files already have it); the latter also generalizes its
DTensor device mesh. Because device_type resolves to "cpu" when no accelerator
is present, these edits are a no-op on CPU and CUDA CI and only take effect on
accelerator backends.
Test Plan:
On CPU (no accelerator; device_type == "cpu", edits are a no-op):
```
python test/dynamo/test_autograd_function.py AutogradFunctionTests.test_apply_kwargs_old_style
python test/dynamo/test_hooks.py HooksTests.test_input_hooks_same
python test/dynamo/test_repros.py ReproTests.test_intermediate_leaf_requires_grad
python test/dynamo/test_fwd_loss_bwd.py TestForwardLossBackward.test_backward_dict_inputs
```
On an accelerator backend, the same nodeids (and their _nested_graph_breaks
variants) that previously failed with a device mismatch now pass.
Authored with an AI assistant (Claude).
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Follow-up to the earlier device-generalization pass. These test/dynamo tests still hardcode CPU input tensors (no device= argument). torch.compile is device-preserving, but accelerator backends that execute the compiled graph on-device return device tensors, so autograd rejects the device mismatch on backward, e.g.:
or the compiled region raises a plain device mismatch when a CPU input meets an on-device intermediate.
Create inputs on the current accelerator via the module-level device_type (torch.accelerator.current_accelerator, falling back to "cpu"), adding device=device_type to input tensor factories and .to(device_type) to nn.Module instances in the affected tests. test_activation_checkpointing.py and test_wrap_inductor_compiled_regions.py gain the module-level device_type definition (the other files already have it); the latter also generalizes its DTensor device mesh. Because device_type resolves to "cpu" when no accelerator is present, these edits are a no-op on CPU and CUDA CI and only take effect on accelerator backends.
Issue #, if available:
Description of changes:
from this PR: #81
By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.