Skip to content
Open
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
5 changes: 2 additions & 3 deletions Voxt/NOTICE
Original file line number Diff line number Diff line change
Expand Up @@ -129,9 +129,8 @@ The Omni native runtime (VoxtNew.app/Contents/Resources/omni)
bin/qwen3_asr_server (and its copy bin/silero_vad_server) is built from
sglang-omni's sglang_omni_mlx/native (this repository, Apache License
2.0) by scripts/build-omni.sh. It carries, linked in or beside it:
- MLX 0.32.5 at commit fc344c9 (libmlx.dylib, libjaccl.dylib,
mlx.metallib), Copyright 2023 Apple Inc., MIT
(LICENSES/omni/mlx.LICENSE.txt)
- MLX 0.32.5 (libmlx.dylib, libjaccl.dylib, mlx.metallib), Copyright
2023 Apple Inc., MIT (LICENSES/omni/mlx.LICENSE.txt)
- CivetWeb 1.16, Copyright 2013-2021 the CivetWeb developers, 2004-2013
Sergey Lyubka, MIT (LICENSES/omni/civetweb.LICENSE.md; only its own
licence applies: none of the optional parts it lists is built)
Expand Down
3 changes: 1 addition & 2 deletions sglang_omni_mlx/native/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,7 @@ set(CMAKE_CXX_STANDARD 20)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_POSITION_INDEPENDENT_CODE ON)

# Note (XXXXRT666): the version of the MLX commit scripts/build_runtime.sh pins;
# MLX's version does not tell commits of its main branch apart.
# Note (XXXXRT666): the MLX release scripts/build_runtime.sh builds.
set(SGLANG_OMNI_MLX_VERSION 0.32.5)
if(NOT MLX_DIR OR NOT EXISTS "${MLX_DIR}/MLXConfig.cmake")
message(FATAL_ERROR "Set MLX_DIR to <MLX ${SGLANG_OMNI_MLX_VERSION} install>/share/cmake/MLX: scripts/build_runtime.sh builds it")
Expand Down
10 changes: 5 additions & 5 deletions sglang_omni_mlx/native/scripts/build_runtime.sh
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
#!/usr/bin/env bash
# Builds the native Qwen3-ASR runtime into a self-contained directory.
# Note (XXXXRT666): MLX is built from a pinned main commit, since no release has
# ml-explore/mlx#4791 yet, with scripts/mlx-patches applied in name order: each
# is the MLX source change of the ml-explore/mlx pull request its name starts
# with. The build is kept per commit and patch set under $work/mlx.
# Note (XXXXRT666): MLX is built from the source of its v0.32.5 release, with
# scripts/mlx-patches applied in name order: each is the MLX source change of
# the ml-explore/mlx pull request its name starts with. The build is kept per
# commit and patch set under $work/mlx.
set -euo pipefail

output="${1:?usage: build_runtime.sh <output-directory> [<work-directory>]}"
Expand All @@ -14,7 +14,7 @@ test "$(uname -m)" = arm64 || { echo "Apple Silicon is required" >&2; exit 1; }
command -v uv >/dev/null || { echo "uv is required" >&2; exit 1; }

deployment_target="${MACOSX_DEPLOYMENT_TARGET:-15.0}"
mlx_commit=fc344c986c4169d99f76b5d95ae6b4a58a359a63
mlx_commit=cfc675e9e59cb6ee29a647cf8fe87ef844eff879 # v0.32.5
shopt -s nullglob
mlx_patches=("$native_dir"/scripts/mlx-patches/*.patch)
shopt -u nullglob
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
diff --git a/mlx/allocator.h b/mlx/allocator.h
index 82bc874..a26f3e4 100644
index 760bf2086..98a360742 100644
--- a/mlx/allocator.h
+++ b/mlx/allocator.h
@@ -53,6 +53,12 @@ class MLX_API Allocator {
Expand All @@ -15,9 +15,9 @@ index 82bc874..a26f3e4 100644
virtual Buffer make_buffer(void* ptr, size_t size) {
return Buffer{nullptr};
};
@@ -85,6 +91,23 @@ class MLX_API Allocator {

MLX_API Allocator& allocator();
@@ -88,6 +94,23 @@ MLX_API Allocator& allocator();
// Whether the active memory is above the memory limit.
MLX_API bool over_memory_limit();

+class AllocationScope {
+ public:
Expand All @@ -40,7 +40,7 @@ index 82bc874..a26f3e4 100644

// The allocator owns data from malloc
diff --git a/mlx/array.h b/mlx/array.h
index 59ab941..bae6993 100644
index 59ab94194..bae6993ec 100644
--- a/mlx/array.h
+++ b/mlx/array.h
@@ -284,7 +284,8 @@ class MLX_API array {
Expand All @@ -62,7 +62,7 @@ index 59ab941..bae6993 100644
switch (dtype()) {
case bool_:
diff --git a/mlx/backend/common/common.cpp b/mlx/backend/common/common.cpp
index 81dc5c1..8d0009c 100644
index e317fe858..97add8ede 100644
--- a/mlx/backend/common/common.cpp
+++ b/mlx/backend/common/common.cpp
@@ -88,6 +88,7 @@ void ExpandDims::eval(const std::vector<array>& inputs, array& out) {
Expand All @@ -74,7 +74,7 @@ index 81dc5c1..8d0009c 100644

double numel = 1;
diff --git a/mlx/backend/cpu/eval.cpp b/mlx/backend/cpu/eval.cpp
index 354820f..d02efe1 100644
index 354820f0f..d02efe113 100644
--- a/mlx/backend/cpu/eval.cpp
+++ b/mlx/backend/cpu/eval.cpp
@@ -22,6 +22,7 @@ void clear_streams() {
Expand All @@ -86,10 +86,10 @@ index 354820f..d02efe1 100644

auto outputs = arr.outputs();
diff --git a/mlx/backend/metal/allocator.cpp b/mlx/backend/metal/allocator.cpp
index ff12293..55e771f 100644
index 80a3f72ba..ddf442433 100644
--- a/mlx/backend/metal/allocator.cpp
+++ b/mlx/backend/metal/allocator.cpp
@@ -42,6 +42,14 @@ bool can_reuse_alien_buffer(void* ptr) {
@@ -43,6 +43,14 @@ bool can_reuse_alien_buffer(void* ptr) {

namespace metal {

Expand All @@ -104,7 +104,7 @@ index ff12293..55e771f 100644
MetalAllocator::MetalAllocator(Device& d)
: device_(d.mtl_device()),
residency_sets_(d.residency_sets()),
@@ -127,6 +135,20 @@ Buffer MetalAllocator::malloc(size_t size) {
@@ -129,6 +137,20 @@ Buffer MetalAllocator::malloc(size_t size) {

// Try the cache
std::unique_lock lk(mutex_);
Expand All @@ -124,8 +124,8 @@ index ff12293..55e771f 100644
+ }
MTL::Buffer* buf = buffer_cache_.reuse_from_cache(size);
if (!buf) {
size_t mem_required = get_active_memory() + get_cache_memory() + size;
@@ -190,11 +212,15 @@ void MetalAllocator::free(Buffer buffer) {
auto cache_size = buffer_cache_.cache_size();
@@ -198,11 +220,15 @@ void MetalAllocator::free(Buffer buffer) {
return;
}

Expand All @@ -140,10 +140,10 @@ index ff12293..55e771f 100644
#endif
-
- std::unique_lock lk(mutex_);
assert(buf->length() <= active_memory_);
active_memory_ -= buf->length();
if (get_cache_memory() < max_pool_size_) {
buffer_cache_.recycle_to_cache(buf);
@@ -209,6 +235,78 @@ void MetalAllocator::free(Buffer buffer) {
if (buffer_cache_.cache_size() < max_pool_size_) {
@@ -218,6 +244,78 @@ void MetalAllocator::free(Buffer buffer) {
}
}

Expand Down Expand Up @@ -220,10 +220,10 @@ index ff12293..55e771f 100644
+}
+
size_t MetalAllocator::size(Buffer buffer) const {
return static_cast<MTL::Buffer*>(buffer.ptr())->length();
}
if (const auto* p = buffer.ptr(); p) {
return static_cast<const MTL::Buffer*>(p)->length();
diff --git a/mlx/backend/metal/allocator.h b/mlx/backend/metal/allocator.h
index 8859513..572a950 100644
index 251d67a2e..faf14b91a 100644
--- a/mlx/backend/metal/allocator.h
+++ b/mlx/backend/metal/allocator.h
@@ -20,6 +20,8 @@ class MetalAllocator : public allocator::Allocator {
Expand All @@ -235,7 +235,7 @@ index 8859513..572a950 100644
virtual Buffer make_buffer(void* ptr, size_t size) override;
virtual void release(Buffer buffer) override;

@@ -41,8 +43,20 @@ class MetalAllocator : public allocator::Allocator {
@@ -48,8 +50,20 @@ class MetalAllocator : public allocator::Allocator {
size_t get_memory_limit();
size_t set_wired_limit(size_t limit);
void clear_cache();
Expand All @@ -256,7 +256,7 @@ index 8859513..572a950 100644
MTL::Device* device_;

// The size of allocations which go on the heap until it is full. This size
@@ -61,6 +75,8 @@ class MetalAllocator : public allocator::Allocator {
@@ -68,6 +82,8 @@ class MetalAllocator : public allocator::Allocator {

// Caching allocator
BufferCache<MTL::Buffer> buffer_cache_;
Expand All @@ -266,7 +266,7 @@ index 8859513..572a950 100644
// Allocation stats
size_t block_limit_;
diff --git a/mlx/backend/metal/device.cpp b/mlx/backend/metal/device.cpp
index 6c0c92f..9151efc 100644
index 100b74ae4..f98a3c973 100644
--- a/mlx/backend/metal/device.cpp
+++ b/mlx/backend/metal/device.cpp
@@ -15,6 +15,7 @@
Expand Down Expand Up @@ -538,10 +538,10 @@ index 6c0c92f..9151efc 100644
#endif

diff --git a/mlx/backend/metal/device.h b/mlx/backend/metal/device.h
index ad5a1d4..ab9da8c 100644
index c0ff6a3c5..a53cad0a5 100644
--- a/mlx/backend/metal/device.h
+++ b/mlx/backend/metal/device.h
@@ -35,8 +35,9 @@ class MLX_API CommandEncoder {
@@ -36,8 +36,9 @@ class MLX_API CommandEncoder {
}
~ConcurrentContext() {
enc.concurrent_ = false;
Expand All @@ -553,15 +553,15 @@ index ad5a1d4..ab9da8c 100644
enc.concurrent_outputs_.clear();
}

@@ -48,6 +49,7 @@ class MLX_API CommandEncoder {
@@ -49,6 +50,7 @@ class MLX_API CommandEncoder {
void set_input_array(const array& a, int idx, int64_t offset = 0);
void set_output_array(array& a, int idx, int64_t offset = 0);
void register_output_array(const array& a);
+ void retain_array(const array& a);

void add_temporary(array arr);
void add_temporaries(std::vector<array> arrays);
@@ -101,10 +103,7 @@ class MLX_API CommandEncoder {
@@ -102,10 +104,7 @@ class MLX_API CommandEncoder {
void commit(std::function<void()> completion = nullptr);
void synchronize();
#ifndef NDEBUG
Expand All @@ -573,15 +573,15 @@ index ad5a1d4..ab9da8c 100644
#endif

MTL::CommandBuffer* get_command_buffer() const {
@@ -115,6 +114,7 @@ class MLX_API CommandEncoder {
@@ -116,6 +115,7 @@ class MLX_API CommandEncoder {
MTL::ComputeCommandEncoder* get_command_encoder();

Device& device_;
+ int stream_index_;
bool exiting_{false};

// Buffer that stores encoded commands.
@@ -122,6 +122,8 @@ class MLX_API CommandEncoder {
@@ -123,6 +123,8 @@ class MLX_API CommandEncoder {
NS::SharedPtr<MTL::CommandBuffer> buffer_;
int buffer_ops_{0};
size_t buffer_sizes_{0};
Expand All @@ -590,7 +590,7 @@ index ad5a1d4..ab9da8c 100644

// The residency set and how many of its sets this queue has attached.
ResidencySets& residency_sets_;
@@ -141,20 +143,23 @@ class MLX_API CommandEncoder {
@@ -142,20 +144,23 @@ class MLX_API CommandEncoder {
NS::SharedPtr<MTL::Fence> fence_;
bool needs_barrier_{false};
bool concurrent_{false};
Expand Down Expand Up @@ -619,7 +619,7 @@ index ad5a1d4..ab9da8c 100644
};

diff --git a/mlx/backend/metal/eval.cpp b/mlx/backend/metal/eval.cpp
index b53feae..5a37187 100644
index b53feaea4..5a371879d 100644
--- a/mlx/backend/metal/eval.cpp
+++ b/mlx/backend/metal/eval.cpp
@@ -2,6 +2,7 @@
Expand Down Expand Up @@ -682,7 +682,7 @@ index b53feae..5a37187 100644
}

diff --git a/mlx/backend/metal/fence.cpp b/mlx/backend/metal/fence.cpp
index 3c133e5..a75ba21 100644
index 3c133e589..a75ba21ff 100644
--- a/mlx/backend/metal/fence.cpp
+++ b/mlx/backend/metal/fence.cpp
@@ -21,6 +21,7 @@ struct FenceImpl {
Expand All @@ -694,7 +694,7 @@ index 3c133e5..a75ba21 100644
cpu_value()[0] = 0;
}
diff --git a/mlx/backend/metal/fft.cpp b/mlx/backend/metal/fft.cpp
index 952f829..4a3f934 100644
index 100dc4fa6..4e2181b21 100644
--- a/mlx/backend/metal/fft.cpp
+++ b/mlx/backend/metal/fft.cpp
@@ -281,6 +281,7 @@ int primitive_root(int n) {
Expand Down
Loading
Loading