Blealtan / efficient-kan

An efficient pure-PyTorch implementation of Kolmogorov-Arnold Network (KAN).
MIT License
3.92k stars 349 forks source link

Is there anyway that I can save the model for later use #17

Closed binhnguyen7tiki closed 4 months ago

binhnguyen7tiki commented 4 months ago

Hi, thank you for your work. As for the title, I would like some ways to save the model for inference. I have tried pickle dump but it does not work. Thanks

hoangthangta commented 4 months ago

You can use: torch.save(model, your_model_path)

Then load it to do inference: model = torch.load(model_path) model.eval()

For more information: https://pytorch.org/tutorials/beginner/saving_loading_models.html

binhna commented 4 months ago

Have you tried this? Not work for me. Because the torch saving seems to use the pickle too. AttributeError: Can't pickle local object 'Symbolic_KANLayer.__init__.<locals>.<listcomp>.<listcomp>.<lambda>'

hoangthangta commented 4 months ago

Can you show me your code?

Blealtan commented 4 months ago

@binhnguyen7tiki Please post the full error message.

@binhna I don't think my implementation includes Symbolic_KANLayer. It should be part of the official implementation.

BTW, it seems the two accounts are the same person? Correct me if I'm wrong.

hoangthangta commented 4 months ago

Have you tried this? Not work for me. Because the torch saving seems to use the pickle too. AttributeError: Can't pickle local object 'Symbolic_KANLayer.__init__.<locals>.<listcomp>.<listcomp>.<lambda>'

Do you use the original KAN (https://github.com/KindXiaoming/pykan) for training your model? Then, ask them there better.

Blealtan commented 4 months ago

Seemingly unrelated to this repo. Close for now and if I'm wrong I'll reopen it.

binhna commented 4 months ago

@Blealtan @hoangthangta sorry for the late reply, and yes, I checked the code again and it was the original KAN indeed. I switched to efficient-kan now and everything seems to be fine. Thank you guys for your help. PS: @Blealtan correct! it was the same guy, I accidentally used my work account in the first place.