Spaces:
Running on Zero
Running on Zero
Commit History
5 days ago
-
deploy qua@5dc7c3f2
Verified signature58dde1b
29 days ago
-
deploy qua@973f7f51
Verified signature933e47f -
deploy qua@8f19ff1d
Verified signature627555e
-
deploy qua@79e42ed5
Verified signaturec026fa0 -
deploy qua@32f334a1
Verified signature3d6ae90
-
deploy qua@f5c8b57f
Verified signaturead71fec -
deploy qua@c2668009
Verified signature0ce8643
-
deploy qua@83007065
Verified signatureef8a4c9
-
deploy qua@8bd7ee6e
Verified signature003b05a
-
deploy
Verified signaturecb0af6c
-
deploy
Verified signaturec6c327a -
deploy
Verified signature35d8fb6
-
deploy
Verified signature472bb49
-
Upload folder using huggingface_hub
Verified signature4a0777e
-
Upload folder using huggingface_hub
Verified signatured46a954
-
Upload folder using huggingface_hub
Verified signature3955329
-
Isolate CPU fallback in spawn subprocess to prevent CUDA state poisoning
Running torch ops in the main Gradio process during CPU fallback triggers C-level CUDA runtime queries that partially initialize CUDA state. Since ZeroGPU uses fork() for GPU workers, all future workers inherit this corrupted state ("bad fork"), causing permanent "No CUDA GPUs are available" errors for ALL users until Space restart. Fix: CPU fallback now runs in a multiprocessing.spawn subprocess with SPACES_ZERO_GPU="" and CUDA_VISIBLE_DEVICES="" — a clean Python interpreter with no ZeroGPU patches and no CUDA access. The main process never touches torch, keeping its CUDA state pristine for future forked workers. Also converts VAD tensor outputs to numpy for subprocess picklability and adds _is_in_bad_fork diagnostic logging at GPU worker entry. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>df9144c -
Eliminate in-decorator CPU fallback to prevent CUDA state poisoning
Move GPU quota retry from gpu_with_fallback() decorator to UI/API callers. The decorator now raises QuotaExhaustedError instead of running torch code after a failed GPU lease, which was corrupting CUDA state for subsequent users via the spaces package's global TorchFunctionMode patches. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>7711775
-
Stop CUDA state poisoning by not invalidating model caches during quota fallback
Debug logging revealed that _park_stale_models() in the quota handler was invalidating model caches (forcing from_pretrained() reloads during CPU fallback), which poisoned CUDA state through the spaces package's TorchFunctionMode hooks. Models are already on CPU when quota errors occur (ZeroGPU moves them back when lease ends), so parking/invalidating is unnecessary. The next GPU lease's _drain_stale_models() handles cleanup safely inside the lease. Also removes all [DEBUG-FALLBACK] diagnostic logging that confirmed the root cause. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>2385694 -
Add debug logging
f90d55a -
Park AoTI cache and detach VAD tensors to prevent CUDA state poisoning
The parking mechanism missed two sources of GPU references that could escape the lease and poison CUDA for subsequent users: AoTI compiled/ exported models and raw VAD output tensors stored in Gradio state. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>99f4672 -
Fix syntax
bb85651 -
Prevent CPU fallback from poisoning CUDA state via GPU model parking
When GPU quota is exhausted, the CPU fallback path was dropping references to GPU-resident models, causing Python GC to fire CUDA tensor destructors outside a GPU lease. This corrupted torch.cuda state permanently, breaking all subsequent GPU requests for every user. Fix: "park" GPU model references in _stale_gpu_refs before invalidating caches, preventing GC. Parked models are safely released inside the next GPU lease via _drain_stale_models(). Also removes the now-unnecessary CPU reload blocks from vad.py and phoneme_asr.py (which were the poison source) and simplifies worker/CUDA error handlers to propagate immediately instead of retrying (which risked further state corruption). Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>0318d9e -
Limit CPU fallback to quota errors only
315860e -
Refine ZeroGPU fallback for worker/runtime errors
64a0a12 -
Reset torch.cuda._initialized on GPU errors instead of nuking global model caches
Replace _invalidate_all_models() (which disrupted concurrent GPU users) with torch.cuda._initialized = False to unpoison CUDA for the next user, plus _models_stale flag so stale models drain safely inside the next GPU lease. Also tune anchor voting params and increase MFA timeout. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>93e5e86 -
Replace os._exit(1) with CPU fallback on GPU errors
Instead of killing the process on non-quota GPU errors (which didn't reliably restart on HF Spaces and lost the user's request), reuse the same CPU fallback path that already works for quota exhaustion: set the per-thread flag, invalidate model caches, and re-run on CPU. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>3f00433 -
Add transition segment detection for non-Quranic phrases (Amin, Takbir, Tahmeed)
Detect and render Amin (after Al-Fatiha), Takbir (Allahu Akbar), and Tahmeed (Sami'a Allahu liman hamidah) as special segment cards with distinct styling. Includes Takbir-at-start detection before Isti'adha/ Basmala, transition mode state machine for consecutive non-Quranic segments, Tahmeed peek-ahead merge for split sami'a+rabbana segments, and unified special segment rendering with name badges. Also simplify GPU error handling: replace per-error-type fallback with immediate process restart for non-quota GPU errors. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>7f362a6 -
Add GPU retry for SDK worker errors instead of immediate CPU fallback
SDK worker_init failures are transient (assigned GPU UUID unavailable). Retrying triggers a new client.schedule() which assigns a different GPU. Previously we fell back to CPU immediately with no retry attempt. - Retry gpu_func() once on SDK worker error (new GPU assignment) - Track consecutive double-failures; cooldown 15s after 2 failures - Pre-check skips GPU during cooldown to avoid wasted scheduling - Reduce CUDA_COOLDOWN_SECONDS 300→30, MAX_CUDA_FAILURES 3→5 - Remove no-op _try_reset_cuda_state() from SDK worker path Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>aadab30 -
Fix SDK worker_init CUDA poisoning: reset immediately instead of 300s cooldown
When ZeroGPU SDK's worker_init fails (quota exhaustion causes torch._C._cuda_init() to fail), it poisons torch.cuda._initialized at the process level. The SDK wraps this as gradio.Error(title="ZeroGPU worker error") with the original CUDA message stripped, bypassing our pattern matching. Now detect these SDK worker errors via e.title and reset CUDA state immediately — no lock is held and no CUDA context is active at worker_init time, so other users can retry GPU fresh without waiting 300s. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>6984b50 -
Fix GPU cross-user contamination: scope errors per-request, not process-wide
Unrecognized GPU/SDK errors (transient network, worker scheduling) were calling _mark_cuda_unhealthy() which blocked ALL users from GPU for 300s. Now only explicit CUDA error patterns trigger process-wide health flags. Also: remove dead global quota code, add thread-safe model loading with double-checked locking, protect CPU-fallback cache mutations with locks, and guard _models_stale flag with _lease_lock. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>a6f747e -
Fix GPU quota flag blocking unrelated users across the shared process
ZeroGPU quota is per-user but _mark_global_quota_exhausted() was setting a process-wide flag, causing User B to get CPU fallback after User A exhausted their own quota. Remove the global flag from quota errors (keep per-thread flag which correctly scopes to the affected request) and tighten the broad 'quota' string match to require 'exceeded/exhausted'. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>f5c9eae -
Eliminate CUDA state poisoning at root cause, not just detection
Three root causes of persistent CUDA poisoning after quota exhaustion: 1. model.to("cpu") in cleanup runs at lease boundary — a CUDA op that fails when SDK revokes GPU, poisoning torch's CUDA runtime. Replaced with stale flag pattern: set flag at lease end, drain caches safely inside the NEXT lease. 2. Quota exhaustion was thread-local only — other threads still hit SDK, triggering CUDA init and poisoning. Added process-global quota tracking so all threads skip GPU immediately after any thread detects exhaustion. 3. No CUDA state recovery after cooldown — torch.cuda._initialized stayed True from failed init. Added _try_reset_cuda_state() to clear it when cooldown expires, allowing clean re-initialization. Also marks CUDA unhealthy on unrecognized errors (catch-all handler). Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>1d373d6 -
Catch SDK-wrapped GPU errors that bypass CUDA error detection
The ZeroGPU SDK catches CUDA errors internally and re-raises its own exception type (e.g. "GPU task aborted") which didn't match our error patterns, causing the bare `raise` to propagate to the UI. Now: - Add "gpu task aborted" to CUDA error patterns - Log exception type/message for all GPU errors (aids debugging) - Replace bare `raise` with catch-all CPU fallback for unrecognized errors - Only timeouts still re-raise; everything else falls back to CPU Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>d2b3d8c -
Fix CUDA state poisoning by eliminating CUDA ops outside GPU leases
The root cause of persistent GPU failure was threefold: 1. _move_models_to_cpu() was called in error handlers OUTSIDE the GPU lease — model.to("cpu") requires CUDA access to copy from GPU, which poisons PyTorch's CUDA state permanently when no lease is active. 2. CPU fallback paths in vad.py and phoneme_asr.py moved shared models mid-inference via model_device_lock that only protected .to() calls, not the surrounding inference — allowing Thread B to yank models to CPU while Thread A was doing GPU inference. 3. _cleanup_after_gpu() called torch.cuda.empty_cache() at the lease boundary, risking CUDA errors during GPU deallocation. Key changes: - Hold model_device_lock for the ENTIRE GPU lease (inference + cleanup) to prevent concurrent device changes mid-inference - Remove all _move_models_to_cpu() calls from error handlers outside the GPU lease — CPU fallback works via per-thread quota flags - Replace model.to("cpu") in CPU fallback with cache invalidation + fre…0d7604b
-
Prevent CUDA state poisoning and add thread-safe GPU lifecycle management
Adds four fixes to prevent ZeroGPU worker_init failures from permanently corrupting the process CUDA state, which was causing GPU to stop working for all users until a full space restart: 1. Process-level CUDA health flag with 5-min cooldown — stops all GPU attempts after a CUDA error to prevent further poisoning 2. GPU lease cleanup — moves models to CPU and calls empty_cache() inside the lease before it is released, preventing stale CUDA references 3. Thread-safe model device transitions via RLock — prevents races where one thread's CPU fallback yanks models mid-inference on another thread 4. Switch usage logging audio codec from Opus to Vorbis for HF viewer compatibility Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>65f2050
-
Harden GPU fallback to prevent CUDA init from permanently poisoning process
Four fixes that prevent torch._C._cuda_init() from being called outside a ZeroGPU lease, which permanently breaks GPU for all users until restart: - Catch CUDA hardware errors (e.g. worker_init "No CUDA GPUs available") in gpu_with_fallback and fall back to CPU instead of re-raising - Replace torch.backends.cudnn.version() and torch.cuda.get_device_name() in _log_env_once with safe alternatives that don't trigger CUDA init - Force CPU device in transcribe_batch and detect_speech_segments when in CPU fallback mode, preventing shared model state from another GPU thread from triggering CUDA operations in the main process - Add try/except and is_user_forced_cpu guard to move_phoneme_asr_to_gpu Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>511d54d
-
Fix race condition where concurrent quota exhaustion permanently breaks GPU
GPU quota state was a process-global variable shared across request threads. When an unlogged user exhausted ZeroGPU quota, a concurrent request's reset_quota_flag() could clear the flag before the CPU fallback path checked it, causing model.to("cuda") outside a GPU context — permanently poisoning CUDA init for all users until space restart. Replace globals with threading.local() for per-request isolation and add RuntimeError safety net in ensure_models_on_gpu to prevent CUDA init from ever escaping. Also add row_group_size to parquet writes. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>47224bd
-
Restructure src/ for cleaner modularity
Create src/core/ for cross-cutting concerns (segment_types, quran_index, zero_gpu, usage_logger), move _dp_core.pyx and phonemizer_utils into alignment/, flatten single-file pipeline/ and mfa/ packages to top-level modules, and delete the segment_processor re-export façade and orphaned utils/ package. Update all 24 imports across 12 files. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>0351f22