AI-MXNet
view release on metacpan or search on metacpan
lib/AI/MXNet/KVStore.pm view on Meta::CPAN
optimizer : Optimizer
the optimizer
=cut
method set_optimizer(AI::MXNet::Optimizer $optimizer)
{
my $is_worker = check_call(AI::MXNetCAPI::KVStoreIsWorkerNode());
if($self->type eq 'dist' and $is_worker)
{
my $optim_str = MIME::Base64::encode_base64(Storable::freeze($optimizer), "");
$self->_send_command_to_servers(0, $optim_str);
}
else
{
$self->_updater(AI::MXNet::Optimizer->get_updater($optimizer));
$self->_set_updater(sub { &{$self->_updater}(@_) });
}
}
=head2 type
lib/AI/MXNet/KVStore.pm view on Meta::CPAN
init the values, and then pull the inited value to all machines. Before
pulling, we can place a barrier to guarantee that the initialization is
finished.
=cut
method _barrier()
{
check_call(AI::MXNetCAPI::KVStoreBarrier($self->handle));
}
=head2 _send_command_to_servers
Send a command to all server nodes
Send a command to all server nodes, which will make each server node run
KVStoreServer.controller
This function returns after the command has been executed in all server
nodes.
Parameters
----------
head : int
the head of the command
body : str
the body of the command
=cut
method _send_command_to_servers(Int $head, Str $body)
{
check_call(
AI::MXNetCAPI::KVStoreSendCommmandToServers(
$self->handle,
$head,
$body
)
);
}
lib/AI/MXNet/KVStoreServer.pm view on Meta::CPAN
$self->init_logging(1);
}
if($cmd_id == 0)
{
my $optimizer = Storable::thaw(MIME::Base64::decode_base64($cmd_body));
$self->kvstore->set_optimizer($optimizer);
}
else
{
my $rank = $self->kvstore->rank;
print("server $rank, unknown command ($cmd_id, $cmd_body)\n");
}
}
}
=head2 run
run the server, whose behavior is like
>>> while receive(x):
... if is_command x: controller(x)
... else if is_key_value x: updater(x)
=cut
method run()
{
check_call(AI::MXNetCAPI::KVStoreRunServer($self->handle, $self->_controller));
}
# Start server/scheduler
func _init_kvstore_server_module()
( run in 0.640 second using v1.01-cache-2.11-cpan-f56aa216473 )