| Files | Last commit | Last update |
|---|---|---|
| 2 months ago | ||
| 5 months ago | ||
| 5 months ago | ||
| 29 days ago | ||
| 5 months ago | ||
| 17 days ago | ||
| 29 days ago | ||
| 4 days ago | ||
| 4 days ago |
StatelessUniform
English | 简体中文
Product Support Status
| Product | Supported |
|---|---|
| Ascend 950PR&950DT products | √ |
| Atlas A3 products | × |
| Atlas A2 products | × |
| Atlas 200I/500 A2 inference products | × |
| Atlas inference products | × |
| Atlas training products | × |
Function Description
-
Operator function: generates a random number tensor that follows the uniform distribution based on the Philox4x32-10 pseudo-random number generation algorithm. The random values are in the range [from, to), and the interpretation of the bounds and upper-bound wrap follows the values after conversion to the output data type.
-
Computation formula:
Let TT be the output data type (FLOAT32, FLOAT16, or BFLOAT16), and fromfrom and toto be DOUBLE scalars. They are first converted to FLOAT32 in the tiling stage, then converted to TT to obtain the bounds aa and bb; the difference dd is also stored as TT:
a=T(FLOAT32(from)),b=T(FLOAT32(to)),d=T(b−a)a = T(\text{FLOAT32}(from)), \quad b = T(\text{FLOAT32}(to)), \quad d = T(b - a)
Here, xix_i is the raw uint32 random number generated by the Philox4x32-10 algorithm, and uiu_i and the candidate value viv_i are computed as follows:
ui=FLOAT32(FLOAT32(xi)×2−32+2−33),vi=T(FLOAT32(ui)×FLOAT32(d)+FLOAT32(a))u_i = \text{FLOAT32}\left(\text{FLOAT32}(x_i) \times 2^{-32} + 2^{-33}\right), \quad v_i = T\left(\text{FLOAT32}(u_i) \times \text{FLOAT32}(d) + \text{FLOAT32}(a)\right)
The candidate value is first converted back to the output data type and then compared with the upper bound bb using
==: if equal, it is replaced with the lower bound aa; otherwise viv_i is kept:yi={a,vi=bvi,vi≠by_i = \begin{cases} a, & v_i = b \\ v_i, & v_i \neq b \end{cases}
The normalization of uiu_i is the same as that of the competitor curand_uniform, i.e., u=x×2−32+2−33u = x \times 2^{-32} + 2^{-33} (computed in FLOAT32). Due to FLOAT32 rounding, uiu_i may reach 1 in FLOAT32, and the candidate value in FLOAT16/BFLOAT16 may also equal the upper bound after conversion to the output type; when the candidate value is exactly equal to the upper bound bb, the upper-bound wrap above is triggered. Therefore, [from,to)[from, to) should be interpreted based on the converted bounds: when a<ba < b, yi∈[a,b)y_i \in [a, b) usually holds, but due to floating-point rounding, when uiu_i is close to 1 the candidate value may be slightly greater than bb and not equal to bb (no wrap), in which case yiy_i may slightly exceed bb; the lower bound aa always holds. When a=ba = b (a degenerate case where fromfrom and toto coincide after conversion to the output type), yiy_i is always aa. The above computation does not change the generation rule of the Philox random sequence and applies only to this operator and its supported products.
Parameter Description
| Parameter Name | Input/Output/Attribute | Description | Data Type | Data Format |
|---|---|---|---|---|
| shape | Input | Shape of the output tensor, a 1-D tensor. | INT64 | ND |
| seed | Input | Random number seed of the Philox algorithm, a 0-D scalar. | INT64 | ND |
| offset | Input | Offset of the Philox algorithm, a 0-D scalar. It must be a multiple of 4. | INT64 | ND |
| from | Input | Inclusive lower bound of the uniform distribution random range, a 0-D scalar. | DOUBLE | ND |
| to | Input | Exclusive upper bound of the uniform distribution random range, a 0-D scalar. | DOUBLE | ND |
| y | Output | Outputs uniform distribution random values with the specified shape, with the value range [from, to); the bounds are interpreted based on the values converted to the output data type (see Computation formula). | FLOAT16, BFLOAT16, FLOAT32 | ND |
| dtype | Attribute | Data type of the output, which is FLOAT32 by default. | Type | - |
Constraint Description
- offset must be a multiple of 4.
- The output tensor supports 0 to 8 dimensions.
- from must be less than or equal to to, and to - from cannot exceed the representation range of the output data type.
Invocation Description
| Invocation Method | Sample Code | Description |
|---|---|---|
| aclnn invocation | test_aclnn_stateless_uniform | Invokes the StatelessUniform operator through the aclnnInplaceUniform API. |
| Graph-mode invocation | test_geir_stateless_uniform | Invokes the StatelessUniform operator by building a graph through the operator IR. |