Common
Common utility functions used across the library.
capture_function_arguments
#
Capture the function arguments and their values from the locals dictionary.
PARAMETER | DESCRIPTION |
---|---|
the_locals
|
The locals dictionary of the function.
TYPE:
|
func
|
The function to capture arguments from.
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
dict
|
A dictionary of function arguments and their values. |
Source code in neps\utils\common.py
disable_warnings
#
Disable certain warning categories for a specific block.
Source code in neps\utils\common.py
dynamic_load_object
#
Dynamically loads an object from a given module file path.
PARAMETER | DESCRIPTION |
---|---|
path
|
File system path or module path to the Python module.
TYPE:
|
object_name
|
Name of the object to import from the module.
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
object
|
The imported object from the module.
TYPE:
|
RAISES | DESCRIPTION |
---|---|
ImportError
|
If the module or object cannot be found. |
Source code in neps\utils\common.py
extract_keyword_defaults
#
Extracts the keywords from a function, if any.
Source code in neps\utils\common.py
gc_disabled
#
gc_disabled() -> Iterator[None]
Context manager to disable garbage collection for a block.
We specifically put this around file I/O operations to minimize the time spend garbage collecting while having the file handle open.
Source code in neps\utils\common.py
get_initial_directory
#
Find the initial directory based on its existence and the presence of the "previous_config.id" file.
PARAMETER | DESCRIPTION |
---|---|
pipeline_directory
|
The current config directory. |
RETURNS | DESCRIPTION |
---|---|
Path
|
The initial directory. |
Source code in neps\utils\common.py
get_value
#
Honestly, don't know why you would use this. Please try not to.
Source code in neps\utils\common.py
is_partial_class
#
load_checkpoint
#
load_checkpoint(
directory: Path | str | None = None,
checkpoint_name: str = "checkpoint",
model: Module | None = None,
optimizer: Optimizer | None = None,
) -> dict | None
Load a checkpoint and return the model state_dict and checkpoint values.
PARAMETER | DESCRIPTION |
---|---|
directory
|
Directory where the checkpoint is located. |
checkpoint_name
|
The name of the checkpoint file.
TYPE:
|
model
|
The PyTorch model to load.
TYPE:
|
optimizer
|
The optimizer to load.
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
dict | None
|
A dictionary containing the checkpoint values, or None if the checkpoint file does not exist hence no checkpointing was previously done. |
Source code in neps\utils\common.py
load_lightning_checkpoint
#
load_lightning_checkpoint(
checkpoint_dir: Path | str,
previous_pipeline_directory: Path | str | None = None,
) -> tuple[Path, dict] | tuple[None, None]
Load the latest checkpoint file from the specified directory.
This function searches for possible checkpoint files in the checkpoint_dir
and loads
the latest one if found. It returns a tuple with the checkpoint path and the loaded
checkpoint data.
PARAMETER | DESCRIPTION |
---|---|
checkpoint_dir
|
The directory where checkpoint files are stored. |
previous_pipeline_directory
|
The previous pipeline directory. |
RETURNS | DESCRIPTION |
---|---|
tuple[Path, dict] | tuple[None, None]
|
A tuple containing the checkpoint path (str) and the loaded checkpoint data (dict) or (None, None) if no checkpoint files are found in the directory. |
Source code in neps\utils\common.py
save_checkpoint
#
save_checkpoint(
directory: Path | str | None = None,
checkpoint_name: str = "checkpoint",
values_to_save: dict | None = None,
model: Module | None = None,
optimizer: Optimizer | None = None,
) -> None
Save a checkpoint including model state_dict and optimizer state_dict to a file.
PARAMETER | DESCRIPTION |
---|---|
directory
|
Directory where the checkpoint will be saved. |
values_to_save
|
Additional values to save in the checkpoint.
TYPE:
|
model
|
The PyTorch model to save.
TYPE:
|
optimizer
|
The optimizer to save.
TYPE:
|
checkpoint_name
|
The name of the checkpoint file.
TYPE:
|