-
Notifications
You must be signed in to change notification settings - Fork 9
/
pretrain.py
52 lines (39 loc) · 1.57 KB
/
pretrain.py
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
import argparse
from logging import getLogger
from recbole.config import Config
from recbole.trainer.trainer import PretrainTrainer
from recbole.data.dataloader import TrainDataLoader
from recbole.utils import init_seed, init_logger
from vqrec import VQRec
from data.dataset import PretrainVQRecDataset
def pretrain(dataset, **kwargs):
# configurations initialization
props = ['props/VQRec.yaml', 'props/pretrain.yaml']
print(props)
# configurations initialization
config = Config(model=VQRec, dataset=dataset, config_file_list=props, config_dict=kwargs)
init_seed(config['seed'], config['reproducibility'])
# logger initialization
init_logger(config)
logger = getLogger()
logger.info(config)
# dataset filtering
dataset = PretrainVQRecDataset(config)
logger.info(dataset)
pretrain_dataset = dataset.build()[0]
pretrain_data = TrainDataLoader(config, pretrain_dataset, None, shuffle=True)
# model loading and initialization
model = VQRec(config, pretrain_data.dataset).to(config['device'])
model.pq_codes = model.pq_codes.to(config['device'])
logger.info(model)
# trainer loading and initialization
trainer = PretrainTrainer(config, model)
# model pre-training
trainer.pretrain(pretrain_data, show_progress=True)
return config['model'], config['dataset']
if __name__ == '__main__':
parser = argparse.ArgumentParser()
parser.add_argument('-d', type=str, default='FHCKM', help='dataset name')
args, unparsed = parser.parse_known_args()
print(args)
model, dataset = pretrain(args.d)