Notes from the work

One email when a tutorial or migration write-up goes live. Nothing else, and an unsubscribe link in every email.

LeanZero

Two people in Romania doing Atlassian migrations, Forge apps and practical AI work for teams that would rather talk to the person doing the job. Most of what we learn ends up on this site.

Services

  • Atlassian migrations
  • Atlassian FastShift
  • Atlassian maintenance
  • Forge app development
  • AI development consultation

Topics

  • Jira
  • Jira Service Management
  • Confluence
  • Bitbucket
  • Atlassian Forge
  • Cloud Migration
  • Local AI
  • AI Coding
  • Certifications
  • Atlassian Team
  • All topics

Company

  • Blog
  • Tutorials
  • Contact

Community

  • Join Discord
  • Support this site

© 2026 LeanZero. All rights reserved.

Privacy policyTerms of service24/7 SupportTrust centerSecurityDPALegal notice
  1. Home
  2. Portfolio
  3. Elzi
  4. Features
  5. Ngram
Elzi feature guide

N-gram tables and prompt lookup

Drafts copied from your own context make code edits much faster, with the same output.

When a model rewrites text that is already in its context, such as a file it is editing, the engine can guess the next tokens by finding the matching run of words (an n-gram) earlier in the prompt and copying what followed. The model then checks the whole guess in one step and keeps only what it agrees with. The answer is still the model's own: in our code-edit tests the output was byte-identical with the lookup on and off. It helps most on code edits and does little for free chat.

Measured gains

TaskMTP onlyMTP + prompt lookupChange
Code edit42.8134.83.15x
Document summary33.332.4none
Free chat37.337.1none
Qwen3.8-27B, our Atlassian fine-tune, 8-bit, on the M3 Ultra Mac Studio, 26 October 2026. Decode in tokens per second, median of three runs, greedy decoding.

On the code edit the model accepted 1,926 of 1,940 drafted tokens (99.3 %), and all 12 outputs were byte-identical across the settings. In our long-context tests the gain shrank as the context grew, because checking a draft costs more over a large KV cache, while almost every draft was still accepted.

Agents usually sample instead of picking the single most likely token. For that case the engine uses exact speculative sampling, and a statistical test found no difference from normal sampling while catching a deliberately wrong version. On our own 4-bit Qwen3.8-Flash-Next build at temperature 1.0 (M5 Max Mac Studio, 2 November 2026), all 591 drafted tokens on a code rewrite were accepted and decode reached 96.7 tokens per second.

Where it doesn't help

  • Quoting or summarising a document: drafts fire, but on the 27B model they bought nothing, as the table shows.
  • Free chat: there is nothing to copy, so there are almost no drafts, and no gain or loss.

How to turn it on

Each model's profile in the MLX engine settings has a "Prompt lookup (n-gram)" control: Auto, On or Off, plus the shortest n-gram, the longest n-gram and the longest draft. Auto keeps the engine's default for that model family. For Qwen 3.5, 3.6 and 3.8 that default is on, matching runs of 8 to 64 tokens and drafting up to 31, so Auto already gets the gain. Changing it restarts the engine.

Prompt lookup works on one Mac only. It is not available on a two-Mac split or on a model served by another Mac over LeanZero Link.

How it relates to MTP

MTP drafts tokens from a small prediction head that some models ship with. Elzi turns it on when the model folder contains that head. On those models, prompt lookup runs inside MTP and the two add up: on the 27B code edit, MTP alone doubled the speed (21.4 to 42.8 tokens per second) and prompt lookup tripled it again. Non-hybrid models without an MTP head can use a separate suffix-decoding lane (hybrid models without one get neither), but Auto leaves that lane off because on Mellum2.1-12B (26 October 2026) it was slower and changed a chat answer.

Related guides

Speed: measured numbersDecode, prefill and time to first token from our own runs, with model, Mac and date.The LeanZero MLX engineThe local model server inside Elzi, built on our fork of Rapid-MLX.Serving a model on one MacElzi checks the memory, mounts the model and keeps long chats inside what fits.

Facts on this page were checked against our own test records on 6 November 2026.

Using Elzi

  • What Elzi is
  • Agent sessions
  • Software build sessions
  • Benchmark runs
  • Nodes and strategies
  • Providers

The MLX engine

  • The LeanZero MLX engine
  • Serving a model on one Mac
  • Distributed serving across two Macs
  • N-gram tables and prompt lookup
  • Speed: measured numbers
  • Memory lock

Media and devices

  • Images
  • Voices
  • LeanZero Link

Elzi

  • All feature guides
  • Download and user manual