MCPcopy Create free account
hub / github.com/OpenImagingLab/FlashVSR / load

Method load

diffsynth/models/lora.py:76–96  ·  view source on GitHub ↗
(self, model, state_dict_lora, lora_prefix, alpha=1.0, model_resource=None)

Source from the content-addressed store, hash-verified

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):

Callers 15

init_cross_kvMethod · 0.45
init_cross_kvMethod · 0.45
init_cross_kvMethod · 0.45
__init__Method · 0.45
load_openai_modelFunction · 0.45
_rescan_model_configsFunction · 0.45
load_state_dictFunction · 0.45
create_modelFunction · 0.45
__init__Method · 0.45
_load_weightsFunction · 0.45
load_checkpointFunction · 0.45
from_pretrainedMethod · 0.45

Calls 5

convert_state_dictMethod · 0.95
from_diffusersMethod · 0.45
state_dict_converterMethod · 0.45
from_civitaiMethod · 0.45
toMethod · 0.45

Tested by

no test coverage detected