Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Dy2St] Optimize while cond break error messages #68508

Open
wants to merge 5 commits into
base: develop
Choose a base branch
from

Conversation

gouzil
Copy link
Member

@gouzil gouzil commented Sep 28, 2024

PR Category

Execute Infrastructure

PR Types

Improvements

Description

改进控制流 break 报错信息

新的报错信息

Traceback (most recent call last):
  File "/Users/gouzi/Documents/git/Paddle/test.py", line 19, in <module>
    print(paddle.jit.to_static(test_optim_break_in_for, full_graph=True)(np.random.random([10, 16]).astype('float32')))
          ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/gouzi/Documents/git/Paddle/build/python/paddle/jit/dy2static/program_translator.py", line 535, in __call__
    return self._perform_call(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/gouzi/Documents/git/Paddle/build/python/paddle/jit/dy2static/program_translator.py", line 855, in _perform_call
    error_data.raise_new_exception()
  File "/Users/gouzi/Documents/git/Paddle/build/python/paddle/jit/dy2static/error.py", line 454, in raise_new_exception
    raise new_exception from None
paddle.jit.dy2static.utils.Dygraph2StaticException: In transformed code:


    File "/Users/gouzi/.cache/paddle/to_static_tmp/37003/test_optim_break_in_for53qdai3x.py", line 51, in test_optim_break_in_for
	_jst.While(_jst.Ld(while_condition_0), _jst.Ld(while_body_0), _jst.Ld(get_args_0), _jst.Ld(set_args_0), return_name_ids=('_', '__break_0'), push_pop_names=None)
    File "/Users/gouzi/Documents/git/Paddle/build/python/paddle/jit/dy2static/convert_operators.py", line 190, in convert_while_loop
	_run_py_while(cond, body, getter, setter)
    File "/Users/gouzi/Documents/git/Paddle/build/python/paddle/jit/dy2static/convert_operators.py", line 274, in _run_py_while
	raise Dygraph2StaticException(textwrap.dedent(err_msg))

    paddle.jit.dy2static.utils.Dygraph2StaticException: You need to use break_flag in the control flow, Python will mistakenly convert the iteration variable from bool to Tensor,
And Tensor has no known value on static graph, for example:
    >>> x = paddle.to_tensor([5, 10])
    >>> for _ in range(10):
    ...     if x.sum() > 5:
    ...         break

There are one common workarounds available:
Explicitly rewrite to the form of a control flow, for example:
    >>> x = paddle.to_tensor([5, 10])
    >>> for _ in range(paddle.to_tensor(10)):
    ...     if x.sum() > 5:
    ...         break

Copy link

paddle-bot bot commented Sep 28, 2024

你的PR提交成功,感谢你对开源项目的贡献!
请关注后续CI自动化测试结果,详情请参考Paddle-CI手册
Your PR has been submitted. Thanks for your contribution!
Please wait for the result of CI firstly. See Paddle CI Manual for details.

Copy link

paddle-ci-bot bot commented Oct 6, 2024

Sorry to inform you that 328f3b0's CIs have passed for more than 7 days. To prevent PR conflicts, you need to re-run all CIs manually.

"python while pred change from bool to variable."
)
err_msg = """\
You need to use break_flag in the control flow, Python will mistakenly convert the iteration variable from bool to Tensor,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

我咋看不懂呢?

  • 首先说明问题
  • 然后给出修改方法
  • 最后给出常见修复示例

Copy link

paddle-ci-bot bot commented Oct 23, 2024

Sorry to inform you that 7885ce9's CIs have passed for more than 7 days. To prevent PR conflicts, you need to re-run all CIs manually.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
contributor External developers
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants