NAME

AI::MXNet::Module::Bucketing

SYNOPSIS

This is alpha release.
Please refer to t dir for examples.

DESCRIPTION

Implements the AI::MXNet::Module::Base API, and allows multiple
symbols to be used depending on the `bucket_key` provided by each different
mini-batch of data

new

Parameters
----------
sym_gen : subref or any perl object that overloads &{} op
    A sub when called with a bucket key, returns a list with triple
    of ($symbol, $data_names, $label_names).
default_bucket_key : str or anything else
    The key for the default bucket.
logger : Logger
context : Context or arrayref of Context
    Default `cpu()`
work_load_list : array ref of Num
    Default undef, indicating uniform workload.
fixed_param_names: arrayref of str
    Default undef, indicating no network parameters are fixed.
state_names : arrayref of str
    states are similar to data and label, but not provided by data iterator.
    Instead they are initialized to 0 and can be set by set_states()

data_names

A list of names for data required by this module.

output_names

A list of names for the outputs of this module.

data_shapes

Get data shapes.
Returns
-------
An array ref of AI::MXNet::DataDesc objects.

label_shapes

Get label shapes.
Returns
-------
An array ref of AI::MXNet::DataDesc objects. The return value could be undef if
the module does not need labels, or if the module is not binded for
training (in this case, label information is not available).
An array ref of AI::MXNet::DataDesc objects.

output_shapes

Get output shapes.
Returns
-------
An array ref of AI::MXNet::DataDesc objects.

get_params

Get current parameters.
Returns
-------
List of ($arg_params, $aux_params), each a hash ref of name to parameters (
AI::MXNet::NDArray) mapping.

set_params

Assign parameter and aux state values.

Parameters
----------
arg_params : HashRef[AI::MXNet::NDArray]
aux_params : HashRef[AI::MXNet::NDArray]
allow_missing : bool
    If true, params could contain missing values, and the initializer will be
    called to fill those missing params.
force_init : bool
    If true, will force re-initialize even if already initialized.

init_params

Initialize parameters.

Parameters
----------
initializer : AI::MXNet::Initializer, default AI::MXNet::Initalizer->Uniform->(scale => 0.01)
arg_params : HashRef
    Default undef. Existing parameters. This has higher priority than `initializer`.
aux_params : HashRef
    Default undef. Existing auxiliary states. This has higher priority than `initializer`.
allow_missing : Bool
    Allow missing values in `arg_params` and `aux_params` (if not undef). In this case,
    missing values will be filled with `initializer` Default 0
force_init : Bool
    Default 0

bind

Binding for a AI::MXNet::Module::Bucketing means setting up the buckets and bind the
executor for the default bucket key. Executors corresponding to other keys are
binded afterwards with 'switch_bucket'.

Parameters
----------
data_shapes : ArrayRef[AI::MXNet::DataDesc|NameShape]
    This should correspond to the symbol for the default bucket.
label_shapes : Maybe[ArrayRef[AI::MXNet::DataDesc|NameShape]]
    This should correspond to the symbol for the default bucket.
for_training : Bool
    Default is 1.
inputs_need_grad : Bool
    Default is 0.
force_rebind : Bool
    Default is 0.
shared_module : AI::MXNet::Module::Bucketing
    Default is undef. This value is currently not used.
grad_req : str, array ref of str, hash ref of str to str
    Requirement for gradient accumulation. Can be 'write', 'add', or 'null'
    (default to 'write').
    Can be specified globally (str) or for each argument (array ref, hash ref).
bucket_key : str
    bucket key for binding. by default use the default_bucket_key

switch_bucket

Switch to a different bucket. This will change $self->_curr_module.

Parameters
----------
bucket_key : str (or any perl object that overloads "" op)
    The key of the target bucket.
data_shapes : ArrayRef[AI::MXNet::DataDesc|NameShape]
    Typically `data_batch.provide_data`.
label_shapes : Maybe[ArrayRef[AI::MXNet::DataDesc|NameShape]]
    Typically `data_batch.provide_label`.

init_optimizer

Install and initialize optimizers.

Parameters
----------
kvstore : str or AI::MXNet::KVStore object
    Default 'local'
optimizer : str or AI::MXNet::Optimizer object
    Default 'sgd'
optimizer_params : hash ref
    Default: { learning_rate =>  0.01 }
force_init : Bool
    Default 0, indicating whether we should force re-initializing the
    optimizer in the case an optimizer is already installed.

forward

Forward computation.

Parameters
----------
data_batch : DataBatch
is_train : Bool
    Default is undef, in which case 'is_train' is taken from $self->for_training.

backward

Backward computation.
Parameters
----------
out_grads : Maybe[ArrayRef[AI::MXNet::NDArray]|AI::MXNet::NDArray]
Default: undef

update

Update parameters according to installed optimizer and the gradient computed
in the previous forward-backward cycle.

get_outputs

Get outputs from a previous forward computation.

Parameters
----------
merge_multi_context : Bool
    Default is 1. In the case when data-parallelism is used, the outputs
    will be collected from multiple devices. A 1 value indicates that we
    should merge the collected results so that they look like from a single
    executor.

Returns
-------
If 'merge_multi_context' is 1, it is like [out1, out2]. Otherwise, it
is like [[out1_dev1, out1_dev2], [out2_dev1, out2_dev2]]. All the output
elements are pdl objects.

get_input_grads

Get the gradients with respect to the inputs of the module.

Parameters
----------
merge_multi_context : Bool
    Default is 1. In the case when data-parallelism is used, the outputs
    will be collected from multiple devices. A 1 value indicates that we
    should merge the collected results so that they look like from a single
    executor.

Returns
-------
If 'merge_multi_context' is 1, it is like [grad1, grad2]. Otherwise, it
is like [[grad1_dev1, grad1_dev2], [grad2_dev1, grad2_dev2]]. All the output
elements are AI::MXNet::NDArray objects.

update_metric Evaluate and accumulate evaluation metric on outputs of the last forward computation.

Parameters
----------
eval_metric : AI::MXNet::EvalMetric
labels : ArrayRef[AI::MXNet::NDArray]
    Typically $data_batch->label.

symbol

The symbol of the current bucket being used.

get_symbol

The symbol of the default bucket being used.

install_monitor

Install monitor on all executors.

Paramters
---------
AI::MXNet::Monitor