[inductor] fix crash issue when input is a view tensor#90150
[inductor] fix crash issue when input is a view tensor#90150blzheng wants to merge 18 commits intopytorch:masterfrom
Conversation
🔗 Helpful Links🧪 See artifacts and rendered test results at hud.pytorch.org/pr/90150
Note: Links to docs will display an error until the docs builds have been completed. ❗ 1 Active SEVsThere are 1 currently active SEVs. If your PR is affected, please view them below: ✅ No FailuresAs of commit b8b02af: This comment was automatically generated by Dr. CI and updates every 15 minutes. |
test/inductor/test_torchinductor.py
Outdated
| fn(a, b) | ||
| assert "kernel_cpp_0" in (e.name for e in prof.profiler.function_events) | ||
|
|
||
| def test_input_is_view(self): |
There was a problem hiding this comment.
To be more accurate, it only happens with an in-place view op and should be fine non-place view, right? Naming it as test_input_is_inplace_view is more appropriate?
There was a problem hiding this comment.
Right. This function name is updated.
1b99e85 to
adcdd91
Compare
adcdd91 to
68894fd
Compare
torch/_dynamo/variables/builder.py
Outdated
| not config.dynamic_shapes | ||
| and self.fake_tensor.shape != self.example.shape | ||
| ): | ||
| self.fake_tensor = self.fake_tensor.reshape(self.example.shape) |
There was a problem hiding this comment.
I replaced the reshape with convert from real tensor in commit a6ac94d
torch/_dynamo/variables/builder.py
Outdated
| ) | ||
| # For inplace ops changing the input's shape (unsqueeze_) | ||
| if ( | ||
| not config.dynamic_shapes |
There was a problem hiding this comment.
What happens with dynamic shapes?
There was a problem hiding this comment.
I added support for dynamic shapes in 953e13c
There was a problem hiding this comment.
To avoid code duplicate, consider to test dynamic_shapes is True and False inside same test code instead of specifying it as a decorator.
There was a problem hiding this comment.
These are from another PR. I guess you need to rebase?
torch/_dynamo/variables/builder.py
Outdated
| self.fake_tensor = converter.from_real_tensor( | ||
| self.fake_tensor.fake_mode, self.example | ||
| ) | ||
| elif config.dynamic_shapes and self.fake_tensor.dim() != self.example.dim(): |
There was a problem hiding this comment.
Is it a complete check to make sure there was inplace op on the inputs?
ee6e855 to
01c8f4c
Compare
|
@pytorchbot rebase |
|
@pytorchbot successfully started a rebase job. Check the current status here |
|
Rebase failed due to Command Raised by https://github.com/pytorch/pytorch/actions/runs/3937177663 |
953e13c to
5999b38
Compare
enhance check condition
|
Successfully rebased |
012142e to
8420392
Compare
…config was deleted by pytorch#93076
|
@pytorchbot merge |
Merge startedYour change will be merged once all checks pass (ETA 0-4 Hours). Learn more about merging in the wiki. Questions? Feedback? Please reach out to the PyTorch DevX Team |
…" (#94329) Had to provide a merge conflict resolution due to conflicts with #94118 This was causing issues with internal tests that look similar to: ``` in clone_preserve_strides x.size(), x.stride(), x.storage_offset() AttributeError: 'KeyedJaggedTensor' object has no attribute 'size' ``` See https://fburl.com/testinfra/nc0du2sp for more information This reverts commit #90150 @jansel can you help @blzheng with re-landing this as a co-development diff? Pull Request resolved: #94329 Approved by: https://github.com/jansel
|
Sorry to revert again but it appears as though this introduces issues with users using TorchRec, see #94329 for more information |
| """ | ||
| return super().run(*args) | ||
| # clone inputs to avoid side effects caused by inplace ops during run_node | ||
| new_args = [torch._prims_common.clone_preserve_strides(x) for x in args] |
There was a problem hiding this comment.
This line in particular is problematic when attempting to use with torchrec's KeyedJaggedTensor, resulting in errors like:
in clone_preserve_strides
x.size(), x.stride(), x.storage_offset()
AttributeError: 'KeyedJaggedTensor' object has no attribute 'size'
There was a problem hiding this comment.
Hi @seemethere I am curious about what case will trigger this issue. I added clone_preserve_strides in two places.
- In this function. As the function description said, *args should be
Tensor. I think Tensor must have attribute 'size', right?
def propagate(self, *args):
"""
Run `module` via interpretation and return the result and
record the shape and type of each node.
Args:
*args (Tensor): the sample input.
Returns:
Any: The value returned from executing the Module
"""
- Similarly, in function aot_dispatch_base, flat_args should be
List[Tensor].
def aot_dispatch_base(flat_fn, flat_args: List[Tensor], aot_config: AOTConfig):
Fix the crash failure mentioned in #93460
cc @jgong5 @mingfeima @XiaobingSuper @sanchitintel @ashokei @jingxu10 @mlazos @soumith @voznesenskym @yanboliang @penguinwu @anijain2305 @EikanWang @Guobing-Chen @chunyuan-w @zhuhaozhe @Xia-Weiwen @wenzhe-nrv @jiayisunx @peterbell10 @desertfire