pad_constant_like check dim failed in optimizer.minimize
Created by: linan142857
Package - paddlepaddle-gpu==v1.3.2.Post87
There are several pad_constant_like ops in my model filling the variables to constant shape.
And the actual dim is provided correct by fluid.layers.Print.
However, after I add the optimizer.minimize(cost)
for training my model, the error appears as following:
File "train.py", line 67, in train sum_cost, inference_program, model_average = train_net(args, pad_num, num_classes) File "/home/vis/liyulin/Development/code/local/kv-parsing/model/model.py", line 256, in train_net _, params_grads = optimizer.minimize(sum_cost) File "/home/vis/anaconda2/lib/python2.7/site-packages/paddle/fluid/optimizer.py", line 414, in minimize parameter_list, no_grad_set) File "/home/vis/anaconda2/lib/python2.7/site-packages/paddle/fluid/optimizer.py", line 326, in backward return append_backward(loss, parameter_list, no_grad_set, callbacks) File "/home/vis/anaconda2/lib/python2.7/site-packages/paddle/fluid/backward.py", line 518, in append_backward append_backward_vars(root_block, fwd_op_num, grad_to_var, grad_info_map) File "/home/vis/anaconda2/lib/python2.7/site-packages/paddle/fluid/backward.py", line 354, in append_backward_vars op_desc.infer_shape(block.desc) paddle.fluid.core.EnforceNotMet: Enforce failed. Expected dout_dim.size() == y_dim.size(), but received dout_dim.size():1 != y_dim.size():2. The dimention of X and Y should be the same. at [/paddle/paddle/fluid/operators/pad_constant_like_op.cc:157] PaddlePaddle Call Stacks: 0 0x7f3c5f3a76ddp void paddle::platform::EnforceNotMet::Initstd::string(std::string, char const*, int) + 365 1 0x7f3c5f3a7a27p paddle::platform::EnforceNotMet::EnforceNotMet(std::string const&, char const*, int) + 87 2 0x7f3c600389dbp paddle::operators::PadConstantLikeOpGrad::InferShape(paddle::framework::InferShapeContext*) const + 2219 3 0x7f3c5f4adc6ep paddle::framework::OpDesc::InferShape(paddle::framework::BlockDesc const&) const + 862 4 0x7f3c5f41dc8cp
the code segment as
`
images = fluid.layers.data(name='pixel', shape=[3, 100, 400], dtype='float32')
content = fluid.layers.data(name='word', shape=[1], dtype='int32', lod_level=1)
adjacency = fluid.layers.data(name='adja', shape=[pad_num, 2], dtype='float32')
tmp = fluid.layers.zeros((pad_num, 1), dtype='float32')
node_label = fluid.layers.data(name='node_label', shape=[1], dtype='int32')
node_label = fluid.layers.cast(x=node_label, dtype='float32')
node_label = fluid.layers.pad_constant_like(tmp, node_label)
node_mask = fluid.layers.data(name='node_mask', shape=[1], dtype='int32')
node_mask = fluid.layers.cast(x=node_mask, dtype='float32')
node_mask = fluid.layers.pad_constant_like(tmp, node_mask)
node_mask.stop_gradient = True
tmp = fluid.layers.zeros((pad_num, pad_num), dtype='float32')
edge_label = fluid.layers.data(name='edge_label', shape=[pad_num], dtype='float32')
edge_label = fluid.layers.cast(x=edge_label, dtype='float32')
edge_label = fluid.layers.pad_constant_like(tmp, edge_label)
edge_mask = fluid.layers.data(name='edge_mask', shape=[pad_num], dtype='int32')
edge_mask = fluid.layers.cast(x=edge_mask, dtype='float32')
edge_mask = fluid.layers.pad_constant_like(tmp, edge_mask)
edge_mask.stop_gradient = True
`