paddlehub 样例程序报错
Created by: smart022
在AI studio中执行 rbtl3的示例代码后报错
import paddlehub as hub
# Load $ hub install rbtl3 pretrained model
module = hub.Module(name="rbtl3")
inputs, outputs, program = module.context(trainable=True, max_seq_len=128)
# Must feed all the tensor of rbtl3's module need
input_ids = inputs["input_ids"]
position_ids = inputs["position_ids"]
segment_ids = inputs["segment_ids"]
input_mask = inputs["input_mask"]
# Use "pooled_output" for sentence-level output.
pooled_output = outputs["pooled_output"]
# Use "sequence_output" for token-level output.
sequence_output = outputs["sequence_output"]
# Use "get_embedding" to get embedding result.
embedding_result = module.get_embedding(texts=[["Sample1_text_a"],["Sample2_text_a","Sample2_text_b"]], use_gpu=True)
# Use "get_params_layer" to get params layer and used to ULMFiTStrategy.
params_layer = module.get_params_layer()
strategy = hub.finetune.strategy.ULMFiTStrategy(params_layer=params_layer)
提示不存在属性 'Parameter' object has no attribute 'gradient_clip_attr'
---------------------------------------------------------------------------AttributeError Traceback (most recent call last)<ipython-input-18-8e630ad859b4> in <module>
16
17 # Use "get_embedding" to get embedding result.
---> 18 embedding_result = module.get_embedding(texts=[["Sample1_text_a"],["Sample2_text_a","Sample2_text_b"]], use_gpu=True)
19
20 # Use "get_params_layer" to get params layer and used to ULMFiTStrategy.
/opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages/paddlehub/module/nlp_module.py in get_embedding(self, texts, use_gpu, batch_size)
406 param.trainable = trainable
407 match = re.match(r'.*layer_(\d+).*', param.name)
--> 408 if match:
409 # layer num begins from 0
410 layer = match.group(1)
/opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages/paddlehub/module/nlp_module.py in __init__(self, pooled_feature, seq_feature, feed_list, data_reader, config)
223 main_program=main_program,
224 data_reader=data_reader,
--> 225 feed_list=feed_list,
226 config=config,
227 metrics_choices=[])
/opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages/paddlehub/finetune/task/base_task.py in __init__(self, feed_list, data_reader, main_program, startup_program, config, metrics_choices)
296
297 else:
--> 298 self._base_main_program = clone_program(
299 main_program, for_test=False)
300 if startup_program is None:
/opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages/paddlehub/common/paddle_helper.py in clone_program(origin_program, for_test)
272
273 def clone_program(origin_program, for_test=False):
--> 274 dest_program = fluid.Program()
275 _copy_vars_and_ops_in_blocks(origin_program.global_block(),
276 dest_program.global_block())
/opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages/paddlehub/common/paddle_helper.py in _copy_vars_and_ops_in_blocks(from_block, to_block)
145
146 def _copy_vars_and_ops_in_blocks(from_block, to_block):
--> 147 for var in from_block.vars:
148 var = from_block.var(var)
149 var_info = copy.deepcopy(get_variable_info(var))
/opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages/paddlehub/common/paddle_helper.py in get_variable_info(var)
63 var_info['trainable'] = var.trainable
64 var_info['optimize_attr'] = var.optimize_attr
---> 65 var_info['regularizer'] = var.regularizer
66 if not version_compare(paddle.__version__, '1.8'):
67 var_info['gradient_clip_attr'] = var.gradient_clip_attr
AttributeError: 'Parameter' object has no attribute 'gradient_clip_attr'
使用的paddle hub 版本包括 1.6.2 , 1.7.0, 均会出现该问题
- 版本、环境信息 1)PaddleHub和PaddlePaddle版本:1.6.2 , 1.7.0 2)系统环境:AI studio