AI-MXNet
view release on metacpan or search on metacpan
lib/AI/MXNet/Module/Base.pm view on Meta::CPAN
=head2 get_states
The states from all devices
Parameters
----------
$merge_multi_context=1 : Bool
Default is true (1). In the case when data-parallelism is used, the states
will be collected from multiple devices. A true value indicate 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 AI::MXNet::NDArray.
=cut
method get_states(Bool $merge_multi_context=1)
{
assert($self->binded and $self->params_initialized);
assert(not $merge_multi_context);
return [];
}
=head2 set_states
Set value for states. You can specify either $states or $value, not both.
Parameters
----------
$states= : Maybe[ArrayRef[ArrayRef[AI::MXNet::NDArray]]]
source states arrays formatted like [[$state1_dev1, $state1_dev2],
[$state2_dev1, $state2_dev2]].
$value= : Maybe[Num]
a single scalar value for all state arrays.
=cut
method set_states(Maybe[ArrayRef[ArrayRef[AI::MXNet::NDArray]]] $states=, Maybe[Num] $value=)
{
assert($self->binded and $self->params_initialized);
assert(not $states and not $value);
}
=head2 install_monitor
Install monitor on all executors
Parameters
----------
$mon : AI::MXNet::Monitor
=cut
method install_monitor(AI::MXNet::Monitor $mon) { confess("NotImplemented") }
=head2 prepare
Prepare the module for processing a data batch.
Usually involves switching a bucket and reshaping.
Parameters
----------
$data_batch : AI::MXNet::DataBatch
=cut
method prepare(AI::MXNet::DataBatch $data_batch){}
################################################################################
# Computations
################################################################################
=head2 forward
Forward computation. It supports data batches with different shapes, such as
different batch sizes or different image sizes.
If reshaping of data batch relates to modification of symbol or module, such as
changing image layout ordering or switching from training to predicting, module
rebinding is required.
Parameters
----------
$data_batch : DataBatch
Could be anything with similar API implemented.
:$is_train= : Bool
Default is undef, which means is_train takes the value of $self->for_training.
=cut
method forward(AI::MXNet::DataBatch $data_batch, Bool :$is_train=) { confess("NotImplemented") }
=head2 backward
Backward computation.
Parameters
----------
$out_grads : Maybe[AI::MXNet::NDArray|ArrayRef[AI::MXNet::NDArray]], optional
Gradient on the outputs to be propagated back.
This parameter is only needed when bind is called
on outputs that are not a loss function.
=cut
method backward(Maybe[AI::MXNet::NDArray|ArrayRef[AI::MXNet::NDArray]] $out_grads=)
{
confess("NotImplemented")
}
=head2 get_outputs
The outputs of the previous forward computation.
Parameters
----------
$merge_multi_context=1 : Bool
=cut
method get_outputs(Bool $merge_multi_context=1) { confess("NotImplemented") }
( run in 0.323 second using v1.01-cache-2.11-cpan-f0fbb3f571b )