-
Notifications
You must be signed in to change notification settings - Fork 820
Automatically omit unused columnwise primary weights for backward overrides #3468
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
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -910,6 +910,7 @@ def __init__(self, name: Optional[str] = None) -> None: | |||||||||||||||||||||||||
| self.param_init_meta = {} | ||||||||||||||||||||||||||
| self.primary_weights_in_fp8 = FP8GlobalStateManager.with_fp8_parameters() | ||||||||||||||||||||||||||
| self.preserve_high_precision_init_val = FP8GlobalStateManager.with_high_precision_init_val() | ||||||||||||||||||||||||||
| self._primary_weights_rowwise_only = False | ||||||||||||||||||||||||||
| self.fsdp_wrapped = False | ||||||||||||||||||||||||||
| self.fsdp_group = None | ||||||||||||||||||||||||||
| self._fp8_workspaces: Dict[str, QuantizedTensor] = {} | ||||||||||||||||||||||||||
|
|
@@ -1845,7 +1846,14 @@ def reset_parameters(self, defer_init: Optional[bool] = False) -> None: | |||||||||||||||||||||||||
| quantizer = self.quantizers["scaling_fwd"][fp8_meta_index] | ||||||||||||||||||||||||||
| if quantizer is None: | ||||||||||||||||||||||||||
| raise RuntimeError("Weight quantizer has not been initialized") | ||||||||||||||||||||||||||
| quantizer.set_usage(rowwise=True, columnwise=torch.is_grad_enabled()) | ||||||||||||||||||||||||||
| self._primary_weights_rowwise_only = ( | ||||||||||||||||||||||||||
| FP8GlobalStateManager.get_fp8_recipe().backward_override | ||||||||||||||||||||||||||
| in ("high_precision", "dequantized") | ||||||||||||||||||||||||||
| ) | ||||||||||||||||||||||||||
| quantizer.set_usage( | ||||||||||||||||||||||||||
| rowwise=True, | ||||||||||||||||||||||||||
| columnwise=torch.is_grad_enabled() and not self._primary_weights_rowwise_only, | ||||||||||||||||||||||||||
|
Comment on lines
+1849
to
+1855
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Initializing a quantized model with either backward override now always disables columnwise primary-weight storage. Previously, omitting this storage was an explicit opt-in, so callers could initialize under an override while retaining both directions. Existing callers that later switch to quantized backward now hit the runtime error at |
||||||||||||||||||||||||||
| ) | ||||||||||||||||||||||||||
|
Comment on lines
+1853
to
+1856
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Couldn't we deduce this case automatically?
Suggested change
|
||||||||||||||||||||||||||
| quantizer.internal = False | ||||||||||||||||||||||||||
| # HybridQuantizer is included so its current-scaling / NVFP4 | ||||||||||||||||||||||||||
| # sub-quantizers get the same cross-shard amax reduction as the | ||||||||||||||||||||||||||
|
|
@@ -2061,6 +2069,12 @@ def _check_weight_tensor_recipe_correspondence(self) -> None: | |||||||||||||||||||||||||
| return | ||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||
| recipe = self.fp8_meta["recipe"] | ||||||||||||||||||||||||||
| if self._primary_weights_rowwise_only and recipe.backward_override is None: | ||||||||||||||||||||||||||
| raise RuntimeError( | ||||||||||||||||||||||||||
| "Primary weights were initialized without columnwise storage, but the current " | ||||||||||||||||||||||||||
| "recipe uses quantized backward. Recreate the model with columnwise primary-weight " | ||||||||||||||||||||||||||
| "storage or keep backward_override set to 'high_precision' or 'dequantized'." | ||||||||||||||||||||||||||
| ) | ||||||||||||||||||||||||||
| weight_tensors = [getattr(self, name) for name in self.weight_names] | ||||||||||||||||||||||||||
| for i, tensor in enumerate(weight_tensors): | ||||||||||||||||||||||||||
| if isinstance(tensor, QuantizedTensorStorage): | ||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||
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.
Similar changes should be made in the op fuser API:
TransformerEngine/transformer_engine/pytorch/ops/basic/basic_linear.py
Lines 331 to 334 in d1e9c33
TransformerEngine/transformer_engine/pytorch/ops/basic/grouped_linear.py
Line 466 in d1e9c33