You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
MLXSharp offers .NET bindings and tooling around [Apple MLX](https://github.com/ml-explore/mlx) that plug directly into the [`Microsoft.Extensions.AI`](https://learn.microsoft.com/dotnet/ai/microsoft-extensions-ai) ecosystem.
4
-
The design mirrors the packaging approach from projects such as [LLamaSharp](https://github.com/SciSharp/LLamaSharp): managed clients sit on top of a native wrapper that can be distributed through NuGet alongside prebuilt binaries.
MLXSharp is the first .NET wrapper around [Apple MLX](https://github.com/ml-explore/mlx) that plugs straight into [`Microsoft.Extensions.AI`](https://learn.microsoft.com/dotnet/ai/microsoft-extensions-ai). It is designed and tested on macOS (Apple silicon) but ships prebuilt native binaries for both macOS and Linux so that NuGet consumers can run out-of-the-box.
7
7
8
-
-`IChatClient`, `IEmbeddingGenerator<string, Embedding<float)>`, and image generation helpers that adhere to the `Microsoft.Extensions.AI` abstractions.
9
-
- Builder-based backend configuration with a deterministic managed implementation for tests and a P/Invoke powered native backend.
10
-
- Native library resolver that probes application directories, `MLXSHARP_LIBRARY`, or packaged runtimes and loads `libmlxsharp` on demand.
11
-
- Dependency injection extensions (`AddMlx`) in **MLXSharp** package.
12
-
- Semantic Kernel integration (`AddMlxChatCompletion`) in separate **MLXSharp.SemanticKernel** package.
13
-
- Integration test suite that exercises chat, embedding, image, and Semantic Kernel flows against both managed and native backends.
8
+
## Highlights
9
+
- .NET 9 / C# 13 preview friendly APIs that implement `IChatClient`, `IEmbeddingGenerator<string, Embedding<float>>`, and image helpers.
10
+
- Dependency Injection extensions (`AddMlx`) and Semantic Kernel integration (`AddMlxChatCompletion`).
11
+
- Native runtime loader that understands `MLXSHARP_LIBRARY`, custom paths, and packaged runtimes.
12
+
- CI pipeline that builds the managed code once, produces macOS and Linux native libraries in parallel, and packs everything into distributable NuGet packages.
14
13
15
-
## Repository Layout
16
-
17
-
```
18
-
├── extern/mlx # Git submodule with the official MLX sources
Core package with `Microsoft.Extensions.AI` integration:
75
-
76
-
```bash
77
-
dotnet add package MLXSharp
65
+
## Repository Layout
78
66
```
79
-
80
-
This package contains:
81
-
- Managed DLL with `Microsoft.Extensions.AI` implementations
82
-
- Native assets in `runtimes/{rid}/native/`:
83
-
-`runtimes/linux-x64/native/libmlxsharp.so.b64` - Base64-encoded stub that `MlxNativeLibrary` expands for CI/testing
84
-
-`runtimes/osx-arm64/native/libmlxsharp.dylib` - built in CI on macOS
85
-
86
-
`MlxNativeLibrary` materialises `libmlxsharp.so` from the encoded payload on first use so Git history stays free of binary blobs while tests retain deterministic behaviour.
The CMake project vendored from MLX builds MLX and the shim in one go. macOS builds enable Metal automatically; disable or tweak MLX options by passing flags such as `-DMLX_BUILD_METAL=OFF` or `-DMLX_BUILD_BLAS_FROM_SOURCE=ON`.
100
+
101
+
## CI overview
102
+
1.`dotnet-build` (Ubuntu): restores the solution and compiles managed projects.
103
+
2.`native-linux` / `native-macos`: compile `libmlxsharp.so` and `libmlxsharp.dylib` in parallel.
104
+
3.`package-test` (macOS): downloads both native artifacts, stages them into `src/MLXSharp/runtimes/{rid}/native`, rebuilds, runs the integration tests, and produces NuGet packages.
105
+
106
+
## Testing
107
+
Tests require a local MLX model bundle. Point `MLXSHARP_MODEL_PATH` to the directory before running:
The suite validates the managed backend, Semantic Kernel extensions, and the native loader by exercising the packaged stub library.
115
+
## Versioning & platform support
116
+
This initial release is focused on macOS developers who want MLX inside .NET applications. Linux binaries are produced to keep NuGet packages complete, and Windows support is not yet available.
0 commit comments