StatelessSampleMultinomial
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: This operator is an internal service operator used when the
aclnnMultinomialGetWorkspaceSizeandaclnnMultinomialTensorGetWorkspaceSizeAPIs build the computation flow. It is used for the with-replacement multinomial distribution sampling path on Ascend 950. Based on the input cumulative distribution and random seed, the operator drawsnum_samplessamples from each multinomial distribution and stores the category indexes of the samples in the output tensor. -
Computation formula:
For the jj-th draw of the dd-th distribution, a random number is generated:
ud,j∼U(0,1]u_{d,j} \sim U(0, 1]
The output is the smallest category index kk that satisfies the following condition:
xd,k−1<ud,j≤xd,kx_{d,k-1} < u_{d,j} \le x_{d,k}
Parameter Description
| Parameter Name | Input/Output/Attribute | Description | Data Type | Data Format |
|---|---|---|---|---|
| x | Input | Input cumulative distribution tensor, with the shape (C) or (N, C). The last dimension represents the cumulative probability of categories. | FLOAT, FLOAT16, BFLOAT16 | ND |
| norm_probs | Optional Input | Normalized probability tensor, with the same shape and data type as x. When it is passed in, it is used for the fallback of zero-probability categories in the sampling results. | FLOAT, FLOAT16, BFLOAT16 | ND |
| seed | Input | Seed of the random number generator, which affects the generated random number sequence. | INT64 | ND |
| offset | Input | Offset of the random number generator, which affects the position in the generated random number sequence. | INT64 | ND |
| num_samples | Attribute | Number of samples drawn from each multinomial distribution. | INT64 | - |
| y | Output | Category indexes of the output samples, with the shape (num_samples) or (N, num_samples). | INT64 | ND |
Constraint Description
xis a 1D or 2D tensor, and its last dimension is the category dimension whose length does not exceed 2242^{24}.norm_probsis an optional input. When it is passed in, its shape and data type are the same as those ofx, andxis the result of computing the cumulative sum ofnorm_probsalong the last dimension. When it is not passed in, the fallback of zero-probability categories is performed by comparing adjacent elements ofx.num_samplesis a positive integer.offsetis an integer multiple of 4.
Invocation Description
| Invocation Method | Sample Code | Description |
|---|---|---|
| aclnn invocation | test_aclnn_multinomial | The StatelessSampleMultinomial service operator is invoked internally when the computation flow is built through the aclnnMultinomial API. |
| aclnn invocation | test_aclnn_multinomial_tensor | The StatelessSampleMultinomial service operator is invoked internally when the computation flow is built through the aclnnMultinomialTensor API. |