-
Notifications
You must be signed in to change notification settings - Fork 271
Add changes to support FSDP #598
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
Merged
Merged
Changes from all commits
Commits
Show all changes
20 commits
Select commit
Hold shift + click to select a range
bc19cc5
Commit 1
4159224
Commit 2
126d70d
Commit 3
067b261
Commit 4
40d90b4
Commit 5
5244420
Commit 6
553d11e
Commit 7
aa56dfc
Commit 8
b762912
Add FSDP tests
7d5990b
update fsdp test
b69d99d
Add peft linear layer monkey patch for hpu
55322c8
Fix issues with activation_checkpointing code
8a5c83b
Add FSDP configuration file for Llama2 FT
ad5a04a
Update as per review comments
0d0ed0d
Run formatter
760a7e7
Rebase to commit 979c13247027fa9c8b9cba5137c4a17e27615589
79ec05a
Additional wrap policy for reducing device memory usage with PEFT
938411e
Update save checkpoint code to fix issue with LoRA + FSDP checkpoints
0df0f76
Delete question-answering/gaudi_config.json
31083c1
Update device id usage in dataclasses.py
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,12 @@ | ||
| { | ||
| "fsdp_auto_wrap_policy": "TRANSFORMER_BASED_WRAP", | ||
| "fsdp_backward_prefetch": "BACKWARD_PRE", | ||
| "fsdp_forward_prefetch": false, | ||
| "fsdp_offload_params": false, | ||
| "fsdp_sharding_strategy": 1, | ||
| "fsdp_state_dict_type": "FULL_STATE_DICT", | ||
| "fsdp_sync_module_states": true, | ||
| "fsdp_use_orig_params": true, | ||
| "transformer_layer_cls_to_wrap": "GaudiLlamaDecoderLayer", | ||
| "fsdp_activation_checkpointing": false | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,12 @@ | ||
| { | ||
| "fsdp_auto_wrap_policy": "TRANSFORMER_BASED_WRAP", | ||
| "fsdp_backward_prefetch": "BACKWARD_PRE", | ||
| "fsdp_forward_prefetch": false, | ||
| "fsdp_offload_params": false, | ||
| "fsdp_sharding_strategy": 1, | ||
| "fsdp_state_dict_type": "FULL_STATE_DICT", | ||
| "fsdp_sync_module_states": true, | ||
| "fsdp_use_orig_params": true, | ||
| "transformer_layer_cls_to_wrap": "BertLayer", | ||
| "fsdp_activation_checkpointing": false | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1 +1,6 @@ | ||
| from .dataclasses import GaudiDistributedType, GaudiDynamoBackend, GaudiTorchDynamoPlugin | ||
| from .dataclasses import ( | ||
| GaudiDistributedType, | ||
| GaudiDynamoBackend, | ||
| GaudiFullyShardedDataParallelPlugin, | ||
| GaudiTorchDynamoPlugin, | ||
| ) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| from .layer import GaudiLoraLayerLinearForward |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,31 @@ | ||
| from typing import Any | ||
|
|
||
| import torch | ||
|
|
||
|
|
||
| def GaudiLoraLayerLinearForward(self, x: torch.Tensor, *args: Any, **kwargs: Any) -> torch.Tensor: | ||
| # https://github.com/huggingface/peft/blob/4b02148af252c17e36b0a4b995f9e8519806fbb5/src/peft/tuners/lora/layer.py#L354C1-L376C22 | ||
| # only differences are avoiding inplace update of "result" to prevent error from torch Dynamo in torch.compile mode of execution | ||
| # and replacing self.base_layer by self._linear | ||
| previous_dtype = x.dtype | ||
|
|
||
| if self.disable_adapters: | ||
| if self.merged: | ||
| self.unmerge() | ||
| result = self._linear(x, *args, **kwargs) | ||
| elif self.merged: | ||
| result = self._linear(x, *args, **kwargs) | ||
| else: | ||
| result = self._linear(x, *args, **kwargs) | ||
| for active_adapter in self.active_adapters: | ||
| if active_adapter not in self.lora_A.keys(): | ||
| continue | ||
| lora_A = self.lora_A[active_adapter] | ||
| lora_B = self.lora_B[active_adapter] | ||
| dropout = self.lora_dropout[active_adapter] | ||
| scaling = self.scaling[active_adapter] | ||
| x = x.to(lora_A.weight.dtype) | ||
| result = result.clone() + lora_B(lora_A(dropout(x))) * scaling | ||
|
|
||
| result = result.to(previous_dtype) | ||
| return result | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.