Created by: pangyoki
PR types
Others
PR changes
APIs
Describe
In Paddle 2.0-beta, PR #26006 add a new default_dtype
API. This PR is used to support global default dtype for distribution related APIs.
Distribution related APIs include:
- op:
- paddle.tensor.random.bernoulli
- paddle.tensor.random.gaussian_random
- paddle.tensor.random.standard_normal
- paddle.tensor.random.normal
- paddle.tensor.random.uniform
- paddle.tensor.random.randn
- paddle.tensor.random.rand
- paddle.tensor.random.randint
- paddle.tensor.random.randperm
- sample method of distribution related classes
- paddle.distribution.Normal
- paddle.distribution.Uniform
They are divided into the following categories:
- have
dtype
parameter and the default value isfloat32
, including:
- paddle.tensor.random.gaussian_random
- paddle.tensor.random.standard_normal
- paddle.tensor.random.uniform
- paddle.tensor.random.randn
- paddle.tensor.random.rand
method:
Set None
to dtype
parameter. if dtype
is None
, get the value of dtype
from global dtype
.
Because global dtype
support [float16
, float32
, float64
], but these distribution related APIs only support [float32
, float64
]. So if global dtype
is float16
, remind users that the dtype has error.
- have
dtype
parameter and the default value isint
, including:
- paddle.tensor.random.randint
- paddle.tensor.random.randperm
Can't use global dtype
for global dtype
not supporting int
.
- don't have
dtype
parameter and have input tensor, including:
- paddle.tensor.random.bernoulli
Be consistent with Pytorch. get the output value of dtype
from dtype of input tensor.
Don't use global dtype
.
- Call other distritbuion APIs, including:
- paddle.tensor.random.normal
- sample method in paddle.distribution.Normal
- sample method in paddle.distribution.Uniform
Let the dtype of uniform
be consistent with the dtype of low
parameter and high
parameter.
Let the dtype of normal
be consistent with the dtype of mean
parameter and std
parameter.
Don't use default dtype
.