Callbacks

class todd.runners.callbacks.AutocastCallback[source]

Bases: BaseCallback[T]

__init__(*args, autocast, **kwargs)[source]
Parameters:

autocast (Config)

Return type:

None

run_iter_context(exit_stack, batch, memo)[source]
Parameters:
Return type:

None

class todd.runners.callbacks.BaseCallback[source]

Bases: RunnerHolderMixin[T], StateDictMixin

after_run(memo)[source]
Parameters:

memo (dict[str, Any])

Return type:

None

after_run_epoch(epoch_memo, memo)[source]
Parameters:
Return type:

None

after_run_iter(batch, memo)[source]
Parameters:
Return type:

None

before_run(memo)[source]
Parameters:

memo (dict[str, Any])

Return type:

None

before_run_epoch(epoch_memo, memo)[source]
Parameters:
Return type:

None

before_run_iter(batch, memo)[source]
Parameters:
Return type:

None

run_epoch_context(exit_stack, epoch_memo, memo)[source]
Parameters:
Return type:

None

run_iter_context(exit_stack, batch, memo)[source]
Parameters:
Return type:

None

should_break(batch, memo)[source]

Determine whether to break the run loop.

Parameters:
  • batch (Any) – inputs.

  • memo (dict[str, Any]) – runtime memory.

Returns:

Whether to break the run loop.

Return type:

bool

Override this method for early stopping, error detection, etc. By default, this method returns False and the run loop ends normally when the dataloader is exhausted.

should_break_epoch(epoch_memo, memo)[source]
Parameters:
Return type:

bool

should_continue(batch, memo)[source]

Determine whether to skip the current iteration.

Parameters:
  • batch (Any) – inputs.

  • memo (dict[str, Any]) – runtime memory.

Returns:

Whether to skip the current iteration.

Return type:

bool

should_continue_epoch(epoch_memo, memo)[source]
Parameters:
Return type:

bool

class todd.runners.callbacks.CheckpointCallback[source]

Bases: IntervalMixin[T], BaseCallback[T]

__init__(*args, state_dict=None, load_state_dict=None, **kwargs)[source]
Parameters:
  • state_dict (Config | None)

  • load_state_dict (Config | None)

Return type:

None

after_run_epoch(epoch_memo, memo)[source]
Parameters:
Return type:

None

after_run_iter(batch, memo)[source]
Parameters:

memo (dict[str, Any])

Return type:

None

bind(*args, **kwargs)[source]
Return type:

None

property latest_checkpoint_dir: Path
property work_dir: Path
class todd.runners.callbacks.ComposedCallback[source]

Bases: BuildPreHookMixin, BaseCallback[T]

__init__(*args, priorities, callbacks, **kwargs)[source]
Parameters:
  • priorities (Iterable[Mapping[Literal['bind', 'should_break', 'should_continue', 'before_run_iter', 'run_iter_context', 'after_run_iter', 'should_break_epoch', 'should_continue_epoch', 'before_run_epoch', 'run_epoch_context', 'after_run_epoch', 'before_run', 'after_run'], int]])

  • callbacks (Iterable[BaseCallback[T]])

Return type:

None

after_run(*args, **kwargs)[source]
Return type:

None

after_run_epoch(*args, **kwargs)[source]
Return type:

None

after_run_iter(*args, **kwargs)[source]
Return type:

None

before_run(*args, **kwargs)[source]
Return type:

None

before_run_epoch(*args, **kwargs)[source]
Return type:

None

before_run_iter(*args, **kwargs)[source]
Return type:

None

bind(*args, **kwargs)[source]
Return type:

None

classmethod build_pre_hook(config, registry, item)[source]
Parameters:
  • config (Config)

  • registry (RegistryMeta)

  • item (Item)

Return type:

Config

property callbacks: list[BaseCallback[T]]
load_state_dict(state_dict, *args, **kwargs)[source]
Parameters:

state_dict (Mapping[str, Any])

Return type:

None

put(callback, priority=None)[source]
Parameters:
  • callback (BaseCallback[T])

  • priority (Mapping[Literal['bind', 'should_break', 'should_continue', 'before_run_iter', 'run_iter_context', 'after_run_iter', 'should_break_epoch', 'should_continue_epoch', 'before_run_epoch', 'run_epoch_context', 'after_run_epoch', 'before_run', 'after_run'], int] | None)

Return type:

None

run_epoch_context(*args, **kwargs)[source]
Return type:

None

run_iter_context(*args, **kwargs)[source]
Return type:

None

should_break(*args, **kwargs)[source]
Return type:

bool

should_break_epoch(*args, **kwargs)[source]
Return type:

bool

should_continue(*args, **kwargs)[source]
Return type:

bool

should_continue_epoch(*args, **kwargs)[source]
Return type:

bool

state_dict(*args, **kwargs)[source]
Return type:

dict[str, Any]

class todd.runners.callbacks.GitCallback[source]

Bases: BaseCallback[T]

__init__(*args, diff=None, **kwargs)[source]
Parameters:

diff (str | None)

Return type:

None

bind(*args, **kwargs)[source]
Return type:

None

class todd.runners.callbacks.IntervalMixin[source]

Bases: BaseCallback[T]

__init__(*args, interval=0, by_epoch=False, **kwargs)[source]
Parameters:
Return type:

None

class todd.runners.callbacks.LRScaleCallback[source]

Bases: BaseCallback[T]

__init__(*args, lr_scaler, **kwargs)[source]
Parameters:

lr_scaler (Config)

Return type:

None

bind(*args, **kwargs)[source]
Return type:

None

class todd.runners.callbacks.LRScheduleCallback[source]

Bases: IntervalMixin[T], BaseCallback[T]

__init__(*args, lr_scheduler, interval=1, **kwargs)[source]
Parameters:
  • lr_scheduler (Config)

  • interval (int)

Return type:

None

after_run_epoch(epoch_memo, memo)[source]
Parameters:
Return type:

None

after_run_iter(batch, memo)[source]
Parameters:
Return type:

None

bind(*args, **kwargs)[source]
Return type:

None

load_state_dict(state_dict, *args, **kwargs)[source]
Parameters:

state_dict (Mapping[str, Any])

Return type:

None

state_dict(*args, **kwargs)[source]
Return type:

dict[str, Any]

class todd.runners.callbacks.LogCallback[source]

Bases: IntervalMixin[T], BaseCallback[T]

__init__(*args, collect_env=None, with_file_handler=False, eta=None, **kwargs)[source]
Parameters:
  • collect_env (Config | None)

  • with_file_handler (bool)

  • eta (Config | None)

Return type:

None

after_run_iter(batch, memo)[source]
Parameters:
Return type:

None

before_run(memo)[source]
Parameters:

memo (dict[str, Any])

Return type:

None

before_run_epoch(epoch_memo, memo)[source]
Parameters:
Return type:

None

before_run_iter(batch, memo)[source]
Parameters:
Return type:

None

bind(*args, **kwargs)[source]
Return type:

None

class todd.runners.callbacks.MetricCallback[source]

Bases: BuildPreHookMixin, BaseCallback

__init__(*args, metrics, map_model_config=None, **kwargs)[source]
Parameters:
  • metrics (Iterable[BaseMetric])

  • map_model_config (Config | None)

Return type:

None

after_run(memo)[source]
Parameters:

memo (dict[str, Any])

Return type:

None

after_run_iter(batch, memo)[source]
Parameters:
Return type:

None

bind(*args, **kwargs)[source]
Return type:

None

classmethod build_pre_hook(config, registry, item)[source]
Parameters:
  • config (Config)

  • registry (RegistryMeta)

  • item (Item)

Return type:

Config

classmethod metrics_build_pre_hook(config, registry, item)[source]
Parameters:
  • config (Config)

  • registry (RegistryMeta)

  • item (Item)

Return type:

Config

class todd.runners.callbacks.MonitorCallback[source]

Bases: BaseCallback[T]

run_epoch_context(exit_stack, epoch_memo, memo)[source]
Parameters:
Return type:

None

run_iter_context(exit_stack, batch, memo)[source]
Parameters:
Return type:

None

class todd.runners.callbacks.OptimizeCallback[source]

Bases: BuildPreHookMixin, BaseCallback[T]

__init__(*args, grad_scaler=None, grad_clipper=None, accumulate=1, check=True, **kwargs)[source]
Parameters:
Return type:

None

after_run_iter(batch, memo)[source]
Parameters:
Return type:

None

before_run(memo)[source]
Parameters:

memo (dict[str, Any])

Return type:

None

classmethod build_pre_hook(config, registry, item)[source]
Parameters:
  • config (Config)

  • registry (RegistryMeta)

  • item (Item)

Return type:

Config

load_state_dict(state_dict, *args, **kwargs)[source]
Parameters:

state_dict (Mapping[str, Any])

Return type:

None

run_iter_context(exit_stack, batch, memo)[source]
Parameters:
Return type:

None

state_dict(*args, **kwargs)[source]
Return type:

dict[str, Any]

property with_grad_clipper: bool
property with_grad_scaler: bool
class todd.runners.callbacks.ShadowCallback[source]

Bases: IntervalMixin[T], BaseCallback[T]

__init__(*args, shadow, **kwargs)[source]
Parameters:

shadow (Config)

Return type:

None

after_run_iter(*args, **kwargs)[source]
Return type:

None

bind(*args, **kwargs)[source]
Return type:

None

load_state_dict(state_dict, *args, **kwargs)[source]
Parameters:

state_dict (Mapping[str, Any])

Return type:

None

state_dict(*args, **kwargs)[source]
Return type:

dict[str, Any]

class todd.runners.callbacks.TensorBoardCallback[source]

Bases: IntervalMixin[T], BaseCallback[T]

__init__(*args, summary_writer=None, main_tag, **kwargs)[source]
Parameters:
  • summary_writer (Config | None)

  • main_tag (str)

Return type:

None

after_run_iter(batch, memo)[source]
Parameters:
Return type:

None

before_run_iter(batch, memo)[source]
Parameters:
Return type:

None

bind(*args, **kwargs)[source]
Return type:

None

property main_tag: str
property summary_writer: SummaryWriter
tag(tag)[source]
Parameters:

tag (str)

Return type:

str

property work_dir: Path