Run this model with HF Jobs

Run metricspace/gemma4-E4B-it-litert-64k-mtp on Hugging Face's managed compute, monitor its progress, and retrieve the results when it's done.

Paste one of these prompts into your coding agent:

Fine-tune on my dataset

Use HF Jobs to fine-tune https://huggingface.co/metricspace/gemma4-E4B-it-litert-64k-mtp. Ask me which dataset to train on, then push the fine-tuned model to a new model repo. Run `hf jobs --help` first to learn the CLI.

Run batch inference

Use HF Jobs to run batch inference with https://huggingface.co/metricspace/gemma4-E4B-it-litert-64k-mtp on the inputs in a mounted HF Bucket. Ask me which Bucket to use, then write the outputs back to it and keep each input ID. Run `hf jobs --help` first to learn the CLI.

metricspace/gemma4-E4B-it-litert-64k-mtp

Community-identical Gemma 4 E4B .litertlm bundle, binary-patched to support a 64k context window on both CPU and GPU. Correct text output verified against the community 32k bundle.

How it was built

Starting from litert-community/gemma-4-E4B-it-litert-lm (32k bundle, magic cache dim 32003), tf_lite_prefill_decode and tf_lite_mtp_drafter are binary-patched 32003 β†’ 65003 (prime, avoids an XNNPack slow path that triggers on composite dims like 65536 or 64006). The patch walks four layers of the TFLite flatbuffer:

  1. Tensor shapes β€” every shape[i] == 32003 rewritten to 65003 (1 900 entries across decode / prefill / verify, 52 more in the drafter).
  2. External buffers backing arange(N) / arange(N)+512 int32 index tables are regenerated for the new length, appended past the end of the file, and Buffer.offset / Buffer.size fields rewritten.
  3. Small RESHAPE / GATHER int32 shape-parameter buffers (≀ 256 B) that contain the baked dim are rewritten in place.
  4. StableHLOCompositeOptions.CompositeAttributes FlexBuffer blobs of every odml.cache_update composite are walked and their kv_cache_batch_size / key_size / value_size / scale_* attributes rewritten from 32003 β†’ 65003. Missing step 4 gave graphs whose tensor shapes were right but whose per-layer composite attributes still referenced 32003 β€” the runtime then corrupts decode output to " agregado<pad><pad>...". All earlier -patched revisions had this bug; this release (v2) is the first with correct text output.

Everything else β€” weights, tokenizer, embedder, per-layer embedder, audio / vision towers, metadata β€” is byte-identical to the community source bundle.

Performance (Apple M5, LiteRT-LM built from main)

Median of 3 runs, 1024-token prefill / 256-token decode, synchronous (--async=false), --conv_type=float, --max_num_tokens=2048 (typical short-chat cache β€” see note below).

Backend Prefill tok/s Decode tok/s TTFT vs CPU
CPU ~30 ~8.9 ~40 s 1Γ—
GPU ~512 ~33 ~2.0 s 3.7Γ—

Decode cost scales roughly linearly with --max_num_tokens. For the long- context floor: at --max_num_tokens=65000 (full bundle capacity), decode lands near 21 tok/s with TTFT β‰ˆ 4.8 s for a 1024-token prompt.

Squeezing more out of the WebGPU delegate (optional, macOS)

The LiteRT-LM v0.10.1 prebuilt of libLiteRtTopKWebGpuSampler.dylib on macOS exports only 3 of the 7 C symbols the runtime dynamically loads: _UpdateConfig, _CanHandleInput, _HandlesInput, and _SetInputTensorsAndInferenceFunc are compiled in but marked non-external (was a private external) because of the macos_exported_symbols.lds export list. The runtime then prints GPU sampler unavailable. Falling back to CPU sampling. and every decode step transfers the full logits tensor GPU β†’ CPU for argmax.

You can promote those 4 symbols in the already-shipped dylib by rewriting its LC_DYLD_EXPORTS_TRIE:

# ctox repo helper (scripts/models/patch_webgpu_sampler_exports.py) β€”
# appends a new 7-symbol exports trie at EOF, extends __LINKEDIT by 200 B,
# and ad-hoc re-signs the dylib. No source rebuild required.
python scripts/models/patch_webgpu_sampler_exports.py \
    <LITERT_LM_PREBUILT_DIR>/libLiteRtTopKWebGpuSampler.dylib

On M5 / Gemma 4 E4B this patch makes the WebGPU sampler load cleanly but gave no measurable decode uplift in my runs β€” the decode bottleneck is WebGPU-delegate kernel-launch overhead, not the sampler. It's still worth applying for correctness (avoids one GPU β†’ CPU transfer per step) and in anticipation of upstream sampler improvements.

Known upstream ceilings (not bundle-level)

  • Speculative decoding (--enable_speculative_decoding=true) crashes the WebGPU path with ALREADY_EXISTS: wgpu::Instance already set when drafter and main model both try to create a WebGPU instance. On CPU it runs but produces 0 % acceptance rate β€” the drafter's first token never matches the verifier, so MTP is a strict slowdown on this runtime version. Keep it off until upstream ships a fix.
  • --gpu_external_tensor_mode=true fails on Gemma 4 bundles with INVALID_ARGUMENT: bytes-per-token exceeds output tensor size β€” the external-tensor path has a hard-coded token count that doesn't match Gemma 4's PLE layout. Can't enable.
  • Embedder / per-layer embedder are hardcoded to CPU in runtime/components/embedding_lookup/embedding_lookup_text.cc on non-Android builds. Forcing them to GPU regresses throughput by β‰ˆ 9 Γ— (E2B drops 68 β†’ 9 tok/s) because the WebGPU delegate has no embedding-lookup kernel and silently falls back with bad scheduling. Leaving them CPU-pinned is correct.
  • No native Metal backend. The gpu_artisan backend referenced in --helpfull is internal-only. WebGPU β†’ Dawn β†’ Metal is the only GPU path on macOS today.

Run

litert-lm run --from-huggingface-repo metricspace/gemma4-E4B-it-litert-64k-mtp \
    model.litertlm -b gpu --prompt "Explain transformers."

For the honest benchmark above use litert_lm_advanced_main:

litert_lm_advanced_main \
    --model_path=model.litertlm \
    --backend=gpu --async=false \
    --max_num_tokens=2048 \
    --conv_type=float \
    --benchmark --benchmark_prefill_tokens=1024 --benchmark_decode_tokens=256

Choosing --max_num_tokens

This flag sets the magic-number rewrite target β€” the actual KV-cache size the runtime allocates and every attention step reads over. The bundle's dim 65003 is only a cap, not the working size. Decode cost is roughly linear in this value, so match it to your real use case:

  • Short chats (≀ 2k tokens): --max_num_tokens=2048 β†’ ~33 tok/s decode.
  • Medium documents (≀ 8k): --max_num_tokens=8192 β†’ ~32 tok/s decode.
  • Long context (up to 64k): --max_num_tokens=65000 β†’ ~21 tok/s decode, 4.8 s TTFT for a 1024-token prompt.

Build recipe

Patched with scripts/models/patch_tflite_cache_length.py (composite- attribute walker included, v2) and repacked with scripts/models/repack_litertlm.py from the ctox repository. The optional sampler-dylib trie patcher lives in scripts/models/patch_webgpu_sampler_exports.py.

Downloads last month
255
Inference Providers NEW
This model isn't deployed by any Inference Provider. πŸ™‹ Ask for provider support

Model tree for metricspace/gemma4-E4B-it-litert-64k-mtp

Finetuned
(540)
this model