Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Problem about Multi-GPU-Train architecture #112

Open
zsnoob opened this issue Nov 20, 2023 · 0 comments
Open

Problem about Multi-GPU-Train architecture #112

zsnoob opened this issue Nov 20, 2023 · 0 comments

Comments

@zsnoob
Copy link

zsnoob commented Nov 20, 2023

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())
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant