Spaces:
Sleeping
Sleeping
hanhaonan02 Claude Fable 5.1 commited on
Commit ·
4b73edf
1
Parent(s): 033094c
Adaptive ZeroGPU step length with a quota explanation
Browse files- Ask for a 600 s xlarge step first (one weight transfer, most posters finish in one step) and fall
back to 300/120/60 s when ZeroGPU answers 'larger than the maximum allowed'.
- Generation budget derives from the step length; status shows the step length.
- Quota hint on failures: 27B BF16 needs the full GPU (2x quota), ~15-25 min per poster; PRO 40 min,
free 5 min, anonymous 2 min per day. README says the same.
Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
Files changed (2)
- README.md+4-2
- demo_ui.py+24-9
18 unmodified lines192021222324252618 unmodified linesand writes the poster as standalone HTML; the Space renders it to PNG.- Model: RL checkpoint-240, BF16, no quantization, 16K context.- Generation runs in ZeroGPU steps of up to 120 s; a full poster usually takes 3–6 steps and thedemo chains them automatically. Sign in to Hugging Face to use your GPU quota.- API: call `/analyze` once (PDF + settings), then `/step` repeatedly until the status starts with`Done`, `Paused` or `Stopped`; each step is its own request so the ZeroGPU token stays valid.- The examples on the page were generated by the same checkpoint with the default instruction and settings.18 unmodified lines1920212223242526272818 unmodified linesand writes the poster as standalone HTML; the Space renders it to PNG.- Model: RL checkpoint-240, BF16, no quantization, 16K context.- The model runs in BF16 on a full 96 GB ZeroGPU slot (`xlarge`, counted 2x against quota). A postertakes about 15–25 minutes of ZeroGPU quota; PRO accounts have 40 min/day, free accounts 5 min andanonymous visitors 2 min, so sign in with a PRO account (on huggingface.co, not the bare hf.space URL)to finish a poster. The demo asks for a 10-minute GPU step first and falls back to shorter steps.- API: call `/analyze` once (PDF + settings), then `/step` repeatedly until the status starts with`Done`, `Paused` or `Stopped`; each step is its own request so the ZeroGPU token stays valid.- The examples on the page were generated by the same checkpoint with the default instruction and settings.
13 unmodified lines1415161718192043 unmodified lines64656667686970717 unmodified lines7980818283848536 unmodified lines12212312412512612712812913013113213313413 unmodified linesROOT = Path(__file__).resolve().parentARTIFACTS = Path(tempfile.mkdtemp(prefix='rap_demo_'))WINDOW = 16384MAX_STEPS = 10 # ZeroGPU steps of <=120 s per runCSS = '''.gradio-container {max-width: 1360px !important; margin: 0 auto;}43 unmodified linesp['input_tokens'] = n; p['continuation_ids'] = []; p['raw'] = ''; p['done'] = Falsereturn p@spaces.GPU(size='xlarge', duration=120)def gpu_chunk(p):inputs = processor.apply_chat_template(chat(p), tokenize=True, add_generation_prompt=True,enable_thinking=False, return_dict=True, return_tensors='pt')prefix = p.get('continuation_ids', [])7 unmodified linesinputs = inputs.to('cuda')start = time.monotonic()with torch.inference_mode():output = model.generate(**inputs, max_new_tokens=min(8192, remaining), max_time=100, do_sample=False,use_cache=True, temperature=None, top_p=None, top_k=None, repetition_penalty=1.1)new_ids = output[0, length:].detach().cpu().tolist()all_ids = prefix + new_ids36 unmodified linesreturn (dict(p, paused=True), f"Stopped after {MAX_STEPS} steps without a complete poster.", None, HIDE, HIDE,gallery, p['spec'], p['raw'], gr.update(visible=True))progress(min(.1 + .12 * k, .9), desc=f'Generating poster HTML (step {k})…')try:r = gpu_chunk(p)except Exception as e: # noqa: BLE001 (quota exhausted, timeout, …)return (dict(p, paused=True), f"Paused after step {k - 1}: {str(e)[:200]}", None, HIDE, HIDE,gallery, p['spec'], p['raw'], gr.update(visible=bool(p.get('continuation_ids'))))p = dict(p, continuation_ids=r['ids'], raw=r['raw'], done=r['done'], step=k)tokens = f"{len(r['ids']):,} tokens · {r['new_tokens'] / max(r['seconds'], .01):.0f} tok/s"if not (r['complete'] or p['done']):return (p, f"Step {k} done · {tokens} · continuing (step {k + 1})…", None, HIDE, HIDE,gallery, p['spec'], p['raw'], gr.update(visible=False))13 unmodified lines1415161718192021222343 unmodified lines6768697071727374757677787 unmodified lines8687888990919236 unmodified lines12913013113213313413513613713813914014114214314414514614714814913 unmodified linesROOT = Path(__file__).resolve().parentARTIFACTS = Path(tempfile.mkdtemp(prefix='rap_demo_'))WINDOW = 16384MAX_STEPS = 10 # chained ZeroGPU steps per runGPU_LADDER = (600, 300, 120, 60) # requested step length; ZeroGPU refuses what the visitor's quota cannot coverQUOTA_HINT = (' — this 27B BF16 model needs the full 96 GB ZeroGPU (2x quota) and a poster takes roughly 15–25 min of quota. ''Daily ZeroGPU quota: PRO 40 min, free account 5 min, anonymous 2 min, so sign in with a PRO account to finish a poster.')CSS = '''.gradio-container {max-width: 1360px !important; margin: 0 auto;}43 unmodified linesp['input_tokens'] = n; p['continuation_ids'] = []; p['raw'] = ''; p['done'] = Falsereturn pdef gpu_seconds(p):return int(p.get('gpu_seconds', 120))@spaces.GPU(size='xlarge', duration=gpu_seconds) # 27B BF16 needs the full 96 GB GPU (2x quota)def gpu_chunk(p):budget = max(30, gpu_seconds(p) - 90) # leave room for moving the weights to the GPU and the prefillinputs = processor.apply_chat_template(chat(p), tokenize=True, add_generation_prompt=True,enable_thinking=False, return_dict=True, return_tensors='pt')prefix = p.get('continuation_ids', [])7 unmodified linesinputs = inputs.to('cuda')start = time.monotonic()with torch.inference_mode():output = model.generate(**inputs, max_new_tokens=min(8192, remaining), max_time=budget, do_sample=False,use_cache=True, temperature=None, top_p=None, top_k=None, repetition_penalty=1.1)new_ids = output[0, length:].detach().cpu().tolist()all_ids = prefix + new_ids36 unmodified linesreturn (dict(p, paused=True), f"Stopped after {MAX_STEPS} steps without a complete poster.", None, HIDE, HIDE,gallery, p['spec'], p['raw'], gr.update(visible=True))progress(min(.1 + .12 * k, .9), desc=f'Generating poster HTML (step {k})…')r = Nonefor secs in [d for d in GPU_LADDER if d <= p.get('gpu_seconds', GPU_LADDER[0])]:p = dict(p, gpu_seconds=secs)try:r = gpu_chunk(p)breakexcept Exception as e: # noqa: BLE001 (quota, duration limit, timeout, …)msg = str(e)if 'larger than the maximum allowed' in msg and secs != GPU_LADDER[-1]:continue # ask for a shorter GPU slothint = QUOTA_HINT if ('maximum allowed' in msg or 'quota' in msg.lower()) else ''return (dict(p, paused=True), f"Paused after step {k - 1}: {msg[:200]}{hint}", None, HIDE, HIDE,gallery, p['spec'], p['raw'], gr.update(visible=bool(p.get('continuation_ids'))))p = dict(p, continuation_ids=r['ids'], raw=r['raw'], done=r['done'], step=k)tokens = f"{len(r['ids']):,} tokens · {r['new_tokens'] / max(r['seconds'], .01):.0f} tok/s · {p['gpu_seconds']} s GPU step"if not (r['complete'] or p['done']):return (p, f"Step {k} done · {tokens} · continuing (step {k + 1})…", None, HIDE, HIDE,gallery, p['spec'], p['raw'], gr.update(visible=False))
README.md+4-2
demo_ui.py+24-9