-
Notifications
You must be signed in to change notification settings - Fork 318
Add empty_like for NF4Tensor to support offloading #881
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
Conversation
🔗 Helpful Links🧪 See artifacts and rendered test results at hud.pytorch.org/pr/pytorch/ao/881
Note: Links to docs will display an error until the docs builds have been completed. ✅ No FailuresAs of commit 04a5b92 with merge base 8236a87 ( This comment was automatically generated by Dr. CI and updates every 15 minutes. |
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.
can you write a test pleaseeee
test/dtypes/test_nf4.py
Outdated
@parametrize("input_size", [(512 * 512,), (512, 512)]) | ||
def test_empty_like(self, input_size: Union[Tuple[int], int]): | ||
nf4_tensor = to_nf4(torch.rand(input_size)) | ||
new_tensor = torch.empty_like(nf4_tensor, device=torch.device("cpu")) |
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.
nit: to make sure device
arg works, can you make sure the nf4_tensor
is on gpu?
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.
If CI is green...
Driss, we can confirm semantics when you're back but I'm fairly confident this is okay
Driss, we can confirm semantics when you're back but I'm fairly confident this is okay
* Rename TorchChat to Torchchat * Adding Issue templates
Ran into issues when trying to offload activations when the activation was an NF4Tensor. (This was found when testing different configs for pytorch/torchtune#1443)
This PR adds
empty_like
and a test case :D The way we implementempty_like
is we traverse through the NF4Tensor's inner tensors and callempty_like
on all of them (quantized_data, quantization_factor, quantization_scalers). This may be semantically sketchy, but since we are creating garbaggio for content anyway that is expected to be overridden later, as long as we preserve the size, this seems fine.