drop llama-cpp-python (unbuildable on Spaces); explain MiMo-over-Gemma choice
Browse filesFiles changed (5)
- App_Creation.ipynb+28
- README.md+31-1
- app.py+16-7
- mimo.py+24
- requirements.txt+12-9
232 unmodified lines233234235236237238232 unmodified lines"That is not available at any price short of a dedicated endpoint:\n"]},{"cell_type": "code","execution_count": null,232 unmodified lines233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266232 unmodified lines"That is not available at any price short of a dedicated endpoint:\n"]},{"cell_type": "markdown","metadata": {},"source": ["### 5.0 — Why MiMo, when Gemma scored higher\n","\n","Part B's actual winner is **Gemma-2-9B at F1 0.969**; this app runs **MiMo-7B at F1 0.945**. That\n","is a hosting decision, not a disagreement with the evaluation. Three constraints a free Space\n","cannot absorb:\n","\n","- **Gemma is gated.** It needs an account with Google's licence accepted plus a read token, so on\n"," a public Space the first thing a new visitor meets is a 403 — or the app has to ask strangers to\n"," paste a token. MiMo downloads for anyone, with no account at all.\n","- **Gemma is 2.6x slower** — 10.95 s per window against MiMo's 4.18 s, measured in Part B on the\n"," same T4. A ZeroGPU grant is capped at 300 s and the scan *plus* the model load must fit inside\n"," it, so the slower model means roughly a third as many regions per run.\n","- **Free ZeroGPU is ~5 minutes per day.** At Gemma's rate that is a couple of batches for a whole\n"," day. Gemma is also ~6 GB in 4-bit against MiMo's ~5 GB — not decisive alone, but it points the\n"," same way.\n","\n","The price is **0.024 F1**, and family-naming falling from 63% to 43%. Both are stated in the\n","interface rather than rounded away. Moving to dedicated paid hardware would make Gemma a change to\n","two repo constants in `mimo.py` plus a token secret — the prompt, prefill and parser are shared\n","and would not need touching.\n","\n","The cell in section 7 prints all four models' Part B scores, so the trade is visible as numbers.\n"]},{"cell_type": "code","execution_count": null,
32 unmodified lines33343536373818 unmodified lines5758596061626332 unmodified linesscores here at all: change how the text is extracted or how the question is asked, and thepublished numbers stop describing this program.## Two runtimes, chosen at startupA Space's hardware is not this code's decision, so `mimo.py` carries both paths and picks one at18 unmodified linesThe prompt, the prefill, the decoding parameters and the parser are byte-identical on both paths.**On ZeroGPU hardware both are offered, and the picker matters.** A free Hugging Face account getsroughly **five minutes of ZeroGPU per day**, and the scheduler reserves a run's full requestedduration up front rather than what it turns out to use — so a couple of batches can exhaust theday. When that happens the Space is not broken: switch the runtime to `cpu` and it keeps working,32 unmodified lines33343536373839404142434445464748495051525354555657585918 unmodified lines7879808182838485868788899091929332 unmodified linesscores here at all: change how the text is extracted or how the question is asked, and thepublished numbers stop describing this program.## Why MiMo, when Gemma scored higherPart B's actual winner is **Gemma-2-9B at F1 0.969**, and this app runs **MiMo-7B at F1 0.945**instead. That is a hosting decision, not a disagreement with the evaluation, and it comes down tothree things a free Space cannot absorb:- **Gemma is gated.** It needs a Hugging Face account with Google's licence accepted, plus a readtoken. On a public Space that means the first thing a new visitor meets is a 403, or the app hasto ask strangers to paste a token. MiMo downloads for anyone, with no account at all.- **Gemma is 2.6× slower** — 10.95 s per window against MiMo's 4.18 s, measured in Part B on thesame T4. On ZeroGPU a single grant is capped at 300 s and the whole scan plus the model load mustfit inside it, so the slower model means roughly a third as many regions per run.- **Free ZeroGPU is about five minutes per day.** At Gemma's rate that is a couple of batches for awhole day; at MiMo's it is meaningfully more. The 9B model is also ~6 GB in 4-bit against MiMo's~5 GB, which is not decisive on its own but points the same way.What it costs: **0.024 F1**, and family-naming accuracy drops from 63% to 43%. Both figures arestated in the interface rather than quietly rounded away. If the Space were ever moved to dedicatedpaid hardware, switching to Gemma would be a change to `mimo.py`'s repo constants and a tokensecret — the prompt, prefill and parser are shared and would not need touching.## Two runtimes, chosen at startupA Space's hardware is not this code's decision, so `mimo.py` carries both paths and picks one at18 unmodified linesThe prompt, the prefill, the decoding parameters and the parser are byte-identical on both paths.**On this Space the CPU path is dormant, and that is not a choice.** `llama-cpp-python` cannot beinstalled here by either available route: the prebuilt wheels are tagged `linux_x86_64` but linkedagainst **musl** while a Space runs on glibc (`libc.musl-x86_64.so.1: cannot open shared objectfile`), and PyPI ships no binary wheel at all — compiling the sdist exceeded the Space build limitwith `Job timeout`. So `requirements.txt` installs neither, the runtime picker hides itself whenonly one backend is live, and the code path stays in `mimo.py` for any machine that does have aworking llama.cpp. The runtime that remains is the one that reproduces Part B exactly, so what waslost is a fallback rather than a capability.**Where both are live, the picker matters.** A free Hugging Face account getsroughly **five minutes of ZeroGPU per day**, and the scheduler reserves a run's full requestedduration up front rather than what it turns out to use — so a couple of batches can exhaust theday. When that happens the Space is not broken: switch the runtime to `cpu` and it keeps working,
167 unmodified lines168169170171172173174175101 unmodified lines27727827928028128212 unmodified lines295296297298299300301302303304305167 unmodified lineshint = ""if "quota" in str(e).lower():hint = ("\n\nA free account gets about **five minutes of ZeroGPU per day**, and the ""scheduler reserves a whole run up front. Switch the runtime to **cpu** — much ""slower, but there is no quota on it — or come back tomorrow.")return (f"## MiMo could not run\n\n`{type(e).__name__}: {e}`{hint}\n\nRuntime selected: "f"**{runtime}**."), [], [], traceback.format_exc()101 unmodified linesEICAR/AMTSO/WICAR/RANSIM test markers. **It is not a general malware scanner**, and real malwaredoes not announce itself the way these samples do.Running on the **{mimo.BACKEND.upper()}** runtime({'4-bit NF4 — Part B’s own configuration' if GPU else 'Q4_K_M GGUF via llama.cpp'}),about {mimo.SECONDS_PER_WINDOW:g}s per region.12 unmodified lines# CPU path is ~30x slower and has no quota at all, which makes it the right answer# once the day's GPU is gone - the Space should not go dark until midnight.runtime_pick = gr.Radio(choices=(["gpu", "cpu"] if GPU else ["cpu"]),value=mimo.BACKEND, label="Runtime",info=("gpu = 4-bit NF4, Part B's own configuration, ~4s/region, but limited by ""your daily ZeroGPU quota. cpu = Q4_K_M GGUF via llama.cpp, ~2min/region, ""unlimited." if GPU else "This Space has no GPU."))per_batch = gr.Slider(1, MAX_PER_BATCH, value=DEFAULT_PER_BATCH, step=1,label="Regions per batch",info=f"One batch is one run of the model. The "167 unmodified lines168169170171172173174175176177178101 unmodified lines28028128228328428528628728828929029112 unmodified lines304305306307308309310311312313314167 unmodified lineshint = ""if "quota" in str(e).lower():hint = ("\n\nA free account gets about **five minutes of ZeroGPU per day**, and the ""scheduler reserves a whole run up front. The quota is per visitor, so this ""affects your account rather than the Space.")hint += ("\n\nSwitch the runtime to **cpu** — much slower, but no quota — or come back ""tomorrow." if mimo.CPU_AVAILABLE else" Fewer regions per batch costs less of it; otherwise it resets in 24 hours.")return (f"## MiMo could not run\n\n`{type(e).__name__}: {e}`{hint}\n\nRuntime selected: "f"**{runtime}**."), [], [], traceback.format_exc()101 unmodified linesEICAR/AMTSO/WICAR/RANSIM test markers. **It is not a general malware scanner**, and real malwaredoes not announce itself the way these samples do.**Why MiMo and not Gemma?** Part B's winner was Gemma-2-9B at F1 0.969, against MiMo's 0.945. ButGemma is gated behind a licence and a token, and it is 2.6× slower per window (10.95 s vs 4.18 s).On free ZeroGPU — one grant capped at 300 s, and roughly five minutes of GPU per day — that is thedifference between a working demo and one that refuses strangers at the door and then runs out ofquota. The cost of the swap is 0.024 F1 and family-naming dropping from 63% to 43%.Running on the **{mimo.BACKEND.upper()}** runtime({'4-bit NF4 — Part B’s own configuration' if GPU else 'Q4_K_M GGUF via llama.cpp'}),about {mimo.SECONDS_PER_WINDOW:g}s per region.12 unmodified lines# CPU path is ~30x slower and has no quota at all, which makes it the right answer# once the day's GPU is gone - the Space should not go dark until midnight.runtime_pick = gr.Radio(choices=mimo.BACKENDS, value=mimo.BACKEND, label="Runtime",visible=len(mimo.BACKENDS) > 1,info=("gpu = 4-bit NF4, Part B's own configuration, ~4s/region, limited by your ""daily ZeroGPU quota. cpu = Q4_K_M GGUF via llama.cpp, ~2min/region, ""unlimited."))per_batch = gr.Slider(1, MAX_PER_BATCH, value=DEFAULT_PER_BATCH, step=1,label="Regions per batch",info=f"One batch is one run of the model. The "
170 unmodified lines171172173174175176180 unmodified lines357358359360361362170 unmodified linesBACKEND = "gpu" if (ZERO_GPU or _cuda_present()) else "cpu"CAVEATS = {"gpu": ("This Space is running Part B's own configuration: the BF16 checkpoint of ""XiaomiMiMo/MiMo-7B-RL quantised to 4-bit NF4 by bitsandbytes, greedy, 200 new tokens, "180 unmodified lines"""Load the GGUF once and keep it. ~4.7 GB resident, well inside a free tier's 16 GB."""global _llmif _llm is None:from huggingface_hub import hf_hub_downloadfrom llama_cpp import Llamaif progress:170 unmodified lines171172173174175176177178179180181182183184185186187188189190191192193194180 unmodified lines375376377378379380381382383384385386170 unmodified linesBACKEND = "gpu" if (ZERO_GPU or _cuda_present()) else "cpu"def _llama_installed() -> bool:"""Whether the CPU runtime can actually run.On a Hugging Face Space it cannot, and that is not a bug to fix here: the prebuilt`llama-cpp-python` wheels are musl-linked while a Space is glibc, and compiling the sdistexceeds the build timeout. `requirements.txt` records both attempts. This flag lets the appstop offering a runtime that would only fail on being chosen."""import importlib.utilreturn importlib.util.find_spec("llama_cpp") is not NoneCPU_AVAILABLE = _llama_installed()BACKENDS = [b for b in ("gpu", "cpu")if (b == "gpu" and BACKEND == "gpu") or (b == "cpu" and CPU_AVAILABLE)] or [BACKEND]CAVEATS = {"gpu": ("This Space is running Part B's own configuration: the BF16 checkpoint of ""XiaomiMiMo/MiMo-7B-RL quantised to 4-bit NF4 by bitsandbytes, greedy, 200 new tokens, "180 unmodified lines"""Load the GGUF once and keep it. ~4.7 GB resident, well inside a free tier's 16 GB."""global _llmif _llm is None:if not CPU_AVAILABLE:raise RuntimeError("the CPU runtime needs llama-cpp-python, which is not installed on this Space. ""The prebuilt wheels are musl-linked (a Space is glibc) and building the sdist ""exceeds the Space build timeout, so only the GPU runtime is available here - ""which is also the one that reproduces Part B exactly.")from huggingface_hub import hf_hub_downloadfrom llama_cpp import Llamaif progress:
8 unmodified lines91011121314151617181920212223248 unmodified lines# Leaving it unpinned in both places is what broke the first deploy - HF fell back to a gradio 3.x# default with no `show_copy_button`.## llama-cpp-python is the CPU fallback runtime, and it has to be built from the PyPI sdist.## The obvious shortcut - abetlen's prebuilt wheel index - does not work here. Those wheels are# tagged plain `linux_x86_64` rather than `manylinux`, and they are linked against musl: pip# installs one happily and then every import dies with# libc.musl-x86_64.so.1: cannot open shared object file# because a Space runs on glibc. PyPI publishes no binary wheel at all, only the sdist, so# compiling is the only route. It costs several minutes of build time; that is the price of a# runtime with no GPU quota attached to it.llama-cpp-pythonspaces # the @spaces.GPU decorator; ZeroGPU refuses to serve a Space without onetransformers>=4.458 unmodified lines91011121314151617181920212223242526278 unmodified lines# Leaving it unpinned in both places is what broke the first deploy - HF fell back to a gradio 3.x# default with no `show_copy_button`.## llama-cpp-python is deliberately ABSENT, and the CPU runtime in `mimo.py` is therefore dormant# on this Space. Both ways of installing it were tried and both fail here:## 1. abetlen's prebuilt wheel index. Those wheels are tagged plain `linux_x86_64` rather than# `manylinux`, and they are linked against musl. pip installs one happily and then every# import dies with `libc.musl-x86_64.so.1: cannot open shared object file`, because a Space# runs on glibc.# 2. the PyPI sdist, which is the only other option since PyPI publishes no binary wheel at all.# Compiling llama.cpp from source exceeded the Space build limit outright: `Job timeout`.## The code path stays in `mimo.py` so the app still runs on a machine that does have a working# llama.cpp, but nothing here installs one. On this Space the GPU path is the only runtime, which# is also the one that reproduces Part B exactly - so the loss is a fallback, not a capability.spaces # the @spaces.GPU decorator; ZeroGPU refuses to serve a Space without onetransformers>=4.45
App_Creation.ipynb+28
README.md+31-1
app.py+16-7
mimo.py+24
requirements.txt+12-9