Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

LightGBM bypassing sink in R #513

Closed
Laurae2 opened this issue May 14, 2017 · 4 comments
Closed

LightGBM bypassing sink in R #513

Laurae2 opened this issue May 14, 2017 · 4 comments

Comments

@Laurae2
Copy link
Contributor

Laurae2 commented May 14, 2017

LightGBM ignores the sink/tee from R, but not for every message (only metric is printed in sink).

library(lightgbm)
data(agaricus.train, package = "lightgbm")
train <- agaricus.train
dtrain <- lgb.Dataset(train$data, label = train$label)
data(agaricus.test, package = "lightgbm")
test <- agaricus.test
dtest <- lgb.Dataset.create.valid(dtrain, test$data, label = test$label)
params <- list(objective = "regression", metric = "l2")
valids <- list(test = dtest)
sink("E:/Temped6/checker.txt") # CHANGE THIS TO APPROPRIATE FILE YOU WANT TO LOG LightGBM
model <- lgb.train(params,
                   dtrain,
                   100,
                   valids,
                   min_data = 1,
                   learning_rate = 1,
                   early_stopping_rounds = 10)
sink()

Expected behavior: all messages in the sink file.

image

@guolinke
Copy link
Collaborator

@Laurae2
Sorry, I am not familiar with R.
The message started with [LightGBM] actually are outputted by C++. I am not sure where do R put them.

@Laurae2
Copy link
Contributor Author

Laurae2 commented May 21, 2017

@guolinke I think it needs to be put in R_ext/Print.h: http://www.hep.by/gnu/r-patched/r-exts/R-exts_134.html#SEC134

The most useful function for printing from a C routine compiled into R is Rprintf. This is used in exactly the same way as printf, but is guaranteed to write to R's output (which might be a GUI console rather than a file, and can be re-directed by sink). It is wise to write complete lines (including the "\n") before returning to R. It is defined in `R_ext/Print.h'.

The function REprintf is similar but writes on the error stream (stderr) which may or may not be different from the standard output stream.

Functions Rvprintf and REvprintf are analogues using the vprintf interface. Because that is a C99 interface, they are only defined by `R_ext/Print.h' in C++ code if the macro R_USE_C99_IN_CXX is defined when it is included.

Another circumstance when it may be important to use these functions is when using parallel computation on a cluster of computational nodes, as their output will be re-directed/logged appropriately.

Maybe on the compilation we can add a -USE_R to specify R compilation, and on the logger checks for the flag existence to redirect messages.

In xgboost they use XGBOOST_CUSTOMIZE_LOGGER and XGBOOST_STRICT_R_MODE flags to customize for the R installation (RNG, messages, NaN representation).

https://github.com/dmlc/xgboost/blob/master/src/logging.cc

https://github.com/dmlc/xgboost/blob/master/include/xgboost/base.h

@guolinke
Copy link
Collaborator

@Laurae2 The difficulty is we cannot including R's header file.. So that it is hard to use R's printf.

@guolinke
Copy link
Collaborator

@Laurae2
It seems we cannot solve this issue.
feel free to reopen if needed.

@lock lock bot locked as resolved and limited conversation to collaborators Mar 11, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

3 participants