---
title: "topKGradient(_:source:axis:k:name:)"
framework: metalperformanceshadersgraph
role: symbol
role_heading: Instance Method
path: "metalperformanceshadersgraph/mpsgraph/topkgradient(_:source:axis:k:name:)"
---

# topKGradient(_:source:axis:k:name:)

Creates a TopKGradient operation and returns the result tensor.

## Declaration

```swift
func topKGradient(_ gradient: MPSGraphTensor, source: MPSGraphTensor, axis: Int, k: Int, name: String?) -> MPSGraphTensor
```

## Parameters

- `gradient`: Tensor containing the incoming gradient.
- `source`: Tensor containing source data.
- `axis`: The dimension along which to compute the TopK values..
- `k`: The number of largest values to return.
- `name`: The name for the operation.

## Return Value

Return Value A valid MPSGraphTensor object.

## Discussion

Discussion Finds the K largest values along the minor dimension of the input. The input must have at least K elements along its minor dimension.
