BlueSkyXN
Tune ZeroGPU duration defaults
948db04
|
Raw History Blame Contribute Delete
6.64 kB

A newer version of the Gradio SDK is available: 6.32.0

Upgrade
metadata
title: Diffusiongemma Zerogpu Space
emoji: 🏢
colorFrom: green
colorTo: gray
sdk: gradio
sdk_version: 6.18.0
python_version: '3.12'
app_file: app.py
pinned: false
license: gpl-3.0

DiffusionGemma GGUF ZeroGPU API

Dedicated Hugging Face ZeroGPU Space for:

unsloth/diffusiongemma-26B-A4B-it-GGUF

This repository is intentionally not a universal GGUF template. DiffusionGemma GGUF uses a block-diffusion architecture and requires the DiffusionGemma branch of llama.cpp plus the dedicated llama-diffusion-cli runner. The standard llama-cli / llama-server path is not the primary runtime here.

What this repo provides

gradio.Server
@app.api(name="chat", concurrency_limit=1)
@spaces.GPU(...)
llama-diffusion-cli subprocess
/v1/models
/v1/chat/completions
/v2/runtime
/v2/logs
/v2/zerogpu/probe

The first version is text-only and final-only. stream=true is supported as a compatibility shim: it sends the final result as one OpenAI-style delta, not token-by-token streaming.

Default model

MODEL_NAME=unsloth/diffusiongemma-26B-A4B-it-GGUF:Q4_K_M
GGUF_FILENAME=diffusiongemma-26B-A4B-it-Q4_K_M.gguf

Q4_K_M is the recommended first deployment target because it is the smallest quantization tier and is the best choice for validating the ZeroGPU + runner + API path.

Recommended Space settings

Create a Hugging Face Space with:

SDK: Gradio
Hardware: ZeroGPU

Recommended environment variables:

GGUF_REPO_ID=unsloth/diffusiongemma-26B-A4B-it-GGUF
GGUF_FILENAME=diffusiongemma-26B-A4B-it-Q4_K_M.gguf
MODEL_NAME=unsloth/diffusiongemma-26B-A4B-it-GGUF:Q4_K_M

ZEROGPU_SIZE=large
DEFAULT_MAX_TOKENS=512
MAX_MAX_TOKENS=2048
DIFFUSION_MAX_STEPS=48
MAX_GPU_DURATION_SECONDS=180
N_GPU_LAYERS=99
PROMPT_MODE=auto

BUILD_LLAMA_DIFFUSION=1
LLAMA_BUILD_CUDA=1
PREPARE_RUNTIME_ON_STARTUP=0
DOWNLOAD_MODEL_ON_STARTUP=0
GRADIO_SSR_MODE=false

The qwen36 reference Space is stable because it uses a prebuilt CUDA runner package through LLAMA_CLI_URL and prepares it on startup. Use the same strategy for DiffusionGemma once you have a tested llama-diffusion-cli package:

BUILD_LLAMA_DIFFUSION=0
LLAMA_DIFFUSION_BIN_URL=https://.../llama-diffusion-cli-linux-cuda-package.tar.gz
PREPARE_RUNTIME_ON_STARTUP=1
DOWNLOAD_MODEL_ON_STARTUP=1

If you attach persistent storage:

DATA_DIR=/data
MODEL_CACHE_DIR=/data/models
BIN_DIR=/data/bin
LLAMA_SRC_DIR=/data/llama.cpp
LLAMA_DIFFUSION_BIN=/data/bin/llama-diffusion-cli

Without persistent storage, the Space will use /tmp/diffusiongemma/..., so model downloads and built binaries may be lost after restart.

Build/runtime strategy

The runner can be supplied in three ways:

  1. Prebuilt binary

    LLAMA_DIFFUSION_BIN=/data/bin/llama-diffusion-cli
    BUILD_LLAMA_DIFFUSION=0
    
  2. Downloaded artifact

    LLAMA_DIFFUSION_BIN_URL=https://your-release/llama-diffusion-cli-linux-cuda.tar.gz
    BUILD_LLAMA_DIFFUSION=0
    
  3. Build inside Space

    BUILD_LLAMA_DIFFUSION=1
    LLAMA_BUILD_CUDA=1
    

Building inside the Space is convenient for the first test, but it is the least deterministic option. The build script adds NVIDIA Python package library paths for CUDA/cuBLAS linking and copies sibling shared libraries next to llama-diffusion-cli, but a prebuilt binary package is still preferable once you know which llama.cpp PR revision works.

Diagnostics

GET /v2/runtime
GET /v2/logs
GET /v2/zerogpu/probe
GET /v2/zerogpu/probe?cli=1

/v2/zerogpu/probe runs inside @spaces.GPU and is the direct way to confirm that ZeroGPU allocated a CUDA device. ?cli=1 probes the runner only if llama-diffusion-cli already exists; it does not trigger a build by itself.

API usage

OpenAI-compatible route

export SPACE_URL="https://YOUR-SPACE.hf.space"
export HF_TOKEN="hf_..."

curl -X POST "$SPACE_URL/v1/chat/completions" \
  -H "Authorization: Bearer $HF_TOKEN" \
  -H "Content-Type: application/json" \
  -d '{
    "model": "unsloth/diffusiongemma-26B-A4B-it-GGUF:Q4_K_M",
    "messages": [
      {"role":"user", "content":"Write a short haiku about GPUs."}
    ],
    "max_tokens": 256,
    "stream": false
  }'

Gradio queue route

export SPACE_URL="https://YOUR-SPACE.hf.space"
export HF_TOKEN="hf_..."

./scripts/call_space_direct.sh "Write a short haiku about GPUs."

Notes on streaming

DiffusionGemma does not generate like a normal autoregressive model. It denoises a token canvas. This repository therefore does not pretend that the intermediate denoising states are normal token deltas.

Current behavior:

stream=false -> returns final assistant message
stream=true  -> returns one final delta, then [DONE]

A later version can expose a diffusion-native endpoint such as:

/gradio_api/call/generate

with frames like:

{"kind":"draft","source":"..."}
{"kind":"commit","source":"..."}
{"kind":"done","source":"..."}

This would mirror the official DiffusionGemma codegen demo more closely, but it should be built only after the llama-diffusion-cli stdout format is validated.

Files

app.py                         # Gradio Server, ZeroGPU endpoint, /v1 routes
src/config.py                  # Environment config
src/models.py                  # Single-model registry and aliases
src/prepare.py                 # Runner build/download and GGUF download
src/prompts.py                 # Text-only prompt handling
src/runner.py                  # llama-diffusion-cli subprocess runner
src/handlers.py                # End-to-end request handling
src/openai.py                  # OpenAI-compatible response helpers
scripts/build_llama_diffusion.sh
scripts/call_space_direct.sh
scripts/call_v1.py
scripts/call_v1_stream.py
scripts/smoke_cli.sh
static/index.html

First deployment checklist

  1. Create a Gradio SDK Space.
  2. Select ZeroGPU hardware.
  3. Upload this repository.
  4. Set GGUF_FILENAME=diffusiongemma-26B-A4B-it-Q4_K_M.gguf.
  5. Set ZEROGPU_SIZE=large.
  6. Deploy.
  7. Inspect logs for llama-diffusion-cli build success.
  8. Call /health.
  9. Call /v2/runtime and /v2/zerogpu/probe.
  10. Run scripts/call_space_direct.sh.
  11. Then test /v1/chat/completions.

Known limitations

  • Text-only first version.
  • No real token streaming.
  • No multimodal mmproj handling.
  • No arbitrary model downloads.
  • No multi-model router.
  • llama-diffusion-cli build may fail if the Space image lacks the required CUDA build tooling; use a prebuilt binary if that happens.