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

Make TE and Apex dependencies optional #9550

Draft
wants to merge 15 commits into
base: main
Choose a base branch
from

Conversation

ashors1
Copy link
Collaborator

@ashors1 ashors1 commented Jun 26, 2024

What does this PR do ?

This PR provides a fallback codepath that defaults to pure Pytorch/jit when TE and Apex are not installed. This depends on NVIDIA/Megatron-LM#893

Collection: [Note which collection this PR will affect]

Changelog

  • Add specific line by line info of high level changes in this PR.

Usage

  • You can potentially add a usage example below
# Add a code snippet demonstrating how to use this 

GitHub Actions CI

The Jenkins CI system has been replaced by GitHub Actions self-hosted runners.

The GitHub Actions CI will run automatically when the "Run CICD" label is added to the PR.
To re-run CI remove and add the label again.
To run CI on an untrusted fork, a NeMo user with write access must first click "Approve and run".

Before your PR is "Ready for review"

Pre checks:

  • Make sure you read and followed Contributor guidelines
  • Did you write any new necessary tests?
  • Did you add or update any necessary documentation?
  • Does the PR affect components that are optional to install? (Ex: Numba, Pynini, Apex etc)
    • Reviewer: Does the PR have correct import guards for all optional libraries?

PR Type:

  • New Feature
  • Bugfix
  • Documentation

If you haven't finished some of the above items you can still open "Draft" PR.

Who can review?

Anyone in the community is free to review the PR once the checks have passed.
Contributor guidelines contains specific people who can review PRs to various areas.

Additional Information

  • Related to # (issue)

@github-actions github-actions bot added core Changes to NeMo Core NLP labels Jun 26, 2024
@ashors1 ashors1 changed the title Ashors/remove te apex deps Make TE and Apex dependencies optional Jun 26, 2024
Signed-off-by: ashors1 <ashors1@users.noreply.github.com>
@github-actions github-actions bot removed the core Changes to NeMo Core label Jun 26, 2024
@ashors1 ashors1 marked this pull request as draft June 26, 2024 23:39
Comment on lines +290 to +304
# def check_adlr_autoresume_termination(iteration, model, optimizer, lr_scheduler, save: bool):
# """Check for autoresume signal and exit if it is received."""
# from apex.ppu.checkpointing import save_checkpoint
#
# autoresume = get_adlr_autoresume()
# # Add barrier to ensure consistency.
# torch.distributed.barrier()
# if autoresume.termination_requested():
# if save:
# save_checkpoint(iteration, model, optimizer, lr_scheduler)
# print_rank_0(">>> autoresume termination request found!")
# if torch.distributed.get_rank() == 0:
# autoresume.request_resume()
# print_rank_0(">>> training terminated. Returning")
# sys.exit(0)

Check notice

Code scanning / CodeQL

Commented-out code Note

This comment appears to contain commented-out code.
}


def get_num_microbatches():

Check warning

Code scanning / CodeQL

Variable defined multiple times Warning

This assignment to 'get_num_microbatches' is unnecessary as it is
redefined
before this value is used.
setup_microbatch_calculator,
)

HAVE_APEX = True

Check notice

Code scanning / CodeQL

Unused local variable Note

Variable HAVE_APEX is not used.
nemo/lightning/apex_utils.py Fixed Show fixed Hide fixed
nemo/lightning/apex_utils.py Fixed Show fixed Hide fixed
nemo/lightning/apex_utils.py Fixed Show fixed Hide fixed
nemo/lightning/apex_utils.py Fixed Show fixed Hide fixed
@github-actions github-actions bot added the CI label Jun 30, 2024
@ericharper ericharper requested review from dimapihtar and removed request for marcromeyn and akoumpa July 3, 2024 19:12
@@ -99,6 +99,9 @@
TransformerConfig = ApexGuardDefaults

HAVE_MEGATRON_CORE = False
from typing import Any

RetroConfig = Any
Copy link
Collaborator

Choose a reason for hiding this comment

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

do we want to do the same for all of others mcore's classes we are trying to import under "try" block?
also, why don't use ApexGuardDefaults?

)

HAVE_APEX = True
except ModuleNotFoundError:
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
except ModuleNotFoundError:
except (ImportError, ModuleNotFoundError):

from apex.transformer.tensor_parallel.layers import (
set_defaults_if_not_set_tensor_model_parallel_attributes,
)
except ModuleNotFoundError:
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
except ModuleNotFoundError:
except (ImportError, ModuleNotFoundError):

from apex.transformer.pipeline_parallel.utils import _GLOBAL_NUM_MICROBATCHES_CALCULATOR
try:
from apex.transformer.pipeline_parallel.utils import _GLOBAL_NUM_MICROBATCHES_CALCULATOR
except ModuleNotFoundError:
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
except ModuleNotFoundError:
except (ImportError, ModuleNotFoundError):

from megatron.core.models.gpt.gpt_layer_specs import get_gpt_layer_with_transformer_engine_spec

get_gpt_layer_spec = get_gpt_layer_with_transformer_engine_spec
except ImportError:
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
except ImportError:
except (ImportError, ModuleNotFoundError):

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants