Skip to content

Commit

Permalink
Use GPU for audio encoder on macOS 13 (#83)
Browse files Browse the repository at this point in the history
* Use gpu on macos 13 for the audio encoder

* Use gpu on macos 13 for the audio encoder

* Update Sources/WhisperKitCLI/CLIArguments.swift
  • Loading branch information
ZachNagengast committed Mar 19, 2024
1 parent bd75392 commit cf75348
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 6 deletions.
12 changes: 9 additions & 3 deletions Sources/WhisperKit/Core/Models.swift
Expand Up @@ -135,7 +135,7 @@ public struct ModelComputeOptions {

public init(
melCompute: MLComputeUnits = .cpuAndGPU,
audioEncoderCompute: MLComputeUnits = .cpuAndNeuralEngine,
audioEncoderCompute: MLComputeUnits? = nil,
textDecoderCompute: MLComputeUnits = .cpuAndNeuralEngine,
prefillCompute: MLComputeUnits = .cpuOnly
) {
Expand All @@ -146,10 +146,16 @@ public struct ModelComputeOptions {
self.prefillCompute = .cpuOnly
return
}

self.melCompute = melCompute
self.audioEncoderCompute = audioEncoderCompute
self.textDecoderCompute = textDecoderCompute
self.prefillCompute = prefillCompute
self.textDecoderCompute = textDecoderCompute

if #available(macOS 14.0, iOS 17.0, watchOS 10, visionOS 1, *) {
self.audioEncoderCompute = audioEncoderCompute ?? .cpuAndNeuralEngine
} else {
self.audioEncoderCompute = audioEncoderCompute ?? .cpuAndGPU
}
}
}

Expand Down
1 change: 0 additions & 1 deletion Sources/WhisperKitCLI/CLIArguments.swift
Expand Up @@ -21,7 +21,6 @@ struct CLIArguments: ParsableArguments {

@Option(help: "Compute units for audio encoder model with {all,cpuOnly,cpuAndGPU,cpuAndNeuralEngine,random}")
var audioEncoderComputeUnits: ComputeUnits = .cpuAndNeuralEngine

@Option(help: "Compute units for text decoder model with {all,cpuOnly,cpuAndGPU,cpuAndNeuralEngine,random}")
var textDecoderComputeUnits: ComputeUnits = .cpuAndNeuralEngine

Expand Down
14 changes: 12 additions & 2 deletions Sources/WhisperKitCLI/Transcribe.swift
Expand Up @@ -32,9 +32,19 @@ struct Transcribe: AsyncParsableCommand {
print("Transcribing audio at \(cliArguments.audioPath)")
}

var audioEncoderComputeUnits = cliArguments.audioEncoderComputeUnits.asMLComputeUnits
let textDecoderComputeUnits = cliArguments.textDecoderComputeUnits.asMLComputeUnits

// Use gpu for audio encoder on macOS below 14
if audioEncoderComputeUnits == .cpuAndNeuralEngine {
if #unavailable(macOS 14.0) {
audioEncoderComputeUnits = .cpuAndGPU
}
}

let computeOptions = ModelComputeOptions(
audioEncoderCompute: cliArguments.audioEncoderComputeUnits.asMLComputeUnits,
textDecoderCompute: cliArguments.textDecoderComputeUnits.asMLComputeUnits
audioEncoderCompute: audioEncoderComputeUnits,
textDecoderCompute: textDecoderComputeUnits
)

let downloadTokenizerFolder: URL? =
Expand Down

0 comments on commit cf75348

Please sign in to comment.