Download app.py from User-2468/Name: direct link, hf CLI and curl.
- Browser
- Download file 7.26 kB
-
https://huggingface.co/spaces/User-2468/Name/resolve/main/app.py
- Command line
-
hf download hf://spaces/User-2468/Name/app.py
-
curl -L -o app.py https://huggingface.co/spaces/User-2468/Name/resolve/main/app.py
7.26 kB
| # Import spaces before torch / model code for ZeroGPU's CUDA emulation. | |
| import spaces | |
| import json | |
| import tempfile | |
| from pathlib import Path | |
| import gradio as gr | |
| from engine import Settings, POLICIES, prompt_ids, generate | |
| from evaluation import CASES, grade | |
| def save_report(report): | |
| # Unique paths avoid overwriting another visitor's report. | |
| folder = Path(tempfile.mkdtemp(prefix="remedi-report-")) | |
| path = folder / "remedi-results.json" | |
| path.write_text(json.dumps(report, ensure_ascii=False, indent=2), encoding="utf-8") | |
| return str(path) | |
| def create_demo(model, tokenizer, diagnostics): | |
| def gpu_run(ids, settings): | |
| return generate(model, tokenizer, ids, settings) | |
| def run(prompt, system, tokens, block, steps, policy, seed, trace): | |
| try: | |
| settings = Settings(int(tokens), int(block), int(steps), policy, int(seed), trace).validate() | |
| ids = prompt_ids(tokenizer, prompt, system) | |
| result = gpu_run(ids, settings) | |
| result.update({"prompt": prompt, "system": system, "environment": diagnostics}) | |
| rows = [[r["block"], r["step"], r["kept"], r["remasked"], r["text"]] for r in result["trace"]] | |
| return result["text"], result["metrics"], rows, save_report(result) | |
| except (ValueError, RuntimeError, TimeoutError) as exc: | |
| raise gr.Error(str(exc)) from exc | |
| def suite(names, tokens, block, steps, policy): | |
| if not names: | |
| raise gr.Error("Select at least one test") | |
| settings = Settings(int(tokens), int(block), int(steps), policy, trace=False).validate() | |
| reports, rows = [], [] | |
| for case in CASES: | |
| if case["name"] not in names: | |
| continue | |
| try: | |
| result = gpu_run(prompt_ids(tokenizer, case["prompt"]), settings) | |
| result.update({"case": case, "grade": grade(result["text"], case)}) | |
| rows.append([case["name"], result["grade"]["status"], result["text"], result["metrics"]["seconds"]]) | |
| reports.append(result) | |
| except Exception as exc: | |
| rows.append([case["name"], "error", str(exc), 0]) | |
| reports.append({"case": case, "error": str(exc)}) | |
| yield rows, save_report({"environment": diagnostics, "results": reports, | |
| "grading": "Strict exact string/JSON checks; manual cases are not scored."}) | |
| with gr.Blocks(title="RemeDi 路 Test bench", theme=gr.themes.Soft(primary_hue="teal"), delete_cache=(3600, 3600)) as demo: | |
| gr.Markdown("# RemeDi 路 Test bench\nExplore **RemeDi-Instruct**, a 9B diffusion language model. Watch tokens become committed and remasked as each block is refined.") | |
| gr.Markdown("Runs on ZeroGPU in BF16. Start with 128 tokens / 16 steps. Each request has a 120-second GPU lease; long runs can time out. Generation is greedy, so the seed does not add variety.") | |
| with gr.Tab("Try a prompt"): | |
| prompt = gr.Textbox(label="Prompt", lines=5, value=CASES[0]["prompt"]) | |
| gr.Examples([[c["prompt"]] for c in CASES], inputs=[prompt]) | |
| system = gr.Textbox(label="System message (optional)", lines=2) | |
| with gr.Row(): | |
| tokens = gr.Slider(1, 256, value=128, step=1, label="Maximum new tokens") | |
| block = gr.Dropdown([16, 32, 64], value=32, label="Block size") | |
| steps = gr.Slider(1, 64, value=16, step=1, label="Steps per block") | |
| policy = gr.Dropdown(POLICIES, value=POLICIES[0], label="Token ranking") | |
| gr.Markdown("**Official raw logits** follows the released inference script. **Learned confidence** ranks using the model's separate policy head; **token probability** uses normalised logits. Both alternatives are experiments, not verified paper reproductions.") | |
| with gr.Row(): | |
| seed = gr.Number(value=112, precision=0, label="Recorded seed") | |
| trace = gr.Checkbox(value=True, label="Capture per-step token trace") | |
| with gr.Row(): | |
| button = gr.Button("Generate", variant="primary") | |
| stop = gr.Button("Stop") | |
| answer = gr.Textbox(label="Response", lines=8, interactive=False) | |
| metrics = gr.JSON(label="Timing and generation metrics") | |
| table = gr.Dataframe(headers=["Block", "Step", "Kept tokens", "Remasked tokens", "Block text"], interactive=False, label="Refinement trace") | |
| download = gr.File(label="Download complete JSON report") | |
| event = button.click(run, [prompt, system, tokens, block, steps, policy, seed, trace], [answer, metrics, table, download], concurrency_id="model", concurrency_limit=1, api_name="generate") | |
| stop.click(fn=None, cancels=[event]) | |
| gr.Markdown("Stop cancels queued work; an active GPU forward may finish before cancellation takes effect. Trace rows describe the current block, including special mask tokens; they are not additional answers.") | |
| with gr.Tab("Test suite"): | |
| gr.Markdown("Small smoke tests, **not a benchmark**. Exact-output cases use strict grading; explanation and code require your review. Each case requests its own GPU lease. Results appear after each case; the report includes prompts, settings, token IDs and timings.") | |
| selection = gr.CheckboxGroup([c["name"] for c in CASES], value=[c["name"] for c in CASES[:3]], label="Cases") | |
| gr.Markdown("Uses the token budget, block size, step count and ranking selected in the prompt tab. Trace is disabled for suite runs. No generated code is executed.") | |
| with gr.Row(): | |
| test_button = gr.Button("Run selected tests", variant="primary") | |
| test_stop = gr.Button("Stop suite") | |
| results = gr.Dataframe(headers=["Case", "Result", "Response / error", "Seconds"], interactive=False) | |
| report = gr.File(label="Download suite results") | |
| test_event = test_button.click(suite, [selection, tokens, block, steps, policy], [results, report], concurrency_id="model", concurrency_limit=1, api_name=False) | |
| test_stop.click(fn=None, cancels=[test_event]) | |
| with gr.Tab("Environment & method"): | |
| gr.JSON(diagnostics, label="Pinned model, tokenizer and runtime") | |
| gr.Markdown("The base LLaDA tokenizer is used because this checkpoint contains no tokenizer files. All checkpoint keys and special token IDs must match before startup succeeds. Each run uses an isolated KV cache. EOS stopping considers generated tokens only. Final partial blocks respect the exact output limit. Timing excludes queueing and initial model download. Tokens become revisable within their current block; completed blocks stay cached.\n\n[Model](https://huggingface.co/maple-research-lab/RemeDi-Instruct) 路 [Official implementation](https://github.com/maple-research-lab/RemeDi) 路 [Paper](https://arxiv.org/abs/2509.23653)") | |
| return demo | |
| if __name__ == "__main__": | |
| from runtime import load_runtime | |
| model, tokenizer, diagnostics = load_runtime() | |
| create_demo(model, tokenizer, diagnostics).queue(max_size=12, default_concurrency_limit=1).launch(show_error=True) | |