Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix the gpu_id format && Optimization of LD #1402

Merged
merged 2 commits into from
Aug 19, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion recbole/config/configurator.py
Original file line number Diff line number Diff line change
Expand Up @@ -460,7 +460,12 @@ 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
Expand Down
6 changes: 4 additions & 2 deletions recbole/data/dataset/dataset.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.")

Expand Down