<!--
{
  "availability" : [
    "iOS: 26.0.0 -",
    "iPadOS: 26.0.0 -",
    "macCatalyst: -",
    "macOS: 26.0.0 -",
    "tvOS: 26.0.0 -",
    "visionOS: 26.0.0 -",
    "watchOS: 26.0.0 -"
  ],
  "documentType" : "symbol",
  "framework" : "Accelerate",
  "identifier" : "/documentation/Accelerate/BNNSGraph/Context/setBatchSize(_:forFunction:)-8eqzm",
  "metadataVersion" : "0.1.0",
  "role" : "Instance Method",
  "symbol" : {
    "kind" : "Instance Method",
    "modules" : [
      "Accelerate"
    ],
    "preciseIdentifier" : "s:10Accelerate9BNNSGraphO7ContextC12setBatchSize_11forFunctionySi_SSSgtF"
  },
  "title" : "setBatchSize(_:forFunction:)"
}
-->

# setBatchSize(_:forFunction:)

Synchronously sets the batch size for a graph.

```
func setBatchSize(_ batchSize: Int, forFunction function: String? = nil)
```

## Parameters

`batchSize`

The batch size.

`function`

The specific function to set shapes for. You may set this to `nil` if there is only one function.

## Discussion

This is a special case of `setDynamicShapes(_:forFunction:)` where the only dynamic sizes that occur are the first index
of their tensor (that is, the batch dimension) and are all equal. This allows just passing a single `batchSize` constant.

This function has no effect if you pass a `batchSize` value that’s less than zero.

> SeeAlso: `BNNSGraphContextSetBatchSize`

---

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)