(self, model, state_dict_lora, lora_prefix, alpha=1.0, model_resource=None)
| 74 | |
| 75 | |
| 76 | def load(self, model, state_dict_lora, lora_prefix, alpha=1.0, model_resource=None): |
| 77 | state_dict_model = model.state_dict() |
| 78 | state_dict_lora = self.convert_state_dict(state_dict_lora, lora_prefix=lora_prefix, alpha=alpha) |
| 79 | if model_resource == "diffusers": |
| 80 | state_dict_lora = model.__class__.state_dict_converter().from_diffusers(state_dict_lora) |
| 81 | elif model_resource == "civitai": |
| 82 | state_dict_lora = model.__class__.state_dict_converter().from_civitai(state_dict_lora) |
| 83 | if isinstance(state_dict_lora, tuple): |
| 84 | state_dict_lora = state_dict_lora[0] |
| 85 | if len(state_dict_lora) > 0: |
| 86 | print(f" {len(state_dict_lora)} tensors are updated.") |
| 87 | for name in state_dict_lora: |
| 88 | fp8=False |
| 89 | if state_dict_model[name].dtype == torch.float8_e4m3fn: |
| 90 | state_dict_model[name]= state_dict_model[name].to(state_dict_lora[name].dtype) |
| 91 | fp8=True |
| 92 | state_dict_model[name] += state_dict_lora[name].to( |
| 93 | dtype=state_dict_model[name].dtype, device=state_dict_model[name].device) |
| 94 | if fp8: |
| 95 | state_dict_model[name] = state_dict_model[name].to(torch.float8_e4m3fn) |
| 96 | model.load_state_dict(state_dict_model) |
| 97 | |
| 98 | |
| 99 | def match(self, model, state_dict_lora): |
no test coverage detected