For the complete documentation index, see llms.txt. Markdown versions of all pages are available by appending .md to any URL (e.g. /max/get-started.md).
Mojo struct
TopK
struct TopK
Registers the mo.top_k graph op with the graph compiler.
Implemented traitsβ
Methodsβ
executeβ
static def execute[dtype: DType, rank: Int, target: StringSlice[ImmStaticOrigin], _trace_name: StringSlice[ImmStaticOrigin]](values: ManagedTensorSlice[IOSpec[_, _].Output, static_spec=values.static_spec], indices: ManagedTensorSlice[IOSpec[_, _].Output, static_spec=indices.static_spec], input: ManagedTensorSlice[IOSpec[_, _].Input, static_spec=input.static_spec], k: Scalar, axis: Scalar, sorted: Scalar[DType.bool], ctx: DeviceContext)
Executes the mo.top_k graph op.
Parameters:
- βdtype (
DType): Element type of the input and output tensors. - βrank (
Int): Tensor rank of the input and output tensors. - βtarget (
StringSlice[ImmStaticOrigin]): Compilation target string. - β_trace_name (
StringSlice[ImmStaticOrigin]): Name used for tracing and debugging.
Args:
- βvalues (
ManagedTensorSlice[IOSpec[_, _].Output, static_spec=values.static_spec]): See the graph op signature. - βindices (
ManagedTensorSlice[IOSpec[_, _].Output, static_spec=indices.static_spec]): See the graph op signature. - βinput (
ManagedTensorSlice[IOSpec[_, _].Input, static_spec=input.static_spec]): Input tensor to reduce. - βk (
Scalar): Number of elements to select. - βaxis (
Scalar): See the graph op signature. - βsorted (
Scalar[DType.bool]): Whether to sort the selected elements. - βctx (
DeviceContext): Device context used to enqueue the kernel.
Raises:
Error: If the operation parameters are invalid.
Was this page helpful?
Thank you! We'll create more content like this.
Thank you for helping us improve!