Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -496,7 +496,6 @@ final class MPSGraphCompositeSampler: @unchecked Sendable {
private let randomData: MPSGraphTensorData
private let topPData: MPSGraphTensorData
private let minPData: MPSGraphTensorData
private let execDescriptor: MPSGraphExecutableExecutionDescriptor

/// Testing only: Override random value for deterministic tests.
var testingOnlyRandomOverride: Float?
Expand Down Expand Up @@ -678,7 +677,6 @@ final class MPSGraphCompositeSampler: @unchecked Sendable {
shape: [1 as NSNumber],
dataType: .float32
)
self.execDescriptor = MPSGraphExecutableExecutionDescriptor()
}

/// Encode composite sampling asynchronously (protocol conformance).
Expand Down Expand Up @@ -725,7 +723,10 @@ final class MPSGraphCompositeSampler: @unchecked Sendable {
cachedOutputBuffer = outputBuffer
}

execDescriptor.completionHandler = { [outputBuffer, outputOffset] (_, error) in
// Per-call descriptor — reusing one across pipelined steps corrupts
// intermediate scratch buffers when multiple runAsync calls overlap.
let desc = MPSGraphExecutableExecutionDescriptor()
desc.completionHandler = { [outputBuffer, outputOffset] (_, error) in
if let error = error {
print("MPSGraph composite sampler error: \(error)")
completion(0)
Expand All @@ -743,7 +744,7 @@ final class MPSGraphCompositeSampler: @unchecked Sendable {
with: queue,
inputs: [logitsData, temperatureData, randomData, topPData, minPData],
results: [outputData],
executionDescriptor: execDescriptor
executionDescriptor: desc
)
}

Expand Down