tensorflow / tensorflow/probability
RelaxedOneHotCategorical not working with bfloat16 mixed precision
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, I was trying to train a model using a RelaxedOneHotCategorical wrapped in a DistributionLambda layer on TPU.
Unfortunately when using the bfloat16 TPU mixed precision option I run into the following error:
ValueError: data type <class 'bfloat16'> not inexact
This seems to occur from within the sampling function of the distribution:
275 uniform = samplers.uniform(
276 shape=uniform_shape,
--> 277 minval=np.finfo(dtype_util.as_numpy_dtype(self.dtype)).tiny,
278 maxval=1.,
279 dtype=self.dtype,
Minimalist example to reproduce:
tfpl.DistributionLambda(lambda x: tfd.RelaxedOneHotCategorical(0.0, x))(tf.ones(1))
Any help would be appreciated, thanks.
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 with the RelaxedOneHotCategorical sampling function, especially the samplers.uniform call using np.finfo(dtype_util.as_numpy_dtype(self.dtype)). Reproduce the failure with the DistributionLambda minimal example under TPU bfloat16 mixed precision. Done means sampling succeeds without the bfloat16 inexact error.
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
- Mostly clear
- Newbie friendliness
- 35/100