<p dir="auto">This could be implemented as <code class="notranslate">dist1.kldiv(dist2)</code> (provided <code class="notranslate">type(dist1) == type(dist2)</code>) or something similar. KL divergence is a very useful diagnostic for policy gradient algorithms in general and some have a KL divergence penalty as part of their objective function (<a href="https://arxiv.org/pdf/1707.02286.pdf" rel="nofollow">e.g.</a>), so I think this would be useful to have.</p>
<p dir="auto"><del>Also, the documentation mentions an <a href="http://pytorch.org/docs/master/distributions.html#torch.distributions.Distribution.entropy" rel="nofollow">entropy()</a> method but doing dir(torch.distributions.Distribution) on my installation shows no such method. Is that correct?</del></p>
<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>
<h2 dir="auto">To Reproduce</h2>
<p dir="auto">When tensors are on cpu, following program acts correctly.</p>
<p dir="auto"># adding 1.0 to a[0] twice<br>
DEVICE = torch.device("cpu")<br>
a = torch.zeros((3), device=DEVICE)<br>
a.index_put_([torch.tensor([0, 0], device=DEVICE)], torch.tensor(1., device=DEVICE), accumulate=True)</p>
<blockquote>
<p dir="auto">tensor([2., 0., 0.])</p>
</blockquote>
<p dir="auto">But on gpu,<br>
DEVICE = torch.device("cuda:0")<br>
a = torch.zeros((3), device=DEVICE)<br>
a.index_put_([torch.tensor([0, 0], device=DEVICE)], torch.tensor(1., device=DEVICE), accumulate=True)</p>
<blockquote>
<p dir="auto">RuntimeError: linearIndex.numel()<em>sliceSize</em>nElemBefore == value.numel() INTERNAL ASSERT FAILED at /opt/conda/conda-bld/pytorch_1587428398394/work/aten/src/ATen/native/cuda/Indexing.cu:220, please report a bug to PyTorch. number of flattened indices did not match number of elements in the value tensor21</p>
</blockquote>
<p dir="auto">It seems adding single value torch.tensor(1.) at multiple indices torch.tensor([0, 0]) is supperted on cpu, but not on gpu.<br>
I could add multiple values torch.tensor([1., 1.]) at multiple indices torch.tensor([0, 0]) bath on cpu and on gpu.</p>
<h2 dir="auto">Environment</h2>
<p dir="auto">PyTorch version: 1.5.0<br>
Is debug build: No<br>
CUDA used to build PyTorch: 10.1</p>
<p dir="auto">OS: Ubuntu 18.04.4 LTS<br>
GCC version: (Ubuntu 7.5.0-3ubuntu1~18.04) 7.5.0<br>
CMake version: version 3.10.2</p>
<p dir="auto">Python version: 3.7<br>
Is CUDA available: Yes<br>
CUDA runtime version: Could not collect<br>
GPU models and configuration: GPU 0: GeForce GTX 1080<br>
Nvidia driver version: 418.87.00<br>
cuDNN version: Could not collect</p>
<p dir="auto">Versions of relevant libraries:<br>
[pip3] numpy==1.18.4<br>
[pip3] torch==1.5.0<br>
[conda] blas                      1.0                         mkl<br>
[conda] cudatoolkit               10.1.243             h6bb024c_0<br>
[conda] mkl                       2020.0                      166<br>
[conda] mkl-service               2.3.0            py37he904b0f_0<br>
[conda] mkl_fft                   1.0.15           py37ha843d7b_0<br>
[conda] mkl_random                1.1.0            py37hd6b4f25_0<br>
[conda] numpy                     1.16.6                   pypi_0    pypi<br>
[conda] numpydoc                  0.9.2                      py_0<br>
[conda] pytorch                   1.5.0           py3.7_cuda10.1.243_cudnn7.6.3_0    pytorch<br>
[conda] torchvision               0.6.0                py37_cu101    pytorch</p>
<p dir="auto">cc <a class="user-mention notranslate" data-hovercard-type="user" data-hovercard-url="/users/mruberry/hovercard" data-octo-click="hovercard-link-click" data-octo-dimensions="link_type:self" href="https://github.com/mruberry">@mruberry</a> <a class="user-mention notranslate" data-hovercard-type="user" data-hovercard-url="/users/kurtamohler/hovercard" data-octo-click="hovercard-link-click" data-octo-dimensions="link_type:self" href="https://github.com/kurtamohler">@kurtamohler</a> <a class="user-mention notranslate" data-hovercard-type="user" data-hovercard-url="/users/brianjo/hovercard" data-octo-click="hovercard-link-click" data-octo-dimensions="link_type:self" href="https://github.com/brianjo">@brianjo</a> <a class="user-mention notranslate" data-hovercard-type="user" data-hovercard-url="/users/jlin27/hovercard" data-octo-click="hovercard-link-click" data-octo-dimensions="link_type:self" href="https://github.com/jlin27">@jlin27</a></p>