MCPcopy Create free account
hub / github.com/FreedomGu/Diffportrait360 / ModelSaver

Function ModelSaver

diffportrait360_release/code/utils/checkpoint.py:43–49  ·  view source on GitHub ↗
(output_dir, model, optimizer=None)

Source from the content-addressed store, hash-verified

41 shutil.rmtree(checkpoint)
42
43def ModelSaver(output_dir, model, optimizer=None):
44 output_model_file = os.path.join(output_dir, "model.pt")
45 state_dict = {k: v.cpu() if isinstance(v, torch.Tensor) else v
46 for k, v in model.state_dict().items()}
47 torch.save(state_dict, output_model_file)
48 if optimizer is not None:
49 torch.save(optimizer.state_dict(), f'{output_dir}/optimizer.pt')
50
51
52# checkpointer from fex. Save to hdfs

Callers

nothing calls this directly

Calls 1

saveMethod · 0.80

Tested by

no test coverage detected