Skip to content

Fix AlltoallvOptions retaining stale split metadata - #528

Closed
taking-lying-flat wants to merge 1 commit into
pytorch:mainfrom
taking-lying-flat:fix/alltoallv-reset-splits
Closed

taking-lying-flat wants to merge 1 commit into
pytorch:mainfrom
taking-lying-flat:fix/alltoallv-reset-splits

Conversation

@taking-lying-flat

Copy link
Copy Markdown

Reusing AlltoallvOptions with a different elementsPerRank updates the buffers but appends the new offsets and lengths to the existing vectors. alltoallv() still indexes their first context->size entries, so the next collective uses the first configuration's splits. When the old lengths still match between peers and fit the new buffers, the operation returns normally with incorrectly distributed data.

Clear offsets and lengths before rebuilding them in splitOffsetsAndLengths(). The shared helper covers all four input/output setter implementations, including both raw pointers and owned UnboundBuffers. The change is two lines and retains the vectors' allocated capacity.

Reproduction with two connected ranks, after the first collective has completed:

std::vector<int> input(4), output(4);
std::vector<int64_t> first = rank == 0
    ? std::vector<int64_t>{1, 3} : std::vector<int64_t>{3, 1};
std::vector<int64_t> second = rank == 0
    ? std::vector<int64_t>{3, 1} : std::vector<int64_t>{1, 3};

gloo::AlltoallvOptions opts(context);
opts.setInput(input.data(), first);
opts.setOutput(output.data(), first);
gloo::alltoallv(opts);

input = {10 + rank * 10, 11 + rank * 10, 12 + rank * 10, 13 + rank * 10};
opts.setInput(input.data(), second);
opts.setOutput(output.data(), second);
gloo::alltoallv(opts);

Both calls return successfully, but the second call produces:

Rank Before this change Expected and after this change
0 [10,20,21,22] [10,11,12,20]
1 [11,12,13,23] [13,21,22,23]

Validation:

  • Built Gloo from source and ran gloo_test --gtest_filter='*AlltoallvTest*': 32 existing tests passed, covering TCP/TCP_LAZY, one/two/four/seven ranks and multiple message sizes.
  • An external real-TCP matrix ran 80 cases per version, three consecutive rounds per case, against the original and fixed implementations. It covers two/three ranks, TCP/TCP_LAZY, all raw/owned input-output combinations, changed splits with new or unchanged pointers, zero-length splits, unchanged splits, fresh options and reuse without resetting. All fixed cases match the reference distribution, and each metadata vector stays at context->size entries.
  • clang-format 18.1.8 --dry-run --Werror gloo/alltoallv.cc and git diff --check passed.

Only the two production lines are included; no test files are changed. The communication checks ran on a single host using CPU TCP transport; other transports and the full repository suite were not run.

@taking-lying-flat

Copy link
Copy Markdown
Author

Consolidated into #527 to keep these small Gloo correctness fixes in one review. The same Alltoallv split-metadata fix is included there as a separate commit; the combined version passed 706 existing tests and the additional reproduction checks. Closing this duplicate PR.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant