MCPcopy Create free account
hub / github.com/Francis-Rings/FlashPortrait / save_weights

Method save_weights

wan/utils/lora_utils.py:329–353  ·  view source on GitHub ↗
(self, file, dtype, metadata)

Source from the content-addressed store, hash-verified

327 return self.parameters()
328
329 def save_weights(self, file, dtype, metadata):
330 if metadata is not None and len(metadata) == 0:
331 metadata = None
332
333 state_dict = self.state_dict()
334
335 if dtype is not None:
336 for key in list(state_dict.keys()):
337 v = state_dict[key]
338 v = v.detach().clone().to("cpu").to(dtype)
339 state_dict[key] = v
340
341 if os.path.splitext(file)[1] == ".safetensors":
342 from safetensors.torch import save_file
343
344 # Precalculate model hashes to save time on indexing
345 if metadata is None:
346 metadata = {}
347 model_hash, legacy_hash = precalculate_safetensors_hashes(state_dict, metadata)
348 metadata["sshs_model_hash"] = model_hash
349 metadata["sshs_legacy_hash"] = legacy_hash
350
351 save_file(state_dict, file, metadata)
352 else:
353 torch.save(state_dict, file)
354
355def create_network(
356 multiplier: float,

Callers

nothing calls this directly

Calls 1

Tested by

no test coverage detected