evomo.utils.state#
Helpers for optional algorithm state whose shape is known after evaluation.
Functions#
|
Register optional persistent state, materializing it before checkpoint loading. |
Module Contents#
- evomo.utils.state.register_lazy_buffer(module: torch.nn.Module, name: str, *, device_like: str) None#
Register optional persistent state, materializing it before checkpoint loading.
The buffer starts as
Noneand accepts normal tensor assignments after evaluation. A fresh instance can restore its shape and dtype from a checkpoint. Already initialized buffers retain PyTorch’s normal shape validation.device_likenames an existing tensor attribute on the same module, such as"pop". Its device is read at load time, so use a parameter or buffer that follows module device transfers. The tensor itself is not captured by the hook. Standardload_state_dict(assign=True)semantics still take precedence: assigned tensors retain the checkpoint’s device and dtype.As with ordinary None buffers, absent checkpoint keys leave fresh state as None. This helper does not infer or validate a problem’s number of constraints.
Example:
self.pop = Mutable(population) register_lazy_buffer(self, "cv", device_like="pop")