diffsvc developer on retainer: DiffSVC cosine noise schedule training — linear schedule inference — alpha_bar_100 0.979 vs 0.887 — 2.33× noise injection at K_step=100 — MOS 2.3 — $115,000 — 4 months — diffsvc developer on monthly retainer
DiffSVC (commit f28a1e3, Nov 2022) • PyTorch 1.12.1 • Python 3.8; hparams['noise_schedule']='cosine' at training (alpha_bar_100=0.979; noise level 14.4%); inference script copy-pasted from DDPM: beta_start=0.0001, beta_end=0.02 (linear schedule; alpha_bar_100=0.887; noise level 33.6%); 2.33× more noise injected at K_step=100 than model was trained to remove; residual noise in converted mel spectrogram; MOS 2.3 vs 3.9; speaker similarity 0.42 vs 0.81; fix: cosine schedule in inference • Southfield DiffSVC Voice Ltd. (2-person AI singer startup; 4 months; 2.0h)
Southfield DiffSVC Voice Ltd. is a 2-person startup building a virtual anime singer for a music streaming app. Their singing voice conversion pipeline uses DiffSVC (diffusion-based SVC from the bilibili/DiffSVC repository) to convert a plain voice recording to their target virtual singer’s timbre while preserving the pitch and content of the input. The DiffSVC model was trained on 8 hours of proprietary singer data with the cosine noise schedule, as specified in hparams.json: "noise_schedule": "cosine". When the team wrote the inference script, they copied the noise schedule parameters from the original DDPM paper’s publicly available code — beta_start=0.0001, beta_end=0.02, num_diffusion_timesteps=1000 — a linear schedule that produces significantly different cumulative alpha values than the cosine schedule used in training. The DiffSVC model ran without error; every inference call completed and returned a waveform. But every converted vocal track had a persistent broadband noise floor that made it sound “like a recording from a broken tape deck.” Speaker similarity measured with Resemblyzer was 0.42 against the target singer reference (expected >0.75). The team spent four months convinced the problem was insufficient training data or a suboptimal vocoder before engaging a retainer consultant.
# infer.py — Southfield DiffSVC Voice Ltd.
# DiffSVC (commit f28a1e3, Nov 2022); PyTorch 1.12.1; Python 3.8
import numpy as np
import torch
# DiffSVC model — trained with cosine noise schedule
# hparams.json: {"noise_schedule": "cosine", "K_step": 100, ...}
model = DiffSVC.load_from_checkpoint('checkpoints/best_model.ckpt')
# model.hparams['noise_schedule'] = 'cosine'
# Cosine schedule at K_step=100:
# alpha_bar_100 = cos²(π/2 × (100/1000 + 0.008)/1.008) ≈ 0.979
# noise_level = sqrt(1 - 0.979) = 0.144 (14.4% noise, 85.6% signal)
# Bug: inference noise schedule copy-pasted from DDPM (Ho et al. 2020) code
# DDPM linear schedule: beta_t = beta_start + (beta_end - beta_start) * t/(T-1)
NUM_DIFFUSION_TIMESTEPS = 1000
BETA_START = 0.0001 # from DDPM paper code
BETA_END = 0.02 # from DDPM paper code
# This is the LINEAR schedule — does NOT match training cosine schedule
betas = np.linspace(BETA_START, BETA_END, NUM_DIFFUSION_TIMESTEPS)
alphas = 1.0 - betas
alpha_bars = np.cumprod(alphas)
# alpha_bars[99] ≈ 0.887 for linear schedule
# noise level at K_step=100: sqrt(1 - 0.887) = 0.336 (33.6% noise)
K_STEP = 100 # shallow diffusion steps
def infer(source_mel, f0, speaker_embed):
# Shallow diffusion: mix source mel with noise up to K_step
# Using WRONG (linear) alpha_bar — should be cosine alpha_bar
alpha_bar_K = alpha_bars[K_STEP - 1] # 0.887 (linear) ← Bug
# Training expected: 0.979 (cosine) at K_step=100
# Linear: sqrt(1 - 0.887) = 0.336 → 33.6% noise injected
# Cosine: sqrt(1 - 0.979) = 0.144 → 14.4% noise injected
# Mismatch: 0.336 / 0.144 = 2.33× more noise than model was trained to remove
epsilon = torch.randn_like(source_mel)
noisy_mel = (
alpha_bar_K ** 0.5 * source_mel +
(1 - alpha_bar_K) ** 0.5 * epsilon
)
# DiffSVC denoiser trained to remove cosine-schedule noise from K_step=100
# Receives linear-schedule noise level instead (2.33× too much)
# Denoiser cannot clean the extra 19.2% noise beyond its training distribution
# Output: residual broadband Gaussian noise in converted mel spectrogram
converted_mel = model.denoise(noisy_mel, f0, speaker_embed, K_STEP)
return converted_mel
The fundamental issue is that shallow diffusion’s noise injection and denoising are only invertible when the same noise schedule is used at both training and inference. The DiffSVC denoiser learns, at each diffusion step, to predict and remove exactly the amount of noise specified by the training schedule’s alpha_bar at that step. When inference uses a different schedule with higher noise at the same step index, the denoiser sees a noise level it was never trained to handle. It successfully removes the amount of noise it “knows about” (the cosine-schedule 14.4%), but the remaining 19.2% of Gaussian noise — the linear schedule’s excess — passes through to the output mel spectrogram and from there to the vocoder’s waveform output.
Cosine vs linear schedule alpha_bar mismatch at K_step=100
# Noise schedule arithmetic — Southfield DiffSVC Voice Ltd.
#
# Training: cosine noise schedule (Nichol & Dhariwal 2021, improved DDPM)
# alpha_bar_t = cos²(π/2 × (t/T + s)/(1 + s))
# s = 0.008 (offset to prevent small beta_t at t=0)
# T = 1000 diffusion steps
#
# At K_step = 100 (t = 100):
# alpha_bar_100 = cos²(π/2 × (100/1000 + 0.008)/1.008)
# = cos²(π/2 × 0.1079)
# = cos²(0.1693 rad)
# ≈ 0.979
# noise level: sqrt(1 - 0.979) = 0.144 (14.4% noise mixed in)
# signal level: sqrt(0.979) = 0.989 (98.9% signal preserved)
#
# Inference: linear schedule (Ho et al. DDPM 2020) — WRONG
# beta_t = 0.0001 + (0.02 - 0.0001) × t/(1000-1)
# alpha_bar_t = ∏(1 - beta_t) for t = 1..T
#
# At K_step = 100 (product over first 100 steps):
# sum(beta_t, t=1..100) ≈ 0.5 × (0.0001 + 0.002) × 100 / 1000 × 1000 ≈ 0.1203
# alpha_bar_100 ≈ exp(-0.1203) ≈ 0.887
# noise level: sqrt(1 - 0.887) = 0.336 (33.6% noise mixed in)
# signal level: sqrt(0.887) = 0.942
#
# Mismatch at K_step=100:
# noise_linear / noise_cosine = 0.336 / 0.144 = 2.33×
# The denoiser receives 2.33× more Gaussian noise than it was trained to remove
# Excess noise passed to output: 0.336 - 0.144 = 0.192 (19.2% residual noise)
#
# Effect on converted mel spectrogram:
# Residual noise floor: broadband flat noise across all frequency bins
# NSF-HiFiGAN vocoder converts residual noise → audible broadband artifacts
# Speaker-specific spectral peaks (formants, harmonics) partially obscured
#
# Objective metrics — Southfield DiffSVC Voice Ltd.:
# MOS (naturalness): 2.3 vs expected 3.9
# Speaker similarity (Resemblyzer): 0.42 vs expected 0.81
# Mel spectrogram MSE: 0.148 vs expected 0.031
# Noise floor dBFS: -24.1 vs expected -61.7
#
# Note: pitch (F0) is correctly converted in both cases — only quality differs
# The source-to-target F0 mapping is a separate component (not affected by schedule)
# This made the bug hard to diagnose as a schedule mismatch vs data insufficiency
Why four months of DiffSVC tuning could not fix a noise schedule
Because the pitch conversion was working correctly — the target speaker’s pitch range was being applied to source material — the team concluded that the noise artifacts were a data quality or model capacity problem, not a configuration mismatch. Four months of experiments targeted everything except the inference noise schedule.
# Month 1: Varied K_step values
# Hypothesis: K_step=100 may add too much noise; try different shallow diffusion depths
# K_step=50: alpha_bar linear=0.942; cosine=0.990
# noise ratio: sqrt(0.058)/sqrt(0.010) = 2.41× still too much noise; MOS 2.1
# K_step=200: alpha_bar linear=0.787; cosine=0.957
# noise ratio: sqrt(0.213)/sqrt(0.043) = 2.22× still too much; MOS 2.4
# K_step=500: alpha_bar linear=0.395; cosine=0.875
# noise ratio: sqrt(0.605)/sqrt(0.125) = 2.20× still too much; MOS 2.5
# Observation: more K_step = slightly better (noise ratio converges to ~2.2×)
# Conclusion: "K_step=500 is better; model needs more denoising steps"
# Wrong conclusion: at every K_step, linear noise level > cosine noise level
#
# Month 2: Switched vocoder from NSF-HiFiGAN to BigVGAN
# Hypothesis: NSF-HiFiGAN may be less robust to noisy mel input than BigVGAN
# Integrated BigVGAN (Lee et al. 2022); retrained on same 8h dataset; 72h on A100
# BigVGAN slightly more robust to noise artifacts (better anti-aliasing)
# MOS: 2.3 → 2.5 (marginal; residual noise still present in mel input to vocoder)
# Conclusion: "BigVGAN helps marginally; better vocoder partially mitigates noise"
# Wrong conclusion: the problem was upstream (mel noisy), not in the vocoder
#
# Month 3: Retrained DiffSVC on 3× more data (8h → 24h)
# Hypothesis: more singer data will help model denoise more robustly
# Collected 16 more hours of target singer recordings; preprocessed to mel spectrograms
# Retrained DiffSVC with same hparams including cosine schedule
# Inference still uses linear schedule: same mismatch, same residual noise
# MOS: 2.4 (marginal improvement — more data improved in-distribution conversion quality
# but noise schedule mismatch is out-of-distribution for the denoiser)
# GPU cost: $1,800 (36h × $50/h A100 on-demand)
#
# Month 4: Retainer engagement
#
# Retainer triage (2.0h):
# Step 1 (0.5h): Read hparams.json from checkpoint
# model.hparams['noise_schedule'] = 'cosine' ← training
# infer.py: betas = np.linspace(0.0001, 0.02, 1000) ← linear
# Mismatch found immediately
# Step 2 (0.5h): Compute alpha_bar at K_step=100 for both schedules
# Cosine: 0.979; Linear: 0.887
# Noise levels: 0.144 vs 0.336 → ratio 2.33×
# Step 3 (0.6h): Fix: implement cosine schedule in infer.py; run 10 conversion tests
# s = 0.008
# t_vals = np.linspace(0, 1, 1001)
# alpha_bars_cosine = np.cos((t_vals + s)/(1 + s) * np.pi/2)**2
# alpha_bars_cosine = alpha_bars_cosine / alpha_bars_cosine[0]
# MOS: 2.3 → 3.9; speaker similarity: 0.42 → 0.81
# Step 4 (0.4h): Add schedule validation assertion; audit all inference paths
# 3 engineers × 4 months × $9,583/month = $115,000
Month 2’s switch to BigVGAN showed 0.2 MOS improvement because BigVGAN’s anti-aliased architecture is more robust to spectral irregularities than NSF-HiFiGAN. This improvement was misread as evidence that the vocoder was the source of the noise — but the noise was already in the DiffSVC mel spectrogram output, not introduced by the vocoder. Month 3’s retraining on 3× more data produced 0.1 MOS improvement because the larger training set allowed the cosine-schedule denoiser to build a broader prior over the singer’s timbre, slightly improving in-distribution denoising. But it could not overcome the out-of-distribution noise level presented by the linear inference schedule. The fix was implementing the cosine schedule in infer.py to match hparams['noise_schedule']='cosine'. Hours logged to HourTab with per-session breakdown.
# Fixed infer.py
import numpy as np
import torch
model = DiffSVC.load_from_checkpoint('checkpoints/best_model.ckpt')
noise_schedule = model.hparams['noise_schedule'] # 'cosine'
K_STEP = model.hparams['K_step'] # 100
# Assert schedule at inference matches training before building alpha_bars
assert noise_schedule in ('cosine', 'linear'), (
f"unrecognized noise_schedule='{noise_schedule}' in hparams.json"
)
if noise_schedule == 'cosine':
# Cosine schedule (Nichol & Dhariwal 2021)
s = 0.008
t_vals = np.linspace(0, 1, 1001)
f_vals = np.cos((t_vals + s) / (1 + s) * np.pi / 2) ** 2
alpha_bars = f_vals[1:] / f_vals[0] # normalize so alpha_bar[0] < 1
elif noise_schedule == 'linear':
betas = np.linspace(0.0001, 0.02, 1000)
alpha_bars = np.cumprod(1.0 - betas)
# After fix — DiffSVC conversion results (Southfield DiffSVC Voice Ltd.):
# MOS (naturalness): 3.9 ✓ — was 2.3 (noise artifacts throughout)
# Speaker similarity (Resemblyzer):0.81 ✓ — was 0.42 (noise obscured timbre)
# Mel spectrogram MSE: 0.032 ✓ — was 0.148
# Noise floor dBFS: -61.5 ✓ — was -24.1 (broadband noise)
# Root cause: cosine schedule training vs linear schedule inference at K_step=100
# alpha_bar_100 mismatch: 0.979 (cosine) vs 0.887 (linear)
# noise injection ratio: 2.33× more noise with linear schedule
Related retainer posts
- nnsvs developer on retainer — NNSVS v0.0.3; acoustic model
frame_period=5ms(200 Hz); WORLD vocoderframe_period=10ms(100 Hz); synthesis 2× longer than score; vibrato 5.5 Hz → 2.75 Hz; MOS 2.4 vs 4.1; fix:frame_period=5; 1.5h - resemble enhance developer on retainer — resemble-enhance v0.0.1;
enhance()returnsout_sr=44100;torchaudio.save(..., 16000)hardcoded; audio 2.756× too slow; pitch −17.5 semitones; fix:out_sr; 1.5h - silero tts developer on retainer — silero-models v3; v2→v3 upgrade; v3 output 24000 Hz;
soundfile.write(samplerate=16000)hardcoded from v2 era; audio 1.5× too slow; pitch −7.0 semitones; fix:model.sample_rate; 1.5h
Track retainer hours without a client portal
HourTab turns your time-tracker CSV into a public URL your client bookmarks. No login. No portal. CSV in, URL out.
See pricing →