NVIDIA Deep Learning Examples
NVIDIA Deep Learning Examples
NCF for PyTorch
Resource
NVIDIA Deep Learning Examples
NVIDIA Deep Learning Examples
NCF for PyTorch

The NCF model focuses on providing recommendations. This is a modified implementation with improved overfitting and better accuracy.

To train your model using mixed or TF32 precision with Tensor Cores or using FP32, perform the following steps using the default parameters of the NCF model on the ML-20m dataset. For the specifics concerning training and inference, refer to the Advanced section.

  1. Clone the repository.
git clone https://github.com/NVIDIA/DeepLearningExamples
cd DeepLearningExamples/PyTorch/Recommendation/NCF
  1. Build an NCF PyTorch Docker container.

After Docker is set up, you can build the NCF image with:

docker build . -t nvidia_ncf
  1. Start an interactive session in the NGC container to run preprocessing/training and inference.

The NCF PyTorch container can be launched with:

docker run --runtime=nvidia -it --rm --ipc=host  -v ${PWD}/data:/data nvidia_ncf bash

This will launch the container and mount the ./data directory as a volume to the /data directory inside the container. Any datasets and experiment results (logs, checkpoints etc.) saved to /data will be accessible in the ./data directory on the host.

  1. Download and preprocess the data.

Download the data from https://grouplens.org/datasets/movielens/20m/ and put it in /data/ml-20m/ml-20m.zip.

Preprocessing consists of sorting the data, dropping the duplicates, renumbering users and items, selecting last interaction of each user to include in the test set, then randomly generating negative test set members (scoring candidates). The preprocessed train and test data is then saved in PyTorch binary format to be loaded just before training.

Note: Preprocessing requires PyTorch and should therefore be run inside the Docker container.

To preprocess the ML-20m dataset, you can run:

./prepare_dataset.sh

Note: This command will return immediately without downloading anything if the data is already present in the /data directory.

This will store the preprocessed training and evaluation data in the /data directory so that it can be later used to train the model (by passing the appropriate --data argument to the ncf.py script).

  1. Start training.

After the Docker container is launched, the training with the default hyperparameters (suitable for a DGX-1V or DGX A100 with 8 GPUs) can be started with:

python -m torch.distributed.launch --nproc_per_node=8 --use_env ncf.py --data /data/cache/ml-20m  --checkpoint_dir /data/checkpoints/

This will result in a checkpoint file being written to /data/checkpoints/model.pth.

  1. Start validation/evaluation.

The trained model can be evaluated by passing the --mode test flag to the run.sh script:

python -m torch.distributed.launch --nproc_per_node=1 --use_env ncf.py --data /data/cache/ml-20m  --mode test --load_checkpoint_path /data/checkpoints/model.pth

NVIDIA uses cookies to improve your experience on our web site. We and our third-party partners also use cookies and other tools to collect and record information you provide as well as information about your interactions with our websites for performance improvement, analytics, and to assist in marketing efforts. By clicking "Accept All", you consent to our use of cookies and other tools as described in our Cookie Policy. You can manage your cookie settings by clicking on "Manage Settings." By continuing to use this site or by clicking one of the buttons below, you agree to our Terms of Service (which contains important waivers). Please see our Privacy Policy for more information on our privacy practices.