Spaces:
Sleeping
Sleeping
Update js/app.py
Browse files94 unmodified lines9596979899100101102103104105187 unmodified lines2932942952962972982993003 unmodified lines30430530630730830931094 unmodified lines"""global _modelif _model is None:# Cap PyTorch intra-op threads to 2 (matching the Hugging Face Spaces free CPU# tier core limit) to prevent CPU CFS scheduler throttling. Capping inter-op# threads to 1 avoids overhead. This prevents thrashing and speeds up inference.torch.set_num_threads(2)torch.set_num_interop_threads(1)# Force Intel oneDNN (MKL-DNN) fast-path math.torch.backends.mkldnn.enabled = True187 unmodified lines# ββ 3. Separate (the expensive step) βββββββββββββββββββββββββββββββββββββββ# segment= is intentionally omitted: apply_model reads model.segment# (architecture-native chunk size) automatically.# overlap=0.25 (25 %) provides the default smooth segment crossfades for# optimal, studio-grade separation without boundary artifacts._N_THREADS = max(os.cpu_count() or 2, 2)with torch.no_grad():with torch.cpu.amp.autocast(enabled=True, dtype=torch.bfloat16):3 unmodified linesdevice="cpu",progress=False,split=True,overlap=0.25, # default high-quality overlapnum_workers=0, # no subprocesses on HF Spaces)[0] # drop batch dim: (stems, 2, samples)del wav_norm94 unmodified lines9596979899100101102103104105106107108109110187 unmodified lines2982993003013023033043053 unmodified lines30931031131231331431594 unmodified lines"""global _modelif _model is None:# Cap PyTorch threads to 2 only on Hugging Face Spaces to prevent CPU CFS throttling.# Otherwise (when running locally), utilize available physical CPU cores (up to 8)# for a massive 3-4x speedup on developer machines.if os.environ.get("HF_SPACE") or os.environ.get("SPACE_ID"):torch.set_num_threads(2)torch.set_num_interop_threads(1)else:n_threads = max(os.cpu_count() or 4, 2)torch.set_num_threads(min(n_threads, 8))torch.set_num_interop_threads(min(n_threads, 4))# Force Intel oneDNN (MKL-DNN) fast-path math.torch.backends.mkldnn.enabled = True187 unmodified lines# ββ 3. Separate (the expensive step) βββββββββββββββββββββββββββββββββββββββ# segment= is intentionally omitted: apply_model reads model.segment# (architecture-native chunk size) automatically.# overlap=0.1 (10 %) reduces CPU computation chunk overhead by 20 % with# negligible, virtually imperceptible quality loss on normal music tracks._N_THREADS = max(os.cpu_count() or 2, 2)with torch.no_grad():with torch.cpu.amp.autocast(enabled=True, dtype=torch.bfloat16):3 unmodified linesdevice="cpu",progress=False,split=True,overlap=0.1, # fast overlapnum_workers=0, # no subprocesses on HF Spaces)[0] # drop batch dim: (stems, 2, samples)del wav_norm
js/app.py+13-8