Use fmt::format for debug strings in Library init (#151629)

Observed several ms taken during `import torch` by c10::str here.

Differential Revision: [D73129453](https://our.internmc.facebook.com/intern/diff/D73129453/)
Pull Request resolved: https://github.com/pytorch/pytorch/pull/151629
Approved by: https://github.com/cyyever, https://github.com/Skylion007, https://github.com/albanD, https://github.com/malfet
ghstack dependencies: #151626, #151627, #151628
This commit is contained in:
Scott Wolchok 2025-04-18 10:04:25 -07:00 committed by PyTorch MergeBot
parent 313ceb4da3
commit cac8d35503

View File

@ -1,6 +1,7 @@
#include <torch/library.h>
#include <ATen/core/dispatch/Dispatcher.h>
#include <fmt/format.h>
namespace torch {
@ -11,7 +12,7 @@ namespace {
#ifdef STRIP_ERROR_MESSAGES
return std::string();
#else
return c10::str("registered at ", file, ":", line);
return fmt::format("registered at {}:{}", file, line);
#endif
}