Repository navigation
Expand file tree
/
Copy pathmain.py
More file actions
57 lines (44 loc) · 1.55 KB
/
Copy pathmain.py
File metadata and controls
57 lines (44 loc) · 1.55 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
from SELFRec import SELFRec
from util.conf import ModelConf
import time
import random
import numpy as np
import torch
import os
def print_models(title, models):
print(f"{'=' * 80}\n{title}\n{'-' * 80}")
for category, model_list in models.items():
print(f"{category}:\n {' '.join(model_list)}\n{'-' * 80}")
def set_seed(seed=42):
"""Set all random seeds to ensure experiment reproducibility"""
random.seed(seed) # Python built-in random module
np.random.seed(seed) # NumPy
torch.manual_seed(seed) # PyTorch CPU
torch.cuda.manual_seed(seed) # PyTorch GPU (single card)
torch.cuda.manual_seed_all(seed) # PyTorch multi-card (if used)
# Ensure CUDA operations are deterministic (may reduce performance)
torch.backends.cudnn.deterministic = True
torch.backends.cudnn.benchmark = False
# Set Python environment variables (optional)
os.environ['PYTHONHASHSEED'] = str(seed)
# Usage example
if __name__ == '__main__':
set_seed(2025)
models = {
'Graph-Based Baseline Models': ['CNSDiff']
}
print('=' * 80)
print(' SELFRec: A library for self-supervised recommendation. ')
print_models("Available Models", models)
model = 'CNSDiff'
s = time.time()
all_models = sum(models.values(), [])
if model in all_models:
conf = ModelConf(f'./conf/{model}.yaml')
rec = SELFRec(conf)
rec.execute()
e = time.time()
print(f"Running time: {e - s:.2f} s")
else:
print('Wrong model name!')
exit(-1)