FilesLast commitLast update
12 days ago
2 months ago
2 months ago
19 days ago
19 days ago
2 months ago
26 days ago
19 days ago
1 month ago
5 days ago
README

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 aclnnMultinomialGetWorkspaceSize and aclnnMultinomialTensorGetWorkspaceSize APIs 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 draws num_samples samples 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

  1. x is a 1D or 2D tensor, and its last dimension is the category dimension whose length does not exceed 2242^{24}.
  2. norm_probs is an optional input. When it is passed in, its shape and data type are the same as those of x, and x is the result of computing the cumulative sum of norm_probs along the last dimension. When it is not passed in, the fallback of zero-probability categories is performed by comparing adjacent elements of x.
  3. num_samples is a positive integer.
  4. offset is 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.