noether.core.models.base¶
Classes¶
Base class for models ( |
Module Contents¶
- class noether.core.models.base.ModelBase(model_config, update_counter=None, path_provider=None, data_container=None, initializer_config=None)¶
Bases:
torch.nn.ModuleBase class for models (
ModelandCompositeModel) that is used to define the interface for all models trainable by theBaseTrainer.Provides methods to initialize the model weights and setup (model-specific) optimizers.
- Parameters:
model_config (noether.core.schemas.models.ModelBaseConfig) – Model configuration. See
ModelBaseConfigfor available options.update_counter (noether.core.utils.training.counter.UpdateCounter | None) – The
UpdateCounterprovided to the optimizer.path_provider (noether.core.providers.PathProvider | None) – A path
PathProviderused by the initializer to store or retrieve checkpoints.data_container (noether.data.container.DataContainer | None) – The
DataContainerwhich includes the data and dataloader. This is currently unused but helpful for quick prototyping only, evaluating forward in debug mode, etc.initializer_config (list[noether.core.schemas.initializers.InitializerConfig] | None) – The initializer config used to initialize the model e.g. from a checkpoint.
- logger¶
- name¶
- update_counter = None¶
- path_provider = None¶
- data_container = None¶
- initializers: list[noether.core.initializers.InitializerBase] = []¶
- model_config¶
- is_initialized = False¶
- property optimizer: noether.core.optimizer.OptimizerWrapper | None¶
- Return type:
- property device: torch.device¶
- Abstractmethod:
- Return type:
- property trainable_param_count: int¶
Returns the number of parameters that require gradients (i.e., are trainable).
- Return type:
- property frozen_param_count: int¶
Returns the number of parameters that do not require gradients (i.e., are frozen).
- Return type:
- property nograd_paramnames: list[str]¶
Returns a list of parameter names that do not have gradients (i.e., grad is None) but require gradients.
- initialize()¶
Initializes weights and optimizer parameters of the model.
- abstractmethod get_named_models()¶
Returns a dict of {model_name: model}, e.g., to log all learning rates of all models/submodels.
- abstractmethod initialize_weights()¶
Initialize the weights of the model.
- Return type:
Self
- abstractmethod apply_initializers()¶
Apply the initializers to the model.
- Return type:
Self
- abstractmethod initialize_optimizer()¶
Initialize the optimizer of the model.
- Return type:
None
- abstractmethod optimizer_step(grad_scaler)¶
Perform an optimization step.
- Parameters:
grad_scaler (torch.amp.grad_scaler.GradScaler | None)
- Return type:
None
- abstractmethod optimizer_schedule_step()¶
Perform the optimizer learning rate scheduler step.
- Return type:
None