-
Notifications
You must be signed in to change notification settings - Fork 233
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
13 changed files
with
526 additions
and
29 deletions.
There are no files selected for viewing
This file contains 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 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 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 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 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 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 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 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 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 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.