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

CentOS7 LGBM_BoosterSaveModel succeed but without model files #6379

Open
ZoeZhang91 opened this issue Mar 22, 2024 · 2 comments
Open

CentOS7 LGBM_BoosterSaveModel succeed but without model files #6379

ZoeZhang91 opened this issue Mar 22, 2024 · 2 comments
Labels

Comments

@ZoeZhang91
Copy link

ZoeZhang91 commented Mar 22, 2024

Description

My code can correctly run with model files like "*.txt" exist in the path on windows. However on CentOS7 with gcc11.2.1, it also seems like "correctly" with no errors, succeed function return values "0" instead,but can not find any trained model files in the path.

At first I doubt about the data format FILE and fwrite in stdio.h, and then i wrote a demo run on CentOS7, it got the expected result: succeed create a txt file with "stdio fwrite test". It's so weird! Can anyone else help me? Thanks a lot!

Reproducible example

Environment info

LightGBM version or commit hash:
2.3.0
Command(s) you used to install LightGBM

Additional Comments

@jameslamb
Copy link
Collaborator

Thanks for using LightGBM.

We'd be happy to help, but need more information. I do not understand what you're trying to do or what create a txt file with "stdio fwrite test" means. Could you please share a minimal, reproducible example (link) and provide any logs or error messages you're observing?

LightGBM version or commit hash: 2.3.0

At this point, LightGBM 2.3.0 is 4.5+ years old (https://github.com/microsoft/LightGBM/releases/tag/v2.3.0). We will try to help you if you can provide more information, but would really appreciate if you can update to a newer version. There have been 4.5+ years of improvements since then, and some of those might have solved whatever problem you're facing.

@ZoeZhang91
Copy link
Author

Thanks for using LightGBM.

We'd be happy to help, but need more information. I do not understand what you're trying to do or what create a txt file with "stdio fwrite test" means. Could you please share a minimal, reproducible example (link) and provide any logs or error messages you're observing?

LightGBM version or commit hash: 2.3.0

At this point, LightGBM 2.3.0 is 4.5+ years old (https://github.com/microsoft/LightGBM/releases/tag/v2.3.0). We will try to help you if you can provide more information, but would really appreciate if you can update to a newer version. There have been 4.5+ years of improvements since then, and some of those might have solved whatever problem you're facing.

Sorry for described my problem in a hurry.
I am trying to train LGBM models(.txt extension) by C API on CentOS7 refer to the c_api_test file. All the interface functions i called from the dynamic library compiled by myself (.so extension) succeed with return value 0,but there were no any model files saved in the specified path. The part of C API train model code is as follows:

const char* config = "boosting=gbdt	objective=regression metric=mae	num_leaves=63 max_depth=7 learning_rate=0.01 feature_fraction=0.9 bagging_fraction=0.9 bagging_seed=0 bagging_freq=1 verbose=-1 reg_alpha=0 num_iterations=1000 early_stopping=200 min_data_in_leaf=1 header=true tree_learner=serial label_column=5	is_save_binary_file=false";	
    
	if(LGBM_DatasetCreateFromFile(c_train, config, nullptr, datasethandle)==0)
	{
	    cout <<" datasethandle succeed. "<< endl;
	}
	if(LGBM_BoosterCreate(*datasethandle, config, outhandle)==0)
	{
		cout <<" LGBM_BoosterCreate succeed. "<< endl;
	}
	int is_finished=0;
	for(int iter=1;iter<601;iter++)
	{
                   if(LGBM_BoosterUpdateOneIter(*outhandle,&is_finished)==0)
		{
			cout <<" LGBM_BoosterUpdateOneIter succeed. "<< endl;
		}
	}
	if(LGBM_BoosterSaveModel(*outhandle, 0, -1, C_API_FEATURE_IMPORTANCE_SPLIT, c_model)==0)
	{
			cout <<" LGBM_BoosterSaveModel succeed. "<< endl;
	}

Then I tried to run the same code on windows 10,Visual Studio 2019 with the dynamic library compiled by myself (.dll extension), it also succeed without any errors, return value 0, but the saved model files do exist!
image001

I traced the LightGBM source code,found that the C API LGBM_BoosterSaveModel saves model by the fwirte function in <stdio.h>
image002

And i was doubt about the data format FILE and fwrite at then, so i runned a short demo that wrote ”stdio fwrite test“ into the txt file who named ”test“ using FILE* and fwrite function on CentOS7, the test code is as follows:
#include <stdio.h>
#include
#include
#include
using namespace std;
int main()
{
FILE* fp=NULL;
string str="stdio fwrite test.";
fp=fopen("/home/admin/BG/test.txt","wb");
if(fp!=NULL)
{
fwrite(str.c_str(),str.size(),1,fp);
cout<<"over."<<endl;
}
fclose(fp);
return 0;
}
However, it is truely succeed, there do exist a test.txt in the specified path, too. So the fwrite‘s suspicion eliminated.
20240325144403

I am really so much confused with my problem, it has disturbed me for several days. Needs your help, thanks again.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants