The main.py script serves as the primary entrypoint for training recommendation models (such as LightGCN) using the BPR (Bayesian Personalized Ranking) loss. It orchestrates model initialization, weight loading, TensorBoard logging, and the training loop.
Key behaviors:
- Model Initialization: Models are instantiated using a registry system (
register.MODELS) based on the world.model_name configuration. - Weight Management: The script automatically determines a filename via
utils.getFileName(). If world.LOAD is enabled, it attempts to load existing weights from that file; otherwise, it starts training from scratch. - Training Loop: For each epoch, the script performs a test evaluation (if
epoch % 10 == 0) using Procedure.Test and then executes the training step via Procedure.BPR_train_original. - Logging: If
world.tensorboard is enabled, it initializes a SummaryWriter with a timestamped directory under world.BOARD_PATH.
# The execution flow follows this pattern:
# 1. Initialize model from register
# 2. Load weights if world.LOAD is True
# 3. Initialize TensorBoard if world.tensorboard is True
# 4. Loop through world.TRAIN_epochs:
# a. Test every 10 epochs
# b. Run BPR training
# c. Save model state