Skip to content

Commit a52cd65

Browse files
authored
revert swift_from_pretrained (#3914)
1 parent 19d524a commit a52cd65

File tree

1 file changed

+11
-0
lines changed

1 file changed

+11
-0
lines changed

swift/tuners/peft.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,17 @@ def from_pretrained(cls, pretrained_model_name_or_path: str, subfolder: Optional
8686

8787

8888
def _create_and_replace_hook(self, peft_config, adapter_name, target, *args, **kwargs):
89+
all_supported_names = ('linear', )
90+
all_supported_types = (torch.nn.Embedding, torch.nn.Conv2d, transformers.pytorch_utils.Conv1D, lora.Linear)
91+
target_modules = getattr(peft_config, 'target_modules', None)
92+
if target is None:
93+
return
94+
95+
if isinstance(target_modules, str) and not any(
96+
[name in target.__class__.__name__.lower()
97+
for name in all_supported_names]) and not any([isinstance(target, type_) for type_ in all_supported_types]):
98+
return
99+
89100
if target.__class__.__name__ == 'NonDynamicallyQuantizableLinear':
90101
return
91102

0 commit comments

Comments
 (0)