Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
tianlh
LightGBM-DCU
Commits
46427128
Unverified
Commit
46427128
authored
Oct 10, 2022
by
José Morales
Committed by
GitHub
Oct 10, 2022
Browse files
suppress alias warnings with verbosity<0 (fixes #4518) (#5253)
parent
c5391c97
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
103 additions
and
31 deletions
+103
-31
include/LightGBM/config.h
include/LightGBM/config.h
+3
-1
src/application/application.cpp
src/application/application.cpp
+13
-10
src/io/config.cpp
src/io/config.cpp
+45
-20
tests/python_package_test/test_engine.py
tests/python_package_test/test_engine.py
+42
-0
No files found.
include/LightGBM/config.h
View file @
46427128
...
@@ -86,7 +86,9 @@ struct Config {
...
@@ -86,7 +86,9 @@ struct Config {
*/
*/
inline
static
bool
SortAlias
(
const
std
::
string
&
x
,
const
std
::
string
&
y
);
inline
static
bool
SortAlias
(
const
std
::
string
&
x
,
const
std
::
string
&
y
);
static
void
KV2Map
(
std
::
unordered_map
<
std
::
string
,
std
::
string
>*
params
,
const
char
*
kv
);
static
void
KeepFirstValues
(
const
std
::
unordered_map
<
std
::
string
,
std
::
vector
<
std
::
string
>>&
params
,
std
::
unordered_map
<
std
::
string
,
std
::
string
>*
out
);
static
void
KV2Map
(
std
::
unordered_map
<
std
::
string
,
std
::
vector
<
std
::
string
>>*
params
,
const
char
*
kv
);
static
void
SetVerbosity
(
const
std
::
unordered_map
<
std
::
string
,
std
::
vector
<
std
::
string
>>&
params
);
static
std
::
unordered_map
<
std
::
string
,
std
::
string
>
Str2Map
(
const
char
*
parameters
);
static
std
::
unordered_map
<
std
::
string
,
std
::
string
>
Str2Map
(
const
char
*
parameters
);
#ifndef __NVCC__
#ifndef __NVCC__
...
...
src/application/application.cpp
View file @
46427128
...
@@ -48,15 +48,15 @@ Application::~Application() {
...
@@ -48,15 +48,15 @@ Application::~Application() {
}
}
void
Application
::
LoadParameters
(
int
argc
,
char
**
argv
)
{
void
Application
::
LoadParameters
(
int
argc
,
char
**
argv
)
{
std
::
unordered_map
<
std
::
string
,
std
::
vector
<
std
::
string
>>
all_params
;
std
::
unordered_map
<
std
::
string
,
std
::
string
>
params
;
std
::
unordered_map
<
std
::
string
,
std
::
string
>
params
;
for
(
int
i
=
1
;
i
<
argc
;
++
i
)
{
for
(
int
i
=
1
;
i
<
argc
;
++
i
)
{
Config
::
KV2Map
(
&
params
,
argv
[
i
]);
Config
::
KV2Map
(
&
all_
params
,
argv
[
i
]);
}
}
// check for alias
ParameterAlias
::
KeyAliasTransform
(
&
params
);
// read parameters from config file
// read parameters from config file
if
(
params
.
count
(
"config"
)
>
0
)
{
bool
config_file_ok
=
true
;
TextReader
<
size_t
>
config_reader
(
params
[
"config"
].
c_str
(),
false
);
if
(
all_params
.
count
(
"config"
)
>
0
)
{
TextReader
<
size_t
>
config_reader
(
all_params
[
"config"
][
0
].
c_str
(),
false
);
config_reader
.
ReadAllLines
();
config_reader
.
ReadAllLines
();
if
(
!
config_reader
.
Lines
().
empty
())
{
if
(
!
config_reader
.
Lines
().
empty
())
{
for
(
auto
&
line
:
config_reader
.
Lines
())
{
for
(
auto
&
line
:
config_reader
.
Lines
())
{
...
@@ -68,16 +68,19 @@ void Application::LoadParameters(int argc, char** argv) {
...
@@ -68,16 +68,19 @@ void Application::LoadParameters(int argc, char** argv) {
if
(
line
.
size
()
==
0
)
{
if
(
line
.
size
()
==
0
)
{
continue
;
continue
;
}
}
Config
::
KV2Map
(
&
params
,
line
.
c_str
());
Config
::
KV2Map
(
&
all_
params
,
line
.
c_str
());
}
}
}
else
{
}
else
{
Log
::
Warning
(
"Config file %s doesn't exist, will ignore"
,
config_file_ok
=
false
;
params
[
"config"
].
c_str
());
}
}
}
}
// check for alias again
Config
::
SetVerbosity
(
all_params
);
// de-duplicate params
Config
::
KeepFirstValues
(
all_params
,
&
params
);
if
(
!
config_file_ok
)
{
Log
::
Warning
(
"Config file %s doesn't exist, will ignore"
,
params
[
"config"
].
c_str
());
}
ParameterAlias
::
KeyAliasTransform
(
&
params
);
ParameterAlias
::
KeyAliasTransform
(
&
params
);
// load configs
config_
.
Set
(
params
);
config_
.
Set
(
params
);
Log
::
Info
(
"Finished loading parameters"
);
Log
::
Info
(
"Finished loading parameters"
);
}
}
...
...
src/io/config.cpp
View file @
46427128
...
@@ -13,7 +13,7 @@
...
@@ -13,7 +13,7 @@
namespace
LightGBM
{
namespace
LightGBM
{
void
Config
::
KV2Map
(
std
::
unordered_map
<
std
::
string
,
std
::
string
>*
params
,
const
char
*
kv
)
{
void
Config
::
KV2Map
(
std
::
unordered_map
<
std
::
string
,
std
::
vector
<
std
::
string
>
>
*
params
,
const
char
*
kv
)
{
std
::
vector
<
std
::
string
>
tmp_strs
=
Common
::
Split
(
kv
,
'='
);
std
::
vector
<
std
::
string
>
tmp_strs
=
Common
::
Split
(
kv
,
'='
);
if
(
tmp_strs
.
size
()
==
2
||
tmp_strs
.
size
()
==
1
)
{
if
(
tmp_strs
.
size
()
==
2
||
tmp_strs
.
size
()
==
1
)
{
std
::
string
key
=
Common
::
RemoveQuotationSymbol
(
Common
::
Trim
(
tmp_strs
[
0
]));
std
::
string
key
=
Common
::
RemoveQuotationSymbol
(
Common
::
Trim
(
tmp_strs
[
0
]));
...
@@ -22,26 +22,61 @@ void Config::KV2Map(std::unordered_map<std::string, std::string>* params, const
...
@@ -22,26 +22,61 @@ void Config::KV2Map(std::unordered_map<std::string, std::string>* params, const
value
=
Common
::
RemoveQuotationSymbol
(
Common
::
Trim
(
tmp_strs
[
1
]));
value
=
Common
::
RemoveQuotationSymbol
(
Common
::
Trim
(
tmp_strs
[
1
]));
}
}
if
(
key
.
size
()
>
0
)
{
if
(
key
.
size
()
>
0
)
{
auto
value_search
=
params
->
find
(
key
);
params
->
operator
[](
key
).
emplace_back
(
value
);
if
(
value_search
==
params
->
end
())
{
// not set
params
->
emplace
(
key
,
value
);
}
else
{
Log
::
Warning
(
"%s is set=%s, %s=%s will be ignored. Current value: %s=%s"
,
key
.
c_str
(),
value_search
->
second
.
c_str
(),
key
.
c_str
(),
value
.
c_str
(),
key
.
c_str
(),
value_search
->
second
.
c_str
());
}
}
}
}
else
{
}
else
{
Log
::
Warning
(
"Unknown parameter %s"
,
kv
);
Log
::
Warning
(
"Unknown parameter %s"
,
kv
);
}
}
}
}
void
GetFirstValueAsInt
(
const
std
::
unordered_map
<
std
::
string
,
std
::
vector
<
std
::
string
>>&
params
,
std
::
string
key
,
int
*
out
)
{
const
auto
pair
=
params
.
find
(
key
);
if
(
pair
!=
params
.
end
())
{
auto
candidate
=
pair
->
second
[
0
].
c_str
();
if
(
!
Common
::
AtoiAndCheck
(
candidate
,
out
))
{
Log
::
Fatal
(
"Parameter %s should be of type int, got
\"
%s
\"
"
,
key
.
c_str
(),
candidate
);
}
}
}
void
Config
::
SetVerbosity
(
const
std
::
unordered_map
<
std
::
string
,
std
::
vector
<
std
::
string
>>&
params
)
{
int
verbosity
=
Config
().
verbosity
;
GetFirstValueAsInt
(
params
,
"verbose"
,
&
verbosity
);
GetFirstValueAsInt
(
params
,
"verbosity"
,
&
verbosity
);
if
(
verbosity
<
0
)
{
LightGBM
::
Log
::
ResetLogLevel
(
LightGBM
::
LogLevel
::
Fatal
);
}
else
if
(
verbosity
==
0
)
{
LightGBM
::
Log
::
ResetLogLevel
(
LightGBM
::
LogLevel
::
Warning
);
}
else
if
(
verbosity
==
1
)
{
LightGBM
::
Log
::
ResetLogLevel
(
LightGBM
::
LogLevel
::
Info
);
}
else
{
LightGBM
::
Log
::
ResetLogLevel
(
LightGBM
::
LogLevel
::
Debug
);
}
}
void
Config
::
KeepFirstValues
(
const
std
::
unordered_map
<
std
::
string
,
std
::
vector
<
std
::
string
>>&
params
,
std
::
unordered_map
<
std
::
string
,
std
::
string
>*
out
)
{
for
(
auto
pair
=
params
.
begin
();
pair
!=
params
.
end
();
++
pair
)
{
auto
name
=
pair
->
first
.
c_str
();
auto
values
=
pair
->
second
;
out
->
emplace
(
name
,
values
[
0
]);
for
(
size_t
i
=
1
;
i
<
pair
->
second
.
size
();
++
i
)
{
Log
::
Warning
(
"%s is set=%s, %s=%s will be ignored. Current value: %s=%s"
,
name
,
values
[
0
].
c_str
(),
name
,
values
[
i
].
c_str
(),
name
,
values
[
0
].
c_str
());
}
}
}
std
::
unordered_map
<
std
::
string
,
std
::
string
>
Config
::
Str2Map
(
const
char
*
parameters
)
{
std
::
unordered_map
<
std
::
string
,
std
::
string
>
Config
::
Str2Map
(
const
char
*
parameters
)
{
std
::
unordered_map
<
std
::
string
,
std
::
vector
<
std
::
string
>>
all_params
;
std
::
unordered_map
<
std
::
string
,
std
::
string
>
params
;
std
::
unordered_map
<
std
::
string
,
std
::
string
>
params
;
auto
args
=
Common
::
Split
(
parameters
,
"
\t\n\r
"
);
auto
args
=
Common
::
Split
(
parameters
,
"
\t\n\r
"
);
for
(
auto
arg
:
args
)
{
for
(
auto
arg
:
args
)
{
KV2Map
(
&
params
,
Common
::
Trim
(
arg
).
c_str
());
KV2Map
(
&
all_
params
,
Common
::
Trim
(
arg
).
c_str
());
}
}
SetVerbosity
(
all_params
);
KeepFirstValues
(
all_params
,
&
params
);
ParameterAlias
::
KeyAliasTransform
(
&
params
);
ParameterAlias
::
KeyAliasTransform
(
&
params
);
return
params
;
return
params
;
}
}
...
@@ -240,16 +275,6 @@ void Config::Set(const std::unordered_map<std::string, std::string>& params) {
...
@@ -240,16 +275,6 @@ void Config::Set(const std::unordered_map<std::string, std::string>& params) {
save_binary
=
true
;
save_binary
=
true
;
}
}
if
(
verbosity
==
1
)
{
LightGBM
::
Log
::
ResetLogLevel
(
LightGBM
::
LogLevel
::
Info
);
}
else
if
(
verbosity
==
0
)
{
LightGBM
::
Log
::
ResetLogLevel
(
LightGBM
::
LogLevel
::
Warning
);
}
else
if
(
verbosity
>=
2
)
{
LightGBM
::
Log
::
ResetLogLevel
(
LightGBM
::
LogLevel
::
Debug
);
}
else
{
LightGBM
::
Log
::
ResetLogLevel
(
LightGBM
::
LogLevel
::
Fatal
);
}
// check for conflicts
// check for conflicts
CheckParamConflict
();
CheckParamConflict
();
}
}
...
...
tests/python_package_test/test_engine.py
View file @
46427128
...
@@ -6,6 +6,7 @@ import math
...
@@ -6,6 +6,7 @@ import math
import
pickle
import
pickle
import
platform
import
platform
import
random
import
random
import
re
from
os
import
getenv
from
os
import
getenv
from
pathlib
import
Path
from
pathlib
import
Path
...
@@ -3768,6 +3769,47 @@ def test_cegb_split_buffer_clean():
...
@@ -3768,6 +3769,47 @@ def test_cegb_split_buffer_clean():
assert
rmse
<
10.0
assert
rmse
<
10.0
def
test_verbosity_and_verbose
(
capsys
):
X
,
y
=
make_synthetic_regression
()
ds
=
lgb
.
Dataset
(
X
,
y
)
params
=
{
'num_leaves'
:
3
,
'verbose'
:
1
,
'verbosity'
:
0
,
}
lgb
.
train
(
params
,
ds
,
num_boost_round
=
1
)
expected_msg
=
(
'[LightGBM] [Warning] verbosity is set=0, verbose=1 will be ignored. '
'Current value: verbosity=0'
)
stdout
=
capsys
.
readouterr
().
out
assert
expected_msg
in
stdout
@
pytest
.
mark
.
parametrize
(
'verbosity_param'
,
lgb
.
basic
.
_ConfigAliases
.
get
(
"verbosity"
))
@
pytest
.
mark
.
parametrize
(
'verbosity'
,
[
-
1
,
0
])
def
test_verbosity_can_suppress_alias_warnings
(
capsys
,
verbosity_param
,
verbosity
):
X
,
y
=
make_synthetic_regression
()
ds
=
lgb
.
Dataset
(
X
,
y
)
params
=
{
'num_leaves'
:
3
,
'subsample'
:
0.75
,
'bagging_fraction'
:
0.8
,
'force_col_wise'
:
True
,
verbosity_param
:
verbosity
,
}
lgb
.
train
(
params
,
ds
,
num_boost_round
=
1
)
expected_msg
=
(
'[LightGBM] [Warning] bagging_fraction is set=0.8, subsample=0.75 will be ignored. '
'Current value: bagging_fraction=0.8'
)
stdout
=
capsys
.
readouterr
().
out
if
verbosity
>=
0
:
assert
expected_msg
in
stdout
else
:
assert
re
.
search
(
r
'\[LightGBM\]'
,
stdout
)
is
None
@
pytest
.
mark
.
skipif
(
not
PANDAS_INSTALLED
,
reason
=
'pandas is not installed'
)
@
pytest
.
mark
.
skipif
(
not
PANDAS_INSTALLED
,
reason
=
'pandas is not installed'
)
def
test_validate_features
():
def
test_validate_features
():
X
,
y
=
make_synthetic_regression
()
X
,
y
=
make_synthetic_regression
()
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment