Skip to content

bug with derivatives of expanded tensors #9145

@shekhovt

Description

@shekhovt

Issue description

When I take derivative of an element of an expanded tensor (or if such expression is a part of the graph) the derivative is incorrect.

Code example

import torch
from torch import Tensor
from torch.nn import Parameter

x = Parameter(Tensor([1]))
y = x.expand([100])
print(torch.autograd.grad(y[0], x)[0].item())
# outputs 100

The expected result is 1

System Info

PyTorch version: 0.4.0
Is debug build: No
CUDA used to build PyTorch: 8.0.61

OS: Debian GNU/Linux 9.3 (stretch)
GCC version: (Debian 6.3.0-18+deb9u1) 6.3.0 20170516
CMake version: version 3.7.2

Python version: 3.5
Is CUDA available: Yes
CUDA runtime version: 9.0.176
GPU models and configuration:
GPU 0: GeForce GTX 1080
GPU 1: GeForce GTX 1080

Nvidia driver version: 384.98
cuDNN version: Probably one of the following:
/usr/local/cuda-7.5/lib64/libcudnn.so.7.0.64
/usr/local/cuda-7.5/lib64/libcudnn_static.a
/usr/local/cuda-9.0/lib64/libcudnn.so.7.0.3
/usr/local/cuda-9.0/lib64/libcudnn_static.a
/usr/local/lib/python3.5/dist-packages/torch/lib/libcudnn-900fef33.so.7.0.5
/usr/local/matlab90/bin/glnxa64/libcudnn.so.7.0.64

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions