Vlad Iliescu commited on
Commit ·
03900da
1
Parent(s): 56efe4e
more fixes
Browse files- lora_utils.py +15 -7
lora_utils.py
CHANGED
|
@@ -181,7 +181,12 @@ def _ensure_pipeline_lora_prefix(state_dict):
|
|
| 181 |
|
| 182 |
|
| 183 |
def _has_lora_tensors(state_dict):
|
| 184 |
-
return any(
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 185 |
|
| 186 |
|
| 187 |
def _strip_state_dict_prefix(state_dict, prefix):
|
|
@@ -639,10 +644,11 @@ def load_lora_adapter(pipe, entry, token=HF_TOKEN):
|
|
| 639 |
for host_name, host in native_hosts:
|
| 640 |
host_state_dict = _state_dict_for_model_host(state_dict, host_name)
|
| 641 |
if not _has_lora_tensors(host_state_dict):
|
| 642 |
-
|
| 643 |
_load_lora_adapter_on_host(host, host_state_dict, entry["adapter_name"])
|
| 644 |
loaded_hosts.append(host)
|
| 645 |
-
|
|
|
|
| 646 |
except Exception as exc:
|
| 647 |
for host in loaded_hosts:
|
| 648 |
_delete_peft_adapter_on_host(host, entry["adapter_name"])
|
|
@@ -667,10 +673,11 @@ def load_lora_adapter(pipe, entry, token=HF_TOKEN):
|
|
| 667 |
for host_name, host in peft_hosts:
|
| 668 |
host_state_dict = _state_dict_for_model_host(state_dict, host_name)
|
| 669 |
if not _has_lora_tensors(host_state_dict):
|
| 670 |
-
|
| 671 |
_load_lora_with_peft(host, host_state_dict, entry["adapter_name"])
|
| 672 |
loaded_hosts.append(host)
|
| 673 |
-
|
|
|
|
| 674 |
except Exception as exc:
|
| 675 |
for host in loaded_hosts:
|
| 676 |
_delete_peft_adapter_on_host(host, entry["adapter_name"])
|
|
@@ -687,9 +694,10 @@ def load_lora_adapter(pipe, entry, token=HF_TOKEN):
|
|
| 687 |
raise
|
| 688 |
|
| 689 |
details = _describe_adapter_hosts(pipe)
|
|
|
|
| 690 |
if native_error is not None:
|
| 691 |
-
raise ValueError(f"Could not load LoRA adapter with native or PEFT fallback: {native_error}. Hosts: {details}") from native_error
|
| 692 |
-
raise ValueError(f"This pipeline does not expose a usable LoRA loader. Hosts: {details}")
|
| 693 |
|
| 694 |
|
| 695 |
def ensure_loras_loaded(pipe, spec_text: str, global_scale: float, active_by_key: dict, token=HF_TOKEN):
|
|
|
|
| 181 |
|
| 182 |
|
| 183 |
def _has_lora_tensors(state_dict):
|
| 184 |
+
return any(
|
| 185 |
+
".lora_A." in key or ".lora_B." in key
|
| 186 |
+
or ".lora_down." in key or ".lora_up." in key
|
| 187 |
+
or ".lora_linear_layer." in key
|
| 188 |
+
for key in state_dict.keys()
|
| 189 |
+
)
|
| 190 |
|
| 191 |
|
| 192 |
def _strip_state_dict_prefix(state_dict, prefix):
|
|
|
|
| 644 |
for host_name, host in native_hosts:
|
| 645 |
host_state_dict = _state_dict_for_model_host(state_dict, host_name)
|
| 646 |
if not _has_lora_tensors(host_state_dict):
|
| 647 |
+
continue
|
| 648 |
_load_lora_adapter_on_host(host, host_state_dict, entry["adapter_name"])
|
| 649 |
loaded_hosts.append(host)
|
| 650 |
+
if loaded_hosts:
|
| 651 |
+
return
|
| 652 |
except Exception as exc:
|
| 653 |
for host in loaded_hosts:
|
| 654 |
_delete_peft_adapter_on_host(host, entry["adapter_name"])
|
|
|
|
| 673 |
for host_name, host in peft_hosts:
|
| 674 |
host_state_dict = _state_dict_for_model_host(state_dict, host_name)
|
| 675 |
if not _has_lora_tensors(host_state_dict):
|
| 676 |
+
continue
|
| 677 |
_load_lora_with_peft(host, host_state_dict, entry["adapter_name"])
|
| 678 |
loaded_hosts.append(host)
|
| 679 |
+
if loaded_hosts:
|
| 680 |
+
return
|
| 681 |
except Exception as exc:
|
| 682 |
for host in loaded_hosts:
|
| 683 |
_delete_peft_adapter_on_host(host, entry["adapter_name"])
|
|
|
|
| 694 |
raise
|
| 695 |
|
| 696 |
details = _describe_adapter_hosts(pipe)
|
| 697 |
+
sample_keys = list(state_dict.keys())[:8]
|
| 698 |
if native_error is not None:
|
| 699 |
+
raise ValueError(f"Could not load LoRA adapter with native or PEFT fallback: {native_error}. Hosts: {details}. Sample keys: {sample_keys}") from native_error
|
| 700 |
+
raise ValueError(f"This pipeline does not expose a usable LoRA loader. Hosts: {details}. Sample keys: {sample_keys}")
|
| 701 |
|
| 702 |
|
| 703 |
def ensure_loras_loaded(pipe, spec_text: str, global_scale: float, active_by_key: dict, token=HF_TOKEN):
|