未验证 提交 84d366d4 编写于 作者: S Steffy-zxf 提交者: GitHub

update codes for static and dynamic graph unification (#5215)

* update docs
上级 653f5193
...@@ -129,13 +129,13 @@ class CNNEncoder(nn.Layer): ...@@ -129,13 +129,13 @@ class CNNEncoder(nn.Layer):
self._activation = conv_layer_activation self._activation = conv_layer_activation
self._output_dim = output_dim self._output_dim = output_dim
self.convs = [ self.convs = paddle.nn.LayerList([
nn.Conv2D( nn.Conv2D(
in_channels=1, in_channels=1,
out_channels=self._num_filter, out_channels=self._num_filter,
kernel_size=(i, self._emb_dim), kernel_size=(i, self._emb_dim),
**kwargs) for i in self._ngram_filter_sizes **kwargs) for i in self._ngram_filter_sizes
] ])
maxpool_output_dim = self._num_filter * len(self._ngram_filter_sizes) maxpool_output_dim = self._num_filter * len(self._ngram_filter_sizes)
if self._output_dim: if self._output_dim:
......
...@@ -50,8 +50,10 @@ class RobertaEmbeddings(nn.Layer): ...@@ -50,8 +50,10 @@ class RobertaEmbeddings(nn.Layer):
def forward(self, input_ids, token_type_ids=None, position_ids=None): def forward(self, input_ids, token_type_ids=None, position_ids=None):
if position_ids is None: if position_ids is None:
# maybe need use shape op to unify static graph and dynamic graph # maybe need use shape op to unify static graph and dynamic graph
seq_length = input_ids.shape[1] ones = paddle.ones_like(input_ids, dtype="int64")
position_ids = paddle.arange(0, seq_length, dtype="int64") seq_length = paddle.cumsum(ones, axis=1)
position_ids = seq_length - ones
position_ids.stop_gradient = True
if token_type_ids is None: if token_type_ids is None:
token_type_ids = paddle.zeros_like(input_ids, dtype="int64") token_type_ids = paddle.zeros_like(input_ids, dtype="int64")
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册