noether.core.utils.training

Submodules

Classes

UpdateCounter

UpdateCounter is used to track the current update, epoch, and sample

ScheduleWrapper

Wrapper around a schedule that handles getting the value based on an UpdateCounter and whether the schedule is

TrainingIteration

Package Contents

class noether.core.utils.training.UpdateCounter(start_iteration, end_iteration, updates_per_epoch, effective_batch_size)

UpdateCounter is used to track the current update, epoch, and sample number during training.

Initializes UpdateCounter.

Parameters:
updates_per_epoch
start_iteration
end_iteration
cur_iteration
effective_batch_size
property is_full_epoch: bool

Returns True if the current update is a full epoch.

Return type:

bool

property epoch_as_float: float

Returns the current epoch as a float value.

Return type:

float

property epoch: int | None

Returns the current epoch.

Return type:

int | None

property update: int | None

Returns the current update.

Return type:

int | None

property sample: int | None

Returns the current sample.

Return type:

int | None

property is_finished: bool

Returns True if the end checkpoint is reached.

Return type:

bool

next_epoch()

Increments the current epoch by 1.

Return type:

None

next_update()

Increments the current update by 1.

Return type:

None

add_samples(num_samples)

Adds samples to the current sample count.

Parameters:

num_samples (int)

Return type:

None

class noether.core.utils.training.ScheduleWrapper(schedule, update_counter=None, interval='update')

Wrapper around a schedule that handles getting the value based on an UpdateCounter and whether the schedule is based on updates or epochs.

Parameters:
schedule
update_counter = None
interval = 'update'
get_value()

Get the current value of the schedule based on the current step in the UpdateCounter.

Return type:

float

class noether.core.utils.training.TrainingIteration(epoch=None, update=None, sample=None)
Parameters:
  • epoch (int | None)

  • update (int | None)

  • sample (int | None)

epoch = None
update = None
sample = None
copy()

Creates a copy of a TrainingIteration object.

Return type:

TrainingIteration

property specified_properties_count: int

Counts the number of specified (non-None) properties.

Return type:

int

property is_fully_specified: bool

Checks if all properties are specified.

Return type:

bool

property is_minimally_specified: bool

Checks if at least one property is specified.

Return type:

bool

get_n_equal_properties(other)

Counts the number of equal properties between two TrainingIteration objects.

Parameters:

other (TrainingIteration) – The other TrainingIteration object to compare with.

Return type:

int

to_fully_specified(updates_per_epoch, effective_batch_size)

Converts the TrainingIteration object to a fully specified TrainingIteration object. This method calculates the missing properties based on the specified ones.

Parameters:
  • updates_per_epoch (int) – The number of updates per epoch.

  • effective_batch_size (int) – The effective batch size used in the training process.

Return type:

TrainingIteration

classmethod from_dict(data)
Parameters:

data (dict[str, int])

Return type:

TrainingIteration

has_same_specified_properties(other)

Checks if the specified properties of two TrainingIteration objects are the same.

Parameters:

other (TrainingIteration) – The other TrainingIteration object to compare with.

Return type:

bool

static from_string(value)

Converts a training iteration string into a TrainingIteration object.

The training iteration string should be in the format “E{epoch}_U{update}_S{sample}”. For instance: E5_U12_S123 corresponds to TrainingIteration(epoch=5, update=12, sample=123).

Parameters:

value (str) – The TrainingIteration string to convert.

Return type:

TrainingIteration

static contains_string(source)

Checks if the source string contains a training iteration string.

Parameters:

source (str) – The source string to check.

Returns:

True if the source string contains a training iteration string, False otherwise.

Return type:

bool

static find_string(source)

Checks if the source string contains a training iteration string and returns it.

Parameters:

source (str) – The source string to check.

Returns:

The found TrainingIteration string.

Return type:

str

static from_filename(fname)

Creates a TrainingIteration object from a filename that contains a training iteration string.

Parameters:

fname (str) – The filename to extract the training iteration string from.

Returns:

The created object.

Return type:

TrainingIteration

static to_fully_specified_from_filenames(directory, training_iteration, prefix=None, suffix=None)

Converts a minimally specified TrainingIteration to a fully specified one from filenames in a given folder. The first file containing a training iteration string and optionally starting with prefix or ending with suffix is used.

Parameters:
  • directory (str) – The directory containing training iteration files.

  • training_iteration (TrainingIteration) – The TrainingIteration object to match against.

  • prefix (str | None) – Optional prefix to filter files.

  • suffix (str | None) – Optional suffix to filter files.

Returns:

The created object.

Return type:

TrainingIteration

Raises:

FileNotFoundError – If no matching file is found.

to_target_specification(target)

Creates a new object that matches the target specification.

Example: ` self=TrainingIteration(epoch=6, update=12, sample=123)` target=TrainingIteration(epoch=5) print(self.to_target_specification(target)) TrainingIteration(epoch=6) ` :param target: The target TrainingIteration object to match against.

Returns:

The created object.

Return type:

TrainingIteration

Parameters:

target (TrainingIteration)