Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

IndependentReparametrizationSampler.sample method creates a tf.Variable #811

Open
pio-neil opened this issue Jan 19, 2024 · 0 comments
Open
Assignees
Labels
enhancement New feature or request

Comments

@pio-neil
Copy link

The IndependentReparametrizationSampler.sample method creates a tf.Variable the first time it's called:

if self._eps is None:
  self._eps = tf.Variable(sample_eps())

This works ok, but causes some strange behaviour with TensorFlow compilation. Specifically, if a tf.Variable is created within a tf.function it causes the function to be traced (compiled) twice in a row, which affects speed.

I think this is due to the dependence of eps on the number of latent model dimensions, but it would be better if this variable creation could be avoid somehow. One suggestion is that the model event shapes could be part of the ProbabilisticModel interface. Something like:

@property
@abstractmethod
def event_shape(self) -> TensorType:
    ....
@uri-granta uri-granta added the enhancement New feature or request label Feb 4, 2024
@uri-granta uri-granta self-assigned this Feb 4, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants