Skip to content

Enhance recipe compatibility #1724

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

Open
wants to merge 16 commits into
base: main
Choose a base branch
from
Open

Conversation

negvet
Copy link
Collaborator

@negvet negvet commented Apr 28, 2025

Description

Enables recipe update on the fly. Added a user warning when this happens.

Enables TE1.x checkpoint loading.

Implemented check that is supposed to catch user-defined bug, when there is a mismatch between the recipes in fp8_model_init and fp8_autocast.
Example case to check: recipe is DelayedScaling (DelayedScaling is set in fp8_autocast()), but the weight tensor is MXFP8Tensor (MXFP8BlockScaling is set in fp8_model_init()).

Type of change

  • Documentation change (change only to the documentation, either a fix or a new content)
  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • Infra/Build change
  • Code refactoring

Changes

Please list the changes introduced in this PR:

  • Added check in the base module class
  • Added test

Checklist:

  • I have read and followed the contributing guidelines
  • The functionality is complete
  • I have commented my code, particularly in hard-to-understand areas
  • I have made corresponding changes to the documentation
  • My changes generate no new warnings
  • I have added tests that prove my fix is effective or that my feature works
  • New and existing unit tests pass locally with my changes

Signed-off-by: Evgeny Tsykunov <etsykunov@nvidia.com>
@negvet
Copy link
Collaborator Author

negvet commented Apr 28, 2025

/te-ci L0


recipe = self.fp8_meta["recipe"]
expected_tensor_class = None
if recipe.delayed() or recipe.float8_current_scaling():
Copy link
Member

Choose a reason for hiding this comment

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

Maybe add a field in the recipe that has this exepected tensor class? Also, I guess for completeness we should not only deal with QuantizedTensor, but also with the *Base (e.g. Float8TensorBase) classes (I know that they are not used for weights in fp8_model_init).

Copy link
Collaborator Author

@negvet negvet Apr 29, 2025

Choose a reason for hiding this comment

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

Maybe add a field in the recipe that has this exepected tensor class?

That is what I also like more. I did not do so due to circular import.
Now, I fixed it with local import, if this is acceptable.
But probably, we need some redesign to better fix this circular import issue (in another PR).

In the future, I would also propose to add a field in the recipe with quantizer class etc.

Copy link
Collaborator Author

@negvet negvet Apr 29, 2025

Choose a reason for hiding this comment

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

Also, I guess for completeness we should not only deal with QuantizedTensor, but also with the *Base (e.g. Float8TensorBase) classes (I know that they are not used for weights in fp8_model_init).

Fixed

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

See 98799f7

else:
raise RuntimeError(f"Unsupported recipe type: {recipe.__class__.__name__}")

weight_tensors = [getattr(self, name) for name in self.weight_names]
Copy link
Member

Choose a reason for hiding this comment

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

@timmoon10 I vaguealy recall that getattr from nn.Module was slow and that you created a faster function for it at some point, do you remember the details?

negvet added 3 commits April 29, 2025 08:11
Signed-off-by: Evgeny Tsykunov <etsykunov@nvidia.com>
Signed-off-by: Evgeny Tsykunov <etsykunov@nvidia.com>
Signed-off-by: Evgeny Tsykunov <etsykunov@nvidia.com>
@negvet negvet force-pushed the et/recipe_compat branch from ecb8b96 to e64188b Compare April 29, 2025 10:02
@negvet
Copy link
Collaborator Author

negvet commented Apr 29, 2025

@ksivaman please take a look at e64188b (recipe change warning)

@negvet negvet marked this pull request as ready for review April 29, 2025 10:14
@negvet
Copy link
Collaborator Author

negvet commented Apr 29, 2025

/te-ci L0

Signed-off-by: Evgeny Tsykunov <etsykunov@nvidia.com>
@negvet
Copy link
Collaborator Author

negvet commented Apr 29, 2025

@ksivaman, 674a3c9 enables recipe change on the fly.

Signed-off-by: Evgeny Tsykunov <etsykunov@nvidia.com>
@negvet
Copy link
Collaborator Author

negvet commented Apr 29, 2025

TE1.x did not save the recipe in the state.
Based on that, the assumption in 5023a32 is the following: if no recipe in state -> it is TE1.x checkpoint with DelayedScaling.
Does it sound like a safe enough assumption?

With this fix, TE1.x checkpoint can be loaded in ToT TE2.x. (for both TE versions, used the same ToT Megatron-LM)

Signed-off-by: Evgeny Tsykunov <etsykunov@nvidia.com>
@negvet
Copy link
Collaborator Author

negvet commented Apr 29, 2025

/te-ci L0

@negvet negvet changed the title Check tensor-recipe compatibility Enhance recipe compatibility Apr 29, 2025
@negvet negvet requested a review from ptrendx April 29, 2025 16:35
negvet and others added 2 commits April 30, 2025 09:23
Signed-off-by: Evgeny Tsykunov <etsykunov@nvidia.com>
@negvet
Copy link
Collaborator Author

negvet commented Apr 30, 2025

/te-ci L0

ptrendx and others added 2 commits May 1, 2025 13:26
Signed-off-by: Kirthi Shankar Sivamani <ksivamani@nvidia.com>
@ksivaman
Copy link
Member

ksivaman commented May 6, 2025

/te-ci L0

@@ -57,6 +57,12 @@
_NUM_MAX_UB_STREAMS = 3
_MIN_STREAM_PRIORITY, _MAX_STREAM_PRIORITY = None, None
layers_atomic_ring_exchange = []
_QUANTIZED_WEIGHT_TENSOR_TYPES = (
Copy link
Member

Choose a reason for hiding this comment

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

We recently merged the change to introduce QuantizedTensorBase class so you should be able to remove this.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Fixed in 7c2f5eb

negvet added 3 commits May 9, 2025 12:23
Signed-off-by: Evgeny Tsykunov <etsykunov@nvidia.com>
Signed-off-by: Evgeny Tsykunov <etsykunov@nvidia.com>
Signed-off-by: Evgeny Tsykunov <etsykunov@nvidia.com>
Signed-off-by: Evgeny Tsykunov <etsykunov@nvidia.com>
@negvet
Copy link
Collaborator Author

negvet commented May 9, 2025

/te-ci L0

@negvet negvet requested a review from ptrendx May 9, 2025 15:54
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