| context {luz} | R Documentation |
Context object
Description
Context object storing information about the model training context. See also ctx.
Public fields
buffersThis is a list of buffers that callbacks can use to write temporary information into
ctx.
Active bindings
recordsstores information about values logged with
self$log.deviceallows querying the current accelerator device
callbackslist of callbacks that will be called.
itercurrent iteration
batchthe current batch data. a list with input data and targets.
inputa shortcut for
ctx$batch[[1]]targeta shortcut for
ctx$batch[[2]]min_epochsthe minimum number of epochs that the model will run on.
max_epochsthe maximum number of epochs that the model will run.
hparamsa list of hyperparameters that were used to initialize
ctx$model.opt_hparamsa list of hyperparameters used to initialize the
ctx$optimizers.train_dataa dataloader that is used for training the model
valid_dataa dataloader using during model validation
acceleratoran
accelerator()used to move data, model and etc the the correct device.optimizersa named list of optimizers that will be used during model training.
verbosebool wether the process is in verbose mode or not.
handlersList of error handlers that can be used. See
rlang::try_fetch()for more info.epoch_handlersList of error handlers that can be used. See
rlang::try_fetch()for more info.trainingA bool indicating if the model is in training or validation mode.
modelThe model being trained.
predLast predicted values.
optCurrent optimizer.
opt_nameCurrent optimizer name.
dataCurrent dataloader in use.
loss_fnLoss function used to train the model
lossLast computed loss values. Detached from the graph.
loss_gradLast computed loss value, not detached, so you can do additional tranformation.
epochCurrent epoch.
metricsList of metrics that are tracked by the process.
Methods
Public methods
Method new()
Initializes the context object with minimal necessary information.
Usage
context$new(verbose, accelerator, callbacks, training)
Arguments
verboseWhether the context should be in verbose mode or not.
acceleratorA luz
accelerator()that configures device placement and others.callbacksA list of callbacks used by the model. See
luz_callback().trainingA boolean that indicates if the context is in training mode or not.
Method log()
Allows logging arbitrary information in the ctx.
Usage
context$log(what, set, value, index = NULL, append = TRUE)
Arguments
what(string) What you are logging.
set(string) Usually 'train' or 'valid' indicating the set you want to lot to. But can be arbitrary info.
valuevalue to log
valueArbitrary value to log.
indexIndex that this value should be logged. If
NULLthe value is added to the end of list, otherwise the index is used.appendIf
TRUEand a value in the corresponding index already exists, then value is appended to the current value. IfFALSEvalue is overwritten in favor of the new value.
Method log_metric()
Log a metric gen its name and value. Metric values are indexed by epoch.
Usage
context$log_metric(name, value)
Arguments
namename of the metric
valuevalue to log
valueArbitrary value to log.
Method get_log()
Get a specific value from the log.
Usage
context$get_log(what, set, index = NULL)
Arguments
what(string) What you are logging.
set(string) Usually 'train' or 'valid' indicating the set you want to lot to. But can be arbitrary info.
indexIndex that this value should be logged. If
NULLthe value is added to the end of list, otherwise the index is used.
Method get_metrics()
Get all metric given an epoch and set.
Usage
context$get_metrics(set, epoch = NULL)
Arguments
set(string) Usually 'train' or 'valid' indicating the set you want to lot to. But can be arbitrary info.
epochThe epoch you want to extract metrics from.
Method get_metric()
Get the value of a metric given its name, epoch and set.
Usage
context$get_metric(name, set, epoch = NULL)
Arguments
namename of the metric
set(string) Usually 'train' or 'valid' indicating the set you want to lot to. But can be arbitrary info.
epochThe epoch you want to extract metrics from.
Method get_formatted_metrics()
Get formatted metrics values
Usage
context$get_formatted_metrics(set, epoch = NULL)
Arguments
set(string) Usually 'train' or 'valid' indicating the set you want to lot to. But can be arbitrary info.
epochThe epoch you want to extract metrics from.
Method get_metrics_df()
Get a data.frame containing all metrics.
Usage
context$get_metrics_df()
Method set_verbose()
Allows setting the verbose attribute.
Usage
context$set_verbose(verbose = NULL)
Arguments
verboseboolean. If
TRUEverbose mode is used. IfFALSEnon verbose. ifNULLwe use the result ofinteractive().
Method clean()
Removes unnecessary information from the context object.
Usage
context$clean()
Method call_callbacks()
Call the selected callbacks. Where name is the callback types to call, eg
'on_epoch_begin'.
Usage
context$call_callbacks(name)
Arguments
namename of the metric
Method state_dict()
Returns a list containing minimal information from the context. Used to create the returned values.
Usage
context$state_dict()
Method unsafe_set_records()
Are you sure you know what you are doing?
Usage
context$unsafe_set_records(records)
Arguments
recordsNew set of records to be set.
Method clone()
The objects of this class are cloneable with this method.
Usage
context$clone(deep = FALSE)
Arguments
deepWhether to make a deep clone.