yeyupiaoling / PPASR

基于PaddlePaddle实现端到端中文语音识别,从入门到实战,超简单的入门案例,超实用的企业项目。支持当前最流行的DeepSpeech2、Conformer、Squeezeformer模型
Apache License 2.0
797 stars 131 forks source link

无法导出efficient_conformer模型(但其它如Conformer则是正常的) #135

Closed springminhcm closed 1 year ago

springminhcm commented 1 year ago

您好,不知可否检查一下,使用export_model.py无法导出模型,但其它如Conformer则是正常的。 错误讯息如下:

/home/t777/anaconda3/envs/ppasr/lib/python3.8/site-packages/paddle/fluid/dygraph/jit.py:838: UserWarning: What you save is a function, and jit.save will generate the name of the model file according to path you specify. When loading these files with jit.load, you get a TranslatedLayer whose inference result is the same as the inference result of the function you saved. warnings.warn( /home/t777/anaconda3/envs/ppasr/lib/python3.8/site-packages/paddle/fluid/layers/control_flow.py:211: UserWarning: Return results from different branches in cond are not same type: false_var returned by fasle_fn is '<class 'int'>' and true_var of true_fn is '<class 'paddle.fluid.framework.Variable'>' warnings.warn( /home/t777/anaconda3/envs/ppasr/lib/python3.8/site-packages/paddle/fluid/layers/control_flow.py:211: UserWarning: Return results from different branches in cond are not same type: false_var returned by fasle_fn is '<class 'paddle.fluid.framework.Variable'>' and true_var of true_fn is '<class 'int'>' warnings.warn( /home/t777/anaconda3/envs/ppasr/lib/python3.8/site-packages/paddle/fluid/layers/control_flow.py:124: UserWarning: the input shapes of select_input should have the same rank, but get (-1, -1, -1, -1), (-1, -1, -1) warnings.warn( /home/t777/anaconda3/envs/ppasr/lib/python3.8/site-packages/paddle/fluid/layers/tensor.py:667: UserWarning: paddle.assign doesn't support float64 input now due to current platform protobuf data limitation, we convert it to float32 warnings.warn( /home/t777/anaconda3/envs/ppasr/lib/python3.8/site-packages/paddle/fluid/layers/control_flow.py:124: UserWarning: the input shapes of select_input should have the same rank, but get (1,), (-1, -1, -1, -1) warnings.warn( Traceback (most recent call last): File "export_model.py", line 22, in trainer.export(save_model_path=args.save_model, File "/home/t777/PPASR/ppasr/trainer.py", line 618, in export paddle.jit.save(infer_model, infer_model_path) File "/home/t777/anaconda3/envs/ppasr/lib/python3.8/site-packages/decorator.py", line 232, in fun return caller(func, *(extras + args), kw) File "/home/t777/anaconda3/envs/ppasr/lib/python3.8/site-packages/paddle/fluid/wrapped_decorator.py", line 26, in impl return wrapped_func(args, kwargs) File "/home/t777/anaconda3/envs/ppasr/lib/python3.8/site-packages/paddle/fluid/dygraph/jit.py", line 649, in wrapper func(layer, path, input_spec, configs) File "/home/t777/anaconda3/envs/ppasr/lib/python3.8/site-packages/decorator.py", line 232, in fun return caller(func, (extras + args), kw) File "/home/t777/anaconda3/envs/ppasr/lib/python3.8/site-packages/paddle/fluid/wrapped_decorator.py", line 26, in impl return wrapped_func(*args, kwargs) File "/home/t777/anaconda3/envs/ppasr/lib/python3.8/site-packages/paddle/fluid/dygraph/base.py", line 67, in impl return func(*args, *kwargs) File "/home/t777/anaconda3/envs/ppasr/lib/python3.8/site-packages/paddle/fluid/dygraph/jit.py", line 959, in save concrete_program = attr_func.concrete_program_specify_input_spec( File "/home/t777/anaconda3/envs/ppasr/lib/python3.8/site-packages/paddle/fluid/dygraph/dygraph_to_static/program_translator.py", line 577, in concrete_program_specify_input_spec concreteprogram, = self.get_concrete_program( File "/home/t777/anaconda3/envs/ppasr/lib/python3.8/site-packages/paddle/fluid/dygraph/dygraph_to_static/program_translator.py", line 485, in get_concrete_program concrete_program, partial_program_layer = self._program_cache[cache_key] File "/home/t777/anaconda3/envs/ppasr/lib/python3.8/site-packages/paddle/fluid/dygraph/dygraph_to_static/program_translator.py", line 955, in getitem self._caches[item_id] = self._build_once(item) File "/home/t777/anaconda3/envs/ppasr/lib/python3.8/site-packages/paddle/fluid/dygraph/dygraph_to_static/program_translator.py", line 939, in _build_once concrete_program = ConcreteProgram.from_func_spec( File "/home/t777/anaconda3/envs/ppasr/lib/python3.8/site-packages/decorator.py", line 232, in fun return caller(func, (extras + args), kw) File "/home/t777/anaconda3/envs/ppasr/lib/python3.8/site-packages/paddle/fluid/wrapped_decorator.py", line 26, in impl return wrapped_func(*args, *kwargs) File "/home/t777/anaconda3/envs/ppasr/lib/python3.8/site-packages/paddle/fluid/dygraph/base.py", line 67, in impl return func(args, **kwargs) File "/home/t777/anaconda3/envs/ppasr/lib/python3.8/site-packages/paddle/fluid/dygraph/dygraph_to_static/program_translator.py", line 895, in from_func_spec error_data.raise_new_exception() File "/home/t777/anaconda3/envs/ppasr/lib/python3.8/site-packages/paddle/fluid/dygraph/dygraph_to_static/error.py", line 350, in raise_newexception six.exec("raise new_exception from None") File "", line 1, in TypeError: In transformed code:

File "/home/t777/PPASR/ppasr/model_utils/efficient_conformer/model.py", line 177, in get_encoder_out_chunk
xs, att_cache, cnn_cache = self.encoder.forward_chunk(xs=speech,
File "/home/t777/PPASR/ppasr/model_utils/efficient_conformer/encoder.py", line 341, in forward_chunk
for i, layer in enumerate(self.encoders):
File "/home/t777/PPASR/ppasr/model_utils/efficient_conformer/encoder.py", line 347, in forward_chunk
xs, _, new_att_cache, new_cnn_cache = layer(
File "/home/t777/PPASR/ppasr/model_utils/conformer/encoder.py", line 393, in forward
x_att, new_att_cache = self.self_attn(x, x, x, mask, pos_emb, cache=att_cache)
File "/home/t777/PPASR/ppasr/model_utils/efficient_conformer/attention.py", line 173, in forward
q, k, v, p, mask, padding_q = self.pad4group(q, k, v, p, mask, self.group_size)
File "/home/t777/PPASR/ppasr/model_utils/efficient_conformer/attention.py", line 56, in pad4group
    # Input Padding (B, T, D) -> (B, T + P, D)
    Q = F.pad(Q, (0, 0, 0, padding_Q), mode='constant', value=0.0)
    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ <--- HERE
    K = F.pad(K, (0, 0, 0, padding_KV), mode='constant', value=0.0)
    V = F.pad(V, (0, 0, 0, padding_KV), mode='constant', value=0.0)

File "/home/t777/anaconda3/envs/ppasr/lib/python3.8/site-packages/paddle/nn/functional/common.py", line 1724, in pad
helper.append_op(
File "/home/t777/anaconda3/envs/ppasr/lib/python3.8/site-packages/paddle/fluid/layer_helper.py", line 45, in append_op
return self.main_program.current_block().append_op(*args, **kwargs)
File "/home/t777/anaconda3/envs/ppasr/lib/python3.8/site-packages/paddle/fluid/framework.py", line 4017, in append_op
op = Operator(
File "/home/t777/anaconda3/envs/ppasr/lib/python3.8/site-packages/paddle/fluid/framework.py", line 2991, in __init__
self._update_desc_attr(attr_name, attr_val)
File "/home/t777/anaconda3/envs/ppasr/lib/python3.8/site-packages/paddle/fluid/framework.py", line 3339, in _update_desc_attr
self._update_desc_plain_attr(name, val)
File "/home/t777/anaconda3/envs/ppasr/lib/python3.8/site-packages/paddle/fluid/framework.py", line 3363, in _update_desc_plain_attr
desc._set_int32s_attr(name, val)

TypeError: _set_int32s_attr(): incompatible function arguments. The following argument types are supported:
1. (self: paddle.fluid.libpaddle.OpDesc, arg0: str, arg1: List[int]) -> None

Invoked with: <paddle.fluid.libpaddle.OpDesc object at 0x7ff4bc1b8df0>, 'paddings', [0, 0, 0, var tmp_36 : LOD_TENSOR.shape(1,).dtype(int32).stop_gradient(False), 0, 0]

yeyupiaoling commented 1 year ago

嗯嗯,这个问题我也没有解决。麻烦用下其他的模型

springminhcm commented 1 year ago

嗯嗯,这个问题我也没有解决。麻烦用下其他的模型

你好,我使用你今日更新的[修复efficient_conformer模型导出问题]后,已经可以正常的导出efficient_conformer了模型,但是执行infer_path.py后,则出现以下错误讯息:

Traceback (most recent call last): File "infer_path.py", line 24, in predictor = PPASRPredictor(configs=args.configs, File "/home/t777/PPASR/ppasr/predict.py", line 90, in init self.predict(audio_data=warmup_audio, is_itn=False) File "/home/t777/PPASR/ppasr/predict.py", line 170, in predict output_data = self.predictor.predict(input_data, audio_len)[0] File "/home/t777/PPASR/ppasr/infer_utils/inference_predictor.py", line 140, in predict self.predictor.run() ValueError: (InvalidArgument) Shape of Input(Paddings) should be equal to [6], but received [4]. [Hint: Expected paddings.size() == 6, but received paddings.size():4 != 6:6.] (at /paddle/paddle/phi/infermeta/unary.cc:2215) [operator < pad3d > error]

yeyupiaoling commented 1 year ago

那我这种处理应该是不行的。我再看看其他办法。

springminhcm commented 1 year ago

那我这种处理应该是不行的。我再看看其他办法。

非常感谢版主热心的帮忙。今天我也有看到你有更新回去,看来这个efficient_conformer不太好搞定呢!