But when I change his form I have a new error with loss.backward, I have this :

RuntimeError: invalid argument 3: Index tensor must be either empty or have same dimensions as input tensor at /opt/conda/conda-bld/pytorch_1549630534704/work/aten/src/THC/generic/THCTensorScatterGather.cu:115

I try to change dimension of my torch.mean(xxx, dim= ), but it’s not the good way,I have this error too :

RuntimeError: grad can be implicitly created only for scalar outputs