-
Notifications
You must be signed in to change notification settings - Fork 669
Fix for async dcp checkpointing with Float8Tensors #2721
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
Changes from 2 commits
641898c
5c34ffc
62d9300
5df7fb4
bbaef50
5ce704e
9e80320
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 | ||||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -152,6 +152,7 @@ def make_empty( | |||||||||||||||||||||||||||||||||||||||||||
| requires_grad=requires_grad, | ||||||||||||||||||||||||||||||||||||||||||||
| data_transpose=data_transpose, | ||||||||||||||||||||||||||||||||||||||||||||
| quantizer=self, | ||||||||||||||||||||||||||||||||||||||||||||
| device=device, | ||||||||||||||||||||||||||||||||||||||||||||
| ) | ||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||
| def calibrate(self, tensor: torch.Tensor) -> None: | ||||||||||||||||||||||||||||||||||||||||||||
|
|
@@ -378,6 +379,7 @@ def make_empty( | |||||||||||||||||||||||||||||||||||||||||||
| requires_grad=requires_grad, | ||||||||||||||||||||||||||||||||||||||||||||
| data_transpose=data_transpose, | ||||||||||||||||||||||||||||||||||||||||||||
| quantizer=self, | ||||||||||||||||||||||||||||||||||||||||||||
| device=device, | ||||||||||||||||||||||||||||||||||||||||||||
| ) | ||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||
| def calibrate(self, tensor: torch.Tensor) -> None: | ||||||||||||||||||||||||||||||||||||||||||||
|
|
@@ -951,6 +953,15 @@ def is_cuda(self): | |||||||||||||||||||||||||||||||||||||||||||
| return self._transpose.is_cuda | ||||||||||||||||||||||||||||||||||||||||||||
| raise RuntimeError("Both data and transpose are None") | ||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||
| @property | ||||||||||||||||||||||||||||||||||||||||||||
| def is_cpu(self): | ||||||||||||||||||||||||||||||||||||||||||||
| """Return whether the tensor is on CPU.""" | ||||||||||||||||||||||||||||||||||||||||||||
| if self._data is not None: | ||||||||||||||||||||||||||||||||||||||||||||
| return self._data.is_cpu | ||||||||||||||||||||||||||||||||||||||||||||
| if self._transpose is not None: | ||||||||||||||||||||||||||||||||||||||||||||
| return self._transpose.is_cpu | ||||||||||||||||||||||||||||||||||||||||||||
| raise RuntimeError("Both data and transpose are None") | ||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||
| @classmethod | ||||||||||||||||||||||||||||||||||||||||||||
| def _make_in_reduce_ex( | ||||||||||||||||||||||||||||||||||||||||||||
| cls, | ||||||||||||||||||||||||||||||||||||||||||||
|
|
@@ -975,7 +986,14 @@ def _make_in_reduce_ex( | |||||||||||||||||||||||||||||||||||||||||||
| ) | ||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||
| def __reduce_ex__(self, protocol: int) -> tuple: | ||||||||||||||||||||||||||||||||||||||||||||
| """Custom pickling to remove references to FP8 metadata objects""" | ||||||||||||||||||||||||||||||||||||||||||||
| """Custom pickling to remove references to FP8 metadata objects | ||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||
| CPU Float8Tensors are serialized as dequantized plain tensors | ||||||||||||||||||||||||||||||||||||||||||||
| for compatibility with torch.load(weights_only=True), which is | ||||||||||||||||||||||||||||||||||||||||||||
| used by DCP async save staging. | ||||||||||||||||||||||||||||||||||||||||||||
| """ | ||||||||||||||||||||||||||||||||||||||||||||
| if self.is_cpu: | ||||||||||||||||||||||||||||||||||||||||||||
| return self.dequantize(dtype=self.dtype).__reduce_ex__(protocol) | ||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||
| if self.is_cpu: | |
| return self.dequantize(dtype=self.dtype).__reduce_ex__(protocol) | |
| def __reduce_ex__(self, protocol: int) -> tuple: | |
| """Custom pickling to remove references to FP8 metadata objects | |
| CPU Float8Tensors are serialized as dequantized plain tensors | |
| for compatibility with torch.load(weights_only=True), which is | |
| used by DCP async save staging. | |
| """ | |
| try: | |
| is_cpu_tensor = self.is_cpu | |
| except RuntimeError: | |
| # Both _data and _transpose are None | |
| is_cpu_tensor = False | |
| if is_cpu_tensor: | |
| return self.dequantize(dtype=self.dtype).__reduce_ex__(protocol) | |
| return ( | |
| Float8Tensor._make_in_reduce_ex, | |
| (self._data, self._fp8_dtype, self._scale_inv, self.dtype, self.shape), | |
| ) |
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.
Fixed by replacing self.is_cpu with explicit checks on _data and _transpose, so cleared tensors fall through to the existing GPU pickling path without raising.
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.
AttributeErrorwhen_quantizerisNonetensor._quantizercan beNoneforFloat8Tensorobjects deserialized via the GPU path (_make_in_reduce_ex), which does not pass aquantizerargument. If a second async DCP save is attempted after a load/save round-trip,new_emptywill be dispatched on the deserialized tensor, causingAttributeError: 'NoneType' object has no attribute 'make_empty'.A guard is needed before calling
make_empty: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.
Good catch — added a guard that raises a clear
RuntimeErrorif_quantizerisNone.