IntelLabs / bayesian-torch

A library for Bayesian neural network layers and uncertainty estimation in Deep Learning extending the core of PyTorch
BSD 3-Clause "New" or "Revised" License
533 stars 73 forks source link

Pytorch version issue #6

Closed hebowei2000 closed 3 years ago

hebowei2000 commented 3 years ago

Hi, it seems that this software only supports Pytorch 1.8.1 LTS or newer version. When I try to use this code in my own project(which is mainly based on Pytorch 1.4.0), some conflicts occur and seemingly unavoidable. Could you please update this software to make it also support some older version Pytorch, for example, 1.4.0. Great Thanks!!!

ranganathkrishnan commented 3 years ago

Hi @hebowei2000, can you please give details on the conflicts that you are observing with PyTorch 1.4.0?

hebowei2000 commented 3 years ago

Thanks! For example, when I use LinearReparameterization class to build a q function neural network in the SAC algorithm, I met an error like this. When I update my Pytorch to 1.8.1 LTS, this error disappears. But some of my former programs only support Pytorch 1.4.0. So directly updating Pytorch to 1.8.1 is not a good idea for me actually. "Traceback (most recent call last): File "bayesian_mujoco_new.py", line 217, in experiment(variant) File "bayesian_mujoco_new.py", line 49, in experiment posterior_rho_init=posterior_rho_init, File "/nfs/project/mingyue/bayesian-torch/bayesian_torch/layers/variational_layers/linear_variational.py", line 90, in init persistent=False) TypeError: register_buffer() got an unexpected keyword argument 'persistent'"

ranganathkrishnan commented 3 years ago

@hebowei2000 , Thanks for the details. We introduced this to avoid saving the buffers in the model checkpoint to reduce the model size, as these buffers are not required after the model is trained (ref commit: https://github.com/IntelLabs/bayesian-torch/commit/09b8d0a2d7a6a8ee2e04402b62c09a3c8b6a19c0). A simple fix to your issue to make backward compatible to PyTorch 1.4.0 is to remove the "persistent=False" from all the variational layer definitions (undo commit https://github.com/IntelLabs/bayesian-torch/commit/09b8d0a2d7a6a8ee2e04402b62c09a3c8b6a19c0 changes). I hope this helps!

hebowei2000 commented 3 years ago

@ranganathkrishnan Great thanks! The issue has been resolved perfectly.