bug描述 Describe the Bug
运行pipline.py中的示例代码时,出现报错 AttributeError: module 'paddle.base.layers' has no attribute 'embedding'
。
示例代码文档:python/paddle/incubate/optimizer/pipeline.py
示例代码url:
Paddle/python/paddle/incubate/optimizer/pipeline.py
Line 49 in a91ca25
| | .. code-block:: python |
以下代码可复现上述问题:
import paddle
import paddle.base as base
import paddle.base.layers as layers
import numpy as np
paddle.enable_static()
with base.device_guard("gpu:0"):
x = paddle.static.data(name='x', shape=[-1, 1], dtype='int64', lod_level=0)
y = paddle.static.data(name='y', shape=[-1, 1], dtype='int64', lod_level=0)
data_loader = base.io.DataLoader.from_generator(
feed_list=[x, y],
capacity=64,
use_double_buffer=True,
iterable=False)
emb_x = layers.embedding(input=x, param_attr=base.ParamAttr(name="embx"), size=[10,2], is_sparse=False)
emb_y = layers.embedding(input=y, param_attr=base.ParamAttr(name="emby",learning_rate=0.9), size=[10,2], is_sparse=False)
得到的输出:
Traceback (most recent call last):
File "/home/bfs/zzy/mycode/DL-Fuzzer-Paddle/my-cov/rq3-my/0-0-incubate.pipline.py", line 16, in <module>
emb_x = layers.embedding(input=x, param_attr=base.ParamAttr(name="embx"), size=[10,2], is_sparse=False)
AttributeError: module 'paddle.base.layers' has no attribute 'embedding'
其他补充信息 Additional Supplementary Information
No response
2条答案
按热度按时间agyaoht71#
请使用embedding = paddle.nn.Embedding接口
lrl1mhuk2#
好的,谢谢,现在代码没有报错了,但是我还有一些疑问。
paddle.nn.Embedding
是在动态图或静态图模式下都可以使用吗?paddle.base.layers
是不再提供embedding接口了吗?这样的话,建议修改一下注释中的示例代码。