forked from huggingface/optimum-habana
-
Notifications
You must be signed in to change notification settings - Fork 17
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add ia3 and adalora support (huggingface#809) (#235)
* Add ia3 and adalora support (huggingface#809) Signed-off-by: Wang, Yi A <yi.a.wang@intel.com> * Fix failure in Llama-70B-FSDP test * Fix peft files --------- Signed-off-by: Wang, Yi A <yi.a.wang@intel.com> Co-authored-by: Wang, Yi <yi.a.wang@intel.com>
- Loading branch information
Showing
6 changed files
with
116 additions
and
36 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 |
---|---|---|
|
@@ -4,4 +4,4 @@ sentencepiece != 0.1.92 | |
protobuf | ||
evaluate | ||
scikit-learn | ||
peft == 0.6.2 | ||
peft == 0.10.0 |
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 @@ | ||
from .layer import GaudiLoraLayerLinearForward | ||
from .layer import GaudiAdaloraLayerSVDLinearForward |
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,31 +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 | ||
|
||
def GaudiAdaloraLayerSVDLinearForward(self, x: torch.Tensor, *args: Any, **kwargs: Any) -> torch.Tensor: | ||
""" | ||
Copied from SVDLinear.forward: https://github.com/huggingface/peft/blob/v0.9.0/src/peft/tuners/adalora/layer.py#L158 | ||
The only differences are: | ||
- fix batch_gemm failure for BF16 case | ||
""" | ||
if self.disable_adapters: | ||
if self.merged: | ||
self.unmerge() | ||
result = self._linear(x, *args, **kwargs) | ||
result = self.base_layer(x, *args, **kwargs) | ||
elif self.merged: | ||
result = self._linear(x, *args, **kwargs) | ||
result = self.base_layer(x, *args, **kwargs) | ||
else: | ||
result = self._linear(x, *args, **kwargs) | ||
result = self.base_layer(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] | ||
lora_E = self.lora_E[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 | ||
ranknum = self.ranknum[active_adapter] + 1e-5 | ||
|
||
x = x.to(lora_A.dtype) | ||
result += (dropout(x) @ (lora_A * lora_E).T @ lora_B.T) * (scaling / ranknum) | ||
|
||
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