tensorflow / tensorflow/probability
tfd.Categorical.log_prob returns wrong dtype
Nobody has claimed this yet.
- Dominant language
- Jupyter Notebook
- Stars
- 4.4k
- Forks
- 1.1k
- PR merge metrics
- No merged PRs in 30d
Description
In tfd.Categorical, the log_prob method derives its return type from the logits (or probs) constructor argument, as in the following:
logits32 = tf.constant([1,2,3,4], dtype=tf.float32)
tfd.Categorical(logits=logits).log_prob(2).dtype == tf.float32 # True
logits64 = tf.constant([1,2,3,4], dtype=tf.float64)
tfd.Categorical(logits=logits).log_prob(2).dtype == tf.float64 # True
However, if a list (batch) of [logits] is supplied, an unexpected type demotion occurs such that the return value of log_prob defaults tf.float32:
logits64 = tf.constant([1,2,3,4], dtype=tf.float64)
tfd.Categorical(logits=[logits]).log_prob(2).dtype == tf.float64 # False
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
Start at tfd.Categorical.log_prob and reproduce the reported dtype difference between a direct float64 logits tensor and a one-element list containing it. Trace how the batched constructor argument determines the return dtype, then add a regression test showing that the list form preserves float64 and run the relevant Categorical tests.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- tensorflow
- Domain
- machine-learning
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 42/100