Package: cogdl
Homepage|Paper|Documentation|Discussion Forum|Dataset|中文CogDL is a graph deep learning toolkit that allows researchers and developers to easily train and compare baseline or customized models for node classification, graph classification, and other important tasks in the graph domain.We summarize the contributions of CogDL as follows:Efficiency: CogDL utilizes well-optimized operators to speed up training and save GPU memory of GNN models.Ease of Use: CogDL provides easy-to-use APIs for running experiments with the given models and datasets using hyper-parameter search.Extensibility: The design of CogDL makes it easy to apply GNN models to new scenarios based on our framework.❗ NewsThe CogDL paperwas accepted byWWW 2023. Find us at WWW 2023! We also release the newv0.6 releasewhich adds more examples of graph self-supervised learning, includingGraphMAE,GraphMAE2, andBGRL.A free GNN course provided by CogDL Team is present atthis link. We also provide adiscussion forumfor Chinese users.The newv0.5.3 releasesupports mixed-precision training by setting \textit{fp16=True} and provides a basicexamplewritten byJittor. It also updates the tutorial in the document, fixes downloading links of some datasets, and fixes potential bugs of operators.News HistoryThe newv0.5.2 releaseadds a GNN example for ogbn-products and updates geom datasets. It also fixes some potential bugs including setting devices, using cpu for inference, etc.The newv0.5.1 releaseadds fast operators including SpMM (cpu version) and scatter_max (cuda version). It also adds lots of datasets for node classification which can be found inthis link. 🎉The newv0.5.0 releasedesigns and implements a unified training loop for GNN. It introducesDataWrapperto help prepare the training/validation/test data andModelWrapperto define the training/validation/test steps. 🎉The newv0.4.1 releaseadds the implementation of Deep GNNs and the recommendation task. It also supports new pipelines for generating embeddings and recommendation. Welcome to join our tutorial on KDD 2021 at 10:30 am - 12:00 am, Aug. 14th (Singapore Time). More details can be found inhttps://kdd2021graph.github.io/. 🎉The newv0.4.0 releaserefactors the data storage (fromDatatoGraph) and provides more fast operators to speed up GNN training. It also includes many self-supervised learning methods on graphs. BTW, we are glad to announce that we will give a tutorial on KDD 2021 in August. Please seethis linkfor more details. 🎉CogDL supports GNN models with Mixture of Experts (MoE). You can installFastMoEand tryMoE GCNin CogDL now!The newv0.3.0 releaseprovides a fast spmm operator to speed up GNN training. We also release the first version ofCogDL paperin arXiv. You can joinour slackfor discussion. 🎉🎉🎉The newv0.2.0 releaseincludes easy-to-useexperimentandpipelineAPIs for all experiments and applications. TheexperimentAPI supports automl features of searching hyper-parameters. This release also providesOAGBertAPI for model inference (OAGBertis trained on large-scale academic corpus by our lab). Some features and models are added by the open source community (thanks to all the contributors 🎉).The newv0.1.2 releaseincludes a pre-training task, many examples, OGB datasets, some knowledge graph embedding methods, and some graph neural network models. The coverage of CogDL is increased to 80%. Some new APIs, such asTrainerandSampler, are developed and being tested.The newv0.1.1 releaseincludes the knowledge link prediction task, many state-of-the-art models, andoptunasupport. We also have aChinese WeChat postabout the CogDL release.Getting StartedRequirements and InstallationPython version >= 3.7PyTorch version >= 1.7.1Please follow the instructions here to install PyTorch (https://github.com/pytorch/pytorch#installation).When PyTorch has been installed, cogdl can be installed using pip as follows:pipinstallcogdlInstall from source via:pipinstallgit+https://github.com/thudm/cogdl.gitOr clone the repository and install with the following commands:gitclonegit@github.com:THUDM/cogdl.gitcdcogdl
pipinstall-e.UsageAPI UsageYou can run all kinds of experiments through CogDL APIs, especiallyexperiment. You can also use your own datasets and models for experiments.
A quickstart example can be found in thequick_start.py. More examples are provided in theexamples/.fromcogdlimportexperiment# basic usageexperiment(dataset="cora",model="gcn")# set other hyper-parametersexperiment(dataset="cora",model="gcn",hidden_size=32,epochs=200)# run over multiple models on different seedsexperiment(dataset="cora",model=["gcn","gat"],seed=[1,2])# automl usagedefsearch_space(trial):return{"lr":trial.suggest_categorical("lr",[1e-3,5e-3,1e-2]),"hidden_size":trial.suggest_categorical("hidden_size",[32,64,128]),"dropout":trial.suggest_uniform("dropout",0.5,0.8),}experiment(dataset="cora",model="gcn",seed=[1,2],search_space=search_space)Command-Line UsageYou can also usepython scripts/train.py --dataset example_dataset --model example_modelto run example_model on example_data.--dataset, dataset name to run, can be a list of datasets with space likecora citeseer. Supported datasets include
'cora', 'citeseer', 'pumbed', 'ppi', 'wikipedia', 'blogcatalog', 'flickr'. More datasets can be found in thecogdl/datasets.--model, model name to run, can be a list of models likegcn gat. Supported models include
'gcn', 'gat', 'graphsage', 'deepwalk', 'node2vec', 'hope', 'grarep', 'netmf', 'netsmf', 'prone'. More models can be found in thecogdl/models.For example, if you want to run GCN and GAT on the Cora dataset, with 5 different seeds:pythonscripts/train.py--datasetcora--modelgcngat--seed01234Expected output:Varianttest_accval_acc('cora', 'gcn')0.8050±0.00470.7940±0.0063('cora', 'gat')0.8234±0.00420.8088±0.0016If you have ANY difficulties to get things working in the above steps, feel free to open an issue. You can expect a reply within 24 hours.❗ FAQHow to contribute to CogDL?If you have a well-performed algorithm and are willing to implement it in our toolkit to help more people, you can firstopen an issueand then create a pull request, detailed information can be foundhere.Before committing your modification, please first runpre-commit installto setup the git hook for checking code format and style usingblackandflake8. Then thepre-commitwill run automatically ongit commit! Detailed information ofpre-commitcan be foundhere.How to enable fast GNN training?CogDL provides a fast sparse matrix-matrix multiplication operator called [GE-SpMM](https://arxiv.org/abs/2007.03179) to speed up training of GNN models on the GPU. 
The feature will be automatically used if it is available.
Note that this feature is still in testing and may not work under some versions of CUDA.How to run parallel experiments with GPUs on several models?If you want to run parallel experiments on your server with multiple GPUs on multiple models, GCN and GAT, on the Cora dataset:$pythonscripts/train.py--datasetcora--modelgcngat--hidden-size64--devices01--seed01234Expected output:VariantAcc('cora', 'gcn')0.8236±0.0033('cora', 'gat')0.8262±0.0032How to use models from other libraries?If you are familiar with other popular graph libraries, you can implement your own model in CogDL using modules from PyTorch Geometric (PyG).
For the installation of PyG, you can follow the instructions from PyG (https://github.com/rusty1s/pytorch_geometric/#installation).
For the quick-start usage of how to use layers of PyG, you can find some examples in the [examples/pyg](https://github.com/THUDM/cogdl/tree/master/examples/pyg/).How to make a successful pull request with unit testTo have a successful pull request, you need to have at least (1) your model implementation and (2) a unit test.You might be confused why your pull request was rejected because of 'Coverage decreased ...' issue even though your model is working fine locally. This is because you have not included a unit test, which essentially runs through the extra lines of code you added. The Travis CI service used by Github conducts all unit tests on the code you committed and checks how many lines of the code have been checked by the unit tests, and if a significant portion of your code has not been checked (insufficient coverage), the pull request is rejected.So how do you do a unit test?Let's say you implement a GNN model in a scriptmodels/nn/abcgnn.pythat does the task of node classification. Then, you need to add a unit test inside the scripttests/tasks/test_node_classification.py(or whatever relevant task your model does).To add the unit test, you simply add a functiontest_abcgnn_cora()(just follow the format of the other unit tests already in the script), fill it with required arguments and the last line in the function'assert 0 <= ret["Acc"] <= 1'is the very basic sanity check conducted by the unit test.After modifyingtests/tasks/test_node_classification.py, commit it together with yourmodels/nn/abcgnn.pyand your pull request should pass.CogDL TeamCogDL is developed and maintained byTsinghua, ZJU, DAMO Academy, and ZHIPU.AI.The core development team can be reached atcogdlteam@gmail.com.Citing CogDLPlease citeour paperif you find our code or results useful for your research:@inproceedings{cen2023cogdl,
    title={CogDL: A Comprehensive Library for Graph Deep Learning},
    author={Yukuo Cen and Zhenyu Hou and Yan Wang and Qibin Chen and Yizhen Luo and Zhongming Yu and Hengrui Zhang and Xingcheng Yao and Aohan Zeng and Shiguang Guo and Yuxiao Dong and Yang Yang and Peng Zhang and Guohao Dai and Yu Wang and Chang Zhou and Hongxia Yang and Jie Tang},
    booktitle={Proceedings of the ACM Web Conference 2023 (WWW'23)},
    year={2023}
}