KEMBAR78
Add empty_like for NF4Tensor to support offloading by janeyx99 · Pull Request #881 · pytorch/ao · GitHub
Skip to content

Conversation

@janeyx99
Copy link
Contributor

@janeyx99 janeyx99 commented Sep 12, 2024

Ran into issues when trying to offload activations when the activation was an NF4Tensor. (This was found when testing different configs for meta-pytorch/torchtune#1443)

This PR adds empty_like and a test case :D The way we implement empty_like is we traverse through the NF4Tensor's inner tensors and call empty_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.

@pytorch-bot
Copy link

pytorch-bot bot commented Sep 12, 2024

🔗 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 Failures

As of commit 04a5b92 with merge base 8236a87 (image):
💚 Looks good so far! There are no failures yet. 💚

This comment was automatically generated by Dr. CI and updates every 15 minutes.

@facebook-github-bot facebook-github-bot added the CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. label Sep 12, 2024
Copy link
Contributor

@drisspg drisspg left a 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

@janeyx99 janeyx99 changed the title Add overloads for NF4Tensor to support offloading Add empty_like for NF4Tensor to support offloading Sep 16, 2024
@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"))
Copy link
Contributor

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?

Copy link
Contributor

@malfet malfet left a 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...

@janeyx99 janeyx99 merged commit a584e24 into main Sep 16, 2024
17 checks passed
@janeyx99 janeyx99 deleted the nf4-support-offloading branch September 16, 2024 20:09
jainapurva pushed a commit that referenced this pull request Sep 22, 2024
Driss, we can confirm semantics when you're back but I'm fairly confident this is okay
jainapurva pushed a commit that referenced this pull request Sep 23, 2024
Driss, we can confirm semantics when you're back but I'm fairly confident this is okay
yanbing-j pushed a commit to yanbing-j/ao that referenced this pull request Dec 9, 2024
* Rename TorchChat to Torchchat

* Adding Issue templates
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants