---
title: "gradientData(forParameter:layer:)"
framework: ML Compute
role: symbol
role_heading: Instance Method
platforms: [iOS 14.0+, iPadOS 14.0+, Mac Catalyst 14.0+, macOS 11.0+, tvOS 14.0+]
path: "mlcompute/mlctraininggraph/gradientdata(forparameter:layer:)"
---

# gradientData(forParameter:layer:)

Gets the gradient data for the trainable parameter and associated layer you specify.

## Declaration

```swift
func gradientData(forParameter parameter: MLCTensor, layer: MLCLayer) -> Data?
```

## Parameters

- `parameter`: The trainable parameter you associated with the layer.
- `layer`: A layer in the training graph.

## Return Value

Return Value The gradient data, or nil.

## Discussion

Discussion The layer must be an instance one of the following types: MLCConvolutionLayer MLCFullyConnectedLayer MLCBatchNormalizationLayer MLCInstanceNormalizationLayer MLCGroupNormalizationLayer MLCLayerNormalizationLayer note: This method returns nil if the layer isn’t trainable or you didn’t execute the training graph with separate calls to forward and gradient passes.

## See Also

### Inspecting Training Graphs

- [bindOptimizerData(_:deviceData:with:)](mlcompute/mlctraininggraph/bindoptimizerdata(_:devicedata:with:).md)
- [optimizer](mlcompute/mlctraininggraph/optimizer.md)
- [deviceMemorySize](mlcompute/mlctraininggraph/devicememorysize.md)
- [gradientTensor(forInput:)](mlcompute/mlctraininggraph/gradienttensor(forinput:).md)
- [sourceGradientTensors(for:)](mlcompute/mlctraininggraph/sourcegradienttensors(for:).md)
- [resultGradientTensors(for:)](mlcompute/mlctraininggraph/resultgradienttensors(for:).md)
