@@ -670,11 +670,11 @@ def init_with_hyperparam(self,
670670 if self .target_mask is not None :
671671 train_targets = train_targets [:, self .target_mask ]
672672 device = torch .device ('cpu' )
673- state_dict = torch .load (path_to_statedict , map_location = device )
673+ state_dict = torch .load (path_to_statedict , map_location = device , _use_new_zipfile_serialization = True )
674674 self ._init_model (train_inputs , train_targets )
675675
676676 self .model .load_state_dict (state_dict )
677- self .model . double ( ) # needed otherwise loads state_dict as float32
677+ self .model = self . model . to ( dtype = torch . float64 ) # needed otherwise loads state_dict as float32
678678 self ._compute_GP_covariances (train_inputs )
679679 self .casadi_predict = self .make_casadi_prediction_func (train_inputs , train_targets )
680680
@@ -724,8 +724,8 @@ def train(self,
724724 test_y = test_y .cuda ()
725725 self .model = self .model .cuda ()
726726 self .likelihood = self .likelihood .cuda ()
727- self .model . double ( )
728- self .likelihood . double ( )
727+ self .model = self . model . to ( dtype = torch . float64 )
728+ self .likelihood = self . likelihood . to ( dtype = torch . float64 )
729729 self .model .train ()
730730 self .likelihood .train ()
731731 self .optimizer = torch .optim .Adam (self .model .parameters (), lr = learning_rate )
@@ -735,7 +735,7 @@ def train(self,
735735 loss = torch .tensor (0 )
736736 i = 0
737737 while i < n_train and torch .abs (loss - last_loss ) > 1e-2 :
738- with torch .no_grad ():
738+ with torch .inference_mode ():
739739 self .model .eval ()
740740 self .likelihood .eval ()
741741 test_output = self .model (test_x .unsqueeze (0 ).repeat (self .output_dimension , 1 , 1 ))
@@ -754,7 +754,7 @@ def train(self,
754754 if test_loss < best_loss :
755755 best_loss = test_loss
756756 state_dict = self .model .state_dict ()
757- torch .save (state_dict , fname )
757+ torch .save (state_dict , fname , _use_new_zipfile_serialization = True )
758758 best_epoch = i
759759
760760 i += 1
@@ -765,7 +765,7 @@ def train(self,
765765 self .likelihood = self .likelihood .cpu ()
766766 train_x = train_x .cpu ()
767767 train_y = train_y .cpu ()
768- self .model .load_state_dict (torch .load (fname ))
768+ self .model .load_state_dict (torch .load (fname , weights_only = False ))
769769 self ._compute_GP_covariances (train_x )
770770 self .casadi_predict = self .make_casadi_prediction_func (train_x , train_y )
771771
@@ -791,7 +791,7 @@ def predict(self,
791791 self .model .eval ()
792792 self .likelihood .eval ()
793793 if isinstance (x , np .ndarray ):
794- x = torch .from_numpy ( x ). double ( )
794+ x = torch .tensor ( x , dtype = torch . float64 )
795795 if self .input_mask is not None :
796796 x = x [:, self .input_mask ]
797797 if requires_grad :
@@ -986,12 +986,12 @@ def init_with_hyperparam(self,
986986 if self .target_mask is not None :
987987 train_targets = train_targets [:, self .target_mask ]
988988 device = torch .device ('cpu' )
989- state_dict = torch .load (path_to_statedict , map_location = device )
989+ state_dict = torch .load (path_to_statedict , map_location = device , _use_new_zipfile_serialization = True )
990990 self ._init_model (train_inputs , train_targets )
991991 if self .NORMALIZE :
992992 train_inputs = torch .from_numpy (self .scaler .transform (train_inputs .numpy ()))
993993 self .model .load_state_dict (state_dict )
994- self .model . double ( ) # needed otherwise loads state_dict as float32
994+ self .model = self . model . to ( dtype = torch . float64 ) # needed otherwise loads state_dict as float32
995995 self ._compute_GP_covariances (train_inputs )
996996 self .casadi_predict = self .make_casadi_prediction_func (train_inputs , train_targets )
997997
@@ -1045,8 +1045,8 @@ def train(self,
10451045 test_y = test_y .cuda ()
10461046 self .model = self .model .cuda ()
10471047 self .likelihood = self .likelihood .cuda ()
1048- self .model . double ( )
1049- self .likelihood . double ( )
1048+ self .model = self . model . to ( dtype = torch . float64 )
1049+ self .likelihood = self . likelihood . to ( dtype = torch . float64 )
10501050 self .model .train ()
10511051 self .likelihood .train ()
10521052 self .optimizer = torch .optim .Adam (self .model .parameters (), lr = learning_rate )
@@ -1056,7 +1056,7 @@ def train(self,
10561056 loss = torch .tensor (0 )
10571057 i = 0
10581058 while i < n_train and torch .abs (loss - last_loss ) > 1e-2 :
1059- with torch .no_grad ():
1059+ with torch .inference_mode ():
10601060 self .model .eval ()
10611061 self .likelihood .eval ()
10621062 test_output = self .model (test_x )
@@ -1074,7 +1074,7 @@ def train(self,
10741074 if test_loss < best_loss :
10751075 best_loss = test_loss
10761076 state_dict = self .model .state_dict ()
1077- torch .save (state_dict , fname )
1077+ torch .save (state_dict , fname , _use_new_zipfile_serialization = True )
10781078 best_epoch = i
10791079
10801080 i += 1
@@ -1085,7 +1085,7 @@ def train(self,
10851085 self .likelihood = self .likelihood .cpu ()
10861086 train_x = train_x .cpu ()
10871087 train_y = train_y .cpu ()
1088- self .model .load_state_dict (torch .load (fname ))
1088+ self .model .load_state_dict (torch .load (fname , weights_only = False ))
10891089 self ._compute_GP_covariances (train_x )
10901090 self .casadi_predict = self .make_casadi_prediction_func (train_x , train_y )
10911091
@@ -1109,7 +1109,7 @@ def predict(self,
11091109 self .model .eval ()
11101110 self .likelihood .eval ()
11111111 if isinstance (x , np .ndarray ):
1112- x = torch .from_numpy ( x ). double ( )
1112+ x = torch .tensor ( x , dtype = torch . float64 )
11131113 if self .input_mask is not None :
11141114 x = x [:, self .input_mask ]
11151115 if self .NORMALIZE :
0 commit comments