Skip to content

Added torchrun compatibility for distributet training across multiple GPUs in a single node (single instance) #4766

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

Merged
merged 22 commits into from
Aug 9, 2024

Conversation

brunopistone
Copy link
Collaborator

Issue #, if available:

Description of changes:

Added possibility to execute remote function with torchrun command, for parallelizing training across multiple GPUs in a single node (single instance).
The functionality can be enabled in the @Remote function as following:

@remote(use_torchrun=True, nproc_per_node=2)
def train(....):
   pass

model = train(....)

Testing done:

Integration tests for evaluating back compatibility with original way of working, added integration test for checking compatibility with new functionality added

Merge Checklist

Put an x in the boxes that apply. You can also fill these out after creating the PR. If you're unsure about any of them, don't hesitate to ask. We're here to help! This is simply a reminder of what we are going to look for before merging your pull request.

General

  • I have read the CONTRIBUTING doc
  • I certify that the changes I am introducing will be backward compatible, and I have discussed concerns about this, if any, with the Python SDK team
  • I used the commit message format described in CONTRIBUTING
  • I have passed the region in to all S3 and STS clients that I've initialized as part of this change.
  • I have updated any necessary documentation, including READMEs and API docs (if appropriate)

Tests

  • I have added tests that prove my fix is effective or that my feature works (if appropriate)
  • I have added unit and/or integration tests as appropriate to ensure backward compatibility of the changes
  • I have checked that my tests are not configured for a specific region or account (if appropriate)
  • I have used unique_name_from_base to create resource names in integ tests (if appropriate)

By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.

@brunopistone brunopistone requested a review from a team as a code owner July 2, 2024 18:01
@brunopistone brunopistone requested a review from mohanasudhan July 2, 2024 18:01
@brunopistone
Copy link
Collaborator Author

Any update @mohanasudhan?

@mohanasudhan
Copy link
Contributor

@mufaddal-rohawala can you help with the review?

Copy link
Member

@mufaddal-rohawala mufaddal-rohawala left a comment

Choose a reason for hiding this comment

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

Adding docstrngs is a blocker.

sage-maker
sage-maker previously approved these changes Aug 7, 2024
@sage-maker
Copy link
Collaborator

@brunopistone Please review the test failures, thanks

@sage-maker
Copy link
Collaborator

@brunopistone
Looks like codestyle is still failing

@@ -951,7 +1001,12 @@ def _get_job_name(job_settings, func):


def _prepare_and_upload_runtime_scripts(
spark_config: SparkConfig, s3_base_uri: str, s3_kms_key: str, sagemaker_session: Session
spark_config: SparkConfig,
Copy link
Collaborator

Choose a reason for hiding this comment

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

Too much whitespace, looks like two tab instead of 1 maybe

@@ -818,3 +818,25 @@ def test_decorator_auto_capture(sagemaker_session, auto_capture_test_container):
f"--rm {auto_capture_test_container}"
)
subprocess.check_output(shlex.split(cmd), stderr=subprocess.STDOUT).decode("utf-8")

def test_decorator_torchrun(
sagemaker_session,
Copy link
Collaborator

Choose a reason for hiding this comment

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

Same here, needs 1 tab instead of 2.

@sage-maker
Copy link
Collaborator

@brunopistone
Your codestyle still failed, refer to client.py line 60 and test_decorator.py line 822. Please make sure you are running the linters locally, thanks

@@ -58,7 +58,6 @@

logger = logging_config.get_logger()

Copy link
Collaborator

Choose a reason for hiding this comment

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

Needs a new line here

@@ -818,3 +818,25 @@ def test_decorator_auto_capture(sagemaker_session, auto_capture_test_container):
f"--rm {auto_capture_test_container}"
)
subprocess.check_output(shlex.split(cmd), stderr=subprocess.STDOUT).decode("utf-8")

Copy link
Collaborator

Choose a reason for hiding this comment

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

and a new line here

fi

printf "INFO: Invoking remote function with torchrun inside conda environment: $conda_env.\\n"
$conda_exe run -n $conda_env torchrun --nproc_per_node $NPROC_PER_NODE -m sagemaker.remote_function.invoke_function "$@"
Copy link
Collaborator

Choose a reason for hiding this comment

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

Line too long

@sage-maker sage-maker merged commit cbd2ed9 into aws:master Aug 9, 2024
14 checks passed
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.

4 participants