io
¶
IO module.
Functions:
-
load_model–Load a model from a file.
-
load_model_state–Load a model from disk.
-
save_model–Save a model and optionally its optimizer state to a file.
-
save_model_state–Save a model's state to disk.
load_model
¶
Load a model from a file.
Parameters:
Returns:
-
dict–A dictionary containing the loaded model state, including the model class name, initialization parameters, epoch number, state dictionary, and optimizer state (if available).
Raises:
-
FileNotFoundError–If the specified file does not exist.
Source code in src/autoden/models/io.py
121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 | |
load_model_state
¶
Load a model from disk.
Parameters:
-
save_epochs_dir(str | Path) –The director where the models are saved
-
epoch_num(int | None, default:None) –The epoch number or if None/-1 the best state will be loaded, by default None
Returns:
-
Mapping–The loaded model state and possibly an optimizer state.
Raises:
-
ValueError–When the directory does not exist or the requested model is not available.
Source code in src/autoden/models/io.py
86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 | |
save_model
¶
save_model(
dst_file: str | Path,
model: Module,
optim_state: Mapping | None = None,
epoch_num: int = 0,
) -> None
Save a model and optionally its optimizer state to a file.
Parameters:
-
dst_file(str or Path) –The destination file path where the model will be saved.
-
model(Module) –The model to be saved. It must implement the
SerializableModelprotocol. -
optim_state(Mapping, default:None) –The state of the optimizer to be saved. Default is None.
-
epoch_num(int, default:0) –The current epoch number. Default is 0.
Raises:
-
ValueError–If the model does not implement the
SerializableModelprotocol.
Source code in src/autoden/models/io.py
13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 | |
save_model_state
¶
save_model_state(
save_epochs_dir: str | Path,
epoch_num: int,
model: Module,
optim_state: Mapping | None = None,
is_best: bool = False,
) -> None
Save a model's state to disk.
This function saves the state of a model and optionally its optimizer to disk.
The model state is saved in a directory specified by save_epochs_dir. If
is_best is True, the model state is saved as "weights.pt". Otherwise, it is
saved with a filename that includes the epoch number.
Parameters:
-
save_epochs_dir(str | Path) –The directory where to save the model state.
-
epoch_num(int) –The epoch number.
-
model(Module) –The model whose state is to be saved.
-
optim_state(Mapping, default:None) –The optimizer state to save, by default None.
-
is_best(bool, default:False) –Whether it is the best fitted model, by default False.
Returns:
-
None–
Source code in src/autoden/models/io.py
48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 | |