Skip to content
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
11 changes: 7 additions & 4 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,10 @@ possible.

## Running Tests

Unit tests run without any special hardware and do not download models.
Note: `swift test` [does not work yet](https://github.com/ml-explore/mlx-swift?tab=readme-ov-file#xcodebuild) — use `xcodebuild` instead:
Unit tests do not download models; tests evaluating MLX arrays need Metal.
For this fork's verified SwiftPM setup, including the matching Metal library
and serial full-precision numerical gate, see [Qwen runtime validation](QWEN38_INTEGRATION.md#validation).
Xcode also assembles the test bundle:

```bash
xcodebuild test -scheme mlx-swift-lm-Package -destination 'platform=macOS' -skipPackagePluginValidation
Expand Down Expand Up @@ -54,8 +56,9 @@ xcodebuild test \

See [Libraries/IntegrationTestHelpers/README.md](Libraries/IntegrationTestHelpers/README.md) for more details.

CI also verifies that DocC documentation builds without warnings for every
library target. Run the same check locally with:
The upstream CI verifies DocC documentation for library targets. Its workflow
jobs are restricted to `ml-explore/mlx-swift-lm`, so they are skipped in this
fork regardless of PR draft status. Run the documentation check locally with:

```bash
scripts/verify-docs.sh
Expand Down
475 changes: 467 additions & 8 deletions Libraries/IntegrationTestHelpers/IntegrationTestHelpers.swift

Large diffs are not rendered by default.

11 changes: 11 additions & 0 deletions Libraries/IntegrationTestHelpers/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,3 +24,14 @@ xcodebuild test \
```

These tests do not run in CI.

The reranker integration tests download BGE v2 M3, Qwen3 Reranker 0.6B, and Jina
Reranker v3 checkpoints. To run only those reference checks:

```bash
xcodebuild test \
-project IntegrationTesting/IntegrationTesting.xcodeproj \
-scheme IntegrationTesting \
-destination 'platform=macOS' \
-only-testing:IntegrationTestingTests/RerankerModelIntegrationTests
```
25 changes: 20 additions & 5 deletions Libraries/MLXEmbedders/ModelFactory.swift
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,24 @@ private func create<C: Decodable, M>(
}
}

private func createBertCompatibleModel(configuration data: Data) throws -> any EmbeddingModel {
let configuration = try JSONDecoder.json5().decode(BertConfiguration.self, from: data)
if configuration.isSequenceClassification {
if configuration.modelType == "bert" {
return BertSequenceClassificationRerankerModel(configuration)
}
return BertRerankerModel(configuration)
}
return BertModel(configuration)
}

/// Registry of model type, e.g 'bert', to functions that can instantiate the model from configuration.
public enum EmbedderTypeRegistry {

public static let shared: ModelTypeRegistry<EmbeddingModel> = .init(creators: [
"bert": create(BertConfiguration.self) { BertModel($0) },
"roberta": create(BertConfiguration.self) { BertModel($0) },
"xlm-roberta": create(BertConfiguration.self) { BertModel($0) },
"bert": createBertCompatibleModel,
"roberta": createBertCompatibleModel,
"xlm-roberta": createBertCompatibleModel,
"distilbert": create(BertConfiguration.self) { BertModel($0) },

"nomic_bert": create(NomicBertConfiguration.self) { NomicBertModel($0, pooler: false) },
Expand Down Expand Up @@ -69,6 +80,8 @@ public class EmbedderRegistry: AbstractModelRegistry, @unchecked Sendable {
public static let snowflake_lg = ModelConfiguration(id: "Snowflake/snowflake-arctic-embed-l")
/// BGE-M3 - Multi-lingual, Multi-functional, Multi-granularity.
public static let bge_m3 = ModelConfiguration(id: "BAAI/bge-m3")
/// BGE Reranker v2 M3 - multilingual encoder reranker.
public static let bge_reranker_v2_m3 = ModelConfiguration(id: "BAAI/bge-reranker-v2-m3")
/// Mixedbread AI Large v1.
public static let mixedbread_large = ModelConfiguration(
id: "mixedbread-ai/mxbai-embed-large-v1")
Expand Down Expand Up @@ -110,6 +123,7 @@ public class EmbedderRegistry: AbstractModelRegistry, @unchecked Sendable {
bge_large,
snowflake_lg,
bge_m3,
bge_reranker_v2_m3,
mixedbread_large,
qwen3_embedding,
lfm2_embedding_350m,
Expand Down Expand Up @@ -217,9 +231,10 @@ public final class EmbedderModelFactory: GenericModelFactory {
async let tokenizerTask = tokenizerLoader.load(
from: configuration.tokenizerDirectory)

try loadWeights(
try await loadWeights(
modelDirectory: modelDirectory, model: model,
perLayerQuantization: baseConfig.perLayerQuantization)
perLayerQuantization: baseConfig.perLayerQuantization,
weightFileSelection: configuration.weightFileSelection)

let tokenizer = try await tokenizerTask

Expand Down
Loading