tensorflow / tensorflow/probability

RelaxedOneHotCategorical not working with bfloat16 mixed precision

Open
#1,255 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, 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

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 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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.