babysor/MockingBird · error · ValueError
`hparams.synthesis_batch_size` must be evenly divisible by n
Error message
`hparams.synthesis_batch_size` must be evenly divisible by n_gpus!
What it means
run_synthesis validates that synthesis_batch_size is a multiple of the number of visible CUDA devices, because the Tacotron synthesis loop shards batches across GPUs. If not divisible, DataParallel sharding would fail or drop samples.
Source
Thrown at models/synthesizer/synthesize.py:22
from models.synthesizer.models.tacotron import Tacotron
from models.synthesizer.utils.symbols import symbols
import numpy as np
from pathlib import Path
from tqdm import tqdm
import sys
def run_synthesis(in_dir, out_dir, model_dir, hparams):
# This generates ground truth-aligned mels for vocoder training
synth_dir = Path(out_dir).joinpath("mels_gta")
synth_dir.mkdir(parents=True, exist_ok=True)
print(str(hparams))
# Check for GPU
if torch.cuda.is_available():
device = torch.device("cuda")
if hparams.synthesis_batch_size % torch.cuda.device_count() != 0:
raise ValueError("`hparams.synthesis_batch_size` must be evenly divisible by n_gpus!")
else:
device = torch.device("cpu")
print("Synthesizer using device:", device)
# Instantiate Tacotron model
model = Tacotron(embed_dims=hparams.tts_embed_dims,
num_chars=len(symbols),
encoder_dims=hparams.tts_encoder_dims,
decoder_dims=hparams.tts_decoder_dims,
n_mels=hparams.num_mels,
fft_bins=hparams.num_mels,
postnet_dims=hparams.tts_postnet_dims,
encoder_K=hparams.tts_encoder_K,
lstm_dims=hparams.tts_lstm_dims,
postnet_K=hparams.tts_postnet_K,
num_highways=hparams.tts_num_highways,
dropout=0., # Use zero dropout for gta mels
stop_threshold=hparams.tts_stop_threshold,View on GitHub (pinned to 28dc5e14f1)
Solutions
- Set synthesis_batch_size to a multiple of n_gpus (e.g. n_gpus, 2*n_gpus, ...)
- Or restrict to one GPU: export CUDA_VISIBLE_DEVICES=0 so device_count()==1
- Re-run with the adjusted hparams override string
Example fix
# before synthesis_batch_size: 1 # with 2 GPUs → ValueError # after synthesis_batch_size: 2 # or CUDA_VISIBLE_DEVICES=0
Defensive patterns
Strategy: validation
Validate before calling
import torch
n = torch.cuda.device_count()
assert hparams.synthesis_batch_size % n == 0 if n else True, \
f'synthesis_batch_size must be divisible by {n}' Prevention
- Set CUDA_VISIBLE_DEVICES to control device_count explicitly
- Derive batch sizes from device_count in launcher scripts
When it happens
Trigger: Running synthesis with torch.cuda.is_available() and hparams.synthesis_batch_size % torch.cuda.device_count() != 0, e.g. batch_size=1 with 2 GPUs.
Common situations: Multi-GPU machine where CUDA_VISIBLE_DEVICES isn't restricted to one device; default hparams batch size not adjusted to GPU count.
Related errors
AI-assisted analysis of babysor/MockingBird@28dc5e14f1 (2026-08-27).
Data as JSON: /api/errors/7c0b42c5d4a85bf5.
Report an issue: GitHub.