<h2 dir="auto">🐛 Bug</h2>
<p dir="auto">Inconsistent shape of index returned from <code class="notranslate">F.max_pool2d_with_indices</code> when used with CUDA tensor. This applies to 3-dimensional tensors.</p>
<h2 dir="auto">To Reproduce</h2>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="x = torch.randn(2, 2, 2).to('cuda')
pred, idx = F.max_pool2d_with_indices(x, 2)
print(pred.shape) # torch.Size([2, 1, 1])
print(idx.shape) # torch.Size([1, 2, 1, 1]) which is inconsistent"><pre class="notranslate"><code class="notranslate">x = torch.randn(2, 2, 2).to('cuda')
pred, idx = F.max_pool2d_with_indices(x, 2)
print(pred.shape) # torch.Size([2, 1, 1])
print(idx.shape) # torch.Size([1, 2, 1, 1]) which is inconsistent
</code></pre></div>
<p dir="auto">Interestingly, this doesn't happen to CPU's tensor.</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="x = torch.randn(2, 2, 2).to('cpu')
pred, idx = F.max_pool2d_with_indices(x, 2)
print(pred.shape) # torch.Size([2, 1, 1])
print(idx.shape) # torch.Size([2, 1, 1]), expected"><pre class="notranslate"><code class="notranslate">x = torch.randn(2, 2, 2).to('cpu')
pred, idx = F.max_pool2d_with_indices(x, 2)
print(pred.shape) # torch.Size([2, 1, 1])
print(idx.shape) # torch.Size([2, 1, 1]), expected
</code></pre></div>
<h2 dir="auto">Environment</h2>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="PyTorch version: 1.5.0
Is debug build: No
CUDA used to build PyTorch: 10.1

OS: Ubuntu 18.04.4 LTS
GCC version: (Ubuntu 7.5.0-3ubuntu1~18.04) 7.5.0
CMake version: Could not collect

Python version: 3.7
Is CUDA available: Yes
CUDA runtime version: 10.1.105
GPU models and configuration: GPU 0: GeForce GTX 1060 6GB
Nvidia driver version: 440.44
cuDNN version: Could not collect

Versions of relevant libraries:
[pip] efficientnet-pytorch==0.6.3
[pip] msgpack-numpy==0.4.4.3
[pip] numpy==1.18.1
[pip] segmentation-models-pytorch==0.1.0
[pip] torch==1.5.0
[pip] torchtext==0.5.0
[pip] torchvision==0.6.0a0+82fd1c8
[conda] blas                      1.0                         mkl
[conda] efficientnet-pytorch      0.6.3                    pypi_0    pypi
[conda] mkl                       2020.0                      166
[conda] mkl-service               2.3.0            py37he904b0f_0
[conda] mkl_fft                   1.0.15           py37ha843d7b_0
[conda] mkl_random                1.1.0            py37hd6b4f25_0
[conda] pytorch                   1.5.0           py3.7_cuda10.1.243_cudnn7.6.3_0    pytorch
[conda] segmentation-models-pytorch 0.1.0                     dev_0    &lt;develop&gt;
[conda] torchtext                 0.5.0                    pypi_0    pypi
[conda] torchvision               0.6.0                py37_cu101    pytorch"><pre class="notranslate"><code class="notranslate">PyTorch version: 1.5.0
Is debug build: No
CUDA used to build PyTorch: 10.1

OS: Ubuntu 18.04.4 LTS
GCC version: (Ubuntu 7.5.0-3ubuntu1~18.04) 7.5.0
CMake version: Could not collect

Python version: 3.7
Is CUDA available: Yes
CUDA runtime version: 10.1.105
GPU models and configuration: GPU 0: GeForce GTX 1060 6GB
Nvidia driver version: 440.44
cuDNN version: Could not collect

Versions of relevant libraries:
[pip] efficientnet-pytorch==0.6.3
[pip] msgpack-numpy==0.4.4.3
[pip] numpy==1.18.1
[pip] segmentation-models-pytorch==0.1.0
[pip] torch==1.5.0
[pip] torchtext==0.5.0
[pip] torchvision==0.6.0a0+82fd1c8
[conda] blas                      1.0                         mkl
[conda] efficientnet-pytorch      0.6.3                    pypi_0    pypi
[conda] mkl                       2020.0                      166
[conda] mkl-service               2.3.0            py37he904b0f_0
[conda] mkl_fft                   1.0.15           py37ha843d7b_0
[conda] mkl_random                1.1.0            py37hd6b4f25_0
[conda] pytorch                   1.5.0           py3.7_cuda10.1.243_cudnn7.6.3_0    pytorch
[conda] segmentation-models-pytorch 0.1.0                     dev_0    &lt;develop&gt;
[conda] torchtext                 0.5.0                    pypi_0    pypi
[conda] torchvision               0.6.0                py37_cu101    pytorch
</code></pre></div>
<h2 dir="auto"><g-emoji class="g-emoji" alias="bug" fallback-src="https://github.githubassets.com/images/icons/emoji/unicode/1f41b.png">🐛</g-emoji> Bug</h2>
<p dir="auto">The parameter <code class="notranslate">requires_grad</code> of <code class="notranslate">new_zeros</code> method of tensors can't set the <code class="notranslate">requires_grad</code> attribute of the created tensor correctly.</p>
<h2 dir="auto">To Reproduce</h2>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="import torch
a = torch.tensor((1.0,))
print(a.new_ones((1,), requires_grad=True).requires_grad)
print(a.new_zeros((1,), requires_grad=True).requires_grad)"><pre class="notranslate"><code class="notranslate">import torch
a = torch.tensor((1.0,))
print(a.new_ones((1,), requires_grad=True).requires_grad)
print(a.new_zeros((1,), requires_grad=True).requires_grad)
</code></pre></div>
<h2 dir="auto">Expected behavior</h2>

<p dir="auto">The output of both print statements should be <code class="notranslate">True</code>. However, while the first is <code class="notranslate">True</code>, the second is <code class="notranslate">False</code>.</p>
<h2 dir="auto">Environment</h2>
<ul dir="auto">
<li>PyTorch Version (e.g., 1.0): 1.4.0</li>
<li>OS (e.g., Linux): Ubuntu 18.04.2 LTS</li>
<li>How you installed PyTorch (<code class="notranslate">conda</code>, <code class="notranslate">pip</code>, source): <code class="notranslate">conda</code></li>
<li>Build command you used (if compiling from source):</li>
<li>Python version: 3.6</li>
<li>CUDA/cuDNN version: 10.1/7.6.1</li>
<li>GPU models and configuration: GeForce RTX 2080 Ti</li>
</ul>
<h2 dir="auto">Additional context</h2>

<p dir="auto">The <code class="notranslate">requires_grad</code> parameter of <code class="notranslate">new_empty</code> and <code class="notranslate">new_full</code> methods also doesn't work.</p>
<p dir="auto">cc <a class="user-mention notranslate" data-hovercard-type="user" data-hovercard-url="/users/ezyang/hovercard" data-octo-click="hovercard-link-click" data-octo-dimensions="link_type:self" href="https://github.com/ezyang">@ezyang</a> <a class="user-mention notranslate" data-hovercard-type="user" data-hovercard-url="/users/gchanan/hovercard" data-octo-click="hovercard-link-click" data-octo-dimensions="link_type:self" href="https://github.com/gchanan">@gchanan</a> <a class="user-mention notranslate" data-hovercard-type="user" data-hovercard-url="/users/zou3519/hovercard" data-octo-click="hovercard-link-click" data-octo-dimensions="link_type:self" href="https://github.com/zou3519">@zou3519</a></p>