| Files | Last commit | Last update |
|---|---|---|
| 9 months ago | ||
| 2 months ago | ||
| 16 days ago | ||
| 16 days ago | ||
| 18 days ago | ||
| 1 month ago | ||
| 1 month ago | ||
| 13 days ago |
TopKV2
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
-
API function: returns the k extreme values and their indices of the input tensor on the specified dimension. The TopKV2 operator supports specifying the value of k through an input tensor and supports a configurable output data type of indices.
-
Computation description:
- When largest=True, the k largest values on the specified dimension and their indices are returned.
- When largest=False, the k smallest values on the specified dimension and their indices are returned.
- When sorted=True, the output results are sorted in descending order (largest=True) or ascending order (largest=False).
- When sorted=False, the output results are not sorted.
Parameter Description
| Parameter Name | Input/Output/Attribute | Description | Data Type | Data Format |
|---|---|---|---|---|
| x | Input | Input tensor for the TopK computation. Dimensions 1-8 are supported. | INT8, UINT8, INT16, UINT16, INT32, UINT32, INT64, UINT64, FLOAT16, FLOAT32, BFLOAT16 | ND |
| k | Input | 0D scalar tensor that indicates the number of extreme values to output on the computation dimension. The value range is [0, x.size(dim)]. | INT32, INT64 | ND |
| values | Output | Output values of the TopK computation. The data type is the same as that of x. The shape is the same as k on the sorting axis and the same as x on non-sorting axes. | INT8, UINT8, INT16, UINT16, INT32, UINT32, INT64, UINT64, FLOAT16, FLOAT32, BFLOAT16 | ND |
| indices | Output | Output indices of the TopK computation. The data type is specified by the indices_dtype attribute. The shape is the same as k on the sorting axis and the same as x on non-sorting axes. | INT32, INT64 | ND |
| sorted | Attribute | Optional Boolean. The default value is True. True indicates that the output results are sorted, and False indicates that the output results are not sorted. | Bool | - |
| dim | Attribute | Optional integer. The default value is -1. It indicates the computation dimension. The value range is [-x.dim(), x.dim()). | Int | - |
| largest | Attribute | Optional Boolean. The default value is True. True indicates that the k largest elements are returned, and False indicates that the k smallest elements are returned. | Bool | - |
| indices_dtype | Attribute | Optional integer. The default value is DT_INT32(3). It indicates the data type of the output indices. DT_INT32(3) or DT_INT64(9) is supported. | Int | - |
| sort_policy | Attribute | Optional integer. The default value is 0. It indicates the sorting policy for TopK candidate results. 0 indicates that the original sorting behavior is used, and 1 indicates that the Bitonic Small TopK path is enabled in the scenario where sorted=True and k is small (2≤k≤32). | Int | - |
- Atlas 200I/500 A2 inference products, Atlas inference products, and Atlas training products: The BFLOAT16 data type is not supported.
Constraint Description
None
Invocation Description
| Invocation Method | Invocation Sample | Description |
|---|---|---|
| Graph-mode invocation | test_geir_top_k_v2 | Invokes the top_k_v2 operator by building a graph through the operator IR. |