I am implementing a fairly complex CustomOp. The documentation is pretty incomplete there…
It does not only have ndarray input parameters, but also other arguments. I’ve been using mx.sym.Custom so far, where the following worked:
mx.sym.Custom(**kwargs)
Here, kwargs is a dict that has entries of type mx.sym (for the input args) and entries of type string. The latter are passed to the CustomOpProp constructor, while the former are passed to forward. Say:
kwargs = {‘x’: mx.sym.Variable(‘x’), ‘myarg’ : ‘foo’}
x is an input to forward,while myarg is passed to CustomOpProp.init
This works fine for what I want to do. But now, I’d like to switch to Gluon / autograd, and suddenly things break. When I write:
mx.nd.Custom(**kwargs)
where now kwargs contains either mx.nd for inputs, or string for CustomOpProp parameters, then I get an error.
More precisely, my CustomOp has three input arguments, called xmat, prior_sqprec, targets, and the CustomOpProp.init has a number of string argument. When I build kwargs and call
mx.nd.Custom(**kwargs)
I get:
Traceback (most recent call last):
File “_ctypes/callbacks.c”, line 315, in 'calling callback function’
File “/Users/matthis/ws_mxnet/src/MatthiasMXNetCode/mymxnet_env/lib/python2.7/site-packages/mxnet-0.12.1-py2.7.egg/mxnet/operator.py”, line 616, in creator
op_prop = prop_cls(**kwargs)
TypeError: init() got an unexpected keyword argument ‘prior_sqprec’
So it complains about the 2nd input argument prior_sqprec, not about xmat or targets.
I have no idea what is going on here. Maybe, my use of mx.sym.Custom is non-standard, but then I need a custom operator with (a) several inputs, and (b) with a number of additional args (which I code as string).
This seems to be a difference between mx.sym.Custom and mx.nd.Custom, which could be an issue for people switching from mx.sym to Gluon.
I can attach full code, but it is pretty long.