ZeroGPU: duration under the 300s cap, weights prefetched outside the grant
Browse files24 unmodified lines2526272829303124 unmodified lines# costs about four seconds and most documents can be read whole; on 2 vCPUs it costs two minutes# and the honest offer is "a few".GPU = mimo.BACKEND == "gpu"MAX_WINDOWS, DEFAULT_WINDOWS = (24, 8) if GPU else (6, 3)WINDOW_COLUMNS = ["#", "where in the skeleton", "markers", "verdict", "family", "evidence"]24 unmodified lines25262728293031323324 unmodified lines# costs about four seconds and most documents can be read whole; on 2 vCPUs it costs two minutes# and the honest offer is "a few".GPU = mimo.BACKEND == "gpu"# The GPU ceiling is not a taste decision: ZeroGPU caps one grant at 300s, so the whole scan plus# the 4-bit load has to fit inside `mimo.GPU_DURATION`.MAX_WINDOWS, DEFAULT_WINDOWS = (mimo.MAX_WINDOWS_GPU, 8) if GPU else (6, 3)WINDOW_COLUMNS = ["#", "where in the skeleton", "markers", "verdict", "family", "evidence"]
248 unmodified lines24925025125225325412 unmodified lines26726826927027127227389 unmodified lines363364365366367368248 unmodified linesreturn lambda fn: fndef _load_gpu():"""MiMo in 4-bit NF4 on the attached device. Cached; ~5 GB of weights."""global _gpu_model12 unmodified linesreturn _gpu_model@_gpu_decorator(300)def _judge_all_gpu(texts: list) -> list:"""Every window in one GPU call, batched the way Part B batched documents.89 unmodified linesreturn []with _lock:if BACKEND == "gpu":if progress:progress(f"MiMo reading {len(texts)} region(s) on the GPU")return _judge_all_gpu(texts)248 unmodified lines24925025125225325425525625725825926026126226326426526626726826912 unmodified lines28228328428528628728828929029129229329429529689 unmodified lines386387388389390391392248 unmodified linesreturn lambda fn: fndef prefetch_weights(progress=None):"""Pull the checkpoint to local disk **before** any GPU is requested.ZeroGPU bills wall-clock inside the decorated call and caps how long one may last, so a 15.7 GBfirst-run download in there does not merely waste the grant - it guarantees the very first scanexceeds the cap and fails. Downloading out here costs nothing but patience, and every latercall finds the files cached."""from huggingface_hub import snapshot_downloadif progress:progress("fetching MiMo-7B weights (15.7 GB, first run only)")snapshot_download(BASE_REPO, allow_patterns=["*.safetensors", "*.json", "*.txt", "*.model"])def _load_gpu():"""MiMo in 4-bit NF4 on the attached device. Cached; ~5 GB of weights."""global _gpu_model12 unmodified linesreturn _gpu_model# The `spaces` client asks the scheduler for 1.5x whatever is requested here, and ZeroGPU caps the# result at 300s - so anything above 200 is refused outright, which is how the first deploy of this# path died. 180 leaves room for the 4-bit load (~40s from cached weights) plus MAX_WINDOWS_GPU# regions at ~4.2s each, and the weights themselves are fetched before any of this is entered.GPU_DURATION = 180MAX_WINDOWS_GPU = 16@_gpu_decorator(GPU_DURATION)def _judge_all_gpu(texts: list) -> list:"""Every window in one GPU call, batched the way Part B batched documents.89 unmodified linesreturn []with _lock:if BACKEND == "gpu":prefetch_weights(progress) # outside the GPU grant, deliberatelyif progress:progress(f"MiMo reading {len(texts)} region(s) on the GPU")return _judge_all_gpu(texts)
app.py+3-1
mimo.py+25-1