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

Tests for distributed #1196

Open
wants to merge 8 commits into
base: main
Choose a base branch
from
Open

Tests for distributed #1196

wants to merge 8 commits into from

Conversation

pggPL
Copy link
Collaborator

@pggPL pggPL commented Sep 23, 2024

Description

I am working on debug API. Before it can be merged, it needs to be tested. We need to ensure that all the new layers will work properly in the distributed case also. The tests present in the repo focus on testing gemm/comm overlapping - the tests I want to add focus more on checking numerical corectness of multiple configurations of TE layers. Moreover, current

Type of change

  • Documentation change (change only to the documentation, either a fix or a new content)
  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • Infra/Build change
  • Code refractor

Changes

  • added numerical tests for distributed training,

Checklist:

  • I have read and followed the contributing guidelines
  • The functionality is complete
  • I have commented my code, particularly in hard-to-understand areas
  • I have made corresponding changes to the documentation
  • My changes generate no new warnings
  • I have added tests that prove my fix is effective or that my feature works
  • New and existing unit tests pass locally with my changes

Pawel Gadzinski and others added 5 commits September 21, 2024 10:40
@timmoon10
Copy link
Collaborator

As mentioned by @ptrendx, we'll need to include these tests in one of the QA scripts (see qa) so that they are included in the CI pipelines. L1_pytorch_distributed_unittest is simplest, but we could also make a new L0 distributed test. If we go that route, it might be worth including the te.Sequential distributed tests as well.

Pawel Gadzinski added 3 commits September 26, 2024 02:19
Signed-off-by: Pawel Gadzinski <pgadzinski@nvidia.com>
Signed-off-by: Pawel Gadzinski <pgadzinski@nvidia.com>

WORLD_RANK = dist.get_rank()
WORLD_SIZE = dist.get_world_size()
assert WORLD_SIZE == 2, "This test uses 2 GPUs. Run with torchrun --nproc_per_node=2."
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

test_numerics.py can launch with a different number of GPUs:

NUM_PROCS: int = min(torch.cuda.device_count(), 4)

Suggested change
assert WORLD_SIZE == 2, "This test uses 2 GPUs. Run with torchrun --nproc_per_node=2."

class HalfGradient(torch.autograd.Function):
@staticmethod
def forward(ctx, input):
ctx.save_for_backward(input)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this needed?

Suggested change
ctx.save_for_backward(input)

output_failed, output_info = _compare_tensors(
"outputs", output_distributed, output_single_node, rtol, atol
)
dist_print(output_info, src=WORLD_RANK, error=output_failed)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Printing successful checks might be too verbose:

Suggested change
dist_print(output_info, src=WORLD_RANK, error=output_failed)
if output_failed:
dist_print(output_info, src=WORLD_RANK, error=True)

Comment on lines +119 to +120
rtol = 0.125 if FP8 else 0.025
atol = 0.0625 if FP8 else 0.00125
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ideally we would use the tightest tolerances possible for the dtype, like in torch.testing.assert_close. I see that the tensor dimensions are small (~64), so we should be able to get away with this.

return to_output


def _check_gradients(model_distributed, model_single, main_grad_check=False):
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Similar questions as in _check_outputs.

for kwargs in kwargs_list:
for parallel_mode in ["column", "row"]:
for sequence_parallel in [False, True]:
_test_linear(parallel_mode, sequence_parallel, **kwargs)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I find it helpful to print the test configs so we can narrow down in the case there's a test failure:

Suggested change
_test_linear(parallel_mode, sequence_parallel, **kwargs)
dist_print(f"_test_linear with {kwargs=}, {parallel_mode=}, {sequence_parallel=}")
_test_linear(parallel_mode, sequence_parallel, **kwargs)

We'd want to do similar logging in all other layer tests.

Comment on lines +55 to +56
@pytest.mark.parametrize("fp8", all_boolean)
def test_linear(fp8):
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Having a separate test for each layer is nice for error reporting, but it adds a few seconds overhead to launch the parallel jobs. It's more scalable to launch a single parallel job and to test all layers and layer configurations internally.

@timmoon10 timmoon10 self-requested a review September 26, 2024 18:57
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

Successfully merging this pull request may close these issues.

2 participants