blei-lab / edward

A probabilistic programming language in TensorFlow. Deep generative models, variational inference.
http://edwardlib.org
Other
4.83k stars 761 forks source link

save Bayesian Neural Network model using simple_save results in a HUGE file #919

Open pswpswpsw opened 5 years ago

pswpswpsw commented 5 years ago

I use Tensorflow default save model API, it works. It can save and read model.

But simply for a two layer neural network with 8 hidden units costs me 68MB to save the model!

Just to report this issue. I don't get it why because the number of variable need to save is simply doubled for most cases in ADVI for mean-field approximation. My best guess is that the number of tensor operations by Edward are huge. So that since simple save saves everything.

In principle, if one save the model by manually collecting all the variable not operation, it should be fine.

update

When I use the manual save, I found the it is the .meta file that is to blame. So somehow, the graph created by Edward under the surface is becoming too much expensive for even saving a simple network.

pswpswpsw commented 5 years ago

I figured this out.

The problem is after each epoch, I want to evaluate the performance by calling ed.evaluate

Everytime I call it, it might add new Node in to the graph, thus it causes the graph to become larger and larger.