Repository navigation
Conversation
🔗 Helpful Links🧪 See artifacts and rendered test results at hud.pytorch.org/pr/178278
Note: Links to docs will display an error until the docs builds have been completed. ⏳ No Failures, 36 PendingAs of commit 61eb42c with merge base 60cc45c ( This comment was automatically generated by Dr. CI and updates every 15 minutes. |
`mps_linear_backward` passed `grad_output.suggest_memory_format()` to `at::empty()` when allocating the weight and bias gradient tensors. When `grad_output` happened to have NHWC-like strides (e.g. from a permute chain), `suggest_memory_format()` returned `ChannelsLast`, which requires rank 4 — but the weight gradient is 2D and the bias gradient is 1D, triggering "required rank 4 tensor to use channels_last format". Replace the verbose `at::empty(size, scalar_type, nullopt, kMPS, nullopt, suggest_memory_format())` calls with `at::empty(size, grad_output.options())` which carries dtype and device without propagating an incorrect memory format. The bug has existed since the original MPS backend introduction in #77343. Fixes #178222 ghstack-source-id: c8e9c2a Pull-Request: #178278
|
|
||
| Tensor output = at::empty( | ||
| input_size, grad_output.scalar_type(), std::nullopt, kMPS, std::nullopt, grad_output.suggest_memory_format()); | ||
| Tensor output = at::empty(input_size, grad_output.options()); |
There was a problem hiding this comment.
Does this copy the layout by default when passing options or just makes it contiguous?
|
@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 |
|
@pytorchbot merge -f "Lint + MPS are green" |
|
The merge job was canceled or timed out. This most often happen if two merge requests were issued for the same PR, or if merge job was waiting for more than 6 hours for tests to finish. In later case, please do not hesitate to reissue the merge command |
Merge startedYour change will be merged immediately since you used the force (-f) flag, bypassing any CI checks (ETA: 1-5 minutes). Please use Learn more about merging in the wiki. Questions? Feedback? Please reach out to the PyTorch DevX Team |
`mps_linear_backward` passed `grad_output.suggest_memory_format()` to `at::empty()` when allocating the weight and bias gradient tensors. When `grad_output` happened to have NHWC-like strides (e.g. from a permute chain), `suggest_memory_format()` returned `ChannelsLast`, which requires rank 4 — but the weight gradient is 2D and the bias gradient is 1D, triggering "required rank 4 tensor to use channels_last format". This logic existed there since the inception of MPS backend in https://github.com/pytorch/pytorch/77343 Replace verbose `at::empty(size, scalar_type, nullopt, kMPS, nullopt, suggest_memory_format())` with more compact `at::empty(size, grad_output.options())` Fixes #178222 Pull Request resolved: #178278 Approved by: https://github.com/Skylion007 Co-authored-by: Xia-Weiwen <[email protected]>
`mps_linear_backward` passed `grad_output.suggest_memory_format()` to `at::empty()` when allocating the weight and bias gradient tensors. When `grad_output` happened to have NHWC-like strides (e.g. from a permute chain), `suggest_memory_format()` returned `ChannelsLast`, which requires rank 4 — but the weight gradient is 2D and the bias gradient is 1D, triggering "required rank 4 tensor to use channels_last format". This logic existed there since the inception of MPS backend in https://github.com/pytorch/pytorch/77343 Replace verbose `at::empty(size, scalar_type, nullopt, kMPS, nullopt, suggest_memory_format())` with more compact `at::empty(size, grad_output.options())` Fixes pytorch#178222 Pull Request resolved: pytorch#178278 Approved by: https://github.com/Skylion007
`mps_linear_backward` passed `grad_output.suggest_memory_format()` to `at::empty()` when allocating the weight and bias gradient tensors. When `grad_output` happened to have NHWC-like strides (e.g. from a permute chain), `suggest_memory_format()` returned `ChannelsLast`, which requires rank 4 — but the weight gradient is 2D and the bias gradient is 1D, triggering "required rank 4 tensor to use channels_last format". This logic existed there since the inception of MPS backend in https://github.com/pytorch/pytorch/77343 Replace verbose `at::empty(size, scalar_type, nullopt, kMPS, nullopt, suggest_memory_format())` with more compact `at::empty(size, grad_output.options())` Fixes pytorch#178222 Pull Request resolved: pytorch#178278 Approved by: https://github.com/Skylion007
`mps_linear_backward` passed `grad_output.suggest_memory_format()` to `at::empty()` when allocating the weight and bias gradient tensors. When `grad_output` happened to have NHWC-like strides (e.g. from a permute chain), `suggest_memory_format()` returned `ChannelsLast`, which requires rank 4 — but the weight gradient is 2D and the bias gradient is 1D, triggering "required rank 4 tensor to use channels_last format". This logic existed there since the inception of MPS backend in https://github.com/pytorch/pytorch/77343 Replace verbose `at::empty(size, scalar_type, nullopt, kMPS, nullopt, suggest_memory_format())` with more compact `at::empty(size, grad_output.options())` Fixes pytorch#178222 Pull Request resolved: pytorch#178278 Approved by: https://github.com/Skylion007
`mps_linear_backward` passed `grad_output.suggest_memory_format()` to `at::empty()` when allocating the weight and bias gradient tensors. When `grad_output` happened to have NHWC-like strides (e.g. from a permute chain), `suggest_memory_format()` returned `ChannelsLast`, which requires rank 4 — but the weight gradient is 2D and the bias gradient is 1D, triggering "required rank 4 tensor to use channels_last format". This logic existed there since the inception of MPS backend in https://github.com/pytorch/pytorch/77343 Replace verbose `at::empty(size, scalar_type, nullopt, kMPS, nullopt, suggest_memory_format())` with more compact `at::empty(size, grad_output.options())` Fixes pytorch#178222 Pull Request resolved: pytorch#178278 Approved by: https://github.com/Skylion007
Stack from ghstack (oldest at bottom):
mps_linear_backwardpassedgrad_output.suggest_memory_format()toat::empty()when allocating the weight and bias gradient tensors. Whengrad_outputhappened to have NHWC-like strides (e.g. from a permutechain),
suggest_memory_format()returnedChannelsLast, which requires rank 4 — but the weight gradient is 2D and the bias gradient is 1D, triggering "required rank 4 tensor to use channels_last format". This logic existed there since the inception of MPS backend in https://github.com/pytorch/pytorch/77343Replace verbose
at::empty(size, scalar_type, nullopt, kMPS, nullopt, suggest_memory_format())with more compactat::empty(size, grad_output.options())Fixes #178222