Paddle icon indicating copy to clipboard operation
Paddle copied to clipboard

`paddlepaddle` 包污染 `logging`,导致功能不可用

Open RedContritio opened this issue 10 months ago • 5 comments

bug描述 Describe the Bug

该 bug 曾在 paddleOCR 中提出 绕开的办法,但应当被视为 bug。

最小可复现代码:

import logging
logging.basicConfig(level=logging.INFO)
logging.info('print done')
# log success 1st
import paddle
logging.info('print loss')
# log failed
import logreset
logreset.reset_logging()
logging.basicConfig(level=logging.INFO)
logging.info('print done again')
# log success 2nd

根据代码的 logging.info 次数,理应输出三次,但实际仅输出了两次。 实际结果:

Python 3.10.12 (main, Jun  7 2023, 12:45:35) [GCC 9.4.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import logging
>>> logging.basicConfig(level=logging.INFO)
>>> logging.info('print done')
INFO:root:print done
>>> import paddle
>>> logging.info('print loss')
>>> import logreset
>>> logreset.reset_logging()
>>> logging.basicConfig(level=logging.INFO)
>>> logging.info('print done again')
INFO:root:print done again
>>> 

其他补充信息 Additional Supplementary Information

No response

RedContritio avatar Sep 10 '23 19:09 RedContritio

你好,感谢你的反馈。这确实是一个影响开发者体验的bug。

我排查到这个问题的根因是paddle.distributed.utils.log_utils提供的get_logger函数使用的name参数默认为"root",而该函数在被调用的时候多次使用了默认参数,这直接影响了root logger的行为。

https://github.com/PaddlePaddle/Paddle/blob/3c19d80ad6f4bf942a7e6f09e69f5fc7211f23b6/python/paddle/distributed/utils/log_utils.py#L18

一个能够立即想到的解决方案是将name参数的默认值修改为"root"以外的其他值。我们会从影响范围等角度进一步评估这一解决方案是否可行,后续进展仍在此issue回复。

Bobholamovic avatar Sep 11 '23 01:09 Bobholamovic

我们会在近期提PR修复这个问题,请关注此issue同步的进展。

Bobholamovic avatar Sep 12 '23 01:09 Bobholamovic

image 你好,我们在develop版本中复现上述代码,实际输出的次数是3次,和你预期一样。请使用最新版本paddle试试。

wuhuachaocoding avatar Sep 13 '23 04:09 wuhuachaocoding

I have python 3.9 and paddlepaddle 2.6.0 installed and still face the issue. Could someone explain what exact commit (probably in dev) fixes it?

EvsanDlg avatar Feb 14 '24 19:02 EvsanDlg

I have python 3.9 and paddlepaddle 2.6.0 installed and still face the issue. Could someone explain what exact commit (probably in dev) fixes it?

@wuhuachaocoding Can you provide the commit ID?

Bobholamovic avatar Feb 15 '24 12:02 Bobholamovic