Skip to content

Commit d691bcb

Browse files
committed
Fix Swift format
1 parent d4edbfb commit d691bcb

3 files changed

Lines changed: 34 additions & 23 deletions

File tree

swift/Sources/CoreAILanguageModels/Samplers/MPSGraphSamplers.swift

Lines changed: 22 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -269,10 +269,12 @@ final class MPSGraphArgmaxSampler: @unchecked Sendable {
269269
self.bitmaskSize = (vocabSize + 31) / 32
270270

271271
// Allocate bitmask buffer (shared memory -- CPU writes visible to GPU without DMA)
272-
guard let bitmaskBuf = device.makeBuffer(
273-
length: bitmaskSize * MemoryLayout<Int32>.size,
274-
options: .storageModeShared
275-
) else {
272+
guard
273+
let bitmaskBuf = device.makeBuffer(
274+
length: bitmaskSize * MemoryLayout<Int32>.size,
275+
options: .storageModeShared
276+
)
277+
else {
276278
throw MPSGraphSamplerError.bufferAllocationFailed
277279
}
278280
self.bitmaskBuffer = bitmaskBuf
@@ -385,9 +387,10 @@ final class MPSGraphArgmaxSampler: @unchecked Sendable {
385387
outputOffset: Int,
386388
completion: @escaping (Int32) -> Void
387389
) {
388-
encode(to: queue, logitsBuffer: logitsBuffer, logitsOffset: logitsOffset,
389-
outputBuffer: outputBuffer, outputOffset: outputOffset,
390-
applyBitmask: false, completion: completion)
390+
encode(
391+
to: queue, logitsBuffer: logitsBuffer, logitsOffset: logitsOffset,
392+
outputBuffer: outputBuffer, outputOffset: outputOffset,
393+
applyBitmask: false, completion: completion)
391394
}
392395

393396
/// Encode argmax sampling with optional bitmask constraint.
@@ -481,9 +484,10 @@ final class MPSGraphArgmaxSampler: @unchecked Sendable {
481484
outputOffset: Int,
482485
completion: @escaping (Int32) -> Void
483486
) {
484-
encodeWithSlice(to: queue, logitsBuffer: logitsBuffer, queryLength: queryLength,
485-
outputBuffer: outputBuffer, outputOffset: outputOffset,
486-
applyBitmask: false, completion: completion)
487+
encodeWithSlice(
488+
to: queue, logitsBuffer: logitsBuffer, queryLength: queryLength,
489+
outputBuffer: outputBuffer, outputOffset: outputOffset,
490+
applyBitmask: false, completion: completion)
487491
}
488492

489493
/// Encode argmax with slice support and optional bitmask.
@@ -908,9 +912,10 @@ final class MPSGraphCompositeSampler: @unchecked Sendable {
908912
outputOffset: Int,
909913
completion: @escaping (Int32) -> Void
910914
) {
911-
encode(to: queue, logitsBuffer: logitsBuffer, logitsOffset: logitsOffset,
912-
outputBuffer: outputBuffer, outputOffset: outputOffset,
913-
applyBitmask: false, completion: completion)
915+
encode(
916+
to: queue, logitsBuffer: logitsBuffer, logitsOffset: logitsOffset,
917+
outputBuffer: outputBuffer, outputOffset: outputOffset,
918+
applyBitmask: false, completion: completion)
914919
}
915920

916921
/// Encode composite sampling with optional bitmask constraint.
@@ -1003,9 +1008,10 @@ final class MPSGraphCompositeSampler: @unchecked Sendable {
10031008
outputOffset: Int,
10041009
completion: @escaping (Int32) -> Void
10051010
) {
1006-
encodeWithSlice(to: queue, logitsBuffer: logitsBuffer, queryLength: queryLength,
1007-
outputBuffer: outputBuffer, outputOffset: outputOffset,
1008-
applyBitmask: false, completion: completion)
1011+
encodeWithSlice(
1012+
to: queue, logitsBuffer: logitsBuffer, queryLength: queryLength,
1013+
outputBuffer: outputBuffer, outputOffset: outputOffset,
1014+
applyBitmask: false, completion: completion)
10091015
}
10101016

10111017
/// Encode composite sampling with slice and optional bitmask.

swift/Tests/GuidedGenerationTests/ConstrainedGenerationSessionTests.swift

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -103,8 +103,9 @@ struct ConstrainedGenerationSessionTests {
103103
// They should be identical
104104
#expect(arrayBitmask!.count == pointerBitmask.count)
105105
for i in 0..<arrayBitmask!.count {
106-
#expect(arrayBitmask![i] == pointerBitmask[i],
107-
"Mismatch at word \(i): array=\(arrayBitmask![i]) pointer=\(pointerBitmask[i])")
106+
#expect(
107+
arrayBitmask![i] == pointerBitmask[i],
108+
"Mismatch at word \(i): array=\(arrayBitmask![i]) pointer=\(pointerBitmask[i])")
108109
}
109110
}
110111

swift/Tests/LanguageModelsTests/MPSGraphSamplerTests.swift

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -907,8 +907,9 @@ struct MPSGraphConstrainedArgmaxTests {
907907
}
908908
let unconstrainedResult = outputBuffer.contents().assumingMemoryBound(to: Int32.self).pointee
909909

910-
#expect(constrainedResult == unconstrainedResult,
911-
"All-ones bitmask should match unconstrained: \(constrainedResult) vs \(unconstrainedResult)")
910+
#expect(
911+
constrainedResult == unconstrainedResult,
912+
"All-ones bitmask should match unconstrained: \(constrainedResult) vs \(unconstrainedResult)")
912913
}
913914

914915
@Test("Bitmask allows only 3 tokens -- argmax picks best among them")
@@ -956,7 +957,8 @@ struct MPSGraphConstrainedCompositeTests {
956957
@Test("Bitmask blocks dominant token -- composite never samples it")
957958
func bitmaskBlocksDominantComposite() async throws {
958959
let device = try #require(Self.device)
959-
let sampler = try MPSGraphCompositeSampler(device: device, vocabSize: Self.vocabSize, k: Self.k, temperature: 1.0)
960+
let sampler = try MPSGraphCompositeSampler(
961+
device: device, vocabSize: Self.vocabSize, k: Self.k, temperature: 1.0)
960962

961963
let logitsBuffer = try #require(device.makeBuffer(length: Self.vocabSize * 2, options: .storageModeShared))
962964
let outputBuffer = try #require(device.makeBuffer(length: 4, options: .storageModeShared))
@@ -995,7 +997,8 @@ struct MPSGraphConstrainedCompositeTests {
995997
@Test("Only 3 tokens allowed -- composite samples exclusively from them")
996998
func compositeOnlyAllowedTokens() async throws {
997999
let device = try #require(Self.device)
998-
let sampler = try MPSGraphCompositeSampler(device: device, vocabSize: Self.vocabSize, k: Self.k, temperature: 1.0)
1000+
let sampler = try MPSGraphCompositeSampler(
1001+
device: device, vocabSize: Self.vocabSize, k: Self.k, temperature: 1.0)
9991002

10001003
let logitsBuffer = try #require(device.makeBuffer(length: Self.vocabSize * 2, options: .storageModeShared))
10011004
let outputBuffer = try #require(device.makeBuffer(length: 4, options: .storageModeShared))
@@ -1036,7 +1039,8 @@ struct MPSGraphConstrainedCompositeTests {
10361039
@Test("Constrained composite latency under 25ms for 32K vocab")
10371040
func constrainedCompositePerformance() async throws {
10381041
let device = try #require(Self.device)
1039-
let sampler = try MPSGraphCompositeSampler(device: device, vocabSize: Self.vocabSize, k: Self.k, temperature: 1.0)
1042+
let sampler = try MPSGraphCompositeSampler(
1043+
device: device, vocabSize: Self.vocabSize, k: Self.k, temperature: 1.0)
10401044

10411045
let logitsBuffer = try #require(device.makeBuffer(length: Self.vocabSize * 2, options: .storageModeShared))
10421046
let outputBuffer = try #require(device.makeBuffer(length: 4, options: .storageModeShared))

0 commit comments

Comments
 (0)