{"record":{"id":"7c0b42c5d4a85bf5","repo":"babysor/MockingBird","slug":"hparams-synthesis-batch-size-must-be-evenly-divi","errorCode":null,"errorMessage":"`hparams.synthesis_batch_size` must be evenly divisible by n_gpus!","messagePattern":"`hparams\\.synthesis_batch_size` must be evenly divisible by n_gpus!","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"models/synthesizer/synthesize.py","lineNumber":22,"sourceCode":"from models.synthesizer.models.tacotron import Tacotron\nfrom models.synthesizer.utils.symbols import symbols\nimport numpy as np\nfrom pathlib import Path\nfrom tqdm import tqdm\nimport sys\n\n\ndef run_synthesis(in_dir, out_dir, model_dir, hparams):\n    # This generates ground truth-aligned mels for vocoder training\n    synth_dir = Path(out_dir).joinpath(\"mels_gta\")\n    synth_dir.mkdir(parents=True, exist_ok=True)\n    print(str(hparams))\n\n    # Check for GPU\n    if torch.cuda.is_available():\n        device = torch.device(\"cuda\")\n        if hparams.synthesis_batch_size % torch.cuda.device_count() != 0:\n            raise ValueError(\"`hparams.synthesis_batch_size` must be evenly divisible by n_gpus!\")\n    else:\n        device = torch.device(\"cpu\")\n    print(\"Synthesizer using device:\", device)\n\n    # Instantiate Tacotron model\n    model = Tacotron(embed_dims=hparams.tts_embed_dims,\n                     num_chars=len(symbols),\n                     encoder_dims=hparams.tts_encoder_dims,\n                     decoder_dims=hparams.tts_decoder_dims,\n                     n_mels=hparams.num_mels,\n                     fft_bins=hparams.num_mels,\n                     postnet_dims=hparams.tts_postnet_dims,\n                     encoder_K=hparams.tts_encoder_K,\n                     lstm_dims=hparams.tts_lstm_dims,\n                     postnet_K=hparams.tts_postnet_K,\n                     num_highways=hparams.tts_num_highways,\n                     dropout=0., # Use zero dropout for gta mels\n                     stop_threshold=hparams.tts_stop_threshold,","sourceCodeStart":4,"sourceCodeEnd":40,"githubUrl":"https://github.com/babysor/MockingBird/blob/28dc5e14f12d7c754612af2fde8e78a4b03f8616/models/synthesizer/synthesize.py#L4-L40","documentation":"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.","triggerScenarios":"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.","commonSituations":"Multi-GPU machine where CUDA_VISIBLE_DEVICES isn't restricted to one device; default hparams batch size not adjusted to GPU count.","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"],"exampleFix":"# before\nsynthesis_batch_size: 1   # with 2 GPUs → ValueError\n\n# after\nsynthesis_batch_size: 2   # or CUDA_VISIBLE_DEVICES=0","handlingStrategy":"validation","validationCode":"import torch\nn = torch.cuda.device_count()\nassert hparams.synthesis_batch_size % n == 0 if n else True, \\\n    f'synthesis_batch_size must be divisible by {n}'","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Set CUDA_VISIBLE_DEVICES to control device_count explicitly","Derive batch sizes from device_count in launcher scripts"],"tags":["multi-gpu","batch-size","dataparallel","synthesis"],"backgroundTag":"batch-size-not-divisible-by-gpu-count","analyzedSha":"28dc5e14f12d7c754612af2fde8e78a4b03f8616","analyzedAt":"2026-08-27T02:26:53.589Z","schemaVersion":2},"datasetVersion":"2026-08-27T03:17:27.898Z"}