lasso-net / lassonet

Feature selection in neural networks
MIT License
215 stars 52 forks source link

TypeError: Expected state_dict to be dict-like, got <class 'NoneType'>. #62

Closed sddthree closed 5 months ago

sddthree commented 5 months ago

TypeError: Expected state_dict to be dict-like, got <class 'NoneType'>.

When I runing example : python friedman.py path_multiplier: 1.01 M: 10 Traceback (most recent call last): File "friedman.py", line 53, in min(rrmse(y_test, model.load(save).predict(X_test)) for save in path), File "friedman.py", line 53, in min(rrmse(y_test, model.load(save).predict(X_test)) for save in path), File "/opt/conda/envs/lassonet/lib/python3.8/site-packages/lassonet-0.0.15-py3.8.egg/lassonet/interfaces.py", line 524, in load self.model.load_state_dict(state_dict) File "/opt/conda/envs/lassonet/lib/python3.8/site-packages/torch/nn/modules/module.py", line 2140, in load_state_dict raise TypeError(f"Expected state_dict to be dict-like, got {type(state_dict)}.") TypeError: Expected state_dict to be dict-like, got <class 'NoneType'>.

since my cuda is 12, so my torch using the latest versin. torch 2.3.0 torchvision 0.18.0

how to solve it?

louisabraham commented 5 months ago

set return_state_dicts=True

ElrondL commented 4 months ago

@louisabraham is it possible to set
return_state_dicts=True as default value across interfaces.py? LassoNet breaks without setting it to be true.

louisabraham commented 4 months ago

The reason why I didn't put it as default is because of the large memory consumption. I could add some logic to make the error message more clear.

ElrondL commented 2 months ago

@louisabraham FYI, running LassoNet 0.0.19 as-is on the example diabetes.py yields the same error

TypeError: Expected state_dict to be dict-like, got <class 'NoneType'>.

louisabraham commented 2 months ago

Can you give your full use case? You should just put the argument mentioned above if you call the path function directly.

ElrondL commented 2 months ago

It's just this example code here I'm afraid https://github.com/lasso-net/lassonet/blob/master/examples/diabetes.py Running it as-is will give error

louisabraham commented 2 months ago

Hey! should be fixed now :)

If you read this: Just add return_state_dicts=True to your model.path call!

ElrondL commented 2 months ago

Thank you @louisabraham !!!