akturtle opened a new issue #8312: Gradient function not returning enough gradients URL: https://github.com/apache/incubator-mxnet/issues/8312 Note: Providing complete information in the most concise form is the best way to get help. This issue template serves as the checklist for essential information to most of the technical issues. ## Description Simple_bind error with custom OP with auxiliary_states Package used (Python/R/Scala/Julia): I'm using Python MXNet commit hash: (Paste the output of `git rev-parse HEAD` here.) a5edbf94094581ee27157eae4f2113115a3994e7 ## Error Message: mxnet/dmlc-core/include/dmlc/./logging.h:308: [10:44:55] src/pass/gradient.cc:159: Check failed: (*rit)->inputs.size() == input_grads.size() (4 vs. 2) Gradient function not returning enough gradient Stack trace returned 10 entries: [bt] (0) /home/xfz/tools/mxnet/python/mxnet/../../lib/libmxnet.so(_ZN4dmlc15LogMessageFatalD1Ev+0x29) [0x7f359e70b199] [bt] (1) /home/xfz/tools/mxnet/python/mxnet/../../lib/libmxnet.so(+0x26dcf8f) [0x7f35a06a9f8f] [bt] (2) /home/xfz/tools/mxnet/python/mxnet/../../lib/libmxnet.so(_ZNSt17_Function_handlerIFN4nnvm5GraphES1_EPS2_E9_M_invokeERKSt9_Any_dataS1_+0x11f) [0x7f359f39ba9f] [bt] (3) /home/xfz/tools/mxnet/python/mxnet/../../lib/libmxnet.so(_ZN4nnvm11ApplyPassesENS_5GraphERKSt6vectorISsSaISsEE+0x501) [0x7f35a06cdfc1] [bt] (4) /home/xfz/tools/mxnet/python/mxnet/../../lib/libmxnet.so(_ZN4nnvm9ApplyPassENS_5GraphERKSs+0x8e) [0x7f359f6b62ae] [bt] (5) /home/xfz/tools/mxnet/python/mxnet/../../lib/libmxnet.so(_ZN4nnvm4pass8GradientENS_5GraphESt6vectorINS_9NodeEntryESaIS3_EES5_S5_St8functionIFS3_OS5_EES6_IFiRKNS_4NodeEEES6_IFS3_RKS3_SG_EES2_IPKNS_2OpESaISL_EESs+0x865) [0x7f359f711b95] [bt] (6) /home/xfz/tools/mxnet/python/mxnet/../../lib/libmxnet.so(_ZN5mxnet4exec13GraphExecutor13InitFullGraphEN4nnvm6SymbolERKSt6vectorINS_9OpReqTypeESaIS5_EE+0x81e) [0x7f359f701a6e] [bt] (7) /home/xfz/tools/mxnet/python/mxnet/../../lib/libmxnet.so(_ZN5mxnet4exec13GraphExecutor9InitGraphEN4nnvm6SymbolERKNS_7ContextERKSt3mapISsS4_St4lessISsESaISt4pairIKSsS4_EEERKSt6vectorIS4_SaIS4_EESL_SL_RKSH_INS_9OpReqTypeESaISM_EE+0x4f) [0x7f359f7023ef] [bt] (8) /home/xfz/tools/mxnet/python/mxnet/../../lib/libmxnet.so(_ZN5mxnet4exec13GraphExecutor4InitEN4nnvm6SymbolERKNS_7ContextERKSt3mapISsS4_St4lessISsESaISt4pairIKSsS4_EEERKSt6vectorIS4_SaIS4_EESL_SL_RKSt13unordered_mapISsNS2_6TShapeESt4hashISsESt8equal_toISsESaISA_ISB_SN_EEERKSM_ISsiSP_SR_SaISA_ISB_iEEERKSH_INS_9OpReqTypeESaIS12_EERKSt13unordered_setISsSP_SR_SaISsEEPSH_INS_7NDArrayESaIS1C_EES1F_S1F_PSM_ISsS1C_SP_SR_SaISA_ISB_S1C_EEEPNS_8ExecutorERKSM_INS2_9NodeEntryES1C_NS2_13NodeEntryHashENS2_14NodeEntryEqualESaISA_IKS1M_S1C_EEE+0xa0) [0x7f359f704070] [bt] (9) /home/xfz/tools/mxnet/python/mxnet/../../lib/libmxnet.so(_ZN5mxnet8Executor10SimpleBindEN4nnvm6SymbolERKNS_7ContextERKSt3mapISsS3_St4lessISsESaISt4pairIKSsS3_EEERKSt6vectorIS3_SaIS3_EESK_SK_RKSt13unordered_mapISsNS1_6TShapeESt4hashISsESt8equal_toISsESaIS9_ISA_SM_EEERKSL_ISsiSO_SQ_SaIS9_ISA_iEEERKSG_INS_9OpReqTypeESaIS11_EERKSt13unordered_setISsSO_SQ_SaISsEEPSG_INS_7NDArrayESaIS1B_EES1E_S1E_PSL_ISsS1B_SO_SQ_SaIS9_ISA_S1B_EEEPS0_+0x194) [0x7f359f704d74] ## Minimum reproducible example create cutom a test OP ` import mxnet as mx class GradientError(mx.operator.CustomOp): def forward(self, is_train, req, in_data, out_data,aux): pass def backward(self, req, out_grad, in_data, out_data, in_grad, aux): pass @mx.operator.register('GradientError') class GradientErrorProp(mx.operator.CustomOpProp): def list_arguments(self): return ['data', 'label'] def list_outputs(self): return ['output'] def list_auxiliary_states(self): # call them 'bias' for zero initialization return [ 'aux_bias1', 'aux_weight2'] def infer_shape(self, in_shape): data_shape=in_shape[0] label_shape = (in_shape[0][0],) out_shape = in_shape[0] aux_bias1_shape = (in_shape[0][0],) aux_weight2_shape = (in_shape[0][0],) return [data_shape,label_shape], [out_shape],\ [aux_bias1_shape,aux_weight2_shape] def create_operator(self, ctx, shapes, dtypes): return GradientError() ` simple_bind custom OP. Then it will give above error `import mxnet as mx from gradientError import * data = mx.sym.Variable('data') label = mx.sym.Variable('label') net = mx.sym.Custom(data=data,label=label,op_type = 'GradientError') input_shapes = {'data':(2, 3,32,32 ),'label':(2,)} xpu = mx.cpu() exe = net.simple_bind(ctx = xpu,**input_shapes) exe.forward() print exe.outputs[0].asnumpy() ` ## What have you tried to solve it? This script works fine with this version:7fcaf15a3a597cc72a342d1bdb00273dec00e78c ---------------------------------------------------------------- This is an automated message from the Apache Git Service. To respond to the message, please log on GitHub and use the URL above to go to the specific comment. For queries about this service, please contact Infrastructure at: us...@infra.apache.org
With regards, Apache Git Services