HEmile / storchastic

Stochastic Automatic Differentiation library for PyTorch.
GNU General Public License v3.0
180 stars 5 forks source link

ValueError: The value argument to log_prob must be a Tensor #90

Closed zhaoguangyuan123 closed 3 years ago

zhaoguangyuan123 commented 3 years ago

I use python=3.8 and pytorch=1.8.1 and test the examplebernoulli_toy.py Error happens in the following line in expect.py log_probs = tensor.distribution.log_prob(tensor) error is ValueError: The value argument to log_prob must be a Tensor

Seems .log_prob() wants a tensor object as input. When I print the 'tensor', it outputs:

x: Stochastic tensor([[0., 0., 0., 0.],
        [0., 0., 0., 1.],
        [0., 0., 1., 0.],
        [0., 0., 1., 1.],
        [0., 1., 0., 0.],
        [0., 1., 0., 1.],
        [0., 1., 1., 0.],
        [0., 1., 1., 1.],
        [1., 0., 0., 0.],
        [1., 0., 0., 1.],
        [1., 0., 1., 0.],
        [1., 0., 1., 1.],
        [1., 1., 0., 0.],
        [1., 1., 0., 1.],
        [1., 1., 1., 0.],
        [1., 1., 1., 1.]]) Batch links: [('x', 16, tensor(0.0625))]

Could you offer some solutions? Thank you

HEmile commented 3 years ago

Hi! What version of the code are you using?

zhaoguangyuan123 commented 3 years ago

Hi, I get a bit confused about version. But I just git clone your_repo and then do thepip install -e .. The verision is version="0.1.0",

Could you expand on your question if information here is insufficient?

best guangyuan

HEmile commented 3 years ago

Fair enough. So you cloned the master branch or the DiCE branch?

zhaoguangyuan123 commented 3 years ago

yes, i cloned the master branch.

HEmile commented 3 years ago

Alright, can you try the DiCE branch? The master branch is pretty outdated :) (I am going to improve that soonish)

zhaoguangyuan123 commented 3 years ago

Sure. I am going to check that branch right away and keep u updated. Thanks

zhaoguangyuan123 commented 3 years ago

I tried "git clone --branch dice --single-branch https://github.com/HEmile/storchastic.git" and then re-run the introduction.py in the examples folder.

However, I still get the same bug.

Did i miss any steps?

best Guangyuan

HEmile commented 3 years ago

Hi Guanyuan, You're right, I wasn't running on torch 1.8.1. Looks like they have a breaking change somewhere. I just pushed a fix https://github.com/HEmile/storchastic/commit/4b464df1395dcacbf46409632a16f006a677dae9 on the dice branch, introduction.py runs properly for me now. Thanks for the report!