You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@mxnet.apache.org by GitBox <gi...@apache.org> on 2020/07/07 20:03:18 UTC
[GitHub] [incubator-mxnet] nikudyshko opened a new issue #18668: InferArgsMap does not infer dtype
nikudyshko opened a new issue #18668:
URL: https://github.com/apache/incubator-mxnet/issues/18668
## Description
While creating a neural network with MXNet cpp-api, if set `dtype` of know args to `1 (corresponds float64)`, `InferArgsMap` will not transfer this type to infered args. This causes error, when creating Executor.
### Error Message
[22:30:58] C:\Users\UserName\Desktop\neural_nets\Mark1\Mark1\mxnet\include\dmlc\logging.h:429: [22:30:58] C:\Users\UserName\Desktop\neural_nets\Mark1\Mark1\mxnet\include\mxnet-cpp\executor.hpp:85: Check failed: MXExecutorBindEX(symbol.GetHandle(), context.GetDeviceType(), context.GetDeviceId(), group_to_ctx.size(), map_keys.data(), dev_types.data(), dev_ids.data(), arg_handles.size(), arg_handles.data(), grad_handles.data(), grad_reqs_uint.data(), aux_handles.size(), aux_handles.data(), shared_exec_handle, &handle_) == 0 (-1 vs. 0) :
## To Reproduce
```cpp
#include <chrono>
#include "mxnet-cpp/MxNetCpp.h"
using namespace mxnet::cpp;
Symbol mlp(const std::vector<int>& layers) {
auto x = Symbol::Variable("X");
auto label = Symbol::Variable("label");
std::vector<Symbol> weights(layers.size());
std::vector<Symbol> biases(layers.size());
std::vector<Symbol> outputs(layers.size());
for (size_t i = 0; i < layers.size(); ++i) {
weights[i] = Symbol::Variable("w" + std::to_string(i));
biases[i] = Symbol::Variable("b" + std::to_string(i));
Symbol fc = FullyConnected(
i == 0 ? x : outputs[i - 1], // data
weights[i],
biases[i],
layers[i]);
outputs[i] = i == layers.size() - 1 ? fc : Activation(fc, ActivationActType::kRelu);
}
return SoftmaxOutput(outputs.back(), label);
}
int main()
{
const int image_size = 28;
const std::vector<int> layers{ 128, 64, 10 };
const int batch_size = 100;
const int max_epoch = 10;
const float learning_rate = 0.1;
const float weight_decay = 1e-2;
auto net = mlp(layers);
Context ctx = Context::cpu(); // Use CPU for training
std::map<std::string, NDArray> args;
args["X"] = NDArray(Shape(batch_size, image_size * image_size), ctx, true, 1); // 1 should correspond to float64
args["label"] = NDArray(Shape(batch_size), ctx, true, 1); // 1 should correspond to float64
// Let MXNet infer shapes other parameters such as weights
net.InferArgsMap(ctx, &args, args);
for (auto& arg : args)
std::cout << arg.first << ' ' << arg.second.GetDType() << '\n';
// Output here:
// X 1
// b0 0
// b1 0
// b2 0
// label 1
// w0 0
// w1 0
// w2 0
// All 0 should be 1
// Create executor by binding parameters to the model
auto* exec = net.SimpleBind(ctx, args); // Error here
return 0;
}
```
### Steps to reproduce
Just compile and run the code above
## What have you tried to solve it?
I've tried to add `dtype`-infering to the code of `InferArgsMap`. This allowed me to create a network, but than an had been thrown on args destruction.
## Environment
Win10 64-bit, VS2019, MXNet
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
users@infra.apache.org