Config schema
frogbox.config
ObjectArgument
module-attribute
Argument that can be passed to an object definition.
CallbackDefinition
Bases: ObjectDefinition
Callback definition.
Attributes:
-
interval(EventStep | LogInterval) –Event describing when to call callback.
-
engine(EngineType) –Which engine to bind the callback to.
CheckpointDefinition
Bases: StrictModel
Checkpoint definition.
Attributes:
-
interval(EventStep or LogInterval) –Interval between saving checkpoints.
-
num_saved(int) –Number of checkpoints to save.
-
metric(str) –Name of metric to compare (optional).
-
mode(CheckpointMode) –Whether to priority maximum or minimum metric value.
CheckpointMode
Config
Bases: StrictModel
Base configuration.
Attributes:
-
type(ConfigType) –Pipeline type.
-
project(str) –Project name.
-
tracker(TrackerType) –Tracker to use for logging.
-
tracker_kwargs(Mapping[str, ObjectArgument] | None) –Keyword-argument to pass to tracker during initialization.
-
log_interval(EventStep | LogInterval) –At which interval to log metrics.
-
batch_size(int) –Batch size.
-
loader_workers(int) –How many subprocesses to use for data loading.
0means the data will be loaded in the main process. -
max_epochs(int) –Maximum number of epochs to train for.
-
gradient_accumulation_steps(int) –Number of steps the gradients should be accumulated across.
-
checkpoints(Sequence[CheckpointDefinition]) – -
datasets(Mapping[str, ObjectDefinition]) –Dataset definitions.
-
loaders(Mapping[str, ObjectDefinition]) –Data loader definitions.
-
metrics(Mapping[str, ObjectDefinition]) –Evaluation metrics.
-
callbacks(Sequence[CallbackDefinition]) –Callback functions.
ConfigType
EngineType
LRSchedulerDefinition
Bases: StrictModel
Learning rate scheduler definition.
Attributes:
-
type(SchedulerType) –Scheduler type.
-
end_value(float) –Final learning rate.
-
warmup_stets(int) –Number of steps to perform warmup. Set to
0to disable warmup.
LogInterval
Bases: StrictModel
Logging interval.
Attributes:
-
event(Events) –Event trigger.
-
interval(int) –How often event should trigger. Defaults to every time (
1). -
first(int) –First step where event should trigger (zero-indexed).
-
last(int) –Last step where vent should trigger (zero-indexed).
LossDefinition
Bases: ObjectDefinition
Loss function definition
Attributes:
-
weight(float) –Loss function weight.
-
transform(ObjectDefinition | None) –Callable that takes in
y_predandyand outputs what is passed to the loss function.
ModelDefinition
Bases: ObjectDefinition
Model definition.
Attributes:
-
optimizers(Mapping[str, OptimizerDefinition]) –Optimizer definitions.
ObjectDefinition
Bases: StrictModel
Object definition.
Describes either an object or callable instance.
Only one of object, function and lambda can provided at a time.
Attributes:
-
object(str | None) –Import path to object constructor.
-
function(str | None) –Import path to function.
-
lambda–Lambda function definition.
Should have format
{args}: {expr}. Example:x, y: x + y. -
args(Sequence[ObjectArgument] | None) –Positional arguments.
-
kwargs(Mapping[str, ObjectArgument] | None) –Keyword arguments.
Example
Creating an object instance:
Creating a function instance:
Creating a lambda function:
OptimizerDefinition
Bases: ObjectDefinition
Optimizer definition.
Attributes:
-
scheduler(LRSchedulerDefinition) –Learning rate scheduler definition.
-
parameters(str | ObjectDefinition | None) –Which parameters in the model to optimize. Must be either a regex matching the parameter names to include or a callable that takes in the model and returns a list of parameters.
Example
Defining target parameters using regex:
Defining target parameters using a function:
SchedulerType
SupervisedConfig
Bases: Config
Supervised pipeline configuration.
Attributes:
-
clip_grad_norm(float | None) –Clip gradients to norm if provided.
-
clip_grad_norm(float | None) –Clip gradients to value if provided.
-
model(ModelDefinition) –Model definition.
-
losses(Mapping[str, LossDefinition]) –Loss functions.
-
trainer_forward(ObjectDefinition | None) –Trainer custom forward function. Should be function that takes
x,yandmodeland returns(y, y_pred). -
evaluator_forward(ObjectDefinition | None) –Evaluator custom forward function. Should be function that takes
x,yandmodeland returns(y, y_pred).
TrackerType
create_object_from_config
create_object_from_config(
config, *additional_args, **additional_kwargs
)
Create object from dictionary configuration.
Dictionary should have a class entry and an optional params entry.
Parameters:
-
(configObjectDefinition) –Object definition.
-
(additional_args*args, default:()) –Additional positional arguments. Appended to positional arguments in
config. -
(additional_kwargs**kwargs, default:{}) –Additional keyword arguments. Keyword arguments in
configtake priority.
parse_log_interval
Create matchable event from log interval configuration.
Returns:
-
MatchableEvent–The parsed interval event.
read_config
read_config(path, format=None, config_vars=None)
Read and render config file using jinja2.
Parameters:
-
(pathstr or path - like) –Path to JSON config file.
-
(formatstr, default:None) –File format to read. If not provided, format will be inferred from filename.
-
(config_varsstr-to-str mapping, default:None) –Keyword arguments to pass to jinja2.