Repository navigation
Replies: 1 comment
|
@arfung I had ERNIE 5.5 support going in parallel, and it is up now as #5720. Because the two were built at the same time, I couldn't take your series as it is. Instead I went through your branches and added the parts that fit on top of #5720, with you as co-author on both commits.
On M3 Ultra the same A/B gave +19 to 24%. Context-copy drafts were already in oMLX's Lightning MTP, so I left that part out. I'm sorry I couldn't bring in more of your work this way, and thank you for sharing it. |
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
(I updated this post to reflect recent changes - including working off of oMLX 0.8.4)
I thought the Ernie 5.5 flash benchmarks looked promising, so I wanted to be able to try the model in oMLX. With a few hours of Claude Fable 5.2 work, here are edits to main and upstream branches of oMLX and mlx-vm to do four things:
To run this in oMLX you need one repository.
mainof my oMLX forkcarries all of it and runs on the mlx-vlm commit that oMLX 0.8.4 already
pins: https://github.com/arfung/omlx. Its README has the model link, the
speeds and the build steps. The same code is on branch
ernie55-preview/9-single-repoas one reviewable commit. The mlx-vlm forkstays up in case the mlx-vlm maintainers want the same changes there.
This is not a pull request. You may already have your own plans for this
model, so please take all of it, part of it or none of it. The contributing
guide asks for a discussion before a first pull request over 1,000 lines, and
this is well over that. If you would like pull requests, tell me which parts,
in what order and in what size.
Credit first
The base port is not mine. It is jonathan308's two closed pull requests,
unchanged: #5601 and Neywa-Labs/mlx-vlm#2829. My branches keep
those commits under their name and stack on top of them. Everything below
depends on that port, or an equivalent, landing first.
What is on offer
Most of the work was written in mlx-vlm, not oMLX. Each branch contains the
ones above it, and both stacks sit on
mainas of 25 November 2026 (oMLX12a577be, mlx-vlme8035ae). Branch 7 is oMLX only and merges the 0.8.4release; branch 8 sits on top of it, and on mlx-vlm on top of branch 6.
Branch 9 is oMLX only. It carries the mlx-vlm side inside oMLX, under
omlx/patches/mlx_vlm_ernie5_5_compat, the way oMLX already carries MiniMaxM3 and GLM-5.3, and returns the mlx-vlm pin to the release's. The fork's
mainis branch 9 plus a README.ernie55-preview/1-baseernie55-preview/2-dspark-draftingernie55-preview/3-prefill-speedernie55-preview/4-decode-speedernie55-preview/5-long-contexternie55-preview/6-concurrencyernie55-preview/7-omlx-0.8.4ernie55-preview/8-decode-pipeliningernie55-preview/9-single-repoBranch 3 also applies without branch 2. Branch 4 needs both. On the oMLX side
branch 4 only moves the mlx-vlm pin to my fork so the series can be installed;
the decode work itself is all in mlx-vlm. Branch 9 moves the pin back: its
pyproject.tomlis the 0.8.4 release's, unchanged.Branch 5 is the one to read first if you only read one. Its oMLX commit
(
3517e920) is a 12-line fix that does not depend on the speed work andapplies to the base port as it stands; see "Long context" below.
Setup
on oMLX 0.8.4 with MLX 0.32.5; columns dated 25 November are on MLX 0.32.4.
(MXFP8 dense projections, MXFP4 routed experts), about 167 GB loaded with the
draft head.
long documents. Each figure is the better of two runs after a warm-up run.
in the same session.
Results
Directly through mlx-vlm, one request, greedy, the same script throughout:
The port as submitted decoded at 16 to 17 tok/s on this machine, without
drafting.
The last column's gain is branch 8. A decode step or verify block used to
build all 43 layers before the GPU started; each layer is now submitted as
soon as it is built, as DeepSeek V4.1 does. Tokens are identical with it on
and off. A one-token step went from 23.2 to about 19 ms and a verify forward
of four and of eight rows from 31.1 and 43.9 ms to about 25 and 37 ms. Each
layer's cache state is evaluated with it; without that, a loop that never
evaluates the cache state runs out of Metal shared events after about 1,500
forwards. Moving to oMLX 0.8.4 and MLX 0.32.5 changed neither decode nor
prefill speed by itself.
Through the server, one request of 256 tokens: 116 tok/s for code and 68 for
prose, and 103 to 112 for code sampled at temperature 0.7.
Prefill, 2,048-token chunks:
for 14.4K and 1,460 for 28.8K.
7.2K-token prompt from 1,425 to 1,736 tok/s and a 28.7K-token prompt from
896 to 1,537, and peak working memory for the longer prompt from 26 GB to
11.5 GB over the loaded model.
with a peak of 6.8 GB over the loaded model. I have not found why the
28.7K figure is lower than it was on 25 November. It is the same on MLX
0.32.4 and 0.32.5, and the server figure has not moved.
Correctness
bit. The hyper-connection, router and combine kernels sum in a different
order, so results differ by rounding.
two prompts picked the same token every time, with a mean next-token KL of
0.002 and 0.011.
to a KL of about 1e-6, against 2e-3 before the kernels.
activations than the dense paths are: next-token KL of 0.0015 against 0.096
at 28.7K tokens.
repository.
build on the real weights, through the server, twelve greedy replies are
the same text (plain, drafted, reasoning, two requests together, a
15K-token prompt and its cached follow-up) and speeds match: plain 50.2
tok/s on both, drafted prose 83 and code 99 to 100, prefill 1,575 tok/s at
15.3K tokens.
Long context
Tested to 500K tokens on the real weights. Two defects turned up.
all-CacheList model
_get_cache_seq_lenreturns the first 4D sub-cache itmeets. ERNIE's first layers hold a 128-token window and a pooled history;
the whole-sequence members sit in the six long-range layers. The length
came back as 128, so a store after a restore sliced its new blocks from the
start of the cache. From a conversation's second call on, the model could
see the first request and the newest suffix and nothing in between. This is
the same shape of bug as fix(hy4): prefix cache saved after a restore holds the wrong token ranges #5534. The fix takes the longest sub-cache.
A three-turn, 18K-token conversation went from 3 of 9 lookups to 9 of 9, and
nine turns grown to 498K tokens from 1 of 9 planted notices recalled to 9 of
9. A 128K conversation built through restores now gives the same 11 answers
as one built in one pass. Blocks written before the fix stay wrong on disk.
context (mlx-vlm). Peak was 210 GB at 128K tokens on the 166 GB model. It
is now 176 GB at 128K and 186 GB at 498K, with the same selection.
With both fixed:
verify blocks and one-token steps were scored on the same 256 tokens as a
reference with fp32 activations and no fast paths. Where the reference was
confident and right, the fast paths lost none of those positions from 64K
up and at most two below that, the same as the stock bf16 path.
text after it. Finding one of thousands of near-identical records gets
unreliable past about 128K (3 of 12 at 498K); the reference misses the same
questions, so I read that as the model.
1,690 tok/s up to 8K, 630 between 64K and 128K and 290 between 383K and
498K, and a 498K-token prompt takes 20 minutes cold. Through the server the
stretch from 64K to 128K runs at about 940 tok/s, probably because oMLX
reserves the cache's capacity up front. A decode step is 19.8 ms at 8K,
21.3 ms at 131K and 24.2 ms at 498K.
Concurrent requests
Batched decode without drafting scales well on this model (a step is about
20 ms for one request, 24 for two, 27 for four and 43 for eight). Two things were wrong when
requests overlapped.
requests decoding together failed with
[metal::malloc] Resource limit (499000) exceededabout 11,500 tokens in: the same failure as [metal::malloc] Resource limit (499000) exceeded — Metal buffer-count exhaustion on GLM-5.3-Flash (ArraysCache hybrids): missing decode materialization, error-path snapshot leaks, unreachable pool clear, pm-ineligible CacheList(KVCache, PoolingCache) #3226, on amodel the 256-token cache materialization was not switched on for. The fix
(
4237d3e5) switches it on for models with a pooled-history cache. I didnot find which array holds the buffers.
together got no more output in total than one alone. Each request now keeps
its own cache and drafter state, and the requests' verify blocks go through
one forward that reads the weights once (
speculative_verify_rowsinmlx-vlm,
omlx/speculative/block_rows.pyin oMLX). The drafter runs once around for all of them in the same way (
draft_block_bases). I did not usemlx-vlm's batched loop because it merges the caches into a left-padded batch
and shifts whole rows when requests accept different numbers of tokens.
Through the server, 400 tokens per request, requests started together, total
tok/s:
Three or more starting together decode without drafting, because drafting
measures no better there. With all branches, three drafting together give
124 tok/s on prose and 129 to 135 on code against 126 and 125 without, and
113 and 119 against 125 and 124 when sampled. Four drafting together are
slower in every case: 132 and 138 to 141 against 148 and 147. A verify row
past the fourth costs about 3 ms, as much as a row of plain batched decode,
and a drafted token is only sometimes kept. A request that arrives while one
or two are drafting joins them.
Requests that started in a larger group used to stay without drafting after
the others had ended. They now move to the drafter once one or two are left,
or once there is room beside requests that already draft (
d5d37878). Arequest leaves the batch with its cache and the token it sampled last, so no
decode step is lost. Total tok/s of the requests still running after the
shorter ones ended:
Four code requests of 150, 150, 150 and 700 tokens finish in 9.7 s instead
of 16.1 s. The move takes under 0.1 s, also after a 29,000-token prompt.
These figures are from 26 November, with all branches.
On a small float32 model each request decodes exactly what it decodes alone
while others join and leave, and a request moved out of the batch decodes
exactly what it would have decoded there. On the real weights two concurrent
multi-turn conversations with prefix-cache restores answered every recall
question, and two 14,000-token generations together ran to the end.
Reproduction
The benchmark is one script that loads the model directly through mlx-vlm and
runs the short prompts and the long documents. I can attach it.
Where the time went
BF16 and was promoted to fp32 on every step, and the hyper-connection
weights were left as a strided transpose, which takes MLX's slow
transposed-GEMV path 86 times per token.
about 72 GPU launches per layer and only 17 of them read weights. The decode
kernels fuse the hyper-connection algebra, the router, the expert combine and
the vocabulary head with MultiMax.
routed experts are shared between rows, so each distinct expert is read once
per block. The expert kernels follow the layout of
fp4_expert_rows.scored every query against the whole context. They now gather each query's
selected keys, and cost is flat with context length.
Limits
kernels are untested on M1 to M4 and on smaller memory sizes.
moves to MLX 0.32.5; the tests pass there and the latest figures were
measured on it. Branches 1 to 6 still sit on the earlier
main.mx.fast.metal_kernelsources inside themlx-vlm model, not native kernels under
omlx/custom_kernels.carries more and longer comments than those rules allow.
drafting does not start when its peers finish, and a fourth request beside
three that draft decodes in its own forward. Requests with a grammar
constraint or logprobs decode without drafting.
install-tested. Branch 9 needs no fork. I ran it from source against a
clean checkout of the mlx-vlm commit oMLX 0.8.4 pins, not from a built
package.
Code, working on my machine under my direction. It has not had an
independent human review.
What did not work
at one row and slower from four rows on.
proposal is wrong, the head's second choice is right 31 to 60% of the time,
and an extra verify row costs about 3 ms.
MLX_MAX_OPS_PER_BUFFER,MLX_MAX_MB_PER_BUFFERandMLX_METAL_FAST_SYNCHmade no measurable difference.
block two to three times faster than mine when benchmarked alone, and is
slower inside a forward at every block size (6 rows: 36.1 ms with mine,
39.0 with MLX's), also when only one projection shape is left to it. A
benchmark of independent launches measures throughput; a decode forward is
one dependent chain.
upstream: about even for three when greedy and slower otherwise (figures
under "Concurrent requests").
Questions
patches under
omlx/patches, or rewritten as native kernels underomlx/custom_kernels? Branch 9 is the second of these.All reactions