close
Skip to content

fix tinyformat#78793

Open
wanghuancoder wants to merge 3 commits intoPaddlePaddle:developfrom
wanghuancoder:fix_tinyformat
Open

fix tinyformat#78793
wanghuancoder wants to merge 3 commits intoPaddlePaddle: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)

是否引起精度变化

@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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants