PaddlePaddle / X2Paddle

Deep learning model converter for PaddlePaddle. (『飞桨』深度学习模型转换工具)
http://www.paddlepaddle.org/
Apache License 2.0
739 stars 165 forks source link

SwinTransformer模型转换失败 #1090

Open UnlimitedWand opened 3 weeks ago

UnlimitedWand commented 3 weeks ago

问题描述

SwinTransformer模型转换失败,使用本仓库转换代码以及模型

运行环境,aarch64, torch是cpu版本,2.5.1和1.10.2都失败,同样的报错 PaddlePaddle = 2.6.1: X2Paddle = 1.5.0

===================Error Information=============== Traceback (most recent call last): File "/work/code/X2Paddle/test_benchmark/PyTorch/SwinTransformer/convert_trace.py", line 27, in pytorch2paddle(torch_module, File "/opt/py310/lib/python3.10/site-packages/x2paddle/convert.py", line 398, in pytorch2paddle mapper.paddle_graph.gen_model(save_dir, File "/opt/py310/lib/python3.10/site-packages/x2paddle/core/program.py", line 308, in gen_model raise e File "/opt/py310/lib/python3.10/site-packages/x2paddle/core/program.py", line 302, in gen_model self.dygraph2static(save_dir, input_shapes, input_types) File "/opt/py310/lib/python3.10/site-packages/x2paddle/core/program.py", line 584, in dygraph2static paddle.jit.save(static_model, File "/opt/py310/lib/python3.10/site-packages/decorator.py", line 232, in fun return caller(func, *(extras + args), kw) File "/opt/py310/lib/python3.10/site-packages/paddle/base/wrapped_decorator.py", line 26, in impl return wrapped_func(args, kwargs) File "/opt/py310/lib/python3.10/site-packages/paddle/jit/api.py", line 809, in wrapper func(layer, path, input_spec, configs) File "/opt/py310/lib/python3.10/site-packages/decorator.py", line 232, in fun return caller(func, (extras + args), kw) File "/opt/py310/lib/python3.10/site-packages/paddle/base/wrapped_decorator.py", line 26, in impl return wrapped_func(*args, kwargs) File "/opt/py310/lib/python3.10/site-packages/paddle/base/dygraph/base.py", line 68, in impl return func(*args, *kwargs) File "/opt/py310/lib/python3.10/site-packages/paddle/jit/api.py", line 1104, in save static_func.concrete_program_specify_input_spec( File "/opt/py310/lib/python3.10/site-packages/paddle/jit/dy2static/program_translator.py", line 986, in concrete_program_specify_input_spec concreteprogram, = self.get_concrete_program( File "/opt/py310/lib/python3.10/site-packages/paddle/jit/dy2static/program_translator.py", line 875, in get_concrete_program concrete_program, partial_program_layer = self._program_cache[ File "/opt/py310/lib/python3.10/site-packages/paddle/jit/dy2static/program_translator.py", line 1648, in getitem self._caches[item_id] = self._build_once(item) File "/opt/py310/lib/python3.10/site-packages/paddle/jit/dy2static/program_translator.py", line 1575, in _build_once concrete_program = ConcreteProgram.from_func_spec( File "/opt/py310/lib/python3.10/site-packages/decorator.py", line 232, in fun return caller(func, (extras + args), kw) File "/opt/py310/lib/python3.10/site-packages/paddle/base/wrapped_decorator.py", line 26, in impl return wrapped_func(*args, *kwargs) File "/opt/py310/lib/python3.10/site-packages/paddle/base/dygraph/base.py", line 68, in impl return func(args, **kwargs) File "/opt/py310/lib/python3.10/site-packages/paddle/jit/dy2static/program_translator.py", line 1346, in from_func_spec error_data.raise_new_exception() File "/opt/py310/lib/python3.10/site-packages/paddle/jit/dy2static/error.py", line 452, in raise_new_exception raise new_exception from None AssertionError: In transformed code:

File "/work/code/X2Paddle/test_benchmark/PyTorch/SwinTransformer/pd_model_trace/x2paddle_code.py", line 545, in forward
    layers_0_downsample_reduction_weight = self.layers_0_downsample_reduction_weight
    x274 = paddle.matmul(x=x272, y=layers_0_downsample_reduction_weight, transpose_y=True)
    x274 = paddle.add(x=x274, y=x47)
    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ <--- HERE
    x276 = 0
    x277 = 2

File "/opt/py310/lib/python3.10/site-packages/paddle/tensor/math.py", line 699, in add
    return _elementwise_op(LayerHelper('elementwise_add', **locals()))
File "/opt/py310/lib/python3.10/site-packages/paddle/tensor/math.py", line 580, in _elementwise_op
    assert y is not None, f'y cannot be None in {original_op_type}'

AssertionError: y cannot be None in elementwise_add
megemini commented 2 weeks ago

@UnlimitedWand 是测试的 https://github.com/PaddlePaddle/X2Paddle/tree/develop/test_benchmark/PyTorch/SwinTransformer 这个吗?

最近在适配 Paddle 3.0,可以拉一下最新的 dev 版本的 x2paddle,用 Paddle 3.0 再试一下 ~

或者参考一下这个 PR https://github.com/PaddlePaddle/X2Paddle/pull/1079