Skip to content
This repository was archived by the owner on Jul 7, 2023. It is now read-only.

Return ed.RandomVariables in initializers and operate on them in regu…#1182

Merged
afrozenator merged 1 commit into
tensorflow:masterfrom
dustinvtran:master
Nov 7, 2018
Merged

Return ed.RandomVariables in initializers and operate on them in regu…#1182
afrozenator merged 1 commit into
tensorflow:masterfrom
dustinvtran:master

Conversation

@dustinvtran

@dustinvtran dustinvtran commented Oct 31, 2018

Copy link
Copy Markdown
Contributor

…larizers.

@markvdw @dusenberrymw @danijar @balajiln: PTAL. After approval, I will merge the PR via an internal process.

@afrozenator: I'm sending this as a GitHub pull request for external collaborators to review and add comments. I'm not sure this change works with Travis, as the test now requires tfp as an import. Has that Q been resolved?

@googlebot googlebot added the cla: yes PR author has signed CLA label Oct 31, 2018

@dusenberrymw dusenberrymw left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This LGTM. Using Edward2 RVs makes this much cleaner, particularly for the KL divergences.

Comment thread tensor2tensor/layers/bayes.py Outdated

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was thinking that we could create and store this in the build function to remove a bit of Python overhead in eager mode, but it looks like Edward2 RVs only sample from the underlying distribution on the first access in eager mode due to rv.value using a memoization strategy by storing the sample on the first access. It seems like it could potentially simplify some use cases if rv.value called rv.distribution.sample on each access to rv.value. That being said, you definitely thought much longer on the design of Edward[1|2], so I bet there is a reason that would make this undesirable.

@dustinvtran dustinvtran Nov 1, 2018

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We memoize for usability reasons, so that you operate on RandomVariables as if they were any other Tensor. For example, if you call x = ed.Normal(...), you would expect y = x + 1 and z = x + 1 to return the same result.

On caching: There's an issue that actually arises before Ed2, which is that during __init__, Distributions call TF ops on its parameters. This breaks gradients if Distribution.__init__ isn't recorded in the gradient tape. @vdumoulin raised a point about this in Brain Chat.

Comment thread tensor2tensor/layers/bayes.py Outdated

@danijar danijar Nov 3, 2018

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Any reason to not create this object in __init__ already instead of saving self.mean and save.stddev separately?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Breaks Eager unfortunately if self.mean and self.stddev depend on trainable variables. See the above comment about caching. It would be nice if Distribution __init__s don't add TF ops to the graph.

@afrozenator afrozenator merged commit a91c2bb into tensorflow:master Nov 7, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

cla: yes PR author has signed CLA

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants