Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use canImport for MLTensor checks #288

Merged
merged 1 commit into from
Dec 31, 2024
Merged
Show file tree
Hide file tree
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
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
Loading