Skip to content
GraphRNN: Generating Realistic Graphs with Deep Auto-regressive Models
Branch: master
Clone or download
Latest commit 3444b8a Jun 6, 2018
Type Name Latest commit message Commit time
Failed to load latest commit information.
baselines utils main Jun 6, 2018
dataset add dataset Nov 20, 2017
eval change definition of caveman dataset Jan 25, 2018
LICENSE readme, license Nov 9, 2017 update readme Jun 4, 2018 modify barabasi dataset Dec 13, 2017 Merge branch 'master' of May 30, 2018 readme May 30, 2018 refactor data May 22, 2018
environment.yml multi-community experiment May 29, 2018 test deepgmg May 29, 2018
requirements.txt update requirements May 29, 2018

GraphRNN: Generating Realistic Graphs with Deep Auto-regressive Model

This repository is the official PyTorch implementation of GraphRNN, a graph generative model using auto-regressive model.

Jiaxuan You*, Rex Ying*, Xiang Ren, William L. Hamilton, Jure Leskovec, GraphRNN: Generating Realistic Graphs with Deep Auto-regressive Model (ICML 2018)


Install PyTorch following the instuctions on the official website. The code has been tested over PyTorch 0.2.0 and 0.4.0 versions.

conda install pytorch torchvision cuda90 -c pytorch

Then install the other dependencies.

pip install -r requirements.txt

Test run


Code description

For the GraphRNN model: is the main executable file, and specific arguments are set in includes training iterations and calls and is where we prepare target graph datasets.

For baseline models:

  • B-A and E-R models are implemented in baselines/
  • Kronecker graph model is implemented in the SNAP software, which can be found in (for generating Kronecker graphs), and (for learning parameters for the model).
  • MMSB is implemented using the EDWARD library (, and is located in baselines.
  • We implemented the DeepGMG model based on the instructions of their paper in
  • We implemented the GraphVAE model based on the instructions of their paper in baselines/graphvae.

Parameter setting: To adjust the hyper-parameter and input arguments to the model, modify the fields of accordingly. For example, args.cuda controls which GPU is used to train the model, and args.graph_type specifies which dataset is used to train the generative model. See the documentation in for more detailed descriptions of all fields.


There are several different types of outputs, each saved into a different directory under a path prefix. The path prefix is set at args.dir_input. Suppose that this field is set to ./:

  • ./graphs contains the pickle files of training, test and generated graphs. Each contains a list of networkx object.
  • ./eval_results contains the evaluation of MMD scores in txt format.
  • ./model_save stores the model checkpoints
  • ./nll saves the log-likelihood for generated graphs as sequences.
  • ./figures is used to save visualizations (see Visualization of graphs section).


The evaluation is done in, where user can choose which settings to evaluate. To evaluate how close the generated graphs are to the ground truth set, we use MMD (maximum mean discrepancy) to calculate the divergence between two sets of distributions related to the ground truth and generated graphs. Three types of distributions are chosen: degree distribution, clustering coefficient distribution. Both of which are implemented in eval/, using multiprocessing python module. One can easily extend the evaluation to compute MMD for other distribution of graphs.

We also compute the orbit counts for each graph, represented as a high-dimensional data point. We then compute the MMD between the two sets of sampled points using ORCA (see at eval/orca. One first needs to compile ORCA by

g++ -O2 -std=c++11 -o orca orca.cpp` 

in directory eval/orca. (the binary file already in repo works in Ubuntu).

To evaluate, run


Arguments specific to evaluation is specified in class evaluate.Args_evaluate. Note that the field Args_evaluate.dataset_name_all must only contain datasets that are already trained, by setting args.graph_type to each of the datasets and running python

Visualization of graphs

The training, testing and generated graphs are saved at 'graphs/'. One can visualize the generated graph using the function utils.load_graph_list, which loads the list of graphs from the pickle file, and util.draw_graph_list, which plots the graph using networkx.


Jesse Bettencourt and Harris Chan have made a great slide introducing GraphRNN in Prof. David Duvenaud’s seminar course Learning Discrete Latent Structure.

You can’t perform that action at this time.