tensorflow / tensorflow/probability
TransformedVariable does not follow array convention for equality (==) comparison
Nobody has claimed this yet.
- Dominant language
- Jupyter Notebook
- Stars
- 4.4k
- Forks
- 1.1k
- PR merge metrics
- No merged PRs in 30d
Description
A tfp.util.TransformedVariable generally behaves like any tensor-like object. For example, a less-than-equal comparison works element-wise, as expected:
import tensorflow as tf
import tensorflow_probability as tfp
var = tf.Variable(1.0)
assert var <= 1.0 and var >= 1.0 and var == 1.0 # passes
t_var = tfp.util.TransformedVariable(1.0, tfp.bijectors.Identity())
assert t_var <= 1.0 and t_var >= 1.0 # passes
However, equality comparison does not behave likewise, and the following fails:
assert t_var == 1.0 # FAILS
This is completely unexpected behaviour which can lead to very subtle downstream bugs.
The reason for this behaviour seems to be due to explicitly removing __eq__ and __ne__ in https://github.com/tensorflow/probability/blob/a91efeb17a6f6fdae97d3465878f5fc7fba12d30/tensorflow_probability/python/util/deferred_tensor.py#L86
What was the motivation for excluding equality comparisons? Would there be any objections to a PR that removes that line, thereby allowing tfp TransformedVariables to behave more expectedly like tf Variables?
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Open tensorflow_probability/python/util/deferred_tensor.py at line 86 and inspect why eq and ne are removed. Run the Python reproducer from the issue and compare TransformedVariable equality with TensorFlow Variable behavior. Done means equality comparisons behave consistently without breaking the existing tensor-like comparisons.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python
- Domain
- machine-learning
- Issue type
- Bug
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Activity status
- Stale
- Clarity
- Clearly specified
- Newbie friendliness
- 42/100