-
-
Notifications
You must be signed in to change notification settings - Fork 161
Description
Describe the bug
I'm am tring to train a model using SSL, pretrain and finetune as described here :
https://pytorch-tabular.readthedocs.io/en/latest/tutorials/08-Self-Supervised%20Learning-DAE/
My pretrain and finetune function works well in case the pretrain pass the ssl model directly to finetune.
The script return the following error in case I save the SSL model and then load. ( this is usefull to split train time and avoid having two long train run for each phase).
Traceback (most recent call last):
File "pytorch_tabular_example.py", line 725, in
finetuned_model = run_fine_tuning_v1(ssl_model, train_data, val_data, target_column, run_finetuning=True)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "pytorch_tabular_example.py", line 662, in run_fine_tuning_v1
finetune_model = ssl_model.create_finetune_model(
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "Lib\site-packages\pytorch_tabular\tabular_model.py", line 1057, in create_finetune_model
model = model_callable(
^^^^^^^^^^^^^^^
File "Lib\site-packages\pytorch_tabular\models\base_model.py", line 676, in init
super().init(
File "\Lib\site-packages\pytorch_tabular\models\base_model.py", line 169, in init
self._build_network()
File "\Lib\site-packages\pytorch_tabular\models\base_model.py", line 718, in _build_network
self._head = self._get_head_from_config()
^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "MLTrn\Lib\site-packages\pytorch_tabular\models\base_model.py", line 696, in _get_head_from_config
return _head_callable(
^^^^^^^^^^^^^^^
File "Lib\site-packages\pytorch_tabular\models\common\heads\blocks.py", line 60, in init
_layers.append(nn.Linear(_curr_units, output_dim))
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "Lib\site-packages\torch\nn\modules\linear.py", line 99, in init
self.weight = Parameter(torch.empty((out_features, in_features), **factory_kwargs))
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
TypeError: empty() received an invalid combination of arguments - got (tuple, dtype=NoneType, device=NoneType), but expected one of:
- (tuple of ints size, *, tuple of names names, torch.memory_format memory_format = None, torch.dtype dtype = None, torch.layout layout = None, torch.device device = None, bool pin_memory = False, bool requires_grad = False)
- (tuple of ints size, *, torch.memory_format memory_format = None, Tensor out = None, torch.dtype dtype = None, torch.layout layout = None, torch.device device = None, bool pin_memory = False, bool requires_grad = False)
To Reproduce
pretrain the model
save using
def save_model(model, path):
model.save_model(path)
log_step("Save Model", f"Model saved at {path}")load it using:
def load_model_v2(path, device='cuda'):
map_location = torch.device(device) if torch.cuda.is_available() else torch.device('cpu')
model = TabularModel.load_model(path, map_location=map_location)
log_step("Load Model", f"Model loaded from {path} on device {map_location}")
return modeland pass it to the same finetuing function that when provided with a model not saved works.
Expected behavior
I can't understand why saving and loading the model and the fine tuining it cause an error while passing the SSL model directly do not cause any issue. Having the ability to save and load the model make debugging and retrain much quicker.
Regards