QVGen icon indicating copy to clipboard operation
QVGen copied to clipboard

Training Script Issues

Open KamenB opened this issue 9 months ago • 2 comments

Hi, me again, thanks once more for the fantastic paper. I'm just in the process of getting the training going and noticed an issue regarding metadata generation in the dataset preparation script (prepare_dataset.py, line 497):

    metadata = [{"num_frames": num_frames, "height": height, "width": width}]

    data_folder_mapper_list = [
        (images, images_dir, lambda img, path: save_image(img[0], path), "png"),
        (image_latents, image_latents_dir, torch.save, "pt"),
        (videos, videos_dir, functools.partial(save_video, fps=fps), "mp4"),
        (video_latents, video_latents_dir, torch.save, "pt"),
        (prompts, prompts_dir, save_prompt, "txt"),
        (prompt_embeds, prompt_embeds_dir, torch.save, "pt"),
        (metadata, videos_dir, save_metadata, "txt"),
    ]
    filenames = [uuid.uuid4() for _ in range(batch_size)]

    for data, folder, save_fn, extension in data_folder_mapper_list:
        if data is None:
            continue
        for slice, filename in zip(data, filenames):
            if isinstance(slice, torch.Tensor):
                slice = slice.clone().to("cpu")
            path = folder.joinpath(f"{filename}.{extension}")
            save_fn(slice, path)

Metadata is a 1-object list, which means the line for slice, filename in zip(data, filenames): loops only once, with the first file in the filenames list. This results in all but the first video in the batch missing their corresponding metadata file. I fixed it on my side by changing the metadata creation to

metadata = [{"num_frames": num_frames, "height": height, "width": width} for _ in range(batch_size)]

P.S. If you have a preferred way to index these issues as I happen upon them, please let me know.

KamenB avatar Feb 03 '26 15:02 KamenB

Next is a slight concurrency issue (prepare_dataset.py, line 779):

    # 5. Complete distributed processing
    if world_size > 1:
        dist.barrier()
        dist.destroy_process_group()

    output_queue.put(None)
    save_thread.shutdown(wait=True)
    save_future.result()

When running this, the save_future.result() call in some processes was happening after the tmp folder was deleted by the main process, causing a crash. The fix was to move the process winddown to before the barrier:

    output_queue.put(None)
    save_thread.shutdown(wait=True)
    save_future.result()
    
    # 5. Complete distributed processing
    if world_size > 1:
        dist.barrier(device_ids=[local_rank])
        dist.destroy_process_group()

Side note: I was getting warnings that barrier didn't know the device id and was guessing it incorrectly, so I added it in as a parameter.

KamenB avatar Feb 03 '26 16:02 KamenB

Thanks for the suggestion. I think you could propose a PR as well.

Since I use the same resolution and frame count for all videos, the first issue should not cause any problems in practice. Also, due to policy constraints, we cannot open-source the filtered training data.

Harahan avatar Feb 03 '26 17:02 Harahan