twodlearn.optimv2 module

class twodlearn.optimv2.BaseOptimizer(**kargs)[source]

Bases: twodlearn.core.common.TdlModel

Manages and runs an optimization operation over a loss tensor.

The basic usage is as follows

optim = Optimizer(
    loss=loss,
    learning_rate=0.01,
    var_list=tdl.core.get_trainable(model))

BaseOptimizer only runs the optimization operation. The BaseOptimizer can be extended using the wrap() method to construct optimizer classes that include monitoring, status bar, checkpoints, value checks, etc. The class can be extended as follows

MonitoredOptimizer = BaseOptimizer.wrap(CheckNan) \
                                  .wrap(Monitor)  \
                                  .wrap(StatusBar)

Tdl autoinitialization with arguments:

optimizer[source]

(Submodel) Optimizer used to perform the optimization. AdamOptimizer is used by default.

_assert_initialized[source]

(MethodInit) assert variables have been initialized

restart[source]

(MethodInit) calls the initializer for all var_list and optimizer variables.

var_list[source]

(InputArgument)

session[source]

(InputArgument)

loss[source]

(InputArgument)

feed_dict[source]

(Submodel)

step_op[source]

(Submodel) operation that performs the weight update.

learning_rate[source]

(Submodel)

train_step[source]

(LazzyProperty)

cleanup(**kwargs)[source]
feed_dict[source]
get_ops()[source]
learning_rate[source]
loss[source]
optimizer[source]

Optimizer used to perform the optimization. AdamOptimizer is used by default.

restart[source]

calls the initializer for all var_list and optimizer variables.

run(n_steps, feed_dict=None, **kargs)[source]
run_step(**kwargs)[source]
session[source]
step_fn(wrapped_fn=None, **kwargs)[source]
step_op[source]

operation that performs the weight update.

train_step[source]
var_list[source]
warmup(**kwargs)[source]
classmethod wrap(Monitor).wrap(Logger)[source]
class twodlearn.optimv2.CheckNan(**kargs)[source]

Bases: twodlearn.core.common.TdlModel

Tdl autoinitialization with arguments:

check_nan[source]

(SubmodelInit) Autoinit with arguments [‘n_trials’]

check_nan[source]

Autoinit with arguments [‘n_trials’]

step_fn(wrapped_fn=None, **kwargs)[source]
warmup(**kwargs)[source]
class twodlearn.optimv2.CheckProgress(**kargs)[source]

Bases: twodlearn.core.common.TdlModel

CheckProgress resets to last checkpoint if progress deteriorates.

Tdl autoinitialization with arguments:

progress[source]

(SubmodelInit) checks if progress has been made in last step.

progress[source]

checks if progress has been made in last step.

Parameters
  • filter_window (int) – size of the buffer used by the moving average filter.

  • reset_multiplier (float) – if current loss > reset_multiplier*filtered_loss, we restore the last checkpoint.

step_fn(wrapped_fn=None, **kwargs)[source]
warmup(**kwargs)[source]
class twodlearn.optimv2.Checkpointable(**kargs)[source]

Bases: twodlearn.core.common.TdlModel

Tdl autoinitialization with arguments:

checkpoints[source]

(SubmodelInit) checkpoints save the value of variables.

checkpoints[source]

checkpoints save the value of variables.

Parameters
  • buffer_size (int) – number of checkpoints saved in the buffer.

  • update_dt (float) – minimum time for the checkpoints to be stored.

step_fn(wrapped_fn=None, **kwargs)[source]
warmup(**kwargs)[source]
class twodlearn.optimv2.CheckpointableProgress(**kargs)[source]

Bases: twodlearn.optimv2.Checkpointable

CheckpointableProgress stores a checkpoint in internal buffer at a given frequency only if progress has been made.

filtered_target[source]

Autoinit with arguments [‘window_size’]

step_fn(wrapped_fn=None, **kwargs)[source]
warmup(**kwargs)[source]
class twodlearn.optimv2.ConstantLr(value)[source]

Bases: object

class twodlearn.optimv2.Monitor(**kargs)[source]

Bases: twodlearn.core.common.TdlModel

Tdl autoinitialization with arguments:

monitor_manager[source]

(SubmodelInit) Autoinit with arguments [‘metrics’, ‘valid_freq’]

feed_valid[source]

(Submodel)

log_folder[source]

(InputArgument)

loss_monitor[source]

(LazzyProperty)

cleanup(**kwargs)[source]
feed_valid[source]
get_ops()[source]
log_folder[source]
loss_monitor[source]
monitor_manager[source]

Autoinit with arguments [‘metrics’, ‘valid_freq’]

step_fn(wrapped_fn=None, **kwargs)[source]
warmup(**kwargs)[source]
class twodlearn.optimv2.Optimizer(**kargs)[source]

Bases: twodlearn.optimv2.Optimizer, twodlearn.optimv2.StatusBar

Tdl autoinitialization with arguments:

optimizer[source]

(Submodel) Optimizer used to perform the optimization. AdamOptimizer is used by default.

_assert_initialized[source]

(MethodInit) assert variables have been initialized

monitor_manager[source]

(SubmodelInit) Autoinit with arguments [‘metrics’, ‘valid_freq’]

feed_valid[source]

(Submodel)

log_folder[source]

(InputArgument)

filtered_target[source]

(SubmodelInit) Autoinit with arguments [‘window_size’]

progress[source]

(SubmodelInit) checks if progress has been made in last step.

loss_monitor[source]

(LazzyProperty)

restart[source]

(MethodInit) calls the initializer for all var_list and optimizer variables.

checkpoints[source]

(SubmodelInit) checkpoints save the value of variables.

check_nan[source]

(SubmodelInit) Autoinit with arguments [‘n_trials’]

var_list[source]

(InputArgument)

session[source]

(InputArgument)

loss[source]

(InputArgument)

feed_dict[source]

(Submodel)

status_bar[source]

(SubmodelInit) Autoinit with arguments [‘update_freq’]

step_op[source]

(Submodel) operation that performs the weight update.

learning_rate[source]

(Submodel)

train_step[source]

(LazzyProperty)

cleanup(**kwargs)[source]
get_ops()[source]
run_step(**kwargs)[source]
warmup(**kwargs)[source]
class twodlearn.optimv2.Saver(**kargs)[source]

Bases: twodlearn.core.common.TdlModel

Tdl autoinitialization with arguments:

saver[source]

(LazzyProperty)

log_folder[source]

(InputArgument)

cleanup(**kwargs)[source]
log_folder[source]
saver[source]
warmup(**kwargs)[source]
class twodlearn.optimv2.StatusBar(**kargs)[source]

Bases: twodlearn.core.common.TdlModel

StatusBar adds a progress bar that also displays some tensor values.

Tdl autoinitialization with arguments:

status_bar[source]

(SubmodelInit) Autoinit with arguments [‘update_freq’]

cleanup(**kwargs)[source]
status_bar[source]

Autoinit with arguments [‘update_freq’]

step_fn(wrapped_fn=None, **kwargs)[source]
warmup(**kwargs)[source]