expose h0 in dynamic_lstm#11391
Conversation
python/paddle/fluid/layers/nn.py
Outdated
| batch_cell_pre_act = helper.create_tmp_variable(dtype) | ||
| inputs = {'Input': input, 'Weight': weight, 'Bias': bias} | ||
| if h_0: | ||
| assert h_0.shape == (-1, size), \ |
There was a problem hiding this comment.
The first dimension represents placeholder of batch size and may not be -1, input.shape[0] might be better than -1 thus we needn't assume users' batch size setting.
There was a problem hiding this comment.
Yeah, if the shape has been checked in the InferShape, maybe the Python doesn't need to check it.
There was a problem hiding this comment.
Infershape doesn't check the shape, we can check it in Python code, it's more clear for the user.
python/paddle/fluid/layers/nn.py
Outdated
| name=None): | ||
| name=None, | ||
| h_0=None, | ||
| c_0=None): |
There was a problem hiding this comment.
Put the name at the end?
Remove the TODO in line 264.
python/paddle/fluid/layers/nn.py
Outdated
| batch_cell_pre_act = helper.create_tmp_variable(dtype) | ||
| inputs = {'Input': input, 'Weight': weight, 'Bias': bias} | ||
| if h_0: | ||
| assert h_0.shape == (-1, size), \ |
There was a problem hiding this comment.
Yeah, if the shape has been checked in the InferShape, maybe the Python doesn't need to check it.
python/paddle/fluid/layers/nn.py
Outdated
| batch size and D is the hidden size. | ||
| c_0(Variable): The initial cell state is an optional | ||
| input. This is a tensor with shape (N x D), where N is the | ||
| batch size. `h_0` and `c_0` can be NULL but only at the same time. |
There was a problem hiding this comment.
Tell the users if not set, the default is zero.
python/paddle/fluid/layers/nn.py
Outdated
| size, size), 'The shape of h0 should be(%d, %d)' % (size, size) | ||
| batch_size, size | ||
| ), 'The shape of h0 should be(batch_size, %d)' % size | ||
| inputs['h0'] = h_0 |
There was a problem hiding this comment.
It also should be inputs['H0'] = h_0 like in LSTM. Sorry for leaving out this.
guoshengCS
left a comment
There was a problem hiding this comment.
LGTM. Thanks for the fix.
Fixed #11340
Fixed #11339
Related issue: #11335