From cbfa99f74da8c6e4669e8089d3bb92e97f31adbf Mon Sep 17 00:00:00 2001 From: Tian Zhen <1204216974@qq.com> Date: Fri, 19 Aug 2022 20:33:07 +0800 Subject: [PATCH 1/2] FIX: fix the gpu_id format && Optimization of LD --- recbole/config/configurator.py | 6 ++++-- recbole/data/dataset/dataset.py | 6 ++++-- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/recbole/config/configurator.py b/recbole/config/configurator.py index fa08764e0..190e0cdae 100644 --- a/recbole/config/configurator.py +++ b/recbole/config/configurator.py @@ -460,7 +460,10 @@ def _set_default_parameters(self): ) def _init_device(self): - self.final_config_dict["gpu_id"] = str(self.final_config_dict["gpu_id"]) + if isinstance(self.final_config_dict["gpu_id"], tuple): + self.final_config_dict["gpu_id"] = ','.join(map(str,list(self.final_config_dict["gpu_id"]))) + else: + self.final_config_dict["gpu_id"] = str(self.final_config_dict["gpu_id"]) gpu_id = self.final_config_dict["gpu_id"] os.environ["CUDA_VISIBLE_DEVICES"] = gpu_id import torch @@ -494,7 +497,6 @@ def _init_device(self): self.final_config_dict["state"] = "error" self.final_config_dict["show_progress"] = False self.final_config_dict["verbose"] = False - def _set_train_neg_sample_args(self): train_neg_sample_args = self.final_config_dict["train_neg_sample_args"] if train_neg_sample_args is None or train_neg_sample_args == "None": diff --git a/recbole/data/dataset/dataset.py b/recbole/data/dataset/dataset.py index d2f4d5253..6bf88ce17 100644 --- a/recbole/data/dataset/dataset.py +++ b/recbole/data/dataset/dataset.py @@ -763,8 +763,10 @@ def disc(arr, method, bucket): arr = np.ones_like(arr) * bucket elif method == "LD": # Logarithm Discretization - arr = np.floor(np.log(arr) ** 2 + 1) - + mask = arr > 2 + x = np.floor(np.log(arr * mask + 1e-9) ** 2 + 1) + x = np.where(mask, x, arr) + _, arr = np.unique(x, return_inverse=True) else: raise ValueError(f"Method [{method}] does not exist.") From 784502dbc393be4db65d455be978729d9dc02853 Mon Sep 17 00:00:00 2001 From: chenyuwuxin Date: Fri, 19 Aug 2022 12:33:45 +0000 Subject: [PATCH 2/2] Format Python code according to PEP8 --- recbole/config/configurator.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/recbole/config/configurator.py b/recbole/config/configurator.py index 190e0cdae..99f979602 100644 --- a/recbole/config/configurator.py +++ b/recbole/config/configurator.py @@ -461,7 +461,9 @@ def _set_default_parameters(self): def _init_device(self): if isinstance(self.final_config_dict["gpu_id"], tuple): - self.final_config_dict["gpu_id"] = ','.join(map(str,list(self.final_config_dict["gpu_id"]))) + self.final_config_dict["gpu_id"] = ",".join( + map(str, list(self.final_config_dict["gpu_id"])) + ) else: self.final_config_dict["gpu_id"] = str(self.final_config_dict["gpu_id"]) gpu_id = self.final_config_dict["gpu_id"] @@ -497,6 +499,7 @@ def _init_device(self): self.final_config_dict["state"] = "error" self.final_config_dict["show_progress"] = False self.final_config_dict["verbose"] = False + def _set_train_neg_sample_args(self): train_neg_sample_args = self.final_config_dict["train_neg_sample_args"] if train_neg_sample_args is None or train_neg_sample_args == "None":