Commit History
-
Sync develop into main (#52)
Unverified signature* Set up develop/main two-stage deploy: retarget dev-en to develop, add prod-en workflow develop -> dev-en Space (staging), main -> prod-en Space (release). See #26 for the release flow design. * Centralize print_*() logging functions in logging_utils.py (#29) Consolidates the named print_*() functions that #23 extracted in model_loading.py, inference.py, examples_ui.py, image_codec.py, and the qwenimage attention/pipeline modules into logging_utils.py, alongside the print_log_*() functions already there, so all logging lives in one file instead of being scattered per-module. Co-authored-by: Claude Sonnet 5 <noreply@anthropic.com> * Rename dev-en's repo variable from HF_SPACE_ID to HF_SPACE_ID_DEV_EN (#30) Matches the <ENV>_<LANG> naming already used by HF_SPACE_ID_PROD_EN and HF_SPACE_ID_PROD_JA — the bare HF_SPACE_ID for dev-en was the odd one out. Co-authored-by: Claude Sonnet 5 <noreply@anthropic.com> * Extract _InferTimer into a generic Timer in timing.py (#32) print_timi…8c202fb
-
Split app.py into cohesive modules (#17)
Unverified signatureapp.py mixed five unrelated concerns in one 733-line file: env/model startup, base64<->PIL image codec, example/suggestion HTML building, per-request inference orchestration, and Gradio UI wiring. Split each into its own module (image_codec.py, examples_ui.py, model_loading.py, inference.py) so app.py is left as thin UI assembly + entrypoint. No behavior changes: every function/class from the original app.py is preserved verbatim in its new home (verified via a def/class-name diff), and the existing test suite still passes unchanged. Co-authored-by: Claude Sonnet 5 <noreply@anthropic.com>63be854
-
Pad declared ZeroGPU duration with a cold-start buffer
Every @spaces.GPU call runs in a fresh worker, so the int8 text_encoder reload (up to ~30s) and full pipe-to-cuda move (up to ~14s) are paid on every request. When the UI's gpu_duration slider only budgeted for the user's expected diffusion time, ZeroGPU would kill the call mid-run with "GPU task aborted" once the declared duration was exceeded (issue #7). Since ZeroGPU bills by actual usage rather than the declared duration, padding it costs nothing but queue priority. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>8ec79ca
-
Fix step-done log ordering vs text_encoder offload/pre-VAE-decode
The step-done print used a timestamp captured at callback entry but printed after the offload/pre-VAE-decode logging (which use fresh perf_counter() calls), making log lines appear out of chronological order on the final step. Print step-done immediately after computing it instead. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>1a04070 -
Reduce default GPU duration for Fast mode from 30s to 15s
Fast mode uses lower resolution, fewer steps, and no text encoder offload, so 30s of reserved ZeroGPU time was more than actually needed. Closes #15 Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>8a3b1b0 -
Add VAE decode logging: pre-decode mem snapshot, tiling prediction, peak reset
Adds three log points to support issue #6 investigation: - [startup] VAE tile threshold confirmation after enable_tiling() - [infer] whether tiling will activate for this image size - [infer] pre-VAE-decode memory snapshot + reset_peak_memory_stats() so the existing "VAE decode + postprocess done" peak reflects only VAE decode Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>a1fde2a -
Raise VAE tile threshold to HIGH_DETAIL.max_dim (2048px) to skip tiling
Tiling only activates when image size exceeds the threshold; at 768px the threshold was always triggered for high_detail outputs (up to 2048px), adding tile-split and blend overhead. FAST mode (<=768px) is unaffected. This is an investigation step to measure peak memory and decode speed with tiling disabled on high_detail — guided by issue #6. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>2f7a843 -
Load text_encoder as int8 (bitsandbytes) when TEXT_ENCODER_INT8_REPO is set
bitsandbytes 8bit models can't be moved between devices with `.to()` (unconditional in transformers, unlike the version-gated allowance for 4bit), so this can't reuse the transformer's cpu-load-then-.to(device) pattern. Instead the quantized text_encoder is loaded directly onto the target CUDA device on first inference call per worker, guarded so it only happens once. Also fixes a crash: high_detail mode's pre-decode text_encoder.to("cpu") offload is skipped once text_encoder is int8, since .to() would raise for it regardless of target device. Repo id comes from the TEXT_ENCODER_INT8_REPO secret; falls back to the existing bf16 text_encoder when unset. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>ae1d43b -
Skip text_encoder CPU offload in fast mode; type mode as an enum
Logged phase timing showed the text_encoder-to-CPU offload before VAE decode costs ~9.7s, while decode itself takes ~113ms. That offload was freeing memory decode never needed at fast mode's small resolution (measured peak stayed well under the MIG slice's headroom) — it exists to prevent OOM at high-detail's much larger 2048px decode, so it's kept there and only skipped for fast mode. Replaced the raw "fast"/"high_detail" string comparisons scattered across dimensions.py and app.py with a Mode enum (mode.py) that owns both behaviors (max_dim, offloads_text_encoder_before_decode) as properties on the variant. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>39867e3 -
Add per-phase timing to pipeline call and text_encoder offload
The existing vae_decode timing bucket (last_step -> pipe_end) lumps together the text_encoder CPU offload, latent unpacking, actual VAE decode, and postprocessing, making it look like decode itself is slow. Split each phase out with its own timestamped log line so the real cost can be seen directly instead of inferred.f30b43a -
Speed up fast mode: lower resolution cap, skip needless VAE tiling, fewer steps
Fast mode's 768px (was 1024px) output now stays under the VAE's tiling threshold, so it decodes in a single pass instead of a tiled decode with blend overhead that was only ever needed for high-detail's 2048px case. Also gives fast mode a lower default step count (3 vs 4), following the existing mode-scoped-default pattern already used for GPU duration. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>9fcf338
-
Log exception type/repr and traceback in infer() error path
Diagnosing "Could not parse server response. Syntax error '<'" reports on High-Detail mode: the browser is getting HTML instead of JSON back from the SSE queue, which points to Gradio failing to serialize the caught exception rather than the underlying error itself (a recent case was a ZeroGPU quota rejection, confirmed via the firered-turbo-logs dataset, whose exact exception type/attrs aren't visible from str(e) alone). This logs the concrete type/module and full traceback so the next occurrence is easier to pin down. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>1f6b940
-
Replace vllm-flash-attn3 kernel with native SDPA cuDNN backend; wire up attn processor
The external vllm-flash-attn3 kernel had no compiled binary for compute capability 12.0 (Blackwell), crashing at construction. Switch to sdpa_kernel(SDPBackend.CUDNN_ATTENTION) which ships inside PyTorch/CUDA itself. Also wire up set_attn_processor() in app.py — previously the class was imported but never applied, leaving the transformer on its default processor the whole time. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>e4b15be -
Free text encoder before VAE decode and enable VAE tiling to fix OOM
Fast-path inference keeps the full ~35GB pipeline resident on the 47.4GB MIG slice, leaving too little headroom for the VAE decoder's fp32-upcast memory spike on large (2048px) outputs. Offload the ~15GB text encoder to CPU once the last denoising step finishes (skipped when accelerate hooks already own placement), and bound decode memory with tiling regardless of output size. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>0a2678b -
Patch RMSNorm for fp8-resident weights; fix crash in prior fp8 commit
8db56cb kept the transformer's weights fp8-resident (instead of upcasting to bf16 at load) to fix the memory OOM that was forcing this Space onto the slow enable_model_cpu_offload path. It patched nn.Linear to upcast its weight just-in-time for the matmul, but this model also uses RMSNorm extensively (attn.norm_q/norm_k/norm_added_q/norm_added_k in every transformer block, plus self.txt_norm) with real learnable weights — confirmed via the checkpoint's safetensors headers, which show 100% of tensors across all 3 shards as F8_E4M3, including norm gains and biases, no mixed precision. diffusers 0.39.0's RMSNorm.forward only upcasts its weight for float16/bfloat16, not float8. Left unpatched, `hidden_states * self.weight` multiplies a bf16 activation by an fp8 weight directly, which PyTorch does not support via type promotion. Verified this reproduces exactly: RuntimeError: Promotion for Float8 Types is not supported, attempted to promote Float and Float8_e4m3fn This adds _fp8_upca…c0f3a61 -
Keep transformer weights fp8-resident instead of upcasting at load
The Rapid-AIO-V23 checkpoint already ships natively in fp8_e4m3fn (~19GB for 20B params), but from_pretrained's torch_dtype=bf16 was casting every tensor up to bf16 at load time (~38GB), which is why the pipeline (~35-40GB transformer + ~14GB text encoder) never comfortably fit this Space's 47GB MIG slice and needed the slow enable_model_cpu_offload fallback (_FAST_PATH_MIN_GB=60, gating out the 47GB slice entirely). This keeps torch_dtype=torch.float8_e4m3fn on the transformer load (a diffusers-supported path — see modeling_utils.py's explicit float8 handling) so weights stay fp8 in memory, and patches every fp8-resident nn.Linear to upcast its own weight to the input's dtype just before the matmul. nn.Linear has no fp8 GEMM kernel on this GPU, so this is not a compute speedup — it's the same bf16 upcast the old code did, just deferred from load-time (all layers at once) to call-time (one layer's weight transiently bf16 at a time), so resident GPU memory drops from ~38GB to ~19GB for…8db56cb -
Refactor _infer_gpu into single-responsibility helper functions
Split the monolithic function into _log_infer_start, _log_gpu_properties, _place_pipe_on_device, _instrument_first_touch, _make_step_callback, and _log_infer_error. _infer_gpu itself is now just the orchestration of these steps, with no behavior change.d9d1b60 -
Fix misleading "includes compile" log label; add first-touch instrumentation
No torch.compile exists in this codebase — the step-1 slowdown every inference is cold-start from enable_model_cpu_offload re-running on every fresh ZeroGPU worker (slice too small for the full-GPU fast path). Added self-removing forward-pre-hooks on text_encoder/transformer/vae to break that cost down by module in the logs.be0f671 -
Revert NF4 quantization: this checkpoint's weights are stored fp8-native
Space startup crashed: RuntimeError: Blockwise 4bit quantization only supports 16/32-bit floats, but got torch.float8_e4m3fn. The transformer safetensors index reports ~19GB total for a 20B-param model (~1 byte/param), confirming prithivMLmods/Qwen-Image-Edit-Rapid- AIO-V23 already ships as fp8, not bf16. bitsandbytes' 4-bit quantizer requires a 16/32-bit source tensor to quantize from and cannot operate on fp8-stored weights directly — and since nothing in this vendored qwenimage code has fp8 compute kernels, the weights still need to be upcast to bf16 for the forward pass to work at all, which is exactly what the pre-quantization code already did. So NF4-on-load isn't a drop-in fix here; doing it properly would mean manually materializing the model in bf16 first and then hand-converting nn.Linear modules to Linear4bit, which needs real GPU verification to get right. Reverting app.py to the pre-quantization state (926cf86) to restore a working Space. The requirements.txt fix pinning…1093d66 -
Quantize transformer to NF4 via bitsandbytes to fix root-cause OOM
The last several commits kept rearranging when the ~54GB bf16 pipeline (20B transformer + Qwen2.5-VL-7B text encoder) touches the GPU, but that footprint never comfortably fit the 47GB 2g.48gb MIG slice regardless of ordering. NF4-quantizing the transformer (the biggest contributor) drops it from ~40GB to ~11GB, bringing full-pipeline GPU residency down to ~25-30GB with real headroom, so the fast pipe.to(device) path should now succeed every time instead of needing the OOM/cpu-offload dance. bitsandbytes rejects device_map="cpu" for a fresh (non-prequantized) config, so the transformer now loads straight onto cuda:0 at startup (paying the "ZeroGPU disk packing" cost once at boot) instead of the CPU-first pattern still used for the rest of the pipeline. Removed the now-obsolete _FAST_PATH_MIN_GB size gate in _infer_gpu since the quantized pipeline should fit regardless of the exact slice size. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>e809108 -
Gate full-GPU fast path on slice size; it OOMs on this Space's 47GB MIG
Verified on the FireRed-Dev logs: the previous commit's full pipe.to(device) attempt OOM'd on the 2g.48gb (47.4GB) MIG slice this Space actually gets (peaked at 46.82GB), wasting ~40s on the failed attempt + cleanup before falling back to cpu offload — strictly worse than the offload-only baseline. Only attempt the fast path when the allocation has real headroom (>=60GB); otherwise go straight to enable_model_cpu_offload as before. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>926cf86 -
Try full pipeline GPU residency before falling back to cpu offload
Each ZeroGPU call runs in a fresh worker (offload hooks are always unset at entry), so enable_model_cpu_offload bought no cross-call reuse — it just replaced one bulk pipe.to(device) transfer with several slower, hook-managed component transfers, adding ~55s of pure data movement to a ~62s call per the FireRed-Dev logs. Try the fast full-GPU path first and only fall back to offload on an actual CUDA OOM (small MIG slices). Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>994c9a0 -
Use sequential CPU offload instead of moving full pipeline to GPU at once
pipe.to(device) staged all ~37GB of weights (transformer + text_encoder + vae) onto GPU simultaneously, which OOM'd on smaller MIG slices (e.g. the 47GB 2g.48gb partition ZeroGPU sometimes hands out). enable_model_cpu_offload uses the pipeline's declared model_cpu_offload_seq to keep only the active component resident on GPU at a time. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>a104380 -
Use cudaMallocAsync allocator to fix MIG GPU CUDACachingAllocator crash
PyTorch's default CUDA Caching Allocator makes NVML memory queries (nvmlDeviceGetMemoryInfo) that fail on MIG GPU instances running as non-root, causing: NVML_SUCCESS == r INTERNAL ASSERT FAILED at CUDACachingAllocator.cpp:1165. The cudaMallocAsync backend avoids these NVML queries entirely. Set via PYTORCH_CUDA_ALLOC_CONF at module level (before any CUDA init) so it is inherited by ZeroGPU's subprocess. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>5ed2ecb -
Add startup environment diagnostics (_log_env)
Prints GPU name/VRAM/compute cap, CUDA version, cuDNN version, system RAM, and key library versions (spaces, diffusers, transformers, gradio, accelerate, peft, torchvision) at startup. Exceptions always print the error message — no silent pass. This would have instantly identified spaces==0.51.0 as the culprit during the July 17 outage. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>9acf075 -
Load model on CPU at startup to bypass slow ZeroGPU disk packing
spaces 0.51.0 (released 2026-07-10) switched to disk-based tensor packing (~19s pack + ~19s unpack per inference), breaking the ~7s inference that worked with spaces 0.50.4's pinned-memory approach. HuggingFace force-injects spaces==0.51.0 so pinning requirements.txt doesn't help. Instead: - Load transformer and pipeline on CPU at startup (ZeroGPU has nothing to pack since no tensors are on GPU) - pipe.to(device) inside @spaces.GPU: ~3-4s PCIe transfer vs ~19s disk - pipe.to("cpu") in finally block so ZeroGPU has nothing to repack Also reverts bad spaces==0.50.4 pin (build error) and raises GPU duration defaults to accommodate the explicit model-move time. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>6c0477d
-
Revert FA3 and torch.compile: incompatible with this GPU environment
torch.compile falls back everywhere due to a torch.device ConstantVariable bug in the installed PyTorch version. FA3 fails at runtime with "no kernel image available" — the vllm-flash-attn3 kernel is not compiled for this GPU's compute capability. Both add overhead with no benefit here. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>a05c007 -
Fix torch.compile crash on torch.device ConstantVariable bug
The installed PyTorch can't treat torch.device as a ConstantVariable during tracing (hit in diffusers' get_timestep_embedding). Setting suppress_errors=True converts the hard crash to a graph break so dynamo falls back to eager for that subgraph while still compiling the 60 transformer blocks. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>d66060a -
Enable FA3 attention and torch.compile for faster inference
Replaces the ZeroGPU-era no-ops with real optimizations suitable for dedicated GPU deployment: FA3 processor on all 60 transformer blocks (with graceful fallback), and torch.compile(mode="reduce-overhead") on the transformer for kernel fusion and CUDA graph capture. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>000cfc0
-
Batch log uploads to avoid HF 256-commits/hour rate limit
Replaces per-inference commit (prune + upload = 2 commits) with a LogUploader class that queues parquet files locally and flushes them in a single batched commit every LOG_BATCH_INTERVAL seconds (default 60). At full load this reduces commit rate from O(requests) to ~1/minute. Also splits _build_commit_ops into _build_add_ops and _build_delete_ops so each helper has a single responsibility, and updates tests accordingly. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>2f63460
-
Log gpu_duration and mode at infer start
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>ae435f6 -
Add user-adjustable GPU Duration slider to Advanced Settings
Exposes the spaces.GPU duration as a UI slider (10–120s, step 5s) so users can tune quota usage per request. Switching modes auto-resets the slider to its default (fast=20s, high_detail=60s). Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>b36328a
-
Raise ZeroGPU durations to 20s fast, 60s high-detail
10s/30s caused aborts on cold ZeroGPU instances where Triton compilation adds 10-20s to the first request. Each new concurrent instance recompiles, so this isn't a one-time startup cost. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>c1f861c -
Tighten ZeroGPU durations to p95-aligned values (10s fast, 30s high-detail)
Based on 410 samples: fast p95=5s (max 13.3s), high-detail p95=18.3s with 2.8% exceeding 30s. Accepts ~5% failure rate; users can retry with remaining daily quota. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>541b505 -
Raise high-detail ZeroGPU duration to 90s (was 60s)
Latest 100 logs show high-detail p95=67.9s and p99=72.6s pipeline time, so 60s was insufficient. 90s covers p99 with headroom for overhead. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>f4a7c5c -
Use per-mode dynamic ZeroGPU duration (30s fast, 60s high-detail)
Fast mode (1024px) p95 pipeline time is ~14.5s so 30s is safe. High-Detail mode (2048px) p99 is ~40s so 60s is kept for that path. Drop mode default params — Gradio always passes it explicitly. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>519548d -
Reduce ZeroGPU duration from 120s to 60s to halve quota usage
Free-tier users get 210s/day; 120s consumed 1-2 uses of their daily quota. p99 pipeline time is ~40s, so 60s still covers all requests with headroom for overhead. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>e8421c5
-
Fix log upload dropped by moving _spawn_log outside @spaces.GPU scope
ZeroGPU runs @spaces.GPU-decorated functions in an isolated subprocess; when the function returns the subprocess exits, killing the daemon log thread before the HuggingFace upload could complete. Moving _spawn_log to infer() (main process) ensures the thread outlives the GPU subprocess. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>394c2c0
-
Reduce ZeroGPU usage by moving CPU work outside GPU scope
- Split infer() into a CPU-only wrapper and @spaces.GPU(duration=120) _infer_gpu() so image decoding, validation, seed resolution, and dimension computation no longer consume GPU quota - Move gc.collect() before the GPU lease is acquired - Remove torch.cuda.synchronize() from the per-step callback (was blocking once per step just for wall-clock logging) - Remove per-step GPU memory queries from the step callback Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>639aead -
Load mode toggle JS via demo.load instead of stripped <script> tag
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>a3f2ffd -
Add Fast / High-Detail mode toggle (768px vs 2048px output)
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>f333d01
-
Add heartbeat logging during model loading
Prints a progress line every 15s while each from_pretrained call blocks, so log streams show the space is alive during cold start. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>b8216f1
-
Revert "Add step-progress bar to inference loader"
This reverts commit 4382eeb6464035463c7193a46a68a60305a37f82.fe3cc96 -
Add step-progress bar to inference loader
- Call progress() in _step_cb so Gradio sends per-step events to client - Make loader-bar-fill width-driven (0→100%) with 0.5s transition - watchProgress() in wire_outputs.js wraps __clickGradioRunBtn/__hideLoader to reset/complete the bar and mirrors Gradio DOM progress to the fill Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>4382eeb -
Fix quick prompt buttons: HTML-escape JSON to avoid breaking onclick attribute
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>ce260d2 -
Fix f-string backslash syntax error in build_suggestion_chips_html
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>b122899 -
Load Quick Prompts from suggestions.json, replace artistic chips with realistic ones
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>62ddcce -
Revert 2K/4K resolution selector (4K too slow for generation)
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>0aa155d -
Add 2K/4K resolution selector to Advanced Settings
- Add `_resolve_output_dimensions` helper to encapsulate max_dim parsing - Wire `max_output_dim` hidden Gradio Textbox (defaults to MAX_OUTPUT_DIM) through infer - Add res-btn toggle group in Advanced Settings panel (HTML + CSS) - Track selection in `window.__setResolution` / `window.__selectedMaxDim` (gallery.js) - Pass selected resolution through run_preprocess.js to the backend Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>ca50d09 -
Refactor app.py: extract helpers, consolidate imports
- _InferTimer class, _gpu_mem_str, _validate_infer_inputs, _resolve_seed, _spawn_log all extracted from infer() - _example_thumbs_html, _example_card_html extracted from build_example_cards_html() - _parse_example_idx extracted from load_example_data() - Consolidate scattered imports (time, traceback) to module top - Move negative_prompt load above infer() where it is used Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>a532114