Home

Awesome

Dist-KGE: A knowledge graph embedding library for multi-GPU and multi-machine training

This is the code and configuration accompanying the paper "Parallel Training of Knowledge Graph Embedding Models: A Comparison of Techniques". The code extends the knowledge graph embedding library LibKGE. For documentation on LibKGE refer to LibKGE repository. We provide the hyper-parameter settings for the experiments in their corresponding configuration files.

Table of contents

  1. News
  2. Quick start
  3. Dataset preparation for parallel training
  4. Single Machine Multi-GPU Training
  5. Multi-GPU Multi-Machine Training
  6. Folder structure of experiment results
  7. Results and Configurations
  8. How to cite

News

In our follow up work "Start small, think big: On hyperparameter optimization for large-scale knowledge graph embeddings", (code), we show (i) the importance of hyperparameter optimiziation (HPO) for large-scale KGEs, and (ii) how to efficently perform HPO on large graphs.

Reported results show strong improvements in terms of MRR.

PaperSettingMRR
This paperFreebase Random RLB 4@1, dim=1280.426
Follow up paperFreebarse Random R 4@1, dim=1280.594
Follow up paperFreebarse Random R 4@1, dim=5120.678

Quick start

# retrieve and install project in development mode
git clone https://github.com/uma-pi1/dist-kge.git
cd dist-kge
pip install -e .

# download and preprocess datasets
cd data
sh download_all.sh
cd ..

# train an example model on toy dataset (you can omit '--job.device cpu' when you have a gpu)
kge start examples/toy-complex-train.yaml --job.device cpu

This example will train on a toy dataset in a sequential setup on CPU.

For further documentation on possible configuration can be found in the file config-default.yaml.

Supported Models

For a list of models for sequential training using a single GPU we refer to LibKGE.

Models supporte for Multi-GPU and Multi-Machine are:

Dataset preparation for parallel training

NOTE: Freebase already comes with multiple partition settings to save preprocessing time

To partition the data run the following commands (you only need to do this once)

Random Partitioning

For random partitioning no further preparation is needed.

Relation Partitioning

cd data
python partition_relation.py <dataset-name> -n <num-partitions>
cd ..

Stratification

cd data 
python partition_stratification.py <dataset-name> -n <num-partitions>
cd ..

Graph-Cut

cd data
python partition_graph_cut.py <dataset-name> -n <num-partitions>
cd ..

Single Machine Multi-GPU Training

Run following example to train on two GPUs with random partitioning (two worker per GPU):

python -m kge start examples/fb15k-complex-parallel.yaml

The most important configuration options for multi-gpu training are:

import:
  - complex
  - distributed_model
model: distributed_model
distributed_model:
  base_model: complex
job:
  distributed:
    num_partitions: 4
    num_workers: 4
    partition_type: random
    master_port: 8888  # change in case this port is used on your machine
  device_pool:
    - cuda:0
    - cuda:1
train:
  type: distributed_negative_sampling
  optimizer:
    default:
      type: dist_adagrad

Multi-GPU Multi-Machine Training

Parameter Server

For multi-machine training we use the parameter server Lapse. To install Lapse and the corresponding python bindings run the following commands:

git clone https://github.com/alexrenz/lapse-ps.git lapse-ps
cd lapse-ps
git checkout 72c7197c6d1795a8de184de84ffbe1b08151756d
make ps KEY_TYPE=int64_t CXX11_ABI=$(python bindings/lookup_torch_abi.py) DEPS_PATH=$(pwd)/deps_bindings
cd bindings 
python setup.py install --user

For further documentation on the python bindings refer to Lapse-Binding documentation.

In case you can not use Lapse, we provide a very inefficient parameter server (for debugging). To use this debugging PS use the option --job.distributed.parameter_server torch

Interface

As we use the gloo backend to communicate between master and worker nodes you need to specify the interface connecting your machines and specify it as --job.distributed.gloo_socket_ifname. You can find out the names of your interfaces with the command

ip address

Example

Run the following example to train on two machines with one GPU each (1@2) with random partitioning:

Command for machine 1

python -m kge start examples/fb15k-complex-distributed.yaml --job.distributed.machine_id 0 --job.distributed.master_ip <ip_of_machine_0>

Command for machine 2

python -m kge start examples/fb15k-complex-distributed.yaml --job.distributed.machine_id 1 --job.distributed.master_ip <ip_of_machine_0>

Important options for distributed training in addition to the options specified in the single-machine setting are:

job:
  distributed:
    master_ip: '<ip_of_machine_0>'  # ip address of the machine with machine_id 0
    num_machines: 2
    num_workers: 4  # total number of workers over all machines
    gloo_socket_ifname: bond0  # name of the interface to use. Use command 'ip address' to find names
    parameter_server: lapse

Different number of workers per machine

If you have two machines with a varying number of GPUs you might want to set a varying number of workers per machine. You can do so with the following commands

Command for machine 1

python -m kge start examples/fb15k-complex-distributed.yaml --job.distributed.machine_id 0 --job.distributed.master_ip <ip_of_machine_0> --job.distributed_num_workers_machine 3

Command for machine 2

python -m kge start examples/fb15k-complex-distributed.yaml --job.distributed.machine_id 1 --job.distributed.master_ip <ip_of_machine_0> --job.distributed.num_workers_machine 1 --job.distributed.already_init_workers 3

Note that you need to specify for each machine how many workers are initialized on the previous machines with job.distributed.already_init_workers if the number of workers varies per machine. You can also create one configuration file per machine, with corresponding settings for num_workers_machine and already_init_workers.

Folder structure of experiment results

Results and Configurations

Partitioning techniques (best-performing variant)

FB15k

ComplEx

SetupPartitioning TechniqueEpoch TimeTime to 0.95 MRRMRRMRR unfilteredHits@1Hits@10Hits@100config
.Sequential (GPU memory)5.9s3.9min0.7780.2450.7290.8620.932config
.Sequential (main memory)7.7s5.1min0.7780.2450.7290.8620.932config
2@1Random (R)2.6s2.0min0.7750.2430.7260.8590.931config
1@2Random (R)2.9s2.2min0.7750.2430.7260.8590.931config
4@2Random (R)1.3s1.3min0.7660.2410.7120.8580.929config

RotatE

SetupPartitioning TechniqueEpoch TimeTime to 0.95 MRRMRRMRR unfilteredHits@1Hits@10Hits@100config
.Sequential (GPU memory)9.5s11.9min0.7050.2320.6300.8340.928config
.Sequential (main memory)11.4s14.3min0.7050.2320.6300.8340.928config
2@1Stratification (CARL)4.6s5.8min0.7250.2390.6640.8350.926config
1@2Stratification (CARL)5.9s7.4min0.7250.2390.6640.8350.926config

Yago3-10

ComplEx

SetupPartitioning TechniqueEpoch TimeTime to 0.95 MRRMRRMRR unfilteredHits@1Hits@10Hits@100config
.Sequential (GPU memory)24.3s35.5min0.5420.1110.4680.6750.791config
.Sequential (main memory)42.6s67.5min0.5420.1110.4680.6750.791config
2@1Relation19.0s33.2min0.5380.1070.4650.6690.787config
1@2Random (RL)19.5s35.8min0.5470.1090.4730.6790.791config
4@2Random (RL)5.6sn.r.0.5030.1060.4230.6530.778config

RotatE

SetupPartitioning TechniqueEpoch TimeTime to 0.95 MRRMRRMRR unfilteredHits@1Hits@10Hits@100config
.Sequential (GPU memory)74.1s259.3min0.4510.1040.3430.6370.773config
.Sequential (main memory)88.0s307.8min0.4510.1040.3430.6370.773config
2@1Stratification (CARL)40.8s166.6min0.4380.1150.3500.6070.764config
1@2Stratification (CARL)43.3s175.8min0.4380.1150.3500.6070.764config

Wikidata5m

ComplEx

SetupPartitioning TechniqueEpoch TimeTime to 0.95 MRRMRRMRR unfilteredHits@1Hits@10Hits@100config
.Sequential (GPU memory)438.4s219.0min0.2970.2550.2460.3850.516config
.Sequential (GPU memory)774.3s387.0min0.2970.2550.2460.3860.516config
2@1Stratification (CARL)232.8s77.6min0.3080.2640.2550.3980.513config
1@2Stratification (CARL)228.0s76.0min0.3080.2640.2550.3980.513config

RotatE

SetupPartitioning TechniqueEpoch TimeTime to 0.95 MRRMRRMRR unfilteredHits@1Hits@10Hits@100config
.Sequential (GPU memory)798.4s199.6min0.2580.2250.2020.3480.453config
.Sequential (GPU memory)985.7s246.4min0.2580.2250.2020.3480.453config
2@1Stratification (ARL)466.7s77.8min0.2640.2300.2130.3440.410config
1@2Stratification (ARL)477.7s79.6min0.2640.2300.2130.3440.410config

Freebase

ComplEx

SetupPartitioning TechniqueEpoch TimeData sent per epochsMRRsMRR unfilteredMRRMRR unfilteredHits@1Hits@10Hits@100config
.Sequential (main memory)3929.0s-0.8110.7760.3640.3110.2980.4870.618config
.Sequential (B) (main memory)3925.2s-0.8150.7820.4260.3450.3700.5280.642config
2@2Random (RLB)966.7s232.8GB0.8160.7820.4260.3520.3710.5290.639config
2@2Relation (rLB)823.8s205.9GB0.8010.7700.3970.3260.3390.5070.631config
2@2Stratification (CARLB)803.9s123.2GB0.7930.7610.3250.2850.2720.4240.563config
2@2Graph-cut (LB)1170.6s42.5GB0.7890.7610.4070.3350.3510.5120.624config
4@2Random (RLB)591.6s251.9GB0.8190.7840.4210.3460.3640.5230.638config

RotatE

SetupPartitioning TechniqueEpoch TimeData sent per epochsMRRsMRR unfilteredMRRMRR unfilteredHits@1Hits@10Hits@100config
.Sequential (main memory)6495.7s-0.7740.7480.5660.4260.5290.6270.677config
.Sequential (B) (main memory)6184.0s-0.8120.7740.5600.4220.5210.6230.674config
2@2Random (RLB)1541.4s232.2GB0.8120.7730.5670.4250.5290.6300.678config
2@2Relation (rLB)1498.1s207.2GB0.7910.7580.5510.4070.5150.6080.656config
2@2Stratification (CARLB)1416.1s123.3GB0.7340.7200.5290.3950.4910.5920.641config
2@2Graph-cut (LB)1867.9s44.5GB0.7750.7490.5600.4100.5260.6160.654config

Row-Adagrad

Row-wise optimizers treat each embedding as a single parameter instead of each dimension of an embedding and therefore reduce storage and communication overhead by about 50%. We observed no negative influence on the resulting embedding quality for all partitioning methods but graph-cut partitioning, where the drop was small but noticeable. Overall, we found Row-Adagrad to be a suitable approach to reduce storage and communication costs. We report on ComplEx, 1@2.

Yago3-10

Partition TechniqueData sent (Adagrad)MRR (Adagrad)Data sent (Row-Adagrad)MRR (Row-Adagrad)
Sequential-0.542-0.542
Random (R)7.2GB0.5385.0GB0.534
Relation7.1GB0.5384.9GB0.542
Stratification0.4GB0.5310.2GB0.539
Graph-cut0.2GB0.2110.1GB0.180

Wikidata5m

Partition TechniqueData sent (Adagrad)MRR (Adagrad)Data sent (Row-Adagrad)MRR (Row-Adagrad)
Sequential-0.297-0.291
Random (R)125.2GB0.29665.7GB0.298
Relation123.8GB0.29663.5GB0.300
Stratification15.0GB0.3087.4GB0.306
Graph-cut6.1GB0.1923.7GB0.181

How to cite

@article{kochsiek2021parallel,
  title={Parallel training of knowledge graph embedding models: a comparison of techniques},
  author={Kochsiek, Adrian and Gemulla, Rainer},
  journal={Proceedings of the VLDB Endowment},
  volume={15},
  number={3},
  pages={633--645},
  year={2021},
  publisher={VLDB Endowment}
}