tensorflow / tensorflow/probability

No trainable variables for real_nvp_default_template

Open
#1,439 3 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Jupyter Notebook
Stars
4.4k
Forks
1.1k
PR merge metrics
No merged PRs in 30d

Description

Hi,

Configuration:
TF version '2.4.0'
TFP version '0.12.2'

I am trying to use real_nvp template in RealNVP bijector as given in the example in the docs
https://www.tensorflow.org/probability/api_docs/python/tfp/bijectors/RealNVP

sample() and log_prob() functions work but I do not see any trainable variables which are declared in the template.

tfd = tfp.distributions
tfb = tfp.bijectors

# A common choice for a normalizing flow is to use a Gaussian for the base
# distribution. (However, any continuous distribution would work.) E.g.,
nvp = tfd.TransformedDistribution(
    distribution=tfd.MultivariateNormalDiag(loc=[0., 0., 0.]),
    bijector=tfb.RealNVP(
        num_masked=2,
        shift_and_log_scale_fn=tfb.real_nvp_default_template(
            hidden_layers=[512, 512])))

x = nvp.sample()
nvp.log_prob(x)
nvp.log_prob([0.0, 0.0, 0.0])

print(nvp.trainable_variables)

>>>()

In fact the bijector itself does not seem to inherit any trainable variables

template = tfb.real_nvp_default_template(hidden_layers=[512, 512])
bijector = tfb.RealNVP(num_masked=1, shift_and_log_scale_fn=template)
bijector.forward([0.5, 1., 2.])
bijector.trainable_variables

>>> ()

Is this supposed to be so?

Thanks

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by running the provided RealNVP and real_nvp_default_template snippets with TensorFlow 2.4.0 and TensorFlow Probability 0.12.2, then inspect how trainable_variables are exposed by the bijector and template. Compare the observed behavior with the RealNVP API example and determine whether the missing variables indicate a bug or expected behavior.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
machine-learning
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.