Skip to content

Save tensors in context of memory_efficient_linear - #3413

Merged
tjruwase merged 2 commits into
masterfrom
tohtana/leak_mem_efficient_linear
May 1, 2023
Merged

tjruwase merged 2 commits into
masterfrom
tohtana/leak_mem_efficient_linear

Conversation

@tohtana

@tohtana tohtana commented Apr 30, 2023

Copy link
Copy Markdown
Collaborator

By default, torch.nn.functional.linear is replaced with LinearFunctionForZeroStage3. However, LinearFunctionForZeroStage3 causes memory leak in some usecases.

In PEFT's LoRA mentioned in #3002, the weight is passed after 'transpose'.

result = F.linear(x, transpose(self.weight, self.fan_in_fan_out), bias=self.bias)

LinearFunctionForZeroStage3 saves the weight in a map and the key is the object's ID. But a new transposed weight is created and the ID changes for each iteration. So the saved weights will increase through iterations.

This PR simply saves weight and bias in the context instead of the IDs.
I don't understand the intention of using IDs to store the weight. If saving IDs instead of tensors is a crucial part of this module, we need another approach to fix this.

@tohtana

tohtana commented May 1, 2023

Copy link
Copy Markdown
Collaborator Author

@tjruwase Thank you for merging this PR!

As I mentioned, I didn't understand the intention of saving tensors in a global map.
I would be happy to fix again if we find any problem with this PR.

@tohtana
tohtana deleted the tohtana/leak_mem_efficient_linear branch May 1, 2023 23:20
@tjruwase

tjruwase commented May 1, 2023

Copy link
Copy Markdown
Contributor

@tohtana, I think your solution is the correct one.

@tohtana

tohtana commented May 2, 2023

Copy link
Copy Markdown
Collaborator Author

Thank you for your reviewing, @tjruwase!

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.

2 participants