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

MLX Cleanup #187

Merged
merged 19 commits into from
Aug 10, 2024
Merged

MLX Cleanup #187

merged 19 commits into from
Aug 10, 2024

Conversation

jkrukowski
Copy link
Contributor

@jkrukowski jkrukowski commented Jul 21, 2024

In this PR:

  • added new params to WhisperKit:

    • mlxModel if specified, it will be used to specify which mlx model to download
    • mlxModelRepo if specified, it will be used to specify the repo where the mlx model is stored
    • mlxModelFolder if specified, it will point to the local folder where the mlx model is stored
  • added new options to CLIArguments:

    • mlxModel, mlxModelPath see the explanation above
    • featureExtractorType, audioEncoderType, textDecoderType to specify which type (coreml or or mlx) should be used for given pipeline step
  • updated readme to reflect the changes above

  • updated makefile to reflect the changes above

  • simplified CI unit test

To do:

- updated readme
- updated makefile
Comment on lines -99 to +97
xcodebuild clean build-for-testing -scheme ${{ matrix.run-config['scheme'] }} -destination '${{ matrix.run-config['clean-destination'] }}' -skipPackagePluginValidation | xcpretty
xcodebuild test -only-testing WhisperKitTests/UnitTests -scheme ${{ matrix.run-config['scheme'] }} -destination '${{ matrix.run-config['test-destination'] }}' -skipPackagePluginValidation
xcodebuild clean build-for-testing test \
${{ matrix.run-config['test-cases'] }} \
-scheme ${{ matrix.run-config['scheme'] }} \
-destination '${{ matrix.run-config['test-destination'] }}' \
-skipPackagePluginValidation
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is merged into single command xcodebuild clean build-for-testing test

Comment on lines +118 to +124
@xcodebuild CLANG_ENABLE_CODE_COVERAGE=NO VALID_ARCHS=arm64 clean build \
-configuration Release \
-scheme whisperkit-Package \
-destination generic/platform=macOS \
-derivedDataPath .build/.xcodebuild/ \
-clonedSourcePackagesDirPath .build/ \
-skipPackagePluginValidation
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we have to use xcodebuild because of mlx

Comment on lines -121 to +145
@swift build -c release --product whisperkit-cli
@xcodebuild CLANG_ENABLE_CODE_COVERAGE=NO VALID_ARCHS=arm64 clean build \
-configuration Release \
-scheme whisperkit-cli \
-destination generic/platform=macOS \
-derivedDataPath .build/.xcodebuild/ \
-clonedSourcePackagesDirPath .build/ \
-skipPackagePluginValidation


test:
@echo "Running tests..."
@swift test -v
@xcodebuild clean build-for-testing test \
-scheme whisperkit-Package \
-only-testing WhisperKitMLXTests/MLXUnitTests \
-only-testing WhisperKitTests/UnitTests \
-destination 'platform=macOS,arch=arm64' \
-skipPackagePluginValidation
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we have to use xcodebuild because of mlx

Package.swift Outdated
Comment on lines 61 to 59
.package(url: "https://github.com/ml-explore/mlx-swift", branch: "main"),
.package(url: "https://github.com/ml-explore/mlx-swift", revision: "d6d9472da5bf7ec2654e8914bd1d15622f45b6a9"),
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the latest version of mlx 0.16.0 breaks the implementation, let's pin it to the last commit before the breaking one, I'll have to talk to mlx team about the issue

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed, solution provided here ml-explore/mlx-swift#117

README.md Outdated
Comment on lines 83 to 87
Task {
let pipe = try? await WhisperKit()
let transcription = try? await pipe!.transcribe(audioPath: "path/to/your/audio.{wav,mp3,m4a,flac}")?.text
print(transcription)
}
let pipe = try await WhisperKit()
// Transcribe the audio file
let transcription = try await pipe.transcribe(audioPath: "path/to/your/audio.{wav,mp3,m4a,flac}")?.text
// Print the transcription
print(transcription)
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

removed not needed Task, decided to remove ? from try ?. When the potential user does copy paste from the readme I think it's better when the error is not ignored

@jkrukowski jkrukowski marked this pull request as ready for review July 25, 2024 15:21
Copy link
Contributor

@ZachNagengast ZachNagengast left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looking great, in the final stages of completing the MLX support project 🎉. Left a few comments and questions here to consider.

Makefile Outdated Show resolved Hide resolved
```

### Model Selection

WhisperKit automatically downloads the recommended model for the device if not specified. You can also select a specific model by passing in the model name:
You have to specify the model by passing the model name:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why this change?

Copy link
Contributor Author

@jkrukowski jkrukowski Aug 10, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Right now user has to pass either model and / or mlxModel, depending whether mlx is used or not

README.md Show resolved Hide resolved
public func prewarmModels() async throws {
try await loadModels(prewarmMode: true)
}

public func loadModels(
prewarmMode: Bool = false
) async throws {
modelState = prewarmMode ? .prewarming : .loading
assert(modelFolder != nil || mlxModelFolder != nil, "Please specify `modelFolder` or `mlxModelFolder`")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will this crash on prod builds? If so it should throw instead of crash.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it's not going to crash on a prod build

@@ -211,114 +228,80 @@ open class WhisperKit {
}
}

/// Sets up the model folder either from a local path or by downloading from a repository.
public func setupModels(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this deleted for a specific reason? Would be preferred to keep with with some adjustments since it was previously a public function and may be getting called elsewhere.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

previously setupModels would set modelFolder property. Right now we have to set either modelFolder or / and mlxModelFolder depending on the pipeline setup. In this context this function doesn't make sense any more

README.md Outdated Show resolved Hide resolved
Copy link
Contributor

@ZachNagengast ZachNagengast left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Approved pending the setupModels change (also to run the tests)

@ZachNagengast
Copy link
Contributor

Test passing ✅

@ZachNagengast ZachNagengast merged commit 2ea8426 into argmaxinc:mlx-support Aug 10, 2024
9 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants