tensorflow / tensorflow/probability

Warning message: Distribution subclass TanhTransformedDistribution inherits _parameter_properties from its parent ...

Open
#1,458 2 comments 4 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

I can see a bunch of super-long warning messages generated from Distribution classes:

https://github.com/tensorflow/probability/blob/main/tensorflow_probability/python/distributions/distribution.py#L291-L325

W1103 21:19:41.807866 140018421924672 distribution.py:296]                                                                        
Distribution subclass TanhTransformedDistribution inherits `_parameter_properties from its parent (TransformedDistribution)       
while also redefining `__init__`. The inherited annotations cover the following                                                   
parameters: dict_keys(['distribution', 'bijector']). It is likely that these do not match the subclass parameters.                
This may lead to errors when computing batch shapes, slicing into batch                                                           
dimensions, calling `.copy()`, flattening the distribution as a CompositeTensor                                                   
(e.g., when it is passed or returned from a `tf.function`), and possibly other                                                    
cases. The recommended pattern for distribution subclasses is to define a new                                                     
`_parameter_properties` method with the subclass parameters, and to store the                                                     
corresponding parameter values as `self._parameters` in `__init__`, after                                                         
calling the superclass constructor:                                                                                               
                                                                                                                                  
class MySubclass(tfd.SomeDistribution):                                                                                           
                                                                                                                                  
  def __init__(self, param_a, param_b):                                                                                           
    parameters = dict(locals())                                                                                                   
    # ... do subclass initialization ...                                                                                          
    super(MySubclass, self).__init__(**base_class_params)                                                                         
    # Ensure that the subclass (not base class) parameters are stored.                                                            
    self._parameters = parameters                                                                                                 
                                                                                                                                  
  def _parameter_properties(self, dtype, num_classes=None):                                                                       
    return dict(                                                                                                                  
      # Annotations may optionally specify properties, such as `event_ndims`,                                                     
      # `default_constraining_bijector_fn`, `specifies_shape`, etc.; see                                                          
      # the `ParameterProperties` documentation for details.                                                                      
      param_a=tfp.util.ParameterProperties(),                                                                                     
      param_b=tfp.util.ParameterProperties())                                                                                                                                                                                                                       

Caller: Just a plain normal TanhTransformedDistribution(distribution): see
https://github.com/deepmind/acme/blob/4544216e322b849e07ce1d964d2129054e611568/acme/jax/networks/distributional.py#L230-L231

I was simply running dm-acme example code. How to reproduce: please run https://github.com/deepmind/acme/blob/master/examples/gym/run_sac.py

The packages I used (non-exhaustive list):

tf-nightly==2.8.0.dev20211102
tfp-nightly==0.15.0.dev20211103
dm-acme (nightly, HEAD)
dm-haiku==0.0.5

Questions:

  • Why is this happening? Is this a bug or invalid usage (perhaps happened due to dm-haiku)? From the user code and implementation of NormalTanhDistribution, I don't see anything suspicious or wrong.
  • Is it possible to disable/ignore such warnings? The package is using a root logger, so module-wise disabling seems not easy.

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 with tensorflow_probability/python/distributions/distribution.py#L291-L325 and reproduce the warning using dm-acme's examples/gym/run_sac.py. Compare the warning's inherited parameters with TanhTransformedDistribution and determine whether the behavior or warning handling is incorrect; done means the reported warning is appropriately resolved or its suppression behavior is clarified.

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
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.