<!--
{
  "availability" : [
    "iOS: 16.0.0 -",
    "iPadOS: 16.0.0 -",
    "macCatalyst: 16.0.0 -",
    "macOS: 13.0.0 -",
    "tvOS: 16.0.0 -",
    "visionOS: 1.0.0 -"
  ],
  "documentType" : "symbol",
  "framework" : "MetalPerformanceShadersGraph",
  "identifier" : "/documentation/MetalPerformanceShadersGraph/MPSGraph/maxPooling4DGradient(withGradientTensor:indicesTensor:outputShapeTensor:descriptor:name:)",
  "metadataVersion" : "0.1.0",
  "role" : "Instance Method",
  "symbol" : {
    "kind" : "Instance Method",
    "modules" : [
      "Metal Performance Shaders Graph",
      "MetalPerformanceShadersGraph"
    ],
    "preciseIdentifier" : "c:objc(cs)MPSGraph(im)maxPooling4DGradientWithGradientTensor:indicesTensor:outputShapeTensor:descriptor:name:"
  },
  "title" : "maxPooling4DGradient(withGradientTensor:indicesTensor:outputShapeTensor:descriptor:name:)"
}
-->

# maxPooling4DGradient(withGradientTensor:indicesTensor:outputShapeTensor:descriptor:name:)

Creates a max-pooling gradient operation and returns the result tensor.

```
func maxPooling4DGradient(withGradientTensor gradient: MPSGraphTensor, indicesTensor indices: MPSGraphTensor, outputShapeTensor outputShape: MPSGraphTensor, descriptor: MPSGraphPooling4DOpDescriptor, name: String?) -> MPSGraphTensor
```

## Parameters

`gradient`

An input gradient tensor.

`indices`

The indices tensor returned from [`maxPooling4DReturnIndices(_:descriptor:name:)`](/documentation/MetalPerformanceShadersGraph/MPSGraph/maxPooling4DReturnIndices(_:descriptor:name:)).

`outputShape`

A tensor containing the shape of the destination gradient.

`descriptor`

A pooling operation descriptor that specifies pooling window sizes, strides, dilation rates, paddings and layouts.

`name`

The name for the operation.

## Return Value

Destination gradient tensor.

## Discussion

With this API MPSGraph computes the max-pooling gradient efficiently by reusing the indices from the forward API instead of recomputing them.
The descriptor must set `returnIndicesMode` and `returnIndicesDataType` to the same value as that set by the forward pass.

---

Copyright &copy; 2026 Apple Inc. All rights reserved. | [Terms of Use](https://www.apple.com/legal/internet-services/terms/site.html) | [Privacy Policy](https://www.apple.com/privacy/privacy-policy)