Skip to content

Fix recv_buffer issue in LLaMA3 DP training - #279

Merged
MC952-arch merged 4 commits into
flagos-ai:mainfrom
whollo:Fix-llama3-train-debug-DP2
Oct 27, 2025
Merged

Fix recv_buffer issue in LLaMA3 DP training#279
MC952-arch merged 4 commits into
flagos-ai:mainfrom
whollo:Fix-llama3-train-debug-DP2

Conversation

@whollo

@whollo whollo commented Oct 24, 2025

Copy link
Copy Markdown
Contributor

Fix the recv_buffer issue encountered when using the DP (Data Parallel) strategy during LLaMA3 training.

@gemini-code-assist

Copy link
Copy Markdown

Summary of Changes

Hello @whollo, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request resolves a recv_buffer issue encountered during LLaMA3 Data Parallel training by enhancing the robustness of environment variable parsing within the flagcx library. The core modification involves updating string comparison functions from strcmp to strcasecmp across various modules, ensuring that configuration settings are correctly interpreted irrespective of the case used in environment variable values.

Highlights

  • Case-Insensitive Environment Variable Checks: Replaced strcmp with strcasecmp for environment variable comparisons in several core files (c2c_algo.cc, cost_model.cc, init.cc, topo.cc, flagcx.cc). This ensures that environment variables like FLAGCX_C2C_ALGO and FLAGCX_ENABLE_TOPO_DETECT are recognized regardless of their casing (e.g., "TRUE" vs "true").
  • Fix for LLaMA3 DP Training: This change specifically addresses a recv_buffer issue that was occurring during LLaMA3 Data Parallel (DP) training, likely caused by the previous case-sensitive environment variable parsing.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Code Review

This pull request improves the user experience by making environment variable checks case-insensitive through the use of strcasecmp. This is a good enhancement for robustness. I have one suggestion to improve portability by replacing the POSIX-specific strcasecmp with a custom helper function. The PR also includes a minor formatting fix and adds a missing newline at the end of a file, which is good practice for tool compatibility. Overall, these are positive changes for the codebase.

Comment thread flagcx/core/c2c_algo.cc Outdated
Comment thread flagcx/flagcx.cc
}
return flagcxSuccess;
} No newline at end of file
}

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

medium

Thank you for adding a newline at the end of the file. It's a good practice that ensures file integrity and compatibility with various tools that expect text files to end with a newline character.

@MC952-arch MC952-arch left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

LGTM

@mikethegoblin mikethegoblin left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

LGTM

@MC952-arch

Copy link
Copy Markdown
Collaborator

@gemini-code-assist please review this pull request in details

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Code Review

This pull request primarily introduces formatting changes via clang-format and enhances the robustness of environment variable checks by making them case-insensitive. While adding checks for alternative capitalizations (e.g., True alongside TRUE) is a good step, I've suggested using strcasecmp for a more comprehensive case-insensitive comparison. This would handle all variations (e.g., true, TRUE, True) and improve both user experience and code maintainability. The other changes are minor formatting adjustments that improve code readability.

Comment thread flagcx/core/c2c_algo.cc
Comment on lines +683 to +684
if (algorithm != NULL && (strcmp(algorithm, "RING_PIPELINED") == 0 ||
strcmp(algorithm, "Ring_pipelined") == 0)) {

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

medium

For better robustness and to handle any case variations (e.g., ring_pipelined, Ring_Pipelined), it's recommended to use a case-insensitive string comparison function like strcasecmp. This will make the environment variable check more user-friendly.

You'll need to include <strings.h> for strcasecmp.

  if (algorithm != NULL && strcasecmp(algorithm, "RING_PIPELINED") == 0) {

Comment thread flagcx/core/c2c_algo.cc
Comment on lines +2098 to +2099
if (algorithm != NULL && (strcmp(algorithm, "XML_INPUT") == 0 ||
strcmp(algorithm, "Xml_input") == 0)) {

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

medium

To handle all case variations of XML_INPUT (like xml_input, Xml_Input, etc.), consider using strcasecmp for a case-insensitive comparison. This improves robustness.

Remember to include <strings.h>.

  if (algorithm != NULL && strcasecmp(algorithm, "XML_INPUT") == 0) {

Comment thread flagcx/core/cost_model.cc
Comment on lines +13 to +14
(strcmp(enableTopoDetect, "TRUE") == 0 ||
strcmp(enableTopoDetect, "True") == 0)) {

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

medium

Using strcasecmp for a case-insensitive comparison against "TRUE" would be more robust, as it would also match "true" and "tRuE". This improves the user experience when setting environment variables.

Make sure to include <strings.h>.

      strcasecmp(enableTopoDetect, "TRUE") == 0) {

Comment thread flagcx/core/init.cc
FLAGCXCHECK(flagcxNetInit(comm));
INFO(FLAGCX_INIT, "Using network %s", comm->netAdaptor->name);
if (env && strcmp(env, "TRUE") == 0) {
if (env && (strcmp(env, "TRUE") == 0 || strcmp(env, "True") == 0)) {

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

medium

Using strcasecmp for a case-insensitive comparison against "TRUE" would be more robust, as it would also match "true" and "tRuE". This improves the user experience when setting environment variables.

Make sure to include <strings.h>.

Suggested change
if (env && (strcmp(env, "TRUE") == 0 || strcmp(env, "True") == 0)) {
if (env && strcasecmp(env, "TRUE") == 0) {

Comment thread flagcx/core/topo.cc
Comment on lines +540 to +541
(strcmp(enable_topo_detect, "TRUE") == 0 ||
strcmp(enable_topo_detect, "True") == 0)) {

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

medium

Using strcasecmp for a case-insensitive comparison against "TRUE" would be more robust, as it would also match "true" and "tRuE". This improves the user experience when setting environment variables.

Make sure to include <strings.h>.

      strcasecmp(enable_topo_detect, "TRUE") == 0) {

Comment thread flagcx/flagcx.cc
Comment on lines +491 to +493
if (enableTopoDetect && (strcmp(enableTopoDetect, "TRUE") == 0 ||
strcmp(enableTopoDetect, "True") ==
0)) { // safety check nic distance is only

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

medium

Using strcasecmp for a case-insensitive comparison against "TRUE" would be more robust, as it would also match "true" and "tRuE". This improves the user experience when setting environment variables.

Make sure to include <strings.h>.

    if (enableTopoDetect && strcasecmp(enableTopoDetect, "TRUE") == 0) { // safety check nic distance is only

@MC952-arch
MC952-arch force-pushed the Fix-llama3-train-debug-DP2 branch from 037cb2c to 363831d Compare October 27, 2025 03:21
@MC952-arch
MC952-arch merged commit ac00cc5 into flagos-ai:main Oct 27, 2025
3 checks passed
liuhe-spec pushed a commit to liuhe-spec/FlagCX that referenced this pull request Nov 28, 2025
---------

Co-authored-by: MC952-arch <MC952-arch@qq.com>
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.

3 participants