MultinomialOperation

Applicable Products

Hardware Model

Supported

Atlas 350 accelerator cards

x

Atlas A3 inference products/Atlas A3 training products

√

Atlas A2 training products/Atlas A2 inference products

√

Atlas training products

x

Atlas inference products

x

Atlas 200I/500 A2 inference products

x

Description

Samples the last axis by randomly extracting numSamples values and outputting the index.

Definition

1
2
3
4
5
struct MultinomialParam {
    uint32_t numSamples = 1;
    uint32_t randSeed = 0;
    uint8_t rsv[8] = {0};
};

Parameters

Member

Type

Default Value

Description

numSamples

uint32_t

1

Number of random samples.

  • The value must be less than or equal to the dimension size of x. The maximum value is 64.
  • The value must be greater than 0 but less than vocSize.

randSeed

uint32_t

0

Random number seed.

rsv[8]

uint8_t

{0}

Reserved

Input

Parameter

Dimension

Data Type

Format

Description

x

[batch, vocSize]

float16

ND

Input tensor. If the input of the last dimension is greater than 98304, a precision error may occur.

Output

Parameter

Dimension

Data Type

Format

Description

output

[batch, numSamples]

int32

ND

Index of the sampled data. dims[1] must be equal to numSamples.

Constraints

Ensure that the last axis is normalized.

API Calling Example

  • Input

    intensor =

    [[0.0701, 0.1021, 0.1010, 0.1005],
    [0.1101, 0.1020, 0.1017, 0.0990],
    [0.0592, 0.1006, 0.1006, 0.1002]]

    numSamples = 1

    randSeed = 0

  • Output

    outtensor =

    [[3],
    [3],
    [3]]