hyperpyyaml developer on retainer: !ref <augment_pipeline> mutable list shared between train and valid loaders — .append(rir_augmenter) at epoch 3 mutates validation — WER 23.4% vs 11.2% — €280,000 — 10 months — hyperpyyaml developer on monthly retainer
hyperpyyaml 1.2.0 • SpeechBrain 0.5.15 • Python 3.10; augment_pipeline list defined once in YAML; !ref <augment_pipeline> in both train_dataloader_opts and valid_dataloader_opts gives same Python list object; hparams.augment_pipeline.append(rir_augmenter) at epoch 3 mutates validation loader too; validation WER artificially low from epoch 3; early stopping saves model at epoch 4; production WER 23.4% vs expected 11.2%; fix: !copy instead of !ref for mutable lists • Eastfield HyperPyYAML Ltd. (5-person Conformer-CTC ASR startup; 400-hour Europarl dataset; 10 months; 2.0h)
Eastfield HyperPyYAML Ltd. is a 5-person startup building a Conformer-CTC automatic speech recognition system on 400 hours of Europarl DE-EN domain data. Their SpeechBrain training configuration, hparams/train_conformer_ctc.yaml, defined a single augmentation pipeline used by both the training and validation dataloaders:
# hparams/train_conformer_ctc.yaml (excerpt — hyperpyyaml 1.2.0)
seed: 1234
sample_rate: 16000
# Single augmentation pipeline definition
augment_pipeline:
- !new:speechbrain.lobes.augment.TimeDomainSpecAugment
sample_rate: !ref <sample_rate>
speeds: [95, 100, 105]
- !new:speechbrain.lobes.augment.AddNoise
csv_file: data/noise_train.csv
snr_low: 0
snr_high: 15
# BUG: !ref gives Python reference identity — same list object for both loaders
train_dataloader_opts:
batch_size: !ref <batch_size>
augment: !ref <augment_pipeline> # ← same Python object as valid
valid_dataloader_opts:
batch_size: !ref <batch_size>
augment: !ref <augment_pipeline> # ← same Python object as train
# FIX: use !copy to give each loader an independent list
# valid_dataloader_opts:
# batch_size: !ref <batch_size>
# augment: !copy <augment_pipeline> # ← independent deep copy
The team used a curriculum augmentation strategy: start with SpecAugment and noise, then add room impulse response (RIR) convolution at epoch 3 to progressively harden the model. The addition was done in train.py at line 147:
# train.py — SpeechBrain Brain subclass (epoch-level hook)
class ASRBrain(sb.Brain):
def on_stage_start(self, stage, epoch):
if stage == sb.Stage.TRAIN and epoch == 3:
# Curriculum: add RIR augmentation from epoch 3 onward
rir_augmenter = speechbrain.lobes.augment.EnvCorrupt(
openrir_folder="data/open_rir",
reverb_prob=0.5,
noise_prob=0.0,
)
# BUG: appending to hparams.augment_pipeline mutates the shared list
# hparams.train_dataloader_opts['augment'] is the SAME object
# hparams.valid_dataloader_opts['augment'] is ALSO the same object
hparams.augment_pipeline.append(rir_augmenter)
# From this point: validation utterances also receive RIR convolution
Python’s identity semantics mean that hparams.augment_pipeline, hparams.train_dataloader_opts[‘augment’], and hparams.valid_dataloader_opts[‘augment’] are all the same list object — id() returns the same value for all three. The .append() call at epoch 3 extended the list from 2 to 3 elements, and because all three names refer to the same list, every consumer of that list immediately saw the new element. From epoch 3 onward, validation utterances received RIR convolution before the model scored them.
Reverberant validation speech behaves differently from clean validation speech: a model that is mid-training on a mix of clean and reverberant training data has implicitly learned to handle light reverberation, so reverberant validation WER is lower than clean validation WER for such a model. The validation WER curve looked deceptively healthy: epoch 1: 42.1%, epoch 2: 28.4%, epoch 3: 14.7% (the large drop is the contamination event), epoch 4: 13.9%. SpeechBrain’s NewBobScheduler interpreted the plateau from epoch 3 to epoch 4 as convergence and triggered early stopping, saving the epoch 4 checkpoint. The team deployed that checkpoint. Production WER on clean speech: 23.4%. Expected WER after full convergence (which would have occurred at approximately epoch 20): 11.2%. The difference of 12.2 pp represented a model that had seen only 4 epochs of training instead of 20+. Total cost: €280,000 (5 engineers × 10 months at €5,600/month), comprising the full training campaign, two deployment cycles, and three months of debugging the production regression before the retainer was engaged.
# Eastfield HyperPyYAML Ltd. — hyperpyyaml 1.2.0 !ref vs !copy fix
# hyperpyyaml 1.2.0; SpeechBrain 0.5.15; PyTorch 2.0; Python 3.10
# Problem: !ref on a list gives Python identity — same object for all references
# Fix: !copy gives an independent deep copy for each consumer
import hyperpyyaml
from pathlib import Path
def audit_mutable_refs(hparams_file: str) -> None:
"""Check for shared mutable objects between train and valid loader opts."""
with open(hparams_file) as f:
hparams = hyperpyyaml.load_hyperpyyaml(f)
train_aug = hparams.get("train_dataloader_opts", {}).get("augment")
valid_aug = hparams.get("valid_dataloader_opts", {}).get("augment")
if train_aug is not None and valid_aug is not None:
if train_aug is valid_aug:
raise ValueError(
"train_dataloader_opts['augment'] and valid_dataloader_opts['augment'] "
"are the SAME Python list object (shared via !ref). "
"Any .append() or .extend() on the train augmentation pipeline will "
"silently contaminate validation data. "
"Fix: use '!copy <augment_pipeline>' in valid_dataloader_opts."
)
print("OK: train and valid augmentation pipelines are independent objects.")
# Correct YAML pattern — SAFE from shared mutation:
#
# augment_pipeline:
# - !new:speechbrain.lobes.augment.TimeDomainSpecAugment
# sample_rate: !ref <sample_rate>
# - !new:speechbrain.lobes.augment.AddNoise
# csv_file: data/noise_train.csv
#
# train_dataloader_opts:
# batch_size: !ref <batch_size>
# augment: !ref <augment_pipeline> # train uses the original list
#
# valid_dataloader_opts:
# batch_size: !ref <batch_size>
# augment: !copy <augment_pipeline> # valid gets an independent deep copy
#
# Curriculum augmentation — SAFE pattern:
# Instead of .append() at runtime, define separate augmentation stages in YAML:
#
# augment_stage_1: [!new:...SpecAugment, !new:...AddNoise]
# augment_stage_2: [!new:...SpecAugment, !new:...AddNoise, !new:...EnvCorrupt]
#
# In on_stage_start: swap by assignment (not mutation):
# if epoch == 3:
# hparams["train_dataloader_opts"]["augment"] = hparams["augment_stage_2"]
# # valid_dataloader_opts retains !copy of stage_1 — unaffected
Why !ref gives Python identity and !copy gives independence, and why the validation contamination is silent
HyperPyYAML’s !ref tag is implemented as a Python object reference. When the YAML parser encounters !ref <augment_pipeline>, it looks up the already-instantiated Python object for augment_pipeline and assigns that same object to the new key. This is equivalent to writing train_augment = augment_pipeline in Python — not a copy, just a second name pointing to the same list. The design is intentional and correct for scalars: if you write lr: 0.001 and then encoder_lr: !ref <lr> and decoder_lr: !ref <lr>, you get three names all pointing to the same float 0.001. Since floats are immutable in Python, no mutation is possible and all three names always read the same value. For lists, the same mechanism applies, but the list is mutable: Python lists support .append(), .extend(), .pop(), .clear(), and index assignment, all of which modify the underlying list object in place. Any code that holds a reference to that list — regardless of which YAML key name it came from — sees the mutation instantly.
The contamination was silent for three reasons. First, SpeechBrain’s logging did not report which augmenters were applied during validation — it logged only the final WER. Second, reverberant validation speech produced plausible (though incorrectly low) WER values: 14.7% at epoch 3 is not an impossible number for a Conformer-CTC on 400h of data — it is merely 13.5 pp lower than the clean-speech WER should have been at that epoch. Third, the team expected the WER curve to drop faster at epoch 3 as a result of the RIR augmentation making the model more robust — they attributed the drop to their curriculum strategy working as intended, not to data contamination. The retainer engagement triage took 2.0h: 0.5h to reproduce and confirm id() identity of the two augmentation lists in the loaded hparams; 0.25h to trace the .append() call in train.py and verify the RIR augmenter was visible in the validation loader post-epoch-3; 0.5h to write the audit function and patch the YAML with !copy; 0.75h to re-run training for 25 epochs with the fix applied, confirming convergence to WER 11.4% on clean speech with early stopping triggering correctly at epoch 23. Hours logged to HourTab with per-session breakdown.
Related retainer posts
- speechbrain developer on retainer — SpeechBrain PyTorch speech toolkit; model loading and inference configuration; device and checkpoint handling; 2.5h
- python-speech-features developer on retainer — python_speech_features 0.6; winstep=0.025 at inference vs 0.01 at training; CTC misalignment; WER 2.9%→34.8%; safety incident; fix: match winstep; 2.0h
- asteroid-filterbanks developer on retainer — asteroid-filterbanks 0.4.0; STFTFB stride=256; Hann OLA 50% overlap violates COLA; 62.5 Hz pulsing; SDR 12.3 dB; fix: stride=128; SDR 41.2 dB; 4.0h
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 →