From 5654b68731f9d3fffc186ce6f528030a7c1cef03 Mon Sep 17 00:00:00 2001 From: Nikita Shulga Date: Mon, 7 Feb 2022 13:51:06 -0800 Subject: [PATCH] Revert D34011981: [pytorch][PR] remove some spurious warnings fixing Test Plan: revert-hammer Differential Revision: D34011981 (https://github.com/pytorch/pytorch/commit/1bad3c4a84ee474adec7a5c241a983e72284b6f5) Original commit changeset: 55bedc8a4092 Original Phabricator Diff: D34011981 (https://github.com/pytorch/pytorch/commit/1bad3c4a84ee474adec7a5c241a983e72284b6f5) fbshipit-source-id: 216643e251597cd7086e7854426f4f189a77adc9 (cherry picked from commit bb3955050062736e44e6163512ee877d751eece0) --- .../autograd/utils/grad_layout_contract.h | 19 +++---------------- 1 file changed, 3 insertions(+), 16 deletions(-) diff --git a/torch/csrc/autograd/utils/grad_layout_contract.h b/torch/csrc/autograd/utils/grad_layout_contract.h index 7d1e66a0fdc..4d1787d55c7 100644 --- a/torch/csrc/autograd/utils/grad_layout_contract.h +++ b/torch/csrc/autograd/utils/grad_layout_contract.h @@ -13,22 +13,9 @@ namespace utils { inline bool obeys_layout_contract(const at::Tensor& grad, const at::Tensor& variable) { TORCH_INTERNAL_ASSERT(!grad.is_sparse()); TORCH_INTERNAL_ASSERT(!variable.is_sparse()); - if (variable.is_non_overlapping_and_dense()) { - // Only look at stride for dimensions that are not of size 1 - const auto& grad_sizes = grad.sizes(); - const auto& grad_strides = grad.strides(); - const auto& variable_strides = variable.strides(); - for (const auto idx : c10::irange(grad_sizes.size())) { - if (grad_sizes[idx] != 1) { - if (grad_strides[idx] != variable_strides[idx]) { - return false; - } - } - } - return true; - } else { - return grad.is_contiguous(at::MemoryFormat::Contiguous); - } + return variable.is_non_overlapping_and_dense() ? + (grad.strides() == variable.strides()) : + grad.is_contiguous(at::MemoryFormat::Contiguous); } // Creates a clone of new_grad that obeys the contract with variable.