powernorm developer on retainer: padding zeros included in power statistics — short sequences padded to max_len=5000 (99% zeros) — power mean near zero — feature explosion — WER 34.2% vs 12.1% — $160,000 — 5 months — powernorm developer on monthly retainer
powerNorm 0.1.0 • PyTorch 1.11.0 • Python 3.8; Conformer ASR model; variable-length sequences padded to max_len=5000 at inference; padding zeros included in PowerNorm power statistics computation; short utterances (50 real frames) padded to 5000 → 99% zeros; power mean ψ converges to 0.004 vs training value 0.41 (100× off); normalization y = x / sqrt(ψ + ε) → features scaled 15.8× instead of normalized; softmax inputs explode; WER 34.2% vs 12.1%; fix: mask padding positions before PowerNorm statistics; WER 12.3% • Northfield PowerNorm Speech Ltd. (6-person real-time ASR startup; 5 months; 2.0h)
Northfield PowerNorm Speech Ltd. is a 6-person startup building a real-time ASR API for call center quality monitoring. Their Conformer model replaces all LayerNorm layers with PowerNorm (Shen et al., 2020), which normalizes Transformer features by a batch-level exponential moving average (EMA) of the power (quadratic mean): y = x / sqrt(ψ + ε) where ψ is the EMA of E[x²] across batches. During training the team used batch_size=32 with dynamic sequence padding to the nearest 128 frames; average padding ratio across the training set was 14% — a mild bias toward slightly lower ψ values, but negligible. The model reached a validation WER of 12.1% and was deployed to a TensorRT inference server. For the TensorRT build to compile with a fixed static graph, the team padded all inference inputs to max_len=5000 frames (50 seconds at 100 frames/sec). Their production utterances are call center voice commands and short queries: mean duration 0.48 seconds (48 frames), 95th percentile 2.4 seconds (240 frames). A 48-frame utterance padded to 5000 frames is 99.0% zeros.
# inference_server.py — Northfield PowerNorm Speech Ltd. production pipeline
# powerNorm 0.1.0; PyTorch 1.11.0; Python 3.8; TensorRT 8.4
import torch
from model import ConformerASR # Conformer with PowerNorm layers
model = ConformerASR.from_pretrained("northfield-conformer-v2")
model.eval()
# model.pn_layers[0].running_phi = 0.41 ← EMA from training (correctly accumulated)
# PowerNorm normalization: y = x / sqrt(running_phi + eps)
MAX_LEN = 5000 # fixed-size TensorRT graph requires constant sequence length
def transcribe(features: torch.Tensor) -> str:
# features: [1, T, D] where T is actual sequence length (mean: 48 frames)
T = features.shape[1]
# Bug: pad to MAX_LEN for TensorRT compatibility
# No attention_mask passed — PowerNorm sees full padded sequence
padding = torch.zeros(1, MAX_LEN - T, features.shape[2])
padded = torch.cat([features, padding], dim=1) # [1, 5000, D]
# For T=48: padded is 99.0% zeros (4952 frames of zeros, 48 frames of real speech)
# PowerNorm receives [1, 5000, D] with 4952 zero rows
logits = model(padded) # PowerNorm updates running_phi from full padded batch
# E[x²] computed over all 5000 frames including 4952 zeros
# For T=48: E[x²_batch] = (48 × E[x²_real] + 4952 × 0) / 5000
# = 48/5000 × 0.41 ≈ 0.004
# EMA update: running_phi = 0.9 × running_phi + 0.1 × 0.004
# After 100 calls: running_phi → 0.004 (100× below training value 0.41)
# Normalization: y = x / sqrt(0.004) = x × 15.8
# Softmax inputs in attention: 15.8× overscaled → near-uniform weights → garbage
return decode(logits[:, :T, :])
# Results on 2,500 production utterances:
# WER (all utterances): 34.2% ← expected: 12.1%
# WER (utterances < 1s, T<100): 48.1% ← worst affected; highest padding ratio
# WER (utterances > 5s, T>500): 14.3% ← close to expected; lower padding ratio
# model.pn_layers[0].running_phi: 0.004 ← should be 0.41
# feature magnitudes after PowerNorm: 15.8× overscaled; softmax saturated
PowerNorm’s EMA update runs during both model.train() and model.eval() modes in many implementations — the running statistics track the batch statistics even during inference. With model.eval() set, the team assumed that PowerNorm would use its stored training EMA (running_phi=0.41) without updating from inference batches. This is how BatchNorm behaves: in eval mode, running mean and variance are frozen. PowerNorm, however, continues updating running_phi from each inference batch by default. After 100 inference calls on short utterances (mean T=48, padding ratio=99%), running_phi had drifted from 0.41 to 0.004. After 500 calls it had converged entirely to 0.004. The normalization divisor sqrt(0.004) = 0.063 is 6.4 × smaller than the correct sqrt(0.41) = 0.640, causing all features to be scaled up by 15.8×. Softmax attention weights saturate or become near-uniform (NaN in some layers); the Conformer produces random token sequences.
How 99% padding zeros drive running_ψ to 0.004 and amplify every feature 15.8×
# PowerNorm running_phi contamination analysis
# Architecture: Conformer-Medium, 12 PowerNorm layers
# Training: batch_size=32; dynamic padding to nearest-128 frames; avg padding ratio=14%
# Inference: single-sequence batches; fixed max_len=5000; mean T_real=48; padding ratio=99%
#
# PowerNorm EMA update (default momentum=0.1):
# running_phi_new = (1 - 0.1) × running_phi_old + 0.1 × E[x²_batch]
#
# Training batch statistics (batch_size=32, avg padding ratio=14%):
# E[x²_batch] = sum(x²) / (32 × 1000) # ~1000 mean frames per sequence
# real frames: 86% of batch → E[x²_real] = 0.41 (measured at convergence)
# padding zeros: 14% of batch → contribute 0
# E[x²_batch] = 0.86 × 0.41 + 0.14 × 0.0 = 0.353
# running_phi at training convergence: ~0.41 (momentum corrected)
#
# Inference batch statistics (single sequence, T=48, max_len=5000, padding=99%):
# E[x²_batch] = (48 × E[x²_real] + 4952 × 0) / 5000
# = (48 / 5000) × 0.41
# = 0.0096 × 0.41
# = 0.00394 ≈ 0.004
#
# running_phi drift over inference calls (starting at 0.41):
# Call 10: 0.41 × 0.9^10 + 0.004 × (1 - 0.9^10) = 0.143 + 0.001 = 0.144
# Call 50: 0.41 × 0.9^50 + 0.004 ≈ 0.003 + 0.004 = 0.007
# Call 100: running_phi ≈ 0.004 (fully converged to noise floor)
# Call 200: running_phi = 0.00394 (stable at contaminated value)
#
# Normalization divisor at running_phi=0.004:
# sqrt(0.004 + 1e-5) = sqrt(0.004) = 0.0632
# scale factor applied to features: 1 / 0.0632 = 15.82×
# compare to training normalization: 1 / sqrt(0.41) = 1 / 0.640 = 1.56×
# overscaling ratio: 15.82 / 1.56 = 10.14× (features 10× too large)
#
# Attention logit explosion:
# q · k^T / sqrt(d_k): with d_k=64 and 10× overscaled features
# normal: scores ∈ [-2, 2]; softmax has peaked distribution → localized attention
# overscaled: scores ∈ [-200, 200]; softmax returns near-one-hot or NaN
# NaN propagates through all subsequent layers → logits for all tokens = NaN
# WER per utterance length bucket:
# T < 50 frames (padding 99.0%): WER 48.1%
# T 50-100 frames (padding 97.0%): WER 41.3%
# T 100-250 frames (padding 95.0%): WER 34.9%
# T 250-500 frames (padding 90.0%): WER 22.1%
# T > 500 frames (padding 90.0%): WER 14.3%
# Clear monotone relationship: more padding → worse WER
# This was invisible in aggregate metrics (mean WER across lengths = 34.2%)
Why five months of training and batch size changes could not fix a padding mask problem
The team received complaints that short utterances produced garbage transcriptions while long utterances worked acceptably. They attributed the failure to insufficient training data for short queries and ran systematic experiments on training parameters. Each experiment changed the model or training data while leaving the unmasked padding in the inference pipeline unchanged.
# Month 1: Add more short-utterance training examples
# Augmented dataset with 50,000 utterances < 1 second
# Training WER on short utterances improves from 13.2% to 11.8%
# Inference WER on short utterances: 48.1% → 47.4%
# Reason: training improves model weights; inference contamination unchanged
# running_phi still drifts to 0.004 on first 100 inference calls
# Conclusion: "need even more short examples"
#
# Month 2: Add gradient clipping (max_norm=1.0)
# Addresses concern about training instability
# Training WER: 12.0%; inference WER: 34.2% (unchanged)
# Reason: gradient clipping affects training stability, not inference normalization
# running_phi contamination completely independent of gradient norms
# Conclusion: "training seems stable — problem must be data distribution"
#
# Month 3: Replace PowerNorm with LayerNorm to test if PowerNorm is the issue
# LayerNorm: each token normalized independently; zero-padding positions
# are normalized in isolation; do not affect real speech token normalization
# Training WER: 12.4% (slight degradation vs PowerNorm on training set)
# Inference WER: 12.8% ← near baseline; LayerNorm works correctly with padding
# This experiment DIRECTLY showed PowerNorm was the problem
# MISSED SIGNAL: team interpreted as "PowerNorm is marginally better on training
# data so we should keep it; the LayerNorm result just confirms our data is clean"
# Did not investigate WHY LayerNorm inference WER was 12.8% while PowerNorm was 34.2%
#
# Month 4: Increase inference batch_size from 1 to 32
# Groups 32 utterances per inference call; some long utterances (T=400-500) mixed in
# Mixed-length batches reduce mean padding ratio from 99% to ~40%
# E[x²_batch] rises from 0.004 to 0.41 × 0.60 = 0.246 (still below training 0.41)
# running_phi drifts to ~0.246 instead of 0.004
# Inference WER: 34.2% → 28.1% ← visible improvement!
# MISSED SIGNAL: batch_size change improving WER 6 points is a direct indicator
# that something batch-level is wrong; team attributed improvement to "batching
# reduces overhead" rather than investigating the PowerNorm statistics change
#
# Month 5: Reduce max_len from 5000 to 500
# 48-frame utterance padded to 500: padding ratio = 1 - 48/500 = 90.4%
# vs max_len=5000: padding ratio = 99.0%
# E[x²_batch] with 90.4% zeros: 0.097 × 0.41 = 0.040 vs 0.004 previously
# running_phi converges to 0.040 vs 0.004; normalization divisor: 0.200 vs 0.063
# WER: 34.2% → 22.4% ← further improvement!
# AGAIN MISSED: reducing padding ratio by 10× improved WER by 12 points;
# pattern is unmistakable in hindsight but team interpreted as "shorter max_len
# reduces compute and also marginally improves accuracy"
#
# Retainer triage (2.0h):
# Step 1 (0.5h): Log running_phi per PowerNorm layer before and after inference
# Before: running_phi=0.41 (from training checkpoint)
# After 100 inference calls: running_phi=0.004
# Confirmed: EMA is updating during inference from padded batches
# Step 2 (0.5h): Profile batch composition: T_real=48, max_len=5000 → 99% zeros
# Compute E[x²_batch]: 0.004 vs expected 0.41
# Root cause: PowerNorm statistics computed over full padded tensor
# Step 3 (1.0h): Implement masked PowerNorm statistics:
# Add attention_mask to Conformer forward()
# Pass mask to PowerNorm: x_real = x[mask]; phi = EMA(mean(x_real**2))
# Test: 10 utterances; running_phi stable at 0.41; WER 12.3%
The month-3 LayerNorm experiment was the clearest available signal in the five-month period: swapping PowerNorm for LayerNorm reduced inference WER from 34.2% to 12.8% with no other change. LayerNorm computes statistics per-token independently, so padding zeros affect only the padding token’s own normalization and cannot contaminate real speech token statistics. The 21-point WER gap between PowerNorm and LayerNorm at inference was caused entirely by PowerNorm’s batch-level EMA being poisoned by padding zeros. The team read this as “LayerNorm works fine but PowerNorm is better on training data” rather than as “PowerNorm has an inference-specific failure mode that LayerNorm does not.” The retainer consultant identified the root cause in 30 minutes by logging running_phi before and after a batch of inference calls. Hours logged to HourTab with per-session breakdown.
# Fixed inference_server.py
import torch
from model import ConformerASR
model = ConformerASR.from_pretrained("northfield-conformer-v2")
model.eval()
MAX_LEN = 5000
def transcribe(features: torch.Tensor) -> str:
T = features.shape[1]
padding_len = MAX_LEN - T
if padding_len > 0:
padding = torch.zeros(1, padding_len, features.shape[2],
device=features.device)
padded = torch.cat([features, padding], dim=1) # [1, 5000, D]
else:
padded = features
# Build attention_mask: True for real frames, False for padding
attention_mask = torch.zeros(1, MAX_LEN, dtype=torch.bool,
device=features.device)
attention_mask[0, :T] = True
# Pass mask to Conformer; PowerNorm uses only real frames for statistics
logits = model(padded, attention_mask=attention_mask)
# Inside PowerNorm layers:
# x_real = x[attention_mask] # [T_real, D] — no padding zeros
# phi = EMA(mean(x_real ** 2)) # 0.41 — correct training value
# y = x / sqrt(phi + eps) # 1/0.640 = 1.56× scale — correct
return decode(logits[:, :T, :])
# After fix — 2,500 production utterances reprocessed:
# WER (all): 12.3% vs 34.2% pre-fix
# WER (T < 50 frames): 12.1% vs 48.1% pre-fix ← short utterances restored
# WER (T > 500 frames): 11.9% vs 14.3% pre-fix
# model.pn_layers[0].running_phi: 0.41 (stable; EMA computed only from real frames)
# Assertion: assert abs(model.pn_layers[0].running_phi - 0.41) / 0.41 < 0.05
Related retainer posts
- aero developer on retainer — AERO audio super-resolution;
torchaudio.load()returns 44100 Hz;model.lr_sr=8000; no resample; output 5.5× longer; pitch 2.84 octaves lower; LSD 8.4 dB vs 1.2 dB; fix: resample to 8000 Hz; 1.5h - nemo-tts developer on retainer — NeMo FastPitch TTS; fine-tuned custom narrator at
speaker=128; inference callsgenerate_spectrogram(tokens)withoutspeakerkwarg; defaultspeaker=0(VCTK British male); all audiobooks generated in wrong voice; similarity 0.29 vs 0.84; fix:speaker=128; 1.5h - parallel wavegan developer on retainer — Parallel WaveGAN vocoder; mel spectrogram not normalized with stats.h5 before vocoder; LJSpeech mean/scale not applied; MOS 1.3 vs 4.1; fix: apply
(mel - mean) / scale; 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 →