Friday, July 31, 2026
banner
Top Selling Multipurpose WP Theme

Determine 1: CUDA-to-MLX optimization translation map. CUDA optimization data may be translated into architecture-native MLX methods moderately than copied instruction-for-instruction.

We face a brand new epoch in computing. {Hardware} is altering quickly — not simply sooner GPUs, however a rising vary of chips from completely different distributors, every with its personal structure and sometimes tailor-made to particular AI workloads. Software program is altering simply as quick, and AI coding instruments now generate in minutes what took months of effort a couple of years in the past.

With a lot of computing now centered on AI, GPU kernels are an important part of its success. These are the low-level packages that run contained in the GPU, and writing environment friendly ones is way from apparent — it takes years of experience to get proper. Transferring a kernel from one vendor’s {hardware} to a different is tougher nonetheless, and sometimes means rediscovering the identical optimizations from scratch. The CUDA ecosystem, for instance, has accrued many years of hard-won kernel experience: hand-tuned implementations of consideration, state house fashions, and different vital operations representing 1000’s of engineering hours. Newer {hardware} ecosystems (Apple Silicon, customized AI accelerators, and others) are rising quick however lack this depth.

On this work we ask whether or not that experience may be transferred robotically. We constructed on K-Search, an evolutionary kernel search framework launched by Cao et al. at Berkeley Sky Lab that makes use of AI to optimize GPU kernels, and prolonged it with a backend for MLX — Apple’s machine-learning framework for its personal Apple Silicon chips. We developed a novel structured CUDA-to-MLX translation layer that lets Ok-Search take present CUDA kernels as a data base and adapt them into high-quality GPU kernels for Apple Silicon, moderately than rebuilding from scratch.

We present that our strategy reaches near-expert stage efficiency on Apple Silicon with 0.97x speedup in comparison with the native MLX Consideration kernel, and as much as a 20x prefill speedup over the neighborhood mlx-lm implementation on the Mamba SSM kernel; we report the numbers, and the way a lot of the acquire comes from the interpretation layer, within the sections beneath. Though we concentrate on MLX kernels for Apple Silicon, the tactic shouldn’t be particular to MLX and applies to any ecosystem the place CUDA experience is transferable.

Why MLX?

Apple’s MLX framework has seen outstanding adoption since late 2023. With Apple Silicon in tons of of tens of millions of MacBooks and Mac Studios, MLX allows native AI inference with out cloud prices. The unified reminiscence structure makes it particularly engaging for mid-sized fashions (7B–70B parameters on M sequence chips).

But beneath this momentum lies a big hole: many performance-critical kernels that the NVIDIA ecosystem takes with no consideration: paged consideration, optimized SSM scan kernels, fused MoE routing are both absent or naive with out hardware-specific tuning. MLX runs fashions accurately however typically leaves vital efficiency on the desk.

This hole is what motivates the remainder of this submit.

Ok-Search is an evolutionary kernel optimization framework initially developed by our first writer Shiyi Cao at UC Berkeley Sky Lab. Given a naive kernel and a {hardware} specification, it runs an iterative optimization loop: an LLM causes about which optimizations to attempt subsequent, a code-writing mannequin generates candidate kernels, and people candidates are compiled and benchmarked on actual {hardware}.

Measurements feed again into the search, which retains refining, pursuing promising instructions and dropping useless ends till efficiency converges.

Pseudocode for K-Search via co-evolving world models

Algorithm 1: Ok-Search by way of co-evolving world fashions. The search alternates between choosing essentially the most promising motion, instantiating and evaluating code till enchancment stagnates, and evolving the world mannequin via insert, replace, and prune operations. Tailored from Cao et al. (2026).

Search is grounded by a Spec: a domain-specific doc encoding {hardware} guidelines, optimization patterns, and mathematical constraints which retains generated code from hallucinating invalid primitives and ensures candidates will really compile and run effectively.

In our runs, a single mannequin (Gemini 3.5 Professional Preview) performs each roles: it maintains the reasoning state and writes the kernels. The reasoning half is prompted as a “GPU kernel efficiency engineer” and requested to work via a hard and fast evaluation earlier than proposing something: classify the kernel (discount, scan, consideration/softmax, …), rewrite the reference computation in canonical type, map out information format and entry patterns, and hypothesize the possible bottleneck (bandwidth, latency, compute, or synchronization) in every runtime regime. Solely then does it emit candidate optimizations, every as a single change implementable in a single iteration.

We name the persistent reasoning state a world mannequin. Slightly than a flat record of issues to attempt, it’s a choice (prefix) tree: every root→leaf path composes a full optimization plan, and sibling branches are competing options. Each node is scored — an overall_rating in [0, 10], a confidence in [0, 1], and per-node impacts on reminiscence bandwidth, register stress, and compute/{hardware} match — so the search can rank partial plans and broaden essentially the most promising ones. The tree persists and grows throughout rounds: refining an thought provides a baby node moderately than overwriting its father or mother, and if the perfect rating fails to enhance for a couple of rounds (a stagnation window) the search backs off to discover another department. A single node, because it seems mid-run on the eye kernel, seems like this:

{
  "motion": "Change the threadgroup-memory softmax discount
             with a register-only discount: every SIMD group
             owns 8 question rows and reduces throughout lanes with
             simd_shuffle_xor, eradicating a threadgroup_barrier.",
  "difficulty_1_to_5": 4,
  "impacts": {
    "memory_bandwidth":  8,
    "register_pressure": 4,   // danger: spill if Br > 8
    "compute_hw_fit":    9    // SIMD width 32; maintain tile 8x8
  },
  "overall_rating_0_to_10": 8,
  "confidence_0_to_1": 0.7
}

Itemizing 1: Instance Ok-Search world-model node. Every candidate optimization data a concrete motion, estimated {hardware} impacts, an general precedence score, and the mannequin’s confidence.

Overview of the K-Search loop

Determine 2: Overview of Ok-Search. The framework operates on a Search State $S_t$ structured as a search tree. The tree consists of Closed nodes (blue, visited states with connected program like $x_{12}$) and a Frontier of Open nodes (orange, pending hypotheses like $u_{13}$). The workflow iterates via three phases: (1) Motion Choice, the place essentially the most promising motion node is retrieved from the frontier based mostly on world mannequin estimated precedence rating $V$; (2) Native Refinement, the place a stochastic coverage $pi_{mathrm{code}}$ samples concrete implementations till stagnation; and (3) World Mannequin Replace, the place the LLM causes over the trajectory to replace the search tree by way of Insert (including new actions), Replace (adjusting $V$, e.g., $u_{11}$ dropping from 0.9 to 0.6), and Prune (eradicating much less promising nodes like $u_{10}$).

The unique Ok-Search paper evaluated this search technique on CUDA kernels from FlashInfer. Throughout GQA decode, MLA decode, MLA prefill, and MoE, Ok-Search improved extra constantly than OpenEvolve and ShinkaEvolve over the identical 120-iteration finances. These outcomes set up the search framework we construct on right here; the rest of this submit asks whether or not its optimization data can switch past CUDA.

K-Search benchmark results compared with OpenEvolve and ShinkaEvolve

Determine 3: Fundamental outcomes from the unique Ok-Search paper. Throughout three runs, Ok-Search achieves stronger best-so-far search scores, per-workload kernel efficiency, and speedup distributions than OpenEvolve and ShinkaEvolve on 4 FlashInfer CUDA kernels. Reproduced precisely from Cao et al. (2026).

Constructing an MLX backend

To deliver Ok-Search to Apple Silicon, we first constructed a local MLX backend. We carried out a full MLX-specific job adapter for Ok-Search, together with:

  • An MLX job backend in k_search/duties/ dealing with kernel compilation and execution on Apple Silicon by way of MLX’s Metallic/C++ APIs.
  • Up to date kernel generator prompts for writing and modifying Metallic/MLX kernels.
  • MLX-specific benchmarking integration utilizing mlx.core measurement utilities.

Translating CUDA experience to MLX

Nevertheless, the extra fascinating problem was not merely working Ok-Search on MLX. The important thing perception is that knowledgeable CUDA kernels encode many years of optimization data that’s transferable to Apple GPU in case you can bridge the conceptual hole. Merely handing an LLM a CUDA kernel and asking it to port it’s not sufficient: with out deep {hardware} context, it produces code that’s syntactically legitimate however architecturally incorrect (incorrect tile sizes, invalid primitives, mismatched reminiscence assumptions).

Our translation layer consists of:

  • Idea mapping tables: A structured glossary of CUDA primitives and their MLX/Metallic equivalents with arduous constraints. For instance:
    • __shared__ maps to Metallic threadgroup reminiscence however with a tough 32 KB restrict (vs. NVIDIA’s 48 KB)
    • warp_reduce maps to MMA (most popular)
    • __syncthreads() turns into threadgroup_barrier(mem_flags::mem_tg)
    • H100’s ~3.35 TB/s HBM3 maps to M3 Max’s ~400 GB/s unified DRAM a bandwidth distinction that reshapes which optimizations are value pursuing.
  • MLX-specific hints and patterns: Concrete code-level patterns for operations with no direct CUDA equal, similar to register-based row reductions utilizing simd_shuffle_xor in an 8×8 MMA tile format, or the “exp2 trick” (changing $exp(x)$ with $exp_2(x log_2 e)$) for sooner softmax on Apple’s quick $exp_2$ {hardware} instruction.
  • Reusable assertions: Knowledgeable kernel behaviors reframed as properties the evolutionary search should protect, moderately than code to repeat.

Matching knowledgeable kernel efficiency: the Consideration kernel

We consider three configurations of an MLX consideration kernel for Apple Silicon: (1) a naive baseline, (2) pure evolution with no further supplied context, and (3) a full context translation layer, which provides the optimizer with architecture-specific implementation data extracted from high-performance kernels (e.g., FlashAttention-2), letting the evolutionary search motive about implementation methods moderately than ranging from a naive kernel. Collectively, these three configurations allow us to isolate the precise influence of the interpretation layer.

Performance scaling of the Attention Kernel through stacked optimizations

Determine 4: Efficiency scaling of the Consideration Kernel via stacked optimizations. The “Full Context” configuration efficiently discovers and implements superior methods like double buffering and loop unrolling, reaching near-expert efficiency.

The bounce from 0.26× to 0.97× the velocity of Apple’s state-of-the-art consideration kernel — illustrates how a lot the interpretation layer issues. With full context, the developed kernel independently discovers the important thing optimizations in FlashAttention 2: threadgroup reminiscence tiling, on-line softmax, Ok-transposition for reminiscence entry, and the exp2 trick. The final of those replaces each softmax exponential with a base-2 exponential,

[e^x = 2^{x log_2 e},]

which is precise and lets the kernel use Apple’s quick quick::exp2() {hardware} instruction immediately as an alternative of paying for a base conversion at runtime.

A 20× sooner prefill: the Mamba SSM kernel

To judge whether or not Ok-Search generalizes past consideration kernels, we utilized it to the state-space mannequin (SSM) kernel utilized by Mamba. Not like consideration, the computational bottleneck is a recurrent state replace moderately than a softmax, offering a considerably completely different optimization problem. We evaluate the developed implementation in opposition to the neighborhood MLX implementation (mlx-lm) and the PyTorch reference implementation (mamba.py) on an M1 Max.

Evaluated on mamba-370m f16, M1 Max 64GB:

Metric mlx-mamba (ours) mlx-lm (neighborhood) mamba.py
Decode 152 tok/s 116 tok/s 40 tok/s
Prefill L=512 5,751 tok/s 329 tok/s 1,089 tok/s
Prefill L=1024 6,010 tok/s 327 tok/s 1,127 tok/s
Prefill L=2048 6,612 tok/s 326 tok/s 1,092 tok/s
Prefill L=4096 6,743 tok/s 339 tok/s 1,042 tok/s

Desk 1: Prefill and decode throughput on mamba-370m (f16, M1 Max 64GB). mlx-mamba (ours) reaches ~20× larger prefill throughput than the neighborhood mlx-lm baseline, whereas decode stays comparable.

The ~20× prefill speedup over mlx-lm comes down to 1 distinction: mlx-lm doesn’t implement a parallel scan for the SSM. The state recurrence

[h_t = bar{a}_t h_{t-1} + bar{b}_t]

seems inherently sequential, however every step may be written as a pair $(bar{a}_t, bar{b}_t)$ below the associative mix

[(a_2, b_2) circ (a_1, b_1) = left(a_2 a_1, a_2 b_1 + b_2right),]

which reproduces the recurrence precisely. As a result of the operator is associative, the entire sequence may be evaluated with a parallel (prefix) scan in $O(log N)$ dependent steps as an alternative of $O(N)$. mlx-lm skips this and processes tokens one after the other, leaving most of Apple Silicon’s compute idle; our developed Metallic kernel applies the scan and makes a lot fuller use of GPU throughput. The acquire reveals up in prefill, the place the complete sequence is offered to scan in parallel, and never in single-token decode, the place there is just one new token per step and no scan to parallelize — which is why the decode row is roughly flat whereas prefill is ~20×.

mamba.py is gradual on each prefill and decode as a result of it’s a PyTorch reference implementation that falls again to CPU or MPS on Apple Silicon, forgoing the hardware-specific optimizations that MLX’s Metallic backend makes attainable.

What’s subsequent?

On the 2 kernels we studied, AI-driven evolutionary kernel search grounded in structured cross-platform translation data reached near-expert efficiency on Apple Silicon and not using a crew of GPU specialists ranging from scratch. We don’t but understand how far this generalizes, however the result’s encouraging.

For us the principle takeaway is that the bottleneck was not the LLM’s potential to put in writing Metallic code, however the high quality of the context and constraints we gave it. Our CUDA translation layer converts present NVIDIA kernel experience into actionable steering for Apple Silicon, and lets Ok-Search’s evolutionary search do the remainder.

We’re actively extending this work in a number of instructions: supporting new architectures, with present efforts targeted on growing new kernels for the IBM Spyre AIU and broader {hardware} targets; including extra kernels similar to paged consideration and fused MoE routing; and bettering integration with the Ok-Search evolution loop to make translation context much more computerized.

Acknowledgements

This work was carried out by IBM Analysis and builds on Ok-Search from the UC Berkeley Sky Lab (Cao et al., 2026). We welcome collaboration and suggestions from the MLX and broader AI methods communities. In case you are engaged on kernel optimization for non-CUDA {hardware}, we’d love to listen to from you.


Quotation

@article{cao2026k,
  title={Ok-Search: LLM Kernel Technology by way of Co-Evolving Intrinsic World Mannequin},
  writer={Cao, Shiyi and Mao, Ziming and Gonzalez, Joseph E and Stoica, Ion},
  journal={arXiv preprint arXiv:2602.19128},
  yr={2026}
}

Appendix: Attempt it your self

The MLX backend is constructed on prime of the open-source Ok-Search repo, so the outcomes right here may be reproduced immediately. The steps are:

1. Clone and set up

git clone https://github.com/caoshiyi/Ok-Search.git
cd Ok-Search

uv pip set up openai wandb
uv pip set up git+https://github.com/caoshiyi/flashinfer-bench-ksearch.git

2. Set your credentials

Open the related script below scripts/ and set three variables on the prime:

KSEARCH_ROOT=/path/to/Ok-Search
API_KEY=your-llm-api-key

3. Run kernel search

# Optimize Flash Consideration on Apple Silicon (world-model mode)
bash scripts/mac_flash_attention_wm.sh

# Or a Mamba SSM kernel, e.g. the selective scan
bash scripts/mamba_selective_scan_fwd_wm.sh

Full CLI reference and documentation are within the README.

banner
Top Selling Multipurpose WP Theme

Converter

Top Selling Multipurpose WP Theme

Newsletter

Subscribe my Newsletter for new blog posts, tips & new photos. Let's stay updated!

banner
Top Selling Multipurpose WP Theme

Leave a Comment

banner
Top Selling Multipurpose WP Theme

Latest

Best selling

22000,00 $
16000,00 $
6500,00 $

Top rated

6500,00 $
22000,00 $
900000,00 $

Products

Knowledge Unleashed
Knowledge Unleashed

Welcome to Ivugangingo!

At Ivugangingo, we're passionate about delivering insightful content that empowers and informs our readers across a spectrum of crucial topics. Whether you're delving into the world of insurance, navigating the complexities of cryptocurrency, or seeking wellness tips in health and fitness, we've got you covered.