Fix concurrency issues due to preconcurrency imports and in MLTensor extension#430
Open
naykutguven wants to merge 4 commits intoargmaxinc:swift-6from
Open
Fix concurrency issues due to preconcurrency imports and in MLTensor extension#430naykutguven wants to merge 4 commits intoargmaxinc:swift-6from
naykutguven wants to merge 4 commits intoargmaxinc:swift-6from
Conversation
There was a problem hiding this comment.
Pull request overview
This PR updates WhisperKit’s CoreML MLTensor helper APIs and token sampling flow to be Swift 6 concurrency-safe by making tensor conversion helpers and sampling updates natively async, removing semaphore-based blocking, and adding tests for the new async helpers.
Changes:
- Converted
MLTensorhelpers (asIntArray,asFloatArray,asMLMultiArray) toasyncand removed semaphore/Task blocking bridging. - Propagated async sampling through
TokenSampling.update(...),GreedyTokenSampler.sampleWithMLTensor(...), andTextDecodercall sites. - Added
@preconcurrency importfor CoreML/AVFoundation interoperability and introduced a new async test suite for the tensor helpers.
Reviewed changes
Copilot reviewed 5 out of 5 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
| Tests/WhisperKitTests/MLTensorExtensionsTests.swift | Adds async unit tests covering the new async MLTensor conversion helpers. |
| Sources/WhisperKit/Utilities/Extensions+Public.swift | Makes MLTensor helper conversions async; adds @preconcurrency import CoreML. |
| Sources/WhisperKit/Core/TextDecoder.swift | Updates decoding flow to await the now-async sampler update. |
| Sources/WhisperKit/Core/Text/TokenSampler.swift | Makes sampling update async and integrates async tensor conversion calls. |
| Sources/WhisperKit/Core/Audio/AudioProcessor.swift | Switches to @preconcurrency import AVFoundation for concurrency annotation compatibility. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
b77c9c4 to
5268003
Compare
5268003 to
16946dc
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Swift 6 concurrency fixes for
MLTensorextensions + async sampler integrationSummary
This PR resolves Swift 6 concurrency issues around
MLTensorhelper APIs by removing semaphore-based bridging and making tensor conversion helpers natively async. It propagates the async API to token sampling call sites and adds targeted unit tests for coverage.What changed
MLTensorpublic helpers to async inSources/WhisperKit/Utilities/Extensions+Public.swift:asIntArray() -> [Int]->asIntArray() async -> [Int]asFloatArray() -> [Float]->asFloatArray() async -> [Float]asMLMultiArray() -> MLMultiArray->asMLMultiArray() async -> MLMultiArrayDispatchSemaphore+Taskblocking patterns in those helpers and replaced them with direct asyncshapedArray(of:)usage.Sources/WhisperKit/Core/Text/TokenSampler.swift:TokenSampling.update(...)is nowasyncGreedyTokenSampler.sampleWithMLTensor(...)is nowasyncSources/WhisperKit/Core/TextDecoder.swifttoawait tokenSampler.update(...).@preconcurrency importfor framework interoperability:Sources/WhisperKit/Utilities/Extensions+Public.swift:CoreMLSources/WhisperKit/Core/Audio/AudioProcessor.swift:AVFoundationTests/WhisperKitTests/MLTensorExtensionsTests.swiftcovering:asIntArrayasFloatArrayforFloat32,FloatType, andInt32asMLMultiArrayround-trips forFloatTypeandInt32Breaking changes (Before / After)
1)
TokenSampling.update(...)is now asyncBefore
After
2)
MLTensorhelper methods are now asyncBefore
After
3) Conforming sampler implementations must be async
Before
After
Risk
@preconcurrencyis intentionally used as an interoperability bridge with current SDK annotations.