ksuit.utils.training.training_iteration

Classes

Module Contents

class ksuit.utils.training.training_iteration.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

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)