Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Problem about Multi-GPU-Train architecture #112

@zsnoob

Description

@zsnoob

In main_task_retrieval.py, fuction "train_epoch", we can see:

        if n_gpu > 1:
            loss = loss.mean()  # mean() to average on multi-gpu.

But in modeling.py, there is:

        if self.training:
            visual_output = allgather(visual_output, self.task_config)
            video_mask = allgather(video_mask, self.task_config)
            sequence_output = allgather(sequence_output, self.task_config)
            torch.distributed.barrier()

which means ALL GPUs' results get synchronized here. For instance, when my batch size is 128, i have 2 GPU to train the model and before the code above, every output's 0th dimension is 64, half of 128. And after this code block, they will be aggregated and output's size will be 128. So, when we get loss value in main_task, there is only a scalar tensor. Looks like there is no need to use "loss.mean()".
I have some print results:

1700469492366

        if n_gpu > 1:
            print(loss)
            print(loss.size())
            loss = loss.mean()  # mean() to average on multi-gpu.
            print(loss)
            print(loss.size())

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions