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

add context parallel group init to mp init #1174

Merged
merged 1 commit into from
Apr 4, 2024

Conversation

amylittleyang
Copy link
Contributor

@amylittleyang amylittleyang commented Apr 3, 2024

What does this PR do?

follow up from D55538929.
update model_parallel/initialize.py to also initialize context parallel groups.
original change made in this PR: https://github.com/fairinternal/llm_inference/pull/333/files

Before submitting

  • Did you have fun?
    • Make sure you had fun coding 🙃
  • Did you read the contributor guideline?
  • Was this discussed/approved via a Github issue? (no need for typos, doc improvements)
    • N/A
  • Did you make sure to update the docs?
    • N/A
  • Did you write any new necessary tests?
    • N/A
  • Did you update the changelog? (if needed)
    • N/A

PR review

Anyone in the community is free to review the PR once the tests have passed.
If we didn't discuss your PR in Github issues there's a high chance it will not be merged.

@facebook-github-bot facebook-github-bot added the CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. label Apr 3, 2024
@amylittleyang amylittleyang marked this pull request as ready for review April 3, 2024 01:12
pipeline_length: int = 1,
*,
model_parallel_backend: Optional[str] = None,
pipeline_backend: Optional[str] = None,
ddp_backend: Optional[str] = None
ddp_backend: Optional[str] = None,
cp_backend: Optional[str] = None,

Choose a reason for hiding this comment

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

can we put cp_backend between model_parallel_backend and pipeline_backend to meet the ordering?

Comment on lines 128 to 130
global _CP_PREV_RANK
global _CP_NEXT_RANK
global _CP_ZERO_RANK

Choose a reason for hiding this comment

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

wondering why we add these?
all these can be derived with CP GROUP RANKS (in fact, PP does that for similar functionalities)

we can always utilize @functools.lru_cache if performance is concern?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Sounds good let me move this part into fbcode. It's probably for convenience in the original PR where they put all comms related changes in this file.

Comment on lines 149 to 151
def model_parallel_is_initialized() -> bool:
"""Check if model and data parallel groups are initialized."""
if _MODEL_PARALLEL_GROUP is None or _DATA_PARALLEL_GROUP is None or _PIPELINE_PARALLEL_GROUP is None:
return False
return True

Choose a reason for hiding this comment

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

defined twice here and below?

also, should we add context parallel group to condition?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good catch!

return True


def get_context_parallel_group():

Choose a reason for hiding this comment

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

add return type annotation for all newly added functions?

Comment on lines 187 to 188
global _PIPELINE_PARALLEL_RANKS
_PIPELINE_PARALLEL_RANKS = None

Choose a reason for hiding this comment

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

why remove?

if torch.distributed.is_available() and torch.distributed.is_initialized():
return torch.distributed.get_world_size(group=get_context_parallel_group())
else:
return 0

Choose a reason for hiding this comment

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

is 0 right default value? usually world size returns 1 by default?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

We should return torch.distributed.get_world_size(...) directly here. get_context_parallel_group() already checks the CP pg is initialized.

@amylittleyang amylittleyang force-pushed the add_context_parallel_init branch 2 times, most recently from 9fb8ed9 to 78471c8 Compare April 3, 2024 20:33
Comment on lines +173 to +169
def get_context_parallel_rank() -> int:
"""Return my rank for the context parallel group."""
return torch.distributed.get_rank(group=get_context_parallel_group())

Choose a reason for hiding this comment

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

looks like line 161-165 is the same function - maybe remove this?

@amylittleyang amylittleyang merged commit 0af41ae into main Apr 4, 2024
1 of 19 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants