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
Models don't accept model_name, saving_path #136
Comments
hey @rmitsch, Thanks for creating this issue, Saving a tabnet model follows the same rule as saving a pytorch model or XGBoost model. The best way I would recommend :
|
Thanks for the quick response! |
hello @rmitsch, Actually you are right, what I said does not work because the network is instantiated only after a fit, which is not very useful in that case (we might change that behaviour in the future). Try this instead, it should work :
|
Indeed, @Optimox , I have noticed that and I even probably have the change locally where I instantiate the network on class |
@eduardocarvp I think the problem with this is that before the fit we do not know either input_dim or output_dim, it's nice to have this computed automatically so I'm not sure how to bypass this. I think the best way would probably to have a method About the save I don't know if we wan't to package something or just give a few methods on how to save and reuse a tabnet model. |
@Optimox Plain old pickling worked, thanks! |
I tried this method. But it gives me an error: PicklingError: Can't pickle <class 'pytorch_tabnet.tab_model.TabNetClassifier'>: it's not the same object as pytorch_tabnet.tab_model.TabNetClassifier . Could you take a look at what might be reason? Thanks! It looks like that I can use this to save the model. However, after I used .fit method using the training dataset on clf, then abovementioned error will occur. |
helo @xywust2014 could you please clarify a bit when the error occurs? |
Thanks a lot for the help. Here are the code.
|
hmm could you try reading the file instead of writting in the second instead of this
try this
|
Thanks a lot!:) I will try that. |
Just chipping in to say - pickle dump/load is working for me... But I've noticed that it means it's not possible to e.g. train the model on a CUDA-enabled machine but then deploy for inference on a CPU-only environment. I suspect there might also be some constraints about porting the model between Python versions or other environment changes? I'd advocate for either of these, if possible:
...Not sure if it belongs in a separate enhancement Issue or is OK to tackle here though! |
@athewsey However have you tried to explicitely switch to cpu for inference after loading your model by doing |
Thanks for the quick response @Optimox! ...But afraid I don't think it'll work 😔 The error below is thrown on
I also tried unpickling the trained file on a GPU-enabled instance (which showed model.device_name = "cpu"
model.device = torch.device(model.device_name)
model.network.device = model.device
model.network.to(model.network.device)
model.network.cpu()
# Still won't unpickle on a non-CUDA env |
yep it was worth a try, I think @eduardocarvp will come with a better solution pretty soon. |
Thanks for the response. It looks like that I can use the pickle method to save&load the model clf without fitting on the training datasets. However, after I used .fit method using the training datasets on clf, then the following error will occur. PicklingError: Can't pickle <class 'pytorch_tabnet.tab_network.TabNet'>: it's not the same object as pytorch_tabnet.tab_network.TabNet |
@xywust2014 could you share a minimal code sample to reproduce your error? Because pickling option seems to be working as long as you stay in the same environment. Without a reproducible bug we can’t help you. |
Thanks. Optimox. I am using python 3.7 on Spyder. This machine has Cuda environment. But for the code below, I chose device_name = 'cpu'. (I set this as 'auto' before, which generates same error.) If I escaped the clf.fit() code, then there won't be any errors.
Thanks guys for the help. |
well I just ran this code in my local machine on census income and it runs without problem... a few notes though, if you are performing hyper parameter tuning you could refer to the README available in the front page of the repo to see "typical" values from the research paper.
I know this does not solve your problem but everything is running just fine on my computer... not sure where this comes from. |
Thanks a lot, Optimox, for the advice. |
Models also don't accept PS: Btw. lr (learning rate) is not documented in the readme. Just saying... |
Hello, well you are actually looking at the develop branch README (maybe we should find a way of defaulting the master branch) so The same thing is happening with The development branch always have some advanced features that the master branch does not get, they will match at the next release in the coming weeks. In the meantime please refer to the the master branch readme in order to get the current documentation. |
The release 1.2 should solve all these problems, feel free to open an new issue if you encounter an other problem. |
Describe the bug
Models don't accept
model_name
,saving_path
as initialization arguments.What is the current behavior?
See above.
If the current behavior is a bug, please provide the steps to reproduce.
clf: TabNetClassifier = TabNetClassifier(saving_path="/home/user123/dev/", device_name="cpu")
Expected behavior
Models should accept
model_name
,saving_path
as initialization arguments as specified in the documentation.Screenshots
Other relevant information:
poetry version:
python version:
Operating System:
Additional tools:
Additional context
On a related note: How can models be persisted? The mentioned init parameters strongly suggest that it is possible, but I couldn't find any information on this - either in the documentation nor in the code.
The text was updated successfully, but these errors were encountered: