Core¶
-
class
catalyst.core.callback.CallbackOrder[source]¶ Bases:
enum.IntFlagAn enumeration.
-
External= 200¶
-
Internal= 0¶
-
Logging= 100¶
-
Metric= 20¶
-
MetricAggregation= 40¶
-
Optimizer= 60¶
-
Scheduler= 120¶
-
Validation= 80¶
-
-
class
catalyst.core.callback.CallbackNode[source]¶ Bases:
enum.IntFlagAn enumeration.
-
All= 0¶
-
Master= 1¶
-
Worker= 2¶
-
-
class
catalyst.core.callback.Callback(order: int, node: int = <CallbackNode.All: 0>, type: int = <CallbackType.Stage: 0>)[source]¶ Bases:
objectAbstract class that all callback (e.g., Logger) classes extends from. Must be extended before usage.
usage example:
-- stage start ---- epoch start (one epoch - one run of every loader) ------ loader start -------- batch start -------- batch handler -------- batch end ------ loader end ---- epoch end -- stage end exception – if an Exception was raised
All callbacks has
ordervalue fromCallbackOrderandnodevalue fromCallbackNode
-
catalyst.core.registry.Callback(factory: Union[Type, Callable[[...], Any]] = None, *factories: Union[Type, Callable[[...], Any]], name: str = None, **named_factories: Union[Type, Callable[[...], Any]]) → Union[Type, Callable[[...], Any]]¶ Adds factory to registry with it’s
__name__attribute or provided name. Signature is flexible.- Parameters
factory – Factory instance
factories – More instances
name – Provided name for first instance. Use only when pass single instance.
named_factories – Factory and their names as kwargs
- Returns
First factory passed
- Return type
(Factory)
-
catalyst.core.registry.Criterion(factory: Union[Type, Callable[[...], Any]] = None, *factories: Union[Type, Callable[[...], Any]], name: str = None, **named_factories: Union[Type, Callable[[...], Any]]) → Union[Type, Callable[[...], Any]]¶ Adds factory to registry with it’s
__name__attribute or provided name. Signature is flexible.- Parameters
factory – Factory instance
factories – More instances
name – Provided name for first instance. Use only when pass single instance.
named_factories – Factory and their names as kwargs
- Returns
First factory passed
- Return type
(Factory)
-
catalyst.core.registry.Optimizer(factory: Union[Type, Callable[[...], Any]] = None, *factories: Union[Type, Callable[[...], Any]], name: str = None, **named_factories: Union[Type, Callable[[...], Any]]) → Union[Type, Callable[[...], Any]]¶ Adds factory to registry with it’s
__name__attribute or provided name. Signature is flexible.- Parameters
factory – Factory instance
factories – More instances
name – Provided name for first instance. Use only when pass single instance.
named_factories – Factory and their names as kwargs
- Returns
First factory passed
- Return type
(Factory)
-
catalyst.core.registry.Scheduler(factory: Union[Type, Callable[[...], Any]] = None, *factories: Union[Type, Callable[[...], Any]], name: str = None, **named_factories: Union[Type, Callable[[...], Any]]) → Union[Type, Callable[[...], Any]]¶ Adds factory to registry with it’s
__name__attribute or provided name. Signature is flexible.- Parameters
factory – Factory instance
factories – More instances
name – Provided name for first instance. Use only when pass single instance.
named_factories – Factory and their names as kwargs
- Returns
First factory passed
- Return type
(Factory)
-
catalyst.core.registry.Module(factory: Union[Type, Callable[[...], Any]] = None, *factories: Union[Type, Callable[[...], Any]], name: str = None, **named_factories: Union[Type, Callable[[...], Any]]) → Union[Type, Callable[[...], Any]]¶ Adds factory to registry with it’s
__name__attribute or provided name. Signature is flexible.- Parameters
factory – Factory instance
factories – More instances
name – Provided name for first instance. Use only when pass single instance.
named_factories – Factory and their names as kwargs
- Returns
First factory passed
- Return type
(Factory)
-
catalyst.core.registry.Model(factory: Union[Type, Callable[[...], Any]] = None, *factories: Union[Type, Callable[[...], Any]], name: str = None, **named_factories: Union[Type, Callable[[...], Any]]) → Union[Type, Callable[[...], Any]]¶ Adds factory to registry with it’s
__name__attribute or provided name. Signature is flexible.- Parameters
factory – Factory instance
factories – More instances
name – Provided name for first instance. Use only when pass single instance.
named_factories – Factory and their names as kwargs
- Returns
First factory passed
- Return type
(Factory)
-
catalyst.core.registry.Sampler(factory: Union[Type, Callable[[...], Any]] = None, *factories: Union[Type, Callable[[...], Any]], name: str = None, **named_factories: Union[Type, Callable[[...], Any]]) → Union[Type, Callable[[...], Any]]¶ Adds factory to registry with it’s
__name__attribute or provided name. Signature is flexible.- Parameters
factory – Factory instance
factories – More instances
name – Provided name for first instance. Use only when pass single instance.
named_factories – Factory and their names as kwargs
- Returns
First factory passed
- Return type
(Factory)
-
catalyst.core.registry.Transform(factory: Union[Type, Callable[[...], Any]] = None, *factories: Union[Type, Callable[[...], Any]], name: str = None, **named_factories: Union[Type, Callable[[...], Any]]) → Union[Type, Callable[[...], Any]]¶ Adds factory to registry with it’s
__name__attribute or provided name. Signature is flexible.- Parameters
factory – Factory instance
factories – More instances
name – Provided name for first instance. Use only when pass single instance.
named_factories – Factory and their names as kwargs
- Returns
First factory passed
- Return type
(Factory)
Callbacks¶
-
class
catalyst.core.callbacks.checkpoint.CheckpointCallback(save_n_best: int = 1, resume: str = None, resume_dir: str = None, metrics_filename: str = '_metrics.json')[source]¶ Bases:
catalyst.core.callbacks.checkpoint.BaseCheckpointCallbackCheckpoint callback to save/restore your model/criterion/optimizer/metrics.
-
__init__(save_n_best: int = 1, resume: str = None, resume_dir: str = None, metrics_filename: str = '_metrics.json')[source]¶ - Parameters
save_n_best (int) – number of best checkpoint to keep
resume (str) – path to checkpoint to load and initialize runner state
metrics_filename (str) – filename to save metrics in checkpoint folder. Must ends on
.jsonor.yml
-
-
class
catalyst.core.callbacks.checkpoint.IterationCheckpointCallback(save_n_last: int = 1, period: int = 100, stage_restart: bool = True, metrics_filename: str = '_metrics_iter.json')[source]¶ Bases:
catalyst.core.callbacks.checkpoint.BaseCheckpointCallbackIteration checkpoint callback to save your model/criterion/optimizer
-
__init__(save_n_last: int = 1, period: int = 100, stage_restart: bool = True, metrics_filename: str = '_metrics_iter.json')[source]¶ - Parameters
save_n_last (int) – number of last checkpoint to keep
period (int) – save the checkpoint every period
stage_restart (bool) – restart counter every stage or not
metrics_filename (str) – filename to save metrics in checkpoint folder. Must ends on
.jsonor.yml
-
-
class
catalyst.core.callbacks.criterion.CriterionCallback(input_key: Union[str, List[str], Dict[str, str]] = 'targets', output_key: Union[str, List[str], Dict[str, str]] = 'logits', prefix: str = 'loss', criterion_key: str = None, multiplier: float = 1.0, **metric_kwargs)[source]¶ Bases:
catalyst.core.callbacks.metrics._MetricCallbackCallback for that measures loss with specified criterion.
-
__init__(input_key: Union[str, List[str], Dict[str, str]] = 'targets', output_key: Union[str, List[str], Dict[str, str]] = 'logits', prefix: str = 'loss', criterion_key: str = None, multiplier: float = 1.0, **metric_kwargs)[source]¶ - Parameters
input_key (Union[str, List[str], Dict[str, str]]) – key/list/dict of keys that takes values from the input dictionary If ‘__all__’, the whole input will be passed to the criterion If None, empty dict will be passed to the criterion.
output_key (Union[str, List[str], Dict[str, str]]) – key/list/dict of keys that takes values from the input dictionary If ‘__all__’, the whole output will be passed to the criterion If None, empty dict will be passed to the criterion.
prefix (str) – prefix for metrics and output key for loss in
state.batch_metricsdictionarycriterion_key (str) – A key to take a criterion in case there are several of them and they are in a dictionary format.
multiplier (float) – scale factor for the output loss.
-
property
metric_fn¶
-
-
class
catalyst.core.callbacks.formatters.MetricsFormatter(message_prefix)[source]¶ Bases:
abc.ABC,logging.FormatterAbstract metrics formatter
-
class
catalyst.core.callbacks.formatters.TxtMetricsFormatter[source]¶ Bases:
catalyst.core.callbacks.formatters.MetricsFormatterTranslate batch metrics in human-readable format.
This class is used by
logging.Loggerto make a string from record. For details refer to official docs for ‘logging’ module.Note
This is inner class used by Logger callback, no need to use it directly!
-
class
catalyst.core.callbacks.formatters.JsonMetricsFormatter[source]¶ Bases:
catalyst.core.callbacks.formatters.MetricsFormatterTranslate batch metrics in json format.
This class is used by
logging.Loggerto make a string from record. For details refer to official docs for ‘logging’ module.Note
This is inner class used by Logger callback, no need to use it directly!
-
class
catalyst.core.callbacks.logging.ConsoleLogger[source]¶ Bases:
catalyst.core.callback.CallbackLogger callback, translates
state.*_metricsto console and text file
-
class
catalyst.core.callbacks.logging.TensorboardLogger(metric_names: List[str] = None, log_on_batch_end: bool = True, log_on_epoch_end: bool = True)[source]¶ Bases:
catalyst.core.callback.CallbackLogger callback, translates
state.metric_managerto tensorboard-
__init__(metric_names: List[str] = None, log_on_batch_end: bool = True, log_on_epoch_end: bool = True)[source]¶ - Parameters
metric_names (List[str]) – list of metric names to log, if none - logs everything
log_on_batch_end (bool) – logs per-batch metrics if set True
log_on_epoch_end (bool) – logs per-epoch metrics if set True
-
-
class
catalyst.core.callbacks.logging.VerboseLogger(always_show: List[str] = None, never_show: List[str] = None)[source]¶ Bases:
catalyst.core.callback.CallbackLogs the params into console
-
__init__(always_show: List[str] = None, never_show: List[str] = None)[source]¶ - Parameters
always_show (List[str]) – list of metrics to always show if None default is
["_timer/_fps"]to remove always_show metrics set it to an empty list[]never_show (List[str]) – list of metrics which will not be shown
-
-
class
catalyst.core.callbacks.optimizer.OptimizerCallback(loss_key: str = 'loss', optimizer_key: str = None, accumulation_steps: int = 1, grad_clip_params: Dict = None, decouple_weight_decay: bool = True)[source]¶ Bases:
catalyst.core.callback.CallbackOptimizer callback, abstraction over optimizer step.
-
__init__(loss_key: str = 'loss', optimizer_key: str = None, accumulation_steps: int = 1, grad_clip_params: Dict = None, decouple_weight_decay: bool = True)[source]¶ - Parameters
grad_clip_params (dict) – params for gradient clipping
accumulation_steps (int) – number of steps before
model.zero_grad()optimizer_key (str) – A key to take a optimizer in case there are several of them and they are in a dictionary format.
loss_key (str) – key to get loss from
state.lossdecouple_weight_decay (bool) – If True - decouple weight decay regularization.
save_model_grads (#) – If True - State.model_grads will
contain gradients calculated (#) –
on backward propagation on current (#) –
batch (#) –
-
static
grad_step(*, optimizer: torch.optim.optimizer.Optimizer, optimizer_wds: List[float] = 0, grad_clip_fn: Callable = None)[source]¶ Makes a gradient step for a given optimizer
- Parameters
optimizer (Optimizer) – the optimizer
optimizer_wds (List[float]) – list of weight decay parameters for each param group
grad_clip_fn (Callable) – function for gradient clipping
-
-
class
catalyst.core.callbacks.phase.PhaseManagerCallback(train_phases: OrderedDict[str, int] = None, valid_phases: OrderedDict[str, int] = None, valid_mode: str = None)[source]¶ Bases:
catalyst.core.callback.CallbackPhaseManagerCallback updates state.phase
-
VALIDATION_MODE_ALL= 'all'¶
-
VALIDATION_MODE_SAME= 'same'¶
-
allowed_valid_modes= ['same', 'all']¶
-
-
class
catalyst.core.callbacks.scheduler.SchedulerCallback(scheduler_key: str = None, mode: str = None, reduced_metric: str = 'loss')[source]¶
-
class
catalyst.core.callbacks.scheduler.LRUpdater(optimizer_key: str = None)[source]¶ Bases:
catalyst.core.callback.CallbackBasic class that all Lr updaters inherit from
-
class
catalyst.core.callbacks.wrappers.PhaseWrapperCallback(base_callback: catalyst.core.callback.Callback, active_phases: List[str] = None, inactive_phases: List[str] = None)[source]¶ Bases:
catalyst.core.callback.CallbackCallbackWrapper which disables/enables handlers dependant on current phase and event type
May be useful i.e. to disable/enable optimizers & losses
-
LEVEL_BATCH= 'batch'¶
-
LEVEL_EPOCH= 'epoch'¶
-
LEVEL_LOADER= 'loader'¶
-
LEVEL_STAGE= 'stage'¶
-
TIME_END= 'end'¶
-
TIME_START= 'start'¶
-
-
class
catalyst.core.callbacks.wrappers.PhaseBatchWrapperCallback(base_callback: catalyst.core.callback.Callback, active_phases: List[str] = None, inactive_phases: List[str] = None)[source]¶ Bases:
catalyst.core.callbacks.wrappers.PhaseWrapperCallback