{"record":{"id":"5171594c02e37ebf","repo":"open-mmlab/mmdetection","slug":"only-num-videos-videos-loaded-but-self-world-si","errorCode":null,"errorMessage":"only {num_videos} videos loaded,but {self.world_size} gpus were given.","messagePattern":"only (.+?) videos loaded,but (.+?) gpus were given\\.","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"mmdet/datasets/samplers/track_img_sampler.py","lineNumber":95,"sourceCode":"            'exist in test mode'\n            video_indices = self.dataset.repeat_indices\n            for index in video_indices:\n                self.indices.extend([(index, frame_ind) for frame_ind in range(\n                    ori_dataset.get_len_per_video(index))])\n        else:\n            assert isinstance(\n                self.dataset, BaseVideoDataset\n            ), 'TrackImgSampler is only supported in BaseVideoDataset or '\n            'dataset wrapper: ClassBalancedDataset and ConcatDataset, but '\n            f'got {type(self.dataset)} '\n            self.test_mode = self.dataset.test_mode\n            num_videos = len(self.dataset)\n\n            if self.test_mode:\n                # in test mode, the images belong to the same video must be put\n                # on the same device.\n                if num_videos < self.world_size:\n                    raise ValueError(f'only {num_videos} videos loaded,'\n                                     f'but {self.world_size} gpus were given.')\n                chunks = np.array_split(\n                    list(range(num_videos)), self.world_size)\n                for videos_inds in chunks:\n                    indices_chunk = []\n                    for video_ind in videos_inds:\n                        indices_chunk.extend([\n                            (video_ind, frame_ind) for frame_ind in range(\n                                self.dataset.get_len_per_video(video_ind))\n                        ])\n                    self.indices.append(indices_chunk)\n            else:\n                for video_ind in range(num_videos):\n                    self.indices.extend([\n                        (video_ind, frame_ind) for frame_ind in range(\n                            self.dataset.get_len_per_video(video_ind))\n                    ])\n","sourceCodeStart":77,"sourceCodeEnd":113,"githubUrl":"https://github.com/open-mmlab/mmdetection/blob/cfd5d3a985b0249de009b67d04f37263e11cdf3d/mmdet/datasets/samplers/track_img_sampler.py#L77-L113","documentation":"In test mode, mmdet's video track img sampler must place all images of one video on the same GPU, so it needs at least as many videos as distributed ranks. With fewer videos than world_size, some rank would receive an empty chunk and the run aborts with this ValueError.","triggerScenarios":"Distributed testing (torchrun/mmlauncher with N processes) of a tracking dataset (e.g. MOT17 via VideoSampler) that contains fewer videos than N — e.g. 2 test videos launched on 8 GPUs.","commonSituations":"Running multi-GPU eval on a small validation subset, a custom tracking dataset with 1-2 videos, or single-video demo scripts accidentally launched with distributed settings; world_size derived from env without matching dataset size.","solutions":["Reduce the number of GPUs/processes to be <= number of test videos (often 1 for small sets)","Add more videos to the dataset split if you truly need multi-GPU eval","Ensure you are not accidentally in test_mode with a distributed launcher for single-video inference; use non-distributed single-process eval instead"],"exampleFix":"# before\ntorchrun --nproc_per_node=8 tools/test.py config.py ckpt.pth  # dataset has 2 videos\n# after\ntorchrun --nproc_per_node=2 tools/test.py config.py ckpt.pth  # or 1 process","handlingStrategy":"validation","validationCode":"num_videos = len(track_dataset)\nworld_size = int(os.environ.get('WORLD_SIZE', 1))\nassert num_videos >= world_size, f'{num_videos} videos < {world_size} GPUs; reduce nproc_per_node'","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Match nproc_per_node to the number of test videos in tracking evals (use 1 for small sets)","Check len(dataset) before launching distributed test jobs on subsets"],"tags":["mmdet","tracking","distributed","world-size","video-sampler"],"backgroundTag":"distributed-world-size-mismatch","analyzedSha":"cfd5d3a985b0249de009b67d04f37263e11cdf3d","analyzedAt":"2026-08-27T20:54:20.183Z","schemaVersion":2},"datasetVersion":"2026-08-28T00:17:15.603Z"}