<!--
{
  "availability" : [
    "iOS: 27.0.0 -",
    "iPadOS: 27.0.0 -",
    "macCatalyst: 27.0.0 -",
    "macOS: 27.0.0 -",
    "tvOS: 27.0.0 -",
    "visionOS: 27.0.0 -"
  ],
  "documentType" : "symbol",
  "framework" : "MetalPerformanceShadersGraph",
  "identifier" : "/documentation/MetalPerformanceShadersGraph/MPSGraph/scaledDotProductAttention(query:key:value: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)scaledDotProductAttentionWithQueryTensor:keyTensor:valueTensor:descriptor:name:"
  },
  "title" : "scaledDotProductAttention(query:key:value:descriptor:name:)"
}
-->

# scaledDotProductAttention(query:key:value:descriptor:name:)

Creates a scaled dot product attention (SDPA) operation using a descriptor and returns the result tensor.

```
func scaledDotProductAttention(query queryTensor: MPSGraphTensor, key keyTensor: MPSGraphTensor, value valueTensor: MPSGraphTensor, descriptor: MPSGraphSDPADescriptor, name: String?) -> MPSGraphTensor
```

## Parameters

`queryTensor`

A tensor that represents the query projection.

`keyTensor`

A tensor that represents the key projection.

`valueTensor`

A tensor that represents the value projection.

`descriptor`

A descriptor specifying scale and optional features (mask, isCausal, sinks).

`name`

The name for the operation.

## Return Value

A valid MPSGraphTensor object.

## Discussion

The descriptor allows configuring an optional attention mask, causal masking, and attention sinks
without requiring a separate API method for each combination of features.

---

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)