Skip to content

Commit

Permalink
Use canImport for MLTensor checks (#288)
Browse files Browse the repository at this point in the history
  • Loading branch information
ZachNagengast authored Dec 31, 2024
1 parent 112a023 commit a7e3858
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 3 deletions.
4 changes: 2 additions & 2 deletions Sources/WhisperKit/Core/Text/TokenSampler.swift
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ open class GreedyTokenSampler: TokenSampling {
self.decodingOptions = decodingOptions
}

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

var result: (token: Int, logprob: Float)
#if swift(>=5.10)
#if canImport(CoreML.MLState)
if #available(macOS 15.0, iOS 18.0, watchOS 11.0, visionOS 2.0, *) {
result = sampleWithMLTensor(logits: logits)
} else {
Expand Down
2 changes: 1 addition & 1 deletion Sources/WhisperKit/Core/Utils/Utils.swift
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ extension MLMultiArray {
}
}

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

0 comments on commit a7e3858

Please sign in to comment.