mirror of
https://github.com/pytorch/pytorch.git
synced 2026-11-20 09:04:25 +08:00
[pytorch] Route default warning sync to LOG(WARNING) - second try (#36984)
Summary: Pull Request resolved: https://github.com/pytorch/pytorch/pull/36984 Follow LOG(WARNING) format for c++ side warnings in order to play well with larger services, especially when using glog. I need to hook up into GLOG internals a bit in order to override FILE/LINE without having to change the whole thing to be macros, but it seems to be stable between glog versions. Note, this also changes caffe2_log_level to warning by default - I think it's a much better default when compiling without glog (or maybe even have info). With glog output, stderr capture doesn't work any more in tests. That's why we instead use c10-level warnings capture. Test Plan: Run unittest in both glog and non-glog build mode: glog: ``` W0416 12:06:49.778215 3311666 exception_test.cpp:23] Warning: I'm a warning (function TestBody) ``` no-glog: ``` [W exception_test.cpp:23] Warning: I'm a warning (function TestBody) ``` Reviewed By: ilia-cher Differential Revision: D21151351 fbshipit-source-id: fa926d9e480db5ff696990dad3d80f79ef79f24a
This commit is contained in:
committed by
Facebook GitHub Bot
parent
b889e0da8a
commit
50a1850d8d
@@ -148,8 +148,7 @@ TEST_F(ModuleTest, RegisterParameterUndefinedTensor) {
|
||||
ASSERT_EQ(model.parameters().size(), 0);
|
||||
}
|
||||
{
|
||||
std::stringstream buffer;
|
||||
CerrRedirect cerr_redirect(buffer.rdbuf());
|
||||
WarningCapture warnings;
|
||||
|
||||
TestModel model;
|
||||
model.register_parameter("undefined_tensor", torch::Tensor());
|
||||
@@ -157,7 +156,7 @@ TEST_F(ModuleTest, RegisterParameterUndefinedTensor) {
|
||||
|
||||
ASSERT_EQ(
|
||||
count_substr_occurrences(
|
||||
buffer.str(),
|
||||
warnings.str(),
|
||||
"Ignoring the `requires_grad=true` function parameter"
|
||||
),
|
||||
1);
|
||||
|
||||
Reference in New Issue
Block a user