-
Notifications
You must be signed in to change notification settings - Fork 2.5k
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 llama3 and distributed checkpoint support in NeVA #9101
Conversation
Signed-off-by: yaoyu-33 <yaoyu.094@gmail.com>
Signed-off-by: yaoyu-33 <yaoyu.094@gmail.com>
Signed-off-by: yaoyu-33 <yaoyu.094@gmail.com>
Signed-off-by: yaoyu-33 <yaoyu.094@gmail.com>
Signed-off-by: yaoyu-33 <yaoyu.094@gmail.com>
# Conflicts: # examples/multimodal/vision_language_foundation/clip/megatron_clip_pretrain.py
Signed-off-by: yaoyu-33 <yaoyu.094@gmail.com>
Signed-off-by: yaoyu-33 <yaoyu.094@gmail.com>
Signed-off-by: yaoyu-33 <yaoyu.094@gmail.com>
Signed-off-by: yaoyu-33 <yaoyu.094@gmail.com>
Signed-off-by: yaoyu-33 <yaoyu.094@gmail.com>
Signed-off-by: yaoyu-33 <yaoyu.094@gmail.com>
# Conflicts: # nemo/collections/multimodal/models/multimodal_llm/neva/neva_model.py
Signed-off-by: yaoyu-33 <yaoyu.094@gmail.com>
for more information, see https://pre-commit.ci
Signed-off-by: yaoyu-33 <yaoyu.094@gmail.com>
Signed-off-by: yaoyu-33 <yaoyu.094@gmail.com>
Signed-off-by: yaoyu-33 <yaoyu.094@gmail.com>
Signed-off-by: yaoyu-33 <yaoyu.094@gmail.com>
for more information, see https://pre-commit.ci
Signed-off-by: yaoyu-33 <yaoyu.094@gmail.com>
Signed-off-by: yaoyu-33 <yaoyu.094@gmail.com>
Signed-off-by: yaoyu-33 <yaoyu.094@gmail.com>
Signed-off-by: yaoyu-33 <yaoyu-33@users.noreply.github.com>
@@ -169,7 +169,7 @@ def eval_model(args): | |||
parser.add_argument("--image-folder", type=str, default="") | |||
parser.add_argument("--question-file", type=str, default="tables/question.json") | |||
parser.add_argument("--answers-file", type=str, default="answer.jsonl") | |||
parser.add_argument("--conv-mode", type=str, default="llava_v0") | |||
parser.add_argument("--conv-mode", type=str, default="llava_v0") # this flag has no use! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
then should we get rid of it..?
@@ -487,6 +544,7 @@ def __init__(self, model): | |||
is_multimodal=self.data_cfg.is_multimodal, | |||
sep_image_conv_front=self.data_cfg.sep_image_conv_front, | |||
conv_template=self.data_cfg.get("conv_template", "nvgpt"), | |||
model_type=self.cfg.mm_cfg.llm.get("model_type", "nvgpt"), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
should we rename this to nemotron?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
that will break many old checkpoint, we might just keep this way for a while...
Signed-off-by: yaoyu-33 <yaoyu.094@gmail.com>
Signed-off-by: yaoyu-33 <yaoyu-33@users.noreply.github.com>
Signed-off-by: yaoyu-33 <yaoyu.094@gmail.com>
nemo/utils/callbacks/dist_ckpt_io.py
Outdated
@@ -75,19 +80,24 @@ def load_checkpoint( | |||
else: | |||
sharded_strategy = None | |||
|
|||
if not strict: | |||
for key in list(sharded_state_dict['state_dict'].keys()): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I assume this is a temporary implementation for a strict flag because we also need to notify the user which keys are skipped.
Also, this will work only with Zarr ckpt format, for PyT Distributed it will be different
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also, I don't think it's correct, because we should use the sharded key, not the state dict key (also doesn't account for nested dicts).
Can you try something like this (I didn't run this code so there might be errors)?
This should work for all backends, nested dicts and use correct keys.
from megatron.core.dist_checkpointing.dict_utils import extract_matching_values
from megatron.core.dist_checkpointing.mapping import ShardedBase
if not strict:
sharded_state_dict = self.adjust_non_strict_load(path, sharded_state_dict)
...
def adjust_non_strict_load(self, path: _PATH, sharded_state_dict: Dict[str, Any]):
ckpt_sharded_metadata = dist_checkpointing.load_tensors_metadata(path)
loaded_keys = []
missing_keys = []
unexpected_keys = []
def should_remove_missing_sharded_base(x: Any):
if isinstance(x, ShardedBase):
if x.key in ckpt_sharded_metadata:
loaded_keys.append(x.key)
return False
else:
unexpected_keys.append(x.key)
return True
return False
_, sharded_state_dict = extract_matching_values(sharded_state_dict, should_remove_missing_sharded_base)
logging.info(f'The following keys are not in the checkpoint and will not be loaded: {unexpected_keys}')
# TODO: compute missing_keys by:
# 1. all_gather_object of loaded_keys
# 2. missing_keys = ckpt_sharded_metadata.keys() - loaded_keys
return sharded_state_dict
sharded_state_dict = super().sharded_state_dict(prefix=prefix, sharded_offsets=sharded_offsets, **kwargs) | ||
|
||
state_dict = self.state_dict(prefix='', keep_vars=True) | ||
state_dict.pop('weight') |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is weight
not needed at all?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
weight
already be take care of in super
for layer_name in state_dict.keys(): | ||
tensor = state_dict[layer_name] | ||
layer_key = f'{prefix}{layer_name}' | ||
sharded_state_dict[layer_key] = make_sharded_tensor_for_checkpoint( | ||
tensor, | ||
layer_key, | ||
prepend_offsets=sharded_offsets, | ||
) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this can be replaced with
from megatron.core.transformer.utils import make_sharded_tensors_for_checkpoint
...
sharded_state_dict.update(make_sharded_tensors_for_checkpoint(state_dict))
Signed-off-by: yaoyu-33 <yaoyu.094@gmail.com>
Signed-off-by: yaoyu-33 <yaoyu-33@users.noreply.github.com>
Signed-off-by: yaoyu-33 <yaoyu.094@gmail.com>
# Conflicts: # nemo/utils/callbacks/dist_ckpt_io.py
def adjust_non_strict_load(self, path: _PATH, sharded_state_dict: Dict[str, Any]): | ||
ckpt_sharded_metadata = dist_checkpointing.load_tensors_metadata(path) | ||
loaded_keys = [] | ||
missing_keys = [] |
Check notice
Code scanning / CodeQL
Unused local variable Note
@@ -12,6 +12,7 @@ | |||
# See the License for the specific language governing permissions and | |||
# limitations under the License. | |||
|
|||
import os |
Check notice
Code scanning / CodeQL
Unused import Note
# Conflicts: # nemo/collections/multimodal/parts/utils.py
* temp save Signed-off-by: yaoyu-33 <yaoyu.094@gmail.com> * temp save 2 Signed-off-by: yaoyu-33 <yaoyu.094@gmail.com> * update code Signed-off-by: yaoyu-33 <yaoyu.094@gmail.com> * enable seq packing Signed-off-by: yaoyu-33 <yaoyu.094@gmail.com> * fix neva and clip Signed-off-by: yaoyu-33 <yaoyu.094@gmail.com> * Enable parallel seq packing algo and few other fixes Signed-off-by: yaoyu-33 <yaoyu.094@gmail.com> * Pipeline parallel support Signed-off-by: yaoyu-33 <yaoyu.094@gmail.com> * Update data preprocess Signed-off-by: yaoyu-33 <yaoyu.094@gmail.com> * fix few pp issues Signed-off-by: yaoyu-33 <yaoyu.094@gmail.com> * enable sequence packing w/ PP Signed-off-by: yaoyu-33 <yaoyu.094@gmail.com> * Fix cu_seqlens in inputs Signed-off-by: yaoyu-33 <yaoyu.094@gmail.com> * add assert Signed-off-by: yaoyu-33 <yaoyu.094@gmail.com> * Depend on PP to decide whether do padding Signed-off-by: yaoyu-33 <yaoyu.094@gmail.com> * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * Add docstring Signed-off-by: yaoyu-33 <yaoyu.094@gmail.com> * Fix few evaluation issues Signed-off-by: yaoyu-33 <yaoyu.094@gmail.com> * Fix few PP evaluation issues Signed-off-by: yaoyu-33 <yaoyu.094@gmail.com> * Address comments Signed-off-by: yaoyu-33 <yaoyu.094@gmail.com> * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * add llama3 template Signed-off-by: yaoyu-33 <yaoyu.094@gmail.com> * address comments Signed-off-by: yaoyu-33 <yaoyu.094@gmail.com> * Fix license Signed-off-by: yaoyu-33 <yaoyu.094@gmail.com> * Fix llama3 Signed-off-by: yaoyu-33 <yaoyu.094@gmail.com> * Few fixes Signed-off-by: yaoyu-33 <yaoyu.094@gmail.com> * Few neva bugs Signed-off-by: yaoyu-33 <yaoyu.094@gmail.com> * Few neva bugs Signed-off-by: yaoyu-33 <yaoyu.094@gmail.com> * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * Few neva bugs Signed-off-by: yaoyu-33 <yaoyu.094@gmail.com> * llama3 inference fix Signed-off-by: yaoyu-33 <yaoyu.094@gmail.com> * Force vision encoder to run in fp32 Signed-off-by: yaoyu-33 <yaoyu.094@gmail.com> * Revert "Force vision encoder to run in fp32" This reverts commit 9d2160d. * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * Try adding distributed format of checkpoint Signed-off-by: yaoyu-33 <yaoyu.094@gmail.com> * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * Allow dist checkpoint to be non-strict Signed-off-by: yaoyu-33 <yaoyu.094@gmail.com> * Fix Signed-off-by: yaoyu-33 <yaoyu.094@gmail.com> * Some fixes for PP + dist ckpt in Neva Signed-off-by: yaoyu-33 <yaoyu.094@gmail.com> * fix peft Signed-off-by: yaoyu-33 <yaoyu.094@gmail.com> * few fixes for lora Signed-off-by: yaoyu-33 <yaoyu.094@gmail.com> * checkpoint updates Signed-off-by: yaoyu-33 <yaoyu.094@gmail.com> * Apply isort and black reformatting Signed-off-by: yaoyu-33 <yaoyu-33@users.noreply.github.com> * bug fix Signed-off-by: yaoyu-33 <yaoyu.094@gmail.com> * Add neva dist checkpoint converter Signed-off-by: yaoyu-33 <yaoyu.094@gmail.com> * Apply isort and black reformatting Signed-off-by: yaoyu-33 <yaoyu-33@users.noreply.github.com> * resolve comments Signed-off-by: yaoyu-33 <yaoyu.094@gmail.com> * update neva dist ckpt apis Signed-off-by: yaoyu-33 <yaoyu.094@gmail.com> * Apply isort and black reformatting Signed-off-by: yaoyu-33 <yaoyu-33@users.noreply.github.com> * fix return Signed-off-by: yaoyu-33 <yaoyu.094@gmail.com> --------- Signed-off-by: yaoyu-33 <yaoyu.094@gmail.com> Signed-off-by: yaoyu-33 <yaoyu-33@users.noreply.github.com> Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com> Co-authored-by: yaoyu-33 <yaoyu-33@users.noreply.github.com> Signed-off-by: Boxiang Wang <boxiangw@nvidia.com>
* temp save Signed-off-by: yaoyu-33 <yaoyu.094@gmail.com> * temp save 2 Signed-off-by: yaoyu-33 <yaoyu.094@gmail.com> * update code Signed-off-by: yaoyu-33 <yaoyu.094@gmail.com> * enable seq packing Signed-off-by: yaoyu-33 <yaoyu.094@gmail.com> * fix neva and clip Signed-off-by: yaoyu-33 <yaoyu.094@gmail.com> * Enable parallel seq packing algo and few other fixes Signed-off-by: yaoyu-33 <yaoyu.094@gmail.com> * Pipeline parallel support Signed-off-by: yaoyu-33 <yaoyu.094@gmail.com> * Update data preprocess Signed-off-by: yaoyu-33 <yaoyu.094@gmail.com> * fix few pp issues Signed-off-by: yaoyu-33 <yaoyu.094@gmail.com> * enable sequence packing w/ PP Signed-off-by: yaoyu-33 <yaoyu.094@gmail.com> * Fix cu_seqlens in inputs Signed-off-by: yaoyu-33 <yaoyu.094@gmail.com> * add assert Signed-off-by: yaoyu-33 <yaoyu.094@gmail.com> * Depend on PP to decide whether do padding Signed-off-by: yaoyu-33 <yaoyu.094@gmail.com> * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * Add docstring Signed-off-by: yaoyu-33 <yaoyu.094@gmail.com> * Fix few evaluation issues Signed-off-by: yaoyu-33 <yaoyu.094@gmail.com> * Fix few PP evaluation issues Signed-off-by: yaoyu-33 <yaoyu.094@gmail.com> * Address comments Signed-off-by: yaoyu-33 <yaoyu.094@gmail.com> * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * add llama3 template Signed-off-by: yaoyu-33 <yaoyu.094@gmail.com> * address comments Signed-off-by: yaoyu-33 <yaoyu.094@gmail.com> * Fix license Signed-off-by: yaoyu-33 <yaoyu.094@gmail.com> * Fix llama3 Signed-off-by: yaoyu-33 <yaoyu.094@gmail.com> * Few fixes Signed-off-by: yaoyu-33 <yaoyu.094@gmail.com> * Few neva bugs Signed-off-by: yaoyu-33 <yaoyu.094@gmail.com> * Few neva bugs Signed-off-by: yaoyu-33 <yaoyu.094@gmail.com> * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * Few neva bugs Signed-off-by: yaoyu-33 <yaoyu.094@gmail.com> * llama3 inference fix Signed-off-by: yaoyu-33 <yaoyu.094@gmail.com> * Force vision encoder to run in fp32 Signed-off-by: yaoyu-33 <yaoyu.094@gmail.com> * Revert "Force vision encoder to run in fp32" This reverts commit 9d2160d. * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * Try adding distributed format of checkpoint Signed-off-by: yaoyu-33 <yaoyu.094@gmail.com> * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * Allow dist checkpoint to be non-strict Signed-off-by: yaoyu-33 <yaoyu.094@gmail.com> * Fix Signed-off-by: yaoyu-33 <yaoyu.094@gmail.com> * Some fixes for PP + dist ckpt in Neva Signed-off-by: yaoyu-33 <yaoyu.094@gmail.com> * fix peft Signed-off-by: yaoyu-33 <yaoyu.094@gmail.com> * few fixes for lora Signed-off-by: yaoyu-33 <yaoyu.094@gmail.com> * checkpoint updates Signed-off-by: yaoyu-33 <yaoyu.094@gmail.com> * Apply isort and black reformatting Signed-off-by: yaoyu-33 <yaoyu-33@users.noreply.github.com> * bug fix Signed-off-by: yaoyu-33 <yaoyu.094@gmail.com> * Add neva dist checkpoint converter Signed-off-by: yaoyu-33 <yaoyu.094@gmail.com> * Apply isort and black reformatting Signed-off-by: yaoyu-33 <yaoyu-33@users.noreply.github.com> * resolve comments Signed-off-by: yaoyu-33 <yaoyu.094@gmail.com> * update neva dist ckpt apis Signed-off-by: yaoyu-33 <yaoyu.094@gmail.com> * Apply isort and black reformatting Signed-off-by: yaoyu-33 <yaoyu-33@users.noreply.github.com> * fix return Signed-off-by: yaoyu-33 <yaoyu.094@gmail.com> --------- Signed-off-by: yaoyu-33 <yaoyu.094@gmail.com> Signed-off-by: yaoyu-33 <yaoyu-33@users.noreply.github.com> Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com> Co-authored-by: yaoyu-33 <yaoyu-33@users.noreply.github.com> Signed-off-by: Jan Lasek <janek.lasek@gmail.com>
* temp save Signed-off-by: yaoyu-33 <yaoyu.094@gmail.com> * temp save 2 Signed-off-by: yaoyu-33 <yaoyu.094@gmail.com> * update code Signed-off-by: yaoyu-33 <yaoyu.094@gmail.com> * enable seq packing Signed-off-by: yaoyu-33 <yaoyu.094@gmail.com> * fix neva and clip Signed-off-by: yaoyu-33 <yaoyu.094@gmail.com> * Enable parallel seq packing algo and few other fixes Signed-off-by: yaoyu-33 <yaoyu.094@gmail.com> * Pipeline parallel support Signed-off-by: yaoyu-33 <yaoyu.094@gmail.com> * Update data preprocess Signed-off-by: yaoyu-33 <yaoyu.094@gmail.com> * fix few pp issues Signed-off-by: yaoyu-33 <yaoyu.094@gmail.com> * enable sequence packing w/ PP Signed-off-by: yaoyu-33 <yaoyu.094@gmail.com> * Fix cu_seqlens in inputs Signed-off-by: yaoyu-33 <yaoyu.094@gmail.com> * add assert Signed-off-by: yaoyu-33 <yaoyu.094@gmail.com> * Depend on PP to decide whether do padding Signed-off-by: yaoyu-33 <yaoyu.094@gmail.com> * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * Add docstring Signed-off-by: yaoyu-33 <yaoyu.094@gmail.com> * Fix few evaluation issues Signed-off-by: yaoyu-33 <yaoyu.094@gmail.com> * Fix few PP evaluation issues Signed-off-by: yaoyu-33 <yaoyu.094@gmail.com> * Address comments Signed-off-by: yaoyu-33 <yaoyu.094@gmail.com> * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * add llama3 template Signed-off-by: yaoyu-33 <yaoyu.094@gmail.com> * address comments Signed-off-by: yaoyu-33 <yaoyu.094@gmail.com> * Fix license Signed-off-by: yaoyu-33 <yaoyu.094@gmail.com> * Fix llama3 Signed-off-by: yaoyu-33 <yaoyu.094@gmail.com> * Few fixes Signed-off-by: yaoyu-33 <yaoyu.094@gmail.com> * Few neva bugs Signed-off-by: yaoyu-33 <yaoyu.094@gmail.com> * Few neva bugs Signed-off-by: yaoyu-33 <yaoyu.094@gmail.com> * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * Few neva bugs Signed-off-by: yaoyu-33 <yaoyu.094@gmail.com> * llama3 inference fix Signed-off-by: yaoyu-33 <yaoyu.094@gmail.com> * Force vision encoder to run in fp32 Signed-off-by: yaoyu-33 <yaoyu.094@gmail.com> * Revert "Force vision encoder to run in fp32" This reverts commit 9d2160d. * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * Try adding distributed format of checkpoint Signed-off-by: yaoyu-33 <yaoyu.094@gmail.com> * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * Allow dist checkpoint to be non-strict Signed-off-by: yaoyu-33 <yaoyu.094@gmail.com> * Fix Signed-off-by: yaoyu-33 <yaoyu.094@gmail.com> * Some fixes for PP + dist ckpt in Neva Signed-off-by: yaoyu-33 <yaoyu.094@gmail.com> * fix peft Signed-off-by: yaoyu-33 <yaoyu.094@gmail.com> * few fixes for lora Signed-off-by: yaoyu-33 <yaoyu.094@gmail.com> * checkpoint updates Signed-off-by: yaoyu-33 <yaoyu.094@gmail.com> * Apply isort and black reformatting Signed-off-by: yaoyu-33 <yaoyu-33@users.noreply.github.com> * bug fix Signed-off-by: yaoyu-33 <yaoyu.094@gmail.com> * Add neva dist checkpoint converter Signed-off-by: yaoyu-33 <yaoyu.094@gmail.com> * Apply isort and black reformatting Signed-off-by: yaoyu-33 <yaoyu-33@users.noreply.github.com> * resolve comments Signed-off-by: yaoyu-33 <yaoyu.094@gmail.com> * update neva dist ckpt apis Signed-off-by: yaoyu-33 <yaoyu.094@gmail.com> * Apply isort and black reformatting Signed-off-by: yaoyu-33 <yaoyu-33@users.noreply.github.com> * fix return Signed-off-by: yaoyu-33 <yaoyu.094@gmail.com> --------- Signed-off-by: yaoyu-33 <yaoyu.094@gmail.com> Signed-off-by: yaoyu-33 <yaoyu-33@users.noreply.github.com> Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com> Co-authored-by: yaoyu-33 <yaoyu-33@users.noreply.github.com>
What does this PR do ?
Add llama3 and distributed checkpoint support in NeVA
Collection: [multimodal]
Changelog
Usage
# 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:
PR Type:
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