Skip to content

fix tinyformat#78793

Merged
zrr1999 merged 3 commits into
PaddlePaddle:developfrom
wanghuancoder:fix_tinyformat
Apr 29, 2026
Merged

fix tinyformat#78793
zrr1999 merged 3 commits into
PaddlePaddle:developfrom
wanghuancoder:fix_tinyformat

Conversation

@wanghuancoder
Copy link
Copy Markdown
Contributor

@wanghuancoder wanghuancoder commented Apr 24, 2026

PR Category

Execute Infrastructure

PR Types

Improvements

Description

删除tinyformat里的assert,防止PADDLE_ENFORCE %个数和变量不匹配时,崩溃在assert上而没有提供PADDLE_ENFORCE更有价值的信息。
业务上发生了这种情况。但不可解释的是,assert只在DEBUG编译下才生效,为何发版的包assert会生效暂时没有找到。

通过如下方式复现问题

#define TINYFORMAT_ERROR(reason) do { std::cerr << reason ; abort(); } while(0)

此后验证本PR,能够有效disable掉assert的崩溃。

但H卡Coverage,test_dygraph_sharding_stage3_for_eager等3个单测会崩溃在PrepareStridedOut中:

2026-04-27T12:46:24.0700284Z     70	--------------------------------------
2026-04-27T12:46:24.0700604Z     71	C++ Traceback (most recent call last):
2026-04-27T12:46:24.0700906Z     72	--------------------------------------
2026-04-27T12:46:24.0701655Z     73	0   egr::Backward(std::vector<paddle::Tensor, std::allocator<paddle::Tensor> > const&, std::vector<paddle::Tensor, std::allocator<paddle::Tensor> > const&, bool, std::string)
2026-04-27T12:46:24.0703059Z     74	1   egr::RunBackward(std::vector<paddle::Tensor, std::allocator<paddle::Tensor> > const&, std::vector<paddle::Tensor, std::allocator<paddle::Tensor> > const&, bool, bool, std::vector<paddle::Tensor, std::allocator<paddle::Tensor> > const&, bool, std::vector<paddle::Tensor, std::allocator<paddle::Tensor> > const&, std::string)
2026-04-27T12:46:24.0704342Z     75	2   MatmulGradNode::operator()(paddle::small_vector<std::vector<paddle::Tensor, std::allocator<paddle::Tensor> >, 15u>&, bool, bool)
2026-04-27T12:46:24.0705187Z     76	3   paddle::experimental::matmul_grad(paddle::Tensor const&, paddle::Tensor const&, paddle::Tensor const&, bool, bool, paddle::Tensor*, paddle::Tensor*)
2026-04-27T12:46:24.0706307Z     77	4   void phi::MatmulGradStrideKernel<float, phi::GPUContext>(phi::GPUContext const&, phi::DenseTensor const&, phi::DenseTensor const&, phi::DenseTensor const&, bool, bool, phi::DenseTensor*, phi::DenseTensor*)
2026-04-27T12:46:24.0707137Z     78	5   phi::PrepareStridedOut(phi::DenseTensor*)
2026-04-27T12:46:24.0707545Z     79	6   phi::DenseTensorMeta::DenseTensorMeta(phi::DenseTensorMeta const&)
2026-04-27T12:46:24.0707920Z     80	
2026-04-27T12:46:24.0708110Z     81	----------------------
2026-04-27T12:46:24.0708368Z     82	Error Message Summary:
2026-04-27T12:46:24.0708612Z     83	----------------------
2026-04-27T12:46:24.0708985Z     84	FatalError: `Segmentation fault` is detected by the operating system.
2026-04-27T12:46:24.0709534Z     85	  [TimeInfo: *** Aborted at 1777293968 (unix time) try "date -d @1777293968" if you are using GNU date ***]
2026-04-27T12:46:24.0710126Z     86	  [SignalInfo: *** SIGSEGV (@0x10) received by PID 7988 (TID 0x7f9905499740) from PID 16 ***]

重命名后问题消失,可能是编译链接错函数了?无法解释。

是否引起精度变化

@paddle-bot
Copy link
Copy Markdown

paddle-bot Bot commented Apr 24, 2026

你的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
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR adjusts Paddle’s bundled tinyformat-based printf utilities to avoid crashing (assert/abort) when the format string’s conversion specifiers don’t match the provided arguments, aiming to preserve more useful PADDLE_ENFORCE error context.

Changes:

  • Replace tinyformat’s assert-based error path with a thrown detail::FormatError.
  • Add catch/fallback behavior in paddle::string::Fprintf / Sprintf to output/return the raw format string on format errors.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 7 comments.

File Description
paddle/utils/string/tinyformat/tinyformat.h Replaces TINYFORMAT_ERROR assert handling with detail::FormatError exceptions thrown on format errors.
paddle/utils/string/printf.h Wraps tinyformat formatting calls with try/catch to fall back to raw format strings when a FormatError is raised.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

"tinyformat: Cannot convert from argument type to "
"integer for use as variable width or precision");
throw FormatError();
return 0;
TINYFORMAT_ERROR(
"tinyformat: Not enough conversion specifiers in format string");
throw FormatError();
return fmtStart;
// Check args remain after reading any variable width/precision
TINYFORMAT_ERROR("tinyformat: Not enough format arguments");
throw FormatError();
return;
void Fprintf(std::ostream& out, const char* fmt, const Args&... args) {
tinyformat::vformat(out, fmt, tinyformat::makeFormatList(args...));
try {
tinyformat::vformat(out, fmt, tinyformat::makeFormatList(args...));
Comment on lines 101 to +108
std::string Sprintf(const char* fmt, const Args&... args) {
std::ostringstream oss;
Fprintf(oss, fmt, args...);
return oss.str();
try {
std::ostringstream oss;
Fprintf(oss, fmt, args...);
return oss.str();
} catch (const tinyformat::detail::FormatError&) {
return fmt;
}
void Fprintf(std::ostream& out, const char* fmt, const Args&... args) {
tinyformat::vformat(out, fmt, tinyformat::makeFormatList(args...));
try {
tinyformat::vformat(out, fmt, tinyformat::makeFormatList(args...));
Comment on lines +122 to +123
// Error handling: Format errors throw detail::FormatError, which is caught
// at the public API level to fall back to the raw format string.
Copy link
Copy Markdown
Member

@ForFishes ForFishes left a comment

Choose a reason for hiding this comment

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

LGTM

@zrr1999 zrr1999 merged commit 7f0b4b5 into PaddlePaddle:develop Apr 29, 2026
94 of 97 checks passed
@risemeup1111
Copy link
Copy Markdown

✅ Cherry-pick successful! Created PR: #78843

@risemeup1111
Copy link
Copy Markdown

✅ Cherry-pick successful! Created PR: #78844

sneaxiy pushed a commit that referenced this pull request May 8, 2026
* fix tinyformat

* for test

Co-authored-by: wanghuancoder <wanghuan29@baidu.com>
sneaxiy pushed a commit that referenced this pull request May 8, 2026
* fix tinyformat

* for test

Co-authored-by: wanghuancoder <wanghuan29@baidu.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants