ksuit.callbacks.base.periodic_callback ====================================== .. py:module:: ksuit.callbacks.base.periodic_callback Attributes ---------- .. autoapisummary:: ksuit.callbacks.base.periodic_callback.IntervalType Classes ------- .. autoapisummary:: ksuit.callbacks.base.periodic_callback.PeriodicCallback Module Contents --------------- .. py:data:: IntervalType .. py:class:: PeriodicCallback(callback_config, trainer, model, data_container, tracker, log_writer, checkpoint_writer, metric_property_provider, name = None) Bases: :py:obj:`ksuit.callbacks.base.callback_base.CallbackBase` Base class for callbacks that are invoked periodically during training. Epoch, update and sample based intervals are supported. ``` Initializes the `PeriodicCallback`. :param callback_config: Configuration of the `PeriodicCallback`. Implements the `CallBackBaseConfig` schema. :param trainer: Trainer of the current run, subclass of `SgdTrainer`. :param model: Model of the current run. :param data_container: DataContainer instance that provides access to all datasets. :param tracker: Tracker instance to log metrics to stdout/disk/online platform. :param log_writer: LogWriter instance to log metrics. :param checkpoint_writer: CheckpointWriter instance to save checkpoints. :param metric_property_provider: MetricPropertyProvider instance to access properties of metrics. :param name: Name of the callback. .. py:attribute:: every_n_epochs .. py:attribute:: every_n_updates .. py:attribute:: every_n_samples .. py:attribute:: batch_size .. py:method:: should_log_after_epoch(training_iteration) Checks after every epoch if the `PeriodicCallback` should be invoked. :param training_iteration: TrainingIteration to check. .. py:method:: should_log_after_update(training_iteration) Checks after every update if the `PeriodicCallback` should be invoked. :param training_iteration: TrainingIteration to check. .. py:method:: should_log_after_sample(training_iteration, effective_batch_size) Checks after every sample if the `PeriodicCallback` should be invoked. :param training_iteration: TrainingIteration to check. :param effective_batch_size: Effective batch size to use for the check (required for checking how many samples have been processed since the last update). .. py:method:: track_after_accumulation_step(*, update_counter, batch, losses, update_outputs, accumulation_steps, accumulation_step) Invoked after every gradient accumulation step. May be used to track metrics. Applies `torch.no_grad()`. :param update_counter: UpdateCounter instance to access current training progress. :param batch: Current batch. :param losses: Losses computed for the current batch. :param update_outputs: Outputs of the model for the current batch. :param accumulation_steps: Total number of accumulation steps. :param accumulation_step: Current accumulation step. .. py:method:: track_after_update_step(update_counter, times) Invoked after every update step. May be used to track metrics. Applies `torch.no_grad()`. :param update_counter: UpdateCounter instance to access current training progress. :param times: Dictionary containing time measurements. .. py:method:: after_epoch(update_counter, **kwargs) Invoked after every epoch to check if callback should be invoked. Applies `torch.no_grad()`. :param update_counter: UpdateCounter instance to access current training progress. .. py:method:: after_update(update_counter, **kwargs) Invoked after every update to check if callback should be invoked. Applies `torch.no_grad()`. :param update_counter: UpdateCounter instance to access current training progress. .. py:method:: updates_till_next_log(update_counter) Calculates how many updates remain until this callback is invoked. :param update_counter: UpdateCounter instance to access current training progress. :returns: Number of updates remaining until the next callback invocation. .. py:method:: updates_per_log_interval(update_counter) Calculates how many updates are from one invocation of this callback to the next. :param update_counter: UpdateCounter instance to access current training progress. :returns: Number of updates between callback invocations. .. py:method:: get_interval_string_verbose() Returns `every_n_epochs`, `every_n_updates` or `every_n_samples` depending on which one is not None. :returns: Interval as, e.g., "every_n_epochs=1" for epoch-based intervals. :rtype: str .. py:method:: to_short_interval_string() Returns `every_n_epochs`, `every_n_updates` or `every_n_samples` depending on which one is not None. :returns: Interval as, e.g., "E1" if `every_n_epochs=1` for epoch-based intervals. :rtype: str