Hi,
I would like to report a possible problem in C API.
I played with C API with a toy model (just adding two numbers) like:
net = mx.gluon.nn.Dense(1, in_units=2)
x = mx.sym.var('data')
y = net(x)
mod = mx.mod.Module(symbol=y, context=mx.cpu(), data_names = ['data'], label_names=[])
mod.bind(data_shapes=[("data", (1,2))], for_training=False)
mod.init_params(mx.init.Constant(1))
mod.save_checkpoint('mx_add', 0)
Then using code for prediction like:
PredictorHandle pred_handler = NULL;
const char* input_keys[] = { "data" };
const mx_uint input_shape_indptr[] = { 0, 2 };
const mx_uint input_shape_data[] = { 1, 2 };
const mx_float input[] = {3, 5};
mx_float output[1];
int result;
// In symbol/params_map we have appropriate files mapped into memory
result = MXPredCreate(symbol_map->mem,
params_map->mem,
params_map->mapsize,
1, /* dev_type: cpu */
0, /* dev_id */
1, /* num_input_nodes */
input_keys,
input_shape_indptr,
input_shape_data,
&pred_handler);
printf("%d, '%s'\n", result, MXGetLastError());
result = MXPredSetInput(pred_handler, input_keys[0], input, 2);
printf("%d, '%s'\n", result, MXGetLastError());
result = MXPredForward(pred_handler);
printf("%d, '%s'\n", result, MXGetLastError());
result = MXPredGetOutput(pred_handler, 0, output, 1);
printf("%d, '%s'\n", result, MXGetLastError());
printf("sum: %f\n", output[0]);
result = MXPredFree(pred_handler);
printf("%d, '%s'\n", result, MXGetLastError());
I was able to obtain, as expected, sum to be 8:
0, ''
0, ''
0, ''
0, ''
sum: 8.000000
0, ''
BUT: when I put into params file something wrong, like weight names with not matching names,
then the prediction doesn’t report any error, and results with unspecified output:
0, ''
0, ''
0, ''
0, ''
sum: 18980598159864999268117905408.000000
0, ''
Shouldn’t predictor creation fail with some error about loading the params file?
Bartosz