Skip to content

Commit a7e3858

Browse files
Use canImport for MLTensor checks (#288)
1 parent 112a023 commit a7e3858

File tree

2 files changed

+3
-3
lines changed

2 files changed

+3
-3
lines changed

Sources/WhisperKit/Core/Text/TokenSampler.swift

+2-2
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ open class GreedyTokenSampler: TokenSampling {
2828
self.decodingOptions = decodingOptions
2929
}
3030

31-
#if swift(>=5.10)
31+
#if canImport(CoreML.MLState)
3232
@available(macOS 15, iOS 18, watchOS 11, visionOS 2, *)
3333
private func sampleWithMLTensor(logits: MLMultiArray) -> (token: Int, logprob: Float) {
3434
// Use MLTensor operations if available for sampling
@@ -209,7 +209,7 @@ open class GreedyTokenSampler: TokenSampling {
209209
var completed = false
210210

211211
var result: (token: Int, logprob: Float)
212-
#if swift(>=5.10)
212+
#if canImport(CoreML.MLState)
213213
if #available(macOS 15.0, iOS 18.0, watchOS 11.0, visionOS 2.0, *) {
214214
result = sampleWithMLTensor(logits: logits)
215215
} else {

Sources/WhisperKit/Core/Utils/Utils.swift

+1-1
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ extension MLMultiArray {
109109
}
110110
}
111111

112-
#if swift(>=5.10)
112+
#if canImport(CoreML.MLState)
113113
@available(macOS 15.0, iOS 18.0, watchOS 11.0, visionOS 2.0, *)
114114
public extension MLTensor {
115115
func asIntArray() -> [Int] {

0 commit comments

Comments
 (0)