NVIDIA / NVIDIA/Megatron-LM

[QUESTION]Why are inputs to ColumnParallelLinear different across ranks in register_forward_hook and register_forward_pre_hook

Open
#1,722 0 comments 0 reactions 0 assignees View on GitHub
question
Dominant language
Python
Stars
17.9k
Forks
4.5k
Avg merge
4d 6h
Merged PRs (30d)
271

Description

Hi Megatron-LM team,

I’m trying to check the input consistency of ColumnParallelLinear across tensor parallel ranks.
Specifically, I registered both a register_forward_hook and a register_forward_pre_hook to capture the input tensors on each rank.

However, when I compare the inputs captured by these hooks on different tensor parallel ranks, I find that they become different after some iterations.

Here is the code I use to check the input consistency across ranks:
```
def check_input_same(
module: torch.nn.Module,
input_: list[torch.Tensor],
output: list[torch.Tensor] | None = None,
) -> None:
"""Hook for saving the input during the forward pass of a module."""
input_tensor = input_[0] if isinstance(input_, list) else input_
input_tensor = input_tensor[0]
all_input = input_tensor.clone().detach()
torch.distributed.all_reduce(all_input)
if torch.allclose(all_input, input_tensor * torch.distributed.get_world_size(), rtol=1e-5, atol=1e-5):
print(f"Input is the same at layer {self._layers[module][0]} at hook.")
else:
print(f"Input is NOT the same at layer {self._layers[module][0]} at hook.")
```

My understanding was that ColumnParallelLinear is supposed to receive identical input on all tensor parallel ranks.
Why would the input tensors captured by register_forward_hook and register_forward_pre_hook be different on different ranks?

Is this expected, or does it indicate a problem in my pipeline or configuration?

Thank you for your time and help!

Best regards,

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.