1
0
mirror of https://github.com/microsoft/qlib.git synced 2026-07-14 00:06:58 +08:00

Fix many bugs in TabNet and use_gpu

This commit is contained in:
D-X-Y
2021-03-12 02:42:25 +00:00
parent f6b019dcec
commit 67fbdafe76
14 changed files with 70 additions and 49 deletions

View File

@@ -82,7 +82,6 @@ class DNNModelPytorch(Model):
self.optimizer = optimizer.lower()
self.loss_type = loss
self.device = torch.device("cuda:%d" % (GPU) if torch.cuda.is_available() and GPU >= 0 else "cpu")
self.use_GPU = torch.cuda.is_available()
self.seed = seed
self.weight_decay = weight_decay
@@ -101,7 +100,7 @@ class DNNModelPytorch(Model):
"\neval_steps : {}"
"\nseed : {}"
"\nvisible_GPU : {}"
"\nuse_GPU : {}"
"\nuse_gpu : {}"
"\nweight_decay : {}".format(
layers,
lr,
@@ -116,7 +115,7 @@ class DNNModelPytorch(Model):
eval_steps,
seed,
GPU,
self.use_GPU,
self.use_gpu,
weight_decay,
)
)
@@ -157,6 +156,10 @@ class DNNModelPytorch(Model):
self.fitted = False
self.dnn_model.to(self.device)
@property
def use_gpu(self):
self.device == torch.device("cpu")
def fit(
self,
dataset: DatasetH,
@@ -254,7 +257,7 @@ class DNNModelPytorch(Model):
# restore the optimal parameters after training ??
self.dnn_model.load_state_dict(torch.load(save_path))
if self.use_GPU:
if self.use_gpu:
torch.cuda.empty_cache()
def get_loss(self, pred, w, target, loss_type):
@@ -276,10 +279,7 @@ class DNNModelPytorch(Model):
self.dnn_model.eval()
with torch.no_grad():
if self.use_GPU:
preds = self.dnn_model(x_test).detach().cpu().numpy()
else:
preds = self.dnn_model(x_test).detach().numpy()
preds = self.dnn_model(x_test).detach().cpu().numpy()
return pd.Series(np.squeeze(preds), index=x_test_pd.index)
def save(self, filename, **kwargs):