<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by R0CKSTAR on Medium]]></title>
        <description><![CDATA[Stories by R0CKSTAR on Medium]]></description>
        <link>https://medium.com/@R0CKSTAR?source=rss-215ab3371ce------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*GZirrqkCCRbzGDAWXN0FUA.jpeg</url>
            <title>Stories by R0CKSTAR on Medium</title>
            <link>https://medium.com/@R0CKSTAR?source=rss-215ab3371ce------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Thu, 03 Dec 2026 04:08:46 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@R0CKSTAR/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[Why Your LLM Benchmark Numbers Keep Changing on Apple Silicon]]></title>
            <link>https://medium.com/@R0CKSTAR/why-your-llm-benchmark-numbers-keep-changing-on-apple-silicon-edc486fceaee?source=rss-215ab3371ce------2</link>
            <guid isPermaLink="false">https://medium.com/p/edc486fceaee</guid>
            <dc:creator><![CDATA[R0CKSTAR]]></dc:creator>
            <pubDate>Fri, 13 Mar 2026 08:07:03 GMT</pubDate>
            <atom:updated>2026-03-13T08:07:03.571Z</atom:updated>
            <content:encoded><![CDATA[<p><em>Investigating performance variance in MLX inference on a MacBook Pro M1</em></p><h3><strong>TL;DR</strong></h3><p>We observed <strong>up to 30% variance</strong> in decode throughput across benchmark runs of the same code on the same hardware — enough to turn a “no regression” into an apparent 14% slowdown, or inflate a 48% improvement to 80%. Using to monitor GPU temperature, power draw, and memory pressure, we identified three root causes: <strong>thermal throttling</strong>, <strong>memory pressure from unified memory</strong>, and <strong>DVFS (Dynamic Voltage and Frequency Scaling)</strong>. This post documents the methodology and provides guidelines for producing reliable benchmarks on Apple Silicon.</p><h3><strong>The Problem</strong></h3><p>While developing a hybrid KV cache for <a href="https://github.com/sgl-project/sglang">SGLang</a>’s MLX backend on Apple Silicon, we encountered a frustrating situation: the same benchmark, run minutes apart, produced wildly different results.</p><pre>| Run                      | BS=1 Decode (tok/s) | BS=4 Decode (tok/s) |<br>|--------------------------|---------------------|---------------------|<br>| Early run (favorable)    | 42.3                | 83.8                |<br>| Later run (unfavorable)  | 28.7                | 63.5                |<br>| Documented baseline      | 40.2                | 46.6                |</pre><p>A 42 → 29 tok/s swing on BS=1 is a <strong>31% drop</strong> with zero code changes. This makes it nearly impossible to evaluate whether an optimization actually works.</p><h3><strong>Test Setup</strong></h3><ul><li><strong>Hardware</strong>: Apple M1 (MacBookPro17,1), 8 GPU cores, 16GB unified memory</li><li><strong>OS</strong>: macOS 26.3.1 (Tahoe)</li><li><strong>Model</strong>: Qwen3–0.6B (BF16)</li><li><strong>Benchmark</strong>: sglang.bench_one_batch with input_len=60, output_len=10</li><li><strong>Monitoring</strong>: apple-smi v0.1.4 - captures GPU/CPU temperature, power draw, GPU frequency, and memory usage</li></ul><h3><strong>The Experiment</strong></h3><p>We ran 6 sequential benchmark iterations with apple-smi snapshots before and after each run:</p><pre>Run 1: BS=1 (cold start)<br>Run 2: BS=4 (immediately after)<br>Run 3: BS=1 (after 15s cooldown)<br>Run 4: BS=4 (after 15s cooldown)<br>Run 5: BS=1 (back-to-back, no cooldown)<br>Run 6: BS=4 (back-to-back, no cooldown)</pre><p><strong>Raw Results</strong></p><pre>| Run | Label       | Decode (tok/s) | GPU Temp Pre→Post | CPU Temp Pre→Post | Power Pre→Post |<br>|-----|-------------|----------------|-------------------|-------------------|----------------|<br>| 1   | BS=1 cold   | **31.6**       | 30°C → 60°C       | 73°C → 74°C       | 17W → 18W      |<br>| 2   | BS=4 cold   | **67.8**       | 59°C → 62°C       | 73°C → 76°C       | 16W → 24W      |<br>| 3   | BS=1 cooled | **32.7**       | 30°C → 64°C       | 73°C → 74°C       | 13W → 19W      |<br>| 4   | BS=4 cooled | **69.7**       | 30°C → 60°C       | 70°C → 76°C       | 13W → 23W      |<br>| 5   | BS=1 hot    | **30.5**       | 60°C → 62°C       | 74°C → 76°C       | 17W → 22W      |<br>| 6   | BS=4 hot    | **69.1**       | 62°C → 65°C       | 75°C → 77°C       | 18W → 21W      |</pre><h3><strong>Root Cause Analysis</strong></h3><p><strong>1. Thermal Throttling</strong></p><p>The M1’s GPU temperature swings from <strong>30°C to 65°C</strong> during a single benchmark run. Apple Silicon uses aggressive thermal management — when the die temperature rises, the SoC reduces clock speeds and power delivery to stay within its thermal envelope.</p><p>Key observation: the GPU starts “cold” at 30°C after idle periods, heats to 60°C+ during computation, and the <strong>warmup phase itself changes the thermal state</strong> for the benchmark phase that follows. This means:</p><ul><li>A “cold” first run benefits from peak clocks during warmup but may throttle during the benchmark</li><li>A “hot” follow-up run starts already throttled</li></ul><p>The M1 MacBook Pro has a fanless design, making it especially susceptible — there’s no active cooling to dissipate heat between runs.</p><p><strong>2. Memory Pressure and Swap</strong></p><pre>RAM usage: 11,340 / 16,384 MiB (69% used)<br>Swap usage: 7,842 MiB</pre><p>With only 16GB of unified memory shared between CPU, GPU, and system, and <strong>~8GB of swap active</strong>, the system is under significant memory pressure. On Apple Silicon, GPU memory <em>is</em> system memory — there’s no dedicated VRAM. This means:</p><ul><li>The OS may page out GPU buffers to swap and page them back in, adding latency spikes</li><li>Background processes competing for memory cause unpredictable eviction of model weights or KV cache buffers</li><li>Swap I/O competes with the SSD controller for bus bandwidth</li></ul><p><strong>3. DVFS (Dynamic Voltage and Frequency Scaling)</strong></p><p>The GPU frequency was consistently reported at <strong>~715 MHz</strong> across all runs, which is near the M1’s base GPU clock. However, Apple’s DVFS operates at a finer granularity than what apple-smi can capture at 1-second intervals - the GPU may boost to higher frequencies for microsecond bursts during computation, with the boost headroom depending on:</p><ul><li>Current thermal state (more headroom when cold)</li><li>Power budget (the M1 has a 13–15W TDP)</li><li>Whether the CPU is also active (CPU and GPU share the power budget)</li></ul><p><strong>4. Background System Activity</strong></p><p>macOS runs numerous background services that spike CPU and I/O:</p><ul><li><strong>Spotlight indexing</strong> (mds_stores) can saturate SSD bandwidth</li><li><strong>Time Machine</strong> snapshots</li><li><strong>cloudd</strong> and iCloud sync</li><li><strong>WindowServer</strong> compositing - even rendering the terminal output competes for GPU cycles</li></ul><p>The CPU temperature baseline of <strong>70–76°C</strong> even before our benchmark starts indicates significant background activity.</p><h3><strong>What the Data Tells Us</strong></h3><p><strong>BS=1 variance is real but manageable</strong></p><pre>| Condition          | Decode (tok/s) | Variance from mean |<br>|--------------------|----------------|--------------------|<br>| Cold start         | 31.6           | ±0% (reference)    |<br>| After cooldown     | 32.7           | +3.5%              |<br>| Back-to-back (hot) | 30.5           | -3.5%              |</pre><p><strong>Range: 30.5–32.7 tok/s (~7% spread)</strong>. This is within the noise floor for meaningful conclusions. However, comparing against the documented baseline of 40.2 tok/s (measured on a different day) shows a <strong>24% gap</strong> — likely due to different background load and memory pressure conditions.</p><p><strong>BS=4 is more stable</strong></p><pre>| Condition          | Decode (tok/s) | Variance from mean |<br>|--------------------|----------------|--------------------|<br>| Cold start         | 67.8           | -1.6%              |<br>| After cooldown     | 69.7           | +1.2%              |<br>| Back-to-back (hot) | 69.1           | +0.3%              |</pre><p><strong>Range: 67.8–69.7 tok/s (~3% spread)</strong>. The BS=4 batched path is more stable because it’s GPU-compute-bound (the GPU stays busy), reducing the impact of scheduling jitter.</p><p><strong>The first decode step is always slow</strong></p><p>Every BS=4 run shows Decode 0 at <strong>35–38 tok/s</strong> while Decode 1+ runs at <strong>66–76 tok/s</strong>. This ~2× gap on the first step is caused by:</p><ol><li><strong>Mode transition overhead</strong>: the hybrid cache switches from native mlx-lm caches to contiguous buffers, patching attention modules on the first batched decode</li><li><strong>MLX lazy evaluation</strong>: the first decode triggers JIT compilation of the new computation graph</li><li><strong>Cache warmup</strong>: the contiguous KV buffers are freshly allocated and may not be in the GPU’s cache hierarchy</li></ol><h3><strong>Guidelines for Reliable Benchmarking on Apple Silicon</strong></h3><p>Based on these findings, here are concrete recommendations:</p><p><strong>Before benchmarking</strong></p><ol><li><strong>Close unnecessary applications</strong> — especially browsers, IDEs, and anything GPU-accelerated</li><li><strong>Wait for background indexing to finish</strong> — check with sudo fs_usage -f filesys mds_stores</li><li><strong>Monitor memory pressure</strong> — if swap exceeds ~2GB, reboot or close apps first</li><li><strong>Let the system idle for 2+ minutes</strong> before starting — check with apple-smi that GPU temp is at baseline (~30°C)</li></ol><p><strong>During benchmarking</strong></p><ol><li><strong>Always use a warmup phase</strong> — the benchmark tool already does this, but ensure warmup is at least 32 tokens</li><li><strong>Run benchmarks sequentially, never in parallel</strong> — even two Python processes compete for the unified memory bus</li><li><strong>Add cooldown periods</strong> — at least 15 seconds between runs to allow thermal recovery</li><li><strong>Run each configuration 3+ times</strong> — report median, not mean (mean is skewed by outliers)</li></ol><p><strong>When comparing</strong></p><ol><li><strong>Use A/B testing in the same session</strong> — git stash → run baseline → git stash pop → run modified, back-to-back</li><li><strong>Report the system state</strong> — include apple-smi output with results so reviewers can assess conditions</li><li><strong>Only trust relative comparisons</strong> — absolute numbers are meaningless across sessions; compare against a baseline run in the same session</li><li><strong>Use median decode throughput, not total throughput</strong> — the “Total” metric includes prefill and amortizes differently across batch sizes</li></ol><p><strong>Example: proper A/B comparison</strong></p><pre># ✅ Good: sequential A/B with system monitoring<br>apple-smi                          # Check system state<br>git stash                          # Switch to baseline<br>bench_one_batch --batch-size 4     # Baseline run<br>sleep 15                           # Cooldown<br>git stash pop                      # Switch to modified<br>bench_one_batch --batch-size 4     # Modified run<br>apple-smi                          # Verify system state hasn&#39;t degraded<br><br># ❌ Bad: parallel runs<br>bench_one_batch --batch-size 1 &amp;   # Competing for GPU<br>bench_one_batch --batch-size 4 &amp;   # Results are meaningless</pre><h3><strong>Conclusion</strong></h3><p>On Apple Silicon, <strong>you cannot trust a single benchmark number</strong>. The unified memory architecture, fanless thermal design, and aggressive DVFS create a system where performance varies by 7–30% depending on conditions invisible to the application.</p><p>The fix is not to eliminate variance (you can’t), but to <strong>measure it, report it, and design your comparison methodology to account for it</strong>. Use apple-smi to capture system state, run back-to-back A/B comparisons in the same thermal window, and report medians with system context.</p><p>Our hybrid KV cache optimization for SGLang’s MLX backend shows a <strong>consistent ~48% improvement</strong> at BS=4 (69 tok/s vs 47 tok/s baseline) when measured with proper methodology — not the 80% we initially reported from a cherry-picked favorable run.</p><p><em>Data collected on March 13, 2026 using v0.1.4 and SGLang’s </em><em>bench_one_batch tool. Model: Qwen3-0.6B on Apple M1 MacBook Pro (16GB).</em></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=edc486fceaee" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[ Accelerating SGLang Inference on macOS: 5× Faster with Native MLX]]></title>
            <link>https://medium.com/@R0CKSTAR/accelerating-sglang-inference-on-macos-5-faster-with-native-mlx-640865e8b350?source=rss-215ab3371ce------2</link>
            <guid isPermaLink="false">https://medium.com/p/640865e8b350</guid>
            <dc:creator><![CDATA[R0CKSTAR]]></dc:creator>
            <pubDate>Thu, 12 Mar 2026 06:30:16 GMT</pubDate>
            <atom:updated>2026-03-12T06:30:16.950Z</atom:updated>
            <content:encoded><![CDATA[<p>SGLang already runs on macOS via PyTorch’s MPS (Metal Performance Shaders) backend — you can launch a server, send requests, and get responses. But performance on Apple Silicon has been underwhelming. In this post, we describe how we integrated a <strong>native MLX execution path</strong> into SGLang that delivers up to <strong>5.3× higher throughput</strong> while using <strong>significantly less memory</strong>. For more information, please see: <a href="https://github.com/sgl-project/sglang/pull/20342">https://github.com/sgl-project/sglang/pull/20342</a></p><h3>The Problem: PyTorch MPS Overhead</h3><p>When SGLang runs on macOS with PyTorch MPS, every operation — matrix multiplications, attention, normalization — goes through PyTorch’s MPS backend, which translates PyTorch ops into Metal Performance Shaders. This translation layer adds substantial overhead:</p><ol><li><strong>Op dispatch overhead</strong>: Each PyTorch operation is individually dispatched to MPS, missing optimization opportunities that come from fusing operations together.</li><li><strong>Memory duplication</strong>: PyTorch loads model weights into MPS memory and allocates a large KV cache, leaving less room for actual inference workloads.</li><li><strong>No fused kernels</strong>: Operations like RMSNorm + RoPE + Attention run as separate Metal dispatches instead of fused GPU kernels.</li></ol><h3>The Solution: Native MLX Execution</h3><p><a href="https://github.com/ml-explore/mlx">MLX</a> is Apple’s machine learning framework designed specifically for Apple Silicon. Unlike PyTorch MPS, MLX compiles operations directly to optimized Metal shaders through its mx.fast API:</p><pre>| Operation           | PyTorch MPS               | MLX                                              |<br>| ------------------- | ------------------------- | ------------------------------------------------ |<br>| RMS Normalization   | Generic MPS kernel        | `mx.fast.rms_norm` (fused Metal shader)          |<br>| Rotary Embeddings   | Multiple MPS dispatches   | `mx.fast.rope` (fused Metal shader)              |<br>| Attention           | Separate Q·K, softmax, ·V | `mx.fast.scaled_dot_product_attention` (fused)   |<br>| Layer Normalization | Generic MPS kernel        | `mx.fast.layer_norm` (fused Metal shader)        |</pre><p>We integrated MLX as an alternative execution backend within SGLang’s existing architecture. The key insight: <strong>keep SGLang’s scheduler and serving infrastructure intact, but route the actual model computation through MLX instead of PyTorch MPS</strong>.</p><h3>Architecture</h3><pre>+---------------------------------------------+<br>|             SGLang Scheduler                |<br>|   (request management, batching, routing)   |<br>+---------------------------------------------+<br>|            MlxTpModelWorker                 |<br>|  +-------------------+ +------------------+ |<br>|  | MlxModelRunnerStub| |  MlxModelRunner  | |<br>|  |  (zero-memory     | |  (actual MLX     | |<br>|  |   bookkeeping)    | |   inference)     | |<br>|  +-------------------+ +------------------+ |<br>+---------------------------------------------+<br>|  mlx-lm models -&gt; mlx.nn -&gt; mx.fast kernels |<br>|              | Metal GPU |                  |<br>+---------------------------------------------+</pre><h4>Three Key Components</h4><ol><li><strong>MlxModelRunner</strong> - The actual inference engine. Loads the model via mlx-lm, manages per-request KV caches, and runs forward passes entirely in MLX. Only the final logits are bridged to PyTorch for compatibility with SGLang&#39;s sampling pipeline.</li></ol><p><strong>2. </strong><strong>MlxModelRunnerStub</strong> - A lightweight ModelRunner subclass that satisfies SGLang&#39;s infrastructure requirements without consuming GPU memory. It provides:</p><ul><li>A _DummyKVCache that reports zero memory usage</li><li>CPU-side bookkeeping pools (req_to_token_pool, token_to_kv_pool_allocator) for the scheduler</li><li>No PyTorch model weights loaded at all</li></ul><p><strong>3. </strong><strong>MlxTpModelWorker</strong> - Routes forward_batch_generation calls to the MLX runner instead of the standard PyTorch path. Handles both prefill and decode phases, including batched prefill for same-length sequences.</p><h4>Zero-Memory Stub Design</h4><p>A critical design decision was the <strong>zero-memory stub</strong>. In the naive approach, SGLang loads PyTorch model weights (~1.2 GB for Qwen3–0.6B) <em>and</em> allocates a PyTorch KV cache (~2.5 GB), even though MLX manages its own weights and cache. This “double-load” wastes ~3.7 GB of unified memory.</p><p>Our stub eliminates this entirely:</p><pre>| Resource                  | Before (double-load) | After (stub)   |<br>| ------------------------- | -------------------- | -------------- |<br>| PyTorch model weights     | ~1.2 GB              | **0 bytes**    |<br>| PyTorch KV cache          | ~2.5 GB              | **0 bytes**    |<br>| Scheduler bookkeeping     | CPU-side pools       | CPU-side pools |<br>| Available KV cache tokens | 17,534               | **40,960**     |</pre><h3>Benchmark Results</h3><p>All benchmarks run on <strong>Apple M1 (16 GB unified memory)</strong> with Qwen3–0.6B, input length 60, output length 10.</p><h4>Batch Size 1</h4><pre>| Metric                     | PyTorch MPS  | MLX Native   | Speedup  |<br>| -------------------------- | ------------ | ------------ | -------- |<br>| Prefill throughput         | 229.97 tok/s | 902.99 tok/s | **3.9×** |<br>| Decode throughput (median) | 7.87 tok/s   | 31.25 tok/s  | **4.0×** |<br>| Total throughput           | 44.19 tok/s  | 201.89 tok/s | **4.6×** |<br>| Prefill latency            | 260.9 ms     | 66.5 ms      | **3.9×** |<br>| Decode latency (median)    | 127.1 ms     | 32.0 ms      | **4.0×** |</pre><h4>Batch Size 4</h4><pre>| Metric                     | PyTorch MPS  | MLX Native     | Speedup  |<br>| -------------------------- | ------------ | -------------- | -------- |<br>| Prefill throughput         | 385.76 tok/s | 1,019.48 tok/s | **2.6×** |<br>| Decode throughput (median) | 18.22 tok/s  | 46.13 tok/s    | **2.5×** |<br>| Total throughput           | 109.26 tok/s | 275.00 tok/s   | **2.5×** |</pre><h4>Memory Efficiency</h4><pre>| Metric                          | PyTorch MPS | MLX Native |<br>| ------------------------------- | ----------- | ---------- |<br>| PyTorch weight memory           | ~1.2 GB     | 0          |<br>| PyTorch KV cache memory         | ~2.5 GB     | 0          |<br>| Max KV cache tokens (scheduler) | 23,290      | 40,960     |</pre><h3>How to Use It</h3><p>Enable the MLX backend with a single environment variable:</p><pre># Benchmark<br>SGLANG_USE_MLX=1 python -m sglang.bench_one_batch \<br>  --model-path Qwen/Qwen3-0.6B \<br>  --trust-remote-code --disable-radix-cache --disable-cuda-graph \<br>  --tp-size 1 --batch-size 1 --input-len 60 --output-len 10<br><br># Launch server (OpenAI-compatible API)<br>SGLANG_USE_MLX=1 python -m sglang.launch_server \<br>  --model-path Qwen/Qwen3-0.6B \<br>  --host 0.0.0.0 --port 30000 \<br>  --trust-remote-code --disable-radix-cache --disable-cuda-graph --tp-size 1</pre><p>The server exposes the standard OpenAI-compatible API, so existing clients work without modification:</p><pre>curl http://localhost:30000/v1/chat/completions \<br>  -H &quot;Content-Type: application/json&quot; \<br>  -d &#39;{&quot;model&quot;: &quot;Qwen/Qwen3-0.6B&quot;, &quot;messages&quot;: [{&quot;role&quot;: &quot;user&quot;, &quot;content&quot;: &quot;What is the capital of France?&quot;}], &quot;temperature&quot;: 0, &quot;max_tokens&quot;: 50}&#39;</pre><h3>Current Limitations</h3><ul><li><strong>Greedy sampling only</strong>: The MLX path currently uses argmax for token selection. Full sampling (top-k, top-p, temperature, penalties) is not yet integrated.</li><li><strong>No KV cache reuse across requests</strong>: Each request maintains its own independent KV cache. SGLang’s radix cache and prefix sharing are not yet connected to the MLX path.</li><li><strong>No continuous batching with cache reuse</strong>: While we support batched prefill and decode, the sophisticated cache management that makes SGLang efficient on CUDA is not yet ported.</li><li><strong>Single model support</strong>: Speculative decoding and draft models are not yet supported through the MLX path.</li></ul><h3>Future Plans</h3><h4>Short Term</h4><ul><li><strong>Full sampling pipeline</strong>: Integrate SGLang’s sampling parameters (temperature, top-k, top-p, repetition penalty) with the MLX forward pass.</li><li><strong>Broader model support</strong>: Test and validate more model architectures beyond Qwen3 (Llama, Mistral, Gemma, etc.) through mlx-lm’s extensive model library.</li></ul><h4>Medium Term</h4><ul><li><strong>Paged KV cache for MLX</strong>: Implement a custom paged KV cache that integrates with SGLang’s req_to_token_pool / token_to_kv_pool_allocator, enabling true cross-request cache sharing and radix cache on Apple Silicon.</li><li><strong>Continuous batching with cache reuse</strong>: Connect SGLang’s scheduler-level batching decisions to MLX’s cache management for production-grade serving performance.</li></ul><h4>Long Term</h4><ul><li><strong>Custom Metal kernels</strong>: Leverage mx.fast.metal_kernel for SGLang-specific fused operations that go beyond what mlx-lm provides out of the box.</li><li><strong>Speculative decoding on Apple Silicon</strong>: Route both draft and target models through MLX for low-latency speculative decoding.</li><li><strong>Tensor parallelism</strong>: Explore multi-GPU inference on Mac Studio / Mac Pro configurations using MLX’s distributed primitives.</li></ul><h3>Acknowledgments</h3><p>This work builds on the foundation laid by <a href="https://medium.com/@R0CKSTAR/running-sglang-natively-on-macos-llms-and-diffusion-models-on-apple-silicon-8a38be78eb37">SGLang’s existing macOS support</a> for both LLM and diffusion model inference on Apple Silicon. The MLX integration extends this by providing a native execution path that eliminates the PyTorch MPS overhead entirely.</p><p>Special thanks to the <a href="https://github.com/ml-explore/mlx">MLX team</a> at Apple for building a framework that makes this level of performance possible on Apple Silicon, and to the <a href="https://github.com/ml-explore/mlx-lm">mlx-lm</a> project for providing optimized model implementations that leverage mx.fast fused kernels.</p><p><em>To try it out, grab the latest SGLang from the </em><em>main branch and set </em><em>SGLANG_USE_MLX=1. Feedback and contributions welcome!</em></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=640865e8b350" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[ Running SGLang Natively on macOS: LLMs and Diffusion Models on Apple Silicon]]></title>
            <link>https://medium.com/@R0CKSTAR/running-sglang-natively-on-macos-llms-and-diffusion-models-on-apple-silicon-8a38be78eb37?source=rss-215ab3371ce------2</link>
            <guid isPermaLink="false">https://medium.com/p/8a38be78eb37</guid>
            <category><![CDATA[llm]]></category>
            <category><![CDATA[diffusion]]></category>
            <category><![CDATA[sglang]]></category>
            <category><![CDATA[macos]]></category>
            <category><![CDATA[metal]]></category>
            <dc:creator><![CDATA[R0CKSTAR]]></dc:creator>
            <pubDate>Thu, 05 Mar 2026 02:33:59 GMT</pubDate>
            <atom:updated>2026-03-05T02:33:59.716Z</atom:updated>
            <content:encoded><![CDATA[<h3>Why macOS Matters for Local AI</h3><p>Apple Silicon machines have quietly become some of the most interesting systems for local AI workloads:</p><ul><li>Powerful GPUs</li><li>Large unified memory (up to 192GB)</li><li>High memory bandwidth</li><li>Metal compute acceleration</li></ul><p>Yet most modern inference frameworks still prioritize Linux + CUDA GPUs.</p><p>That leaves macOS developers in an awkward position: powerful hardware, but limited tooling.</p><p>Recently, I worked on enabling native macOS execution for SGLang, and the result is something quite exciting:</p><blockquote><em>You can now run both LLMs and diffusion models natively on macOS using SGLang.</em></blockquote><p>To my knowledge, this is the first time SGLang supports both model types on Apple Silicon in the same runtime environment.</p><h3>What is SGLang?</h3><p>SGLang is a high-performance inference framework designed for serving large language models and multimodal models efficiently. ([SGLang Documentation][1])</p><p>Key capabilities include:</p><ul><li>Continuous batching</li><li>Prefix caching (RadixAttention)</li><li>Quantization support</li><li>OpenAI-compatible APIs</li><li>Multi-GPU and distributed serving</li><li>Support for language models, embeddings, reward models, and diffusion models</li></ul><p>The framework is widely used for production inference pipelines and research experimentation.</p><p>Historically, SGLang primarily targeted:</p><ul><li>NVIDIA GPUs</li><li>AMD GPUs</li><li>Moore Threads GPUs</li><li>Ascend NPUs</li><li>CPUs</li></ul><p>But macOS support has been missing — until now.</p><h3>Enabling macOS Support</h3><p>I recently contributed a pull request that allows SGLang to run on macOS using Apple Silicon hardware.</p><p>👉 PR: <a href="https://github.com/sgl-project/sglang/pull/19549">sgl-project/sglang#19549</a></p><p>The goal was simple:</p><blockquote><em>Allow developers to experiment with SGLang directly on their Mac, without requiring a Linux GPU server.</em></blockquote><p>This required addressing a number of issues including:</p><ul><li>device backend detection</li><li>runtime compatibility</li><li>fallback implementations for unsupported GPU features</li><li>ensuring diffusion pipelines also function correctly</li></ul><p>The result is a working runtime capable of executing:</p><ul><li>LLM inference</li><li>diffusion generation</li></ul><p>directly on macOS.</p><h3>Running SGLang on macOS</h3><p>Below is a simplified setup flow.</p><h3>1. Clone the repository</h3><pre>git clone https://github.com/sgl-project/sglang.git<br>cd sglang</pre><h3>2. Install dependencies</h3><p>SGLang can be installed using pip or uv.</p><pre>brew install ffmpeg uv</pre><pre># Create and activate a virtual environment<br>uv venv -p 3.11 sglang-diffusion<br>source sglang-diffusion/bin/activate</pre><pre># Install the Python packages<br>uv pip install --upgrade pip<br>rm -f python/pyproject.toml &amp;&amp; mv python/pyproject_other.toml python/pyproject.toml<br>uv pip install -e &quot;python[all_mps]&quot;</pre><p>Using uv significantly speeds up dependency installation.</p><h3>3. Launch an LLM server</h3><p>Example:</p><pre>uv run python -m sglang.launch_server \<br>  --model-path Qwen/Qwen3-0.6B --trust-remote-code \<br>  --disable-radix-cache --disable-cuda-graph --tp-size 1 \<br>  --host 0.0.0.0 --port 43436</pre><p>Once the server is running, you can send requests through the OpenAI-compatible API.</p><h3>4. Run a Diffusion Model</h3><p>SGLang also supports image generation pipelines.</p><p>Example:</p><pre>uv sglang generate \<br>  --model-path black-forest-labs/FLUX.1-dev \<br>  --prompt &quot;A logo With Bold Large text: SGL Diffusion&quot;</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*LptD80RKmiWzEHhg" /></figure><h3>Monitoring GPU Usage on macOS</h3><p>One problem when working with AI workloads on macOS is lack of simple GPU monitoring tools.</p><p>On Linux we have:</p><pre>nvidia-smi</pre><p>But on Apple Silicon there is no direct equivalent.</p><p>To make debugging easier, I built a small tool:</p><h3>apple-smi</h3><p>apple-smi <a href="https://github.com/yeahdongcn/apple-smi">https://github.com/yeahdongcn/apple-smi</a></p><p>apple-smi is a lightweight CLI tool that provides GPU monitoring for Apple Silicon, similar to nvidia-smi.</p><p>It allows developers to inspect:</p><ul><li>Metal GPU utilization</li><li>GPU memory usage</li><li>real-time inference load</li></ul><p>Example usage:</p><pre>&gt; pip install apple-smi<br>&gt; apple-smi</pre><p>Example output:</p><pre>&gt; apple-smi<br>Thu Mar 05 10:07:03 2026<br>+-----------------------------------------------------------------------------------------+<br>| APPLE-SMI 0.1.2              macOS Version: 26.3 (25D125)              Metal Version: 4 |<br>+-----------------------------------------+------------------------+----------------------+<br>| GPU  Name                               |                 Disp.A |                      |<br>|      Temp                 Pwr:Usage/Cap |           Memory-Usage |             GPU-Util |<br>|=========================================+========================+======================|<br>|   0  Apple M1 (8-Core GPU)              |                     On |                      |<br>|       30C                    9.1W / 20W |    14181MiB / 16384MiB |                  45% |<br>+-----------------------------------------+------------------------+----------------------+<br><br>+-----------------------------------------------------------------------------------------+<br>| Processes:                                                                              |<br>| GPU         PID  Type  Process name                                          GPU Memory |<br>|                                                                                   Usage |<br>|=========================================================================================|<br>|   0       58547   C    sglang::scheduler                                         248MiB |<br>|   0       58548   C    sglang::detokenizer                                       195MiB |<br>|   0       58408   C    python3                                                    39MiB |<br>+-----------------------------------------------------------------------------------------+</pre><h3>Why macOS Is Interesting for LLM Inference</h3><p>Apple Silicon machines are unique because they use unified memory architecture.</p><p>Instead of having separate CPU and GPU memory pools, both processors share the same memory space.</p><p>This enables scenarios like:</p><ul><li>running large models locally</li><li>avoiding memory copies</li><li>experimenting with multi-stage pipelines</li></ul><p>On machines such as:</p><ul><li>Mac Studio</li><li>Mac Pro</li><li>high-end MacBook Pro</li></ul><p>you can have 64GB–192GB unified memory, which is extremely useful for model experimentation.</p><h3>Call for Contributors (MLX / Metal Developers)</h3><p>This macOS backend is still very early stage.</p><p>There are many opportunities for improvements.</p><p>Areas where contributors could help:</p><ul><li>MLX kernel optimizations</li><li>Metal compute kernels</li><li>attention implementations</li><li>memory scheduling improvements</li><li>batching optimization</li></ul><p>If you are working on:</p><ul><li>Apple MLX</li><li>Metal GPU programming</li><li>PyTorch MPS</li><li>macOS inference frameworks</li></ul><p>your contributions could significantly accelerate macOS inference performance.</p><h3>Help Test Large Models</h3><p>If you have access to large-memory Apple Silicon machines, testing would be extremely valuable.</p><p>For example:</p><ul><li>Mac Studio</li><li>Mac Pro</li><li>M-series Max / Ultra chips</li></ul><p>Please try running different models and report:</p><ul><li>which models run successfully</li><li>performance observations</li><li>memory usage patterns</li><li>bugs or runtime issues</li></ul><p>Feedback from real hardware helps improve macOS support significantly.</p><h3>The Bigger Picture</h3><p>The local AI ecosystem is evolving rapidly.</p><p>A few years ago, serious AI workloads required:</p><pre>Linux + NVIDIA GPUs</pre><p>Today, things are changing.</p><p>Apple Silicon machines are powerful enough to run meaningful workloads locally.</p><p>With frameworks like SGLang, it becomes possible to build full AI pipelines locally on macOS:</p><pre>Prompt → LLM → Image Prompt → Diffusion → Result</pre><p>All running on your own machine.</p><h3>Final Thoughts</h3><p>This macOS support is only the beginning.</p><p>There is huge potential for improving performance and usability on Apple Silicon.</p><p>If you’re interested in:</p><ul><li>local AI development</li><li>MLX or Metal optimization</li><li>inference frameworks</li><li>running models locally</li></ul><p>please consider contributing.</p><p>Together we can make macOS a serious platform for open-source AI inference.</p><h3>Links</h3><p>SGLang <a href="https://github.com/sgl-project/sglang">https://github.com/sgl-project/sglang</a></p><p>macOS Support PR <a href="https://github.com/sgl-project/sglang/pull/19549">sgl-project/sglang#19549</a></p><p>apple-smi <a href="https://github.com/yeahdongcn/apple-smi">https://github.com/yeahdongcn/apple-smi</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=8a38be78eb37" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>