Skip to content

Commit acc7fd6

Browse files
authored
Merge branch 'main' into sukru/constrained-session-extensions
2 parents 9b507bc + f3e8689 commit acc7fd6

12 files changed

Lines changed: 25 additions & 25 deletions

File tree

swift/Sources/CoreAIDiffusionPipeline/Components/CoreAIDenoiser.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ public final class CoreAIDenoiser: Sendable {
3131
let batchSize = latents.shape[0]
3232

3333
var timestepArray = NDArray(shape: [batchSize], scalarType: .float32)
34-
var timestepView = timestepArray.mutableView(as: Float.self)
34+
let timestepView = timestepArray.mutableView(as: Float.self)
3535
timestepView.withUnsafeMutablePointer { ptr, _, _ in
3636
for i in 0..<batchSize { ptr[i] = timestep }
3737
}
@@ -58,7 +58,7 @@ public final class CoreAIDenoiser: Sendable {
5858

5959
let shape = latents.shape
6060
var result = NDArray(shape: shape, scalarType: .float32)
61-
var resultView = result.mutableView(as: Float.self)
61+
let resultView = result.mutableView(as: Float.self)
6262
resultView.withUnsafeMutablePointer { ptr, _, _ in
6363
for i in 0..<floats.count { ptr[i] = floats[i] }
6464
}

swift/Sources/CoreAIDiffusionPipeline/Components/CoreAIDiffusionModelFunction.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -55,13 +55,13 @@ public actor CoreAIDiffusionModelFunction {
5555
switch resolved.scalarType {
5656
#if !((os(macOS) || targetEnvironment(macCatalyst)) && arch(x86_64))
5757
case .float16:
58-
var view = array.mutableView(as: Float16.self)
58+
let view = array.mutableView(as: Float16.self)
5959
view.withUnsafeMutablePointer { ptr, _, _ in
6060
for j in 0..<data.count { ptr[j] = Float16(data[j]) }
6161
}
6262
#endif
6363
case .float32:
64-
var view = array.mutableView(as: Float.self)
64+
let view = array.mutableView(as: Float.self)
6565
view.withUnsafeMutablePointer { ptr, _, _ in
6666
for j in 0..<data.count { ptr[j] = data[j] }
6767
}
@@ -83,7 +83,7 @@ public actor CoreAIDiffusionModelFunction {
8383
guard case .ndArray(let nd) = fn.descriptor.inputDescriptor(of: name) else { continue }
8484
let resolved = nd.resolvingDynamicDimensions(shape)
8585
var array = NDArray(descriptor: resolved)
86-
var view = array.mutableView(as: Int32.self)
86+
let view = array.mutableView(as: Int32.self)
8787
view.withUnsafeMutablePointer { ptr, _, _ in
8888
for j in 0..<data.count { ptr[j] = data[j] }
8989
}

swift/Sources/CoreAIDiffusionPipeline/Components/CoreAILatentCodec.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ public final class CoreAILatentDecoder: Sendable {
4444
let outW = shape[3] * 8
4545
let outShape = [1, 3, outH, outW]
4646
var result = NDArray(shape: outShape, scalarType: .float32)
47-
var resultView = result.mutableView(as: Float.self)
47+
let resultView = result.mutableView(as: Float.self)
4848
resultView.withUnsafeMutablePointer { ptr, _, _ in
4949
for i in 0..<outputFloats.count { ptr[i] = outputFloats[i] }
5050
}
@@ -107,7 +107,7 @@ public final class CoreAILatentEncoder: Sendable {
107107
// Scale and return as NDArray
108108
let outShape = [1, 4, height / 8, width / 8]
109109
var result = NDArray(shape: outShape, scalarType: .float32)
110-
var resultView = result.mutableView(as: Float.self)
110+
let resultView = result.mutableView(as: Float.self)
111111
resultView.withUnsafeMutablePointer { ptr, _, _ in
112112
for i in 0..<outputFloats.count { ptr[i] = outputFloats[i] * scaleFactor }
113113
}

swift/Sources/CoreAIDiffusionPipeline/Pipelines/Flux2Pipeline.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -274,7 +274,7 @@ public struct Flux2Pipeline: DiffusionPipeline {
274274
let image = try DiffusionUtilities.pixelsToCGImage(pixels, height: outputHeight, width: outputWidth)
275275

276276
var latentsND = NDArray(shape: latentShape, scalarType: .float32)
277-
var latentsView = latentsND.mutableView(as: Float.self)
277+
let latentsView = latentsND.mutableView(as: Float.self)
278278
latentsView.withUnsafeMutablePointer { ptr, _, _ in
279279
for i in 0..<noise.count { ptr[i] = noise[i] }
280280
}

swift/Sources/CoreAIDiffusionPipeline/Pipelines/SD3Pipeline.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,7 @@ public struct SD3Pipeline: DiffusionPipeline {
160160
pixels, height: imageSize, width: imageSize)
161161

162162
var latentsND = NDArray(shape: latentShape, scalarType: .float32)
163-
var latentsView = latentsND.mutableView(as: Float.self)
163+
let latentsView = latentsND.mutableView(as: Float.self)
164164
latentsView.withUnsafeMutablePointer { ptr, _, _ in
165165
for i in 0..<latents.count { ptr[i] = latents[i] }
166166
}
@@ -226,7 +226,7 @@ public struct SD3Pipeline: DiffusionPipeline {
226226
}
227227

228228
var inputArray = NDArray(shape: [1, Self.clipSeqLen], scalarType: .int32)
229-
var view = inputArray.mutableView(as: Int32.self)
229+
let view = inputArray.mutableView(as: Int32.self)
230230
view.withUnsafeMutablePointer { ptr, _, _ in
231231
for i in 0..<ids.count { ptr[i] = ids[i] }
232232
}

swift/Sources/CoreAIDiffusionPipeline/Pipelines/StableDiffusionPipeline.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -161,7 +161,7 @@ public struct StableDiffusionPipeline: DiffusionPipeline {
161161

162162
// Wrap latents back to NDArray for GenerationResult
163163
var latentsND = NDArray(shape: latentShape, scalarType: .float32)
164-
var latentsView = latentsND.mutableView(as: Float.self)
164+
let latentsView = latentsND.mutableView(as: Float.self)
165165
latentsView.withUnsafeMutablePointer { ptr, _, _ in
166166
for i in 0..<latents.count { ptr[i] = latents[i] }
167167
}

swift/Sources/CoreAILanguageModels/InferenceEngines/CoreAISequentialEngine.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -484,7 +484,7 @@ public final class CoreAISequentialEngine: InferenceEngine, @unchecked Sendable
484484
let dstBlockStride = dstShape[seqDim...].reduce(1, *) // S_new * D
485485

486486
source.view(as: LogitsScalarType.self).withUnsafePointer { srcPtr, _, _ in
487-
var dstView = destination.mutableView(as: LogitsScalarType.self)
487+
let dstView = destination.mutableView(as: LogitsScalarType.self)
488488
dstView.withUnsafeMutablePointer { dstPtr, _, _ in
489489
for block in 0..<numBlocks {
490490
let srcOff = block * srcBlockStride
@@ -500,7 +500,7 @@ public final class CoreAISequentialEngine: InferenceEngine, @unchecked Sendable
500500

501501
private func zeroFill(_ array: inout NDArray) {
502502
let count = array.shape.reduce(1, *)
503-
var view = array.mutableView(as: LogitsScalarType.self)
503+
let view = array.mutableView(as: LogitsScalarType.self)
504504
// Inlined constant write — under -Onone, fillNDArray's
505505
// `(Int) -> LogitsScalarType` closure is invoked per element (no inlining),
506506
// which made zeroing the KV cache (~14.7M elements for a 32K-context

swift/Sources/CoreAILanguageModels/InferenceEngines/CoreAISequentialVLMEngine.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -580,7 +580,7 @@ public final class CoreAISequentialVLMEngine: MultimodalInferenceEngine, @unchec
580580
"scatterMerge only supports float16 embeddings; got \(imageEmbeddings.scalarType)")
581581
}
582582
imageEmbeddings.view(as: Float16.self).withUnsafePointer { imgPtr, _, _ in
583-
var mutableView = merged.mutableView(as: Float16.self)
583+
let mutableView = merged.mutableView(as: Float16.self)
584584
mutableView.withUnsafeMutablePointer { mergedPtr, _, _ in
585585
for (i, pos) in imagePositions.enumerated() {
586586
let srcOffset = i * hiddenDim
@@ -916,7 +916,7 @@ public final class CoreAISequentialVLMEngine: MultimodalInferenceEngine, @unchec
916916
let dstBlockStride = dstShape[seqDim...].reduce(1, *)
917917

918918
source.view(as: LogitsScalarType.self).withUnsafePointer { srcPtr, _, _ in
919-
var dstView = destination.mutableView(as: LogitsScalarType.self)
919+
let dstView = destination.mutableView(as: LogitsScalarType.self)
920920
dstView.withUnsafeMutablePointer { dstPtr, _, _ in
921921
for block in 0..<numBlocks {
922922
let srcOff = block * srcBlockStride
@@ -932,7 +932,7 @@ public final class CoreAISequentialVLMEngine: MultimodalInferenceEngine, @unchec
932932

933933
private func zeroFill(_ array: inout NDArray) {
934934
let count = array.shape.reduce(1, *)
935-
var view = array.mutableView(as: LogitsScalarType.self)
935+
let view = array.mutableView(as: LogitsScalarType.self)
936936
view.withUnsafeMutablePointer { ptr, _, _ in
937937
for i in 0..<count {
938938
ptr[i] = 0

swift/Sources/CoreAILanguageModels/InferenceEngines/CoreAIStaticShapeEngine.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -494,7 +494,7 @@ public final class StaticShapeEngine: InferenceEngine, @unchecked Sendable {
494494
}
495495
if case .ndArray(let nd) = desc.inputDescriptor(of: posName) {
496496
var pos = NDArray(descriptor: nd)
497-
var posView = pos.mutableView(as: UInt16.self)
497+
let posView = pos.mutableView(as: UInt16.self)
498498
guard var posSpan = posView.contiguousElements else {
499499
throw InferenceRuntimeError.invalidState("pos array has non-contiguous layout")
500500
}
@@ -517,7 +517,7 @@ public final class StaticShapeEngine: InferenceEngine, @unchecked Sendable {
517517
case .ndArray(let nd) = desc.inputDescriptor(of: stepName)
518518
{
519519
var step = NDArray(descriptor: nd)
520-
var stepView = step.mutableView(as: Int32.self)
520+
let stepView = step.mutableView(as: Int32.self)
521521
guard var stepSpan = stepView.contiguousElements else {
522522
throw InferenceRuntimeError.invalidState("step array has non-contiguous layout")
523523
}
@@ -544,7 +544,7 @@ public final class StaticShapeEngine: InferenceEngine, @unchecked Sendable {
544544
}
545545

546546
var tokenArray = NDArray(descriptor: tokenNDDesc)
547-
var tokenView = tokenArray.mutableView(as: Int32.self)
547+
let tokenView = tokenArray.mutableView(as: Int32.self)
548548
guard var tokenSpan = tokenView.contiguousElements else {
549549
throw InferenceRuntimeError.invalidState("tokenArray has non-contiguous layout")
550550
}

swift/Sources/CoreAIObjectDetector/ObjectDetector.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -209,7 +209,7 @@ public struct ObjectDetector {
209209

210210
if descriptor.scalarType == .float16 {
211211
#if !((os(macOS) || targetEnvironment(macCatalyst)) && arch(x86_64))
212-
var view = imageArray.mutableView(as: Float16.self)
212+
let view = imageArray.mutableView(as: Float16.self)
213213
guard var span = view.contiguousElements else {
214214
throw DetectionRuntimeError.invalidConfiguration(
215215
"Image input NDArray is not contiguous")
@@ -223,7 +223,7 @@ public struct ObjectDetector {
223223
fatalError("Float16 is not supported on this platform")
224224
#endif
225225
} else {
226-
var view = imageArray.mutableView(as: Float.self)
226+
let view = imageArray.mutableView(as: Float.self)
227227
guard var span = view.contiguousElements else {
228228
throw DetectionRuntimeError.invalidConfiguration(
229229
"Image input NDArray is not contiguous")

0 commit comments

Comments
 (0)