{"id":14530559,"url":"https://github.com/Emory-Melody/GraphSlim","last_synced_at":"2025-09-02T02:31:07.005Z","repository":{"id":245815146,"uuid":"760524195","full_name":"Emory-Melody/GraphSlim","owner":"Emory-Melody","description":"A Python library for graph reduction including condensation, coarsening, and sparsification.","archived":false,"fork":false,"pushed_at":"2025-03-28T22:01:07.000Z","size":10915,"stargazers_count":18,"open_issues_count":1,"forks_count":3,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-03-28T23:21:30.720Z","etag":null,"topics":["graph","graph-coarsening","graph-condensation","graph-neural-network","graph-reduction","graph-sparsification"],"latest_commit_sha":null,"homepage":"https://arxiv.org/pdf/2406.16715?","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/Emory-Melody.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2024-02-20T15:23:04.000Z","updated_at":"2025-03-28T22:05:25.000Z","dependencies_parsed_at":"2024-06-24T10:28:23.176Z","dependency_job_id":"3af10d89-a06c-4c8c-b0b9-9b23f1ae3826","html_url":"https://github.com/Emory-Melody/GraphSlim","commit_stats":null,"previous_names":["rockcor/graphslim"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/Emory-Melody/GraphSlim","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Emory-Melody%2FGraphSlim","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Emory-Melody%2FGraphSlim/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Emory-Melody%2FGraphSlim/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Emory-Melody%2FGraphSlim/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Emory-Melody","download_url":"https://codeload.github.com/Emory-Melody/GraphSlim/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Emory-Melody%2FGraphSlim/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":273219785,"owners_count":25066235,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","status":"online","status_checked_at":"2025-09-02T02:00:09.530Z","response_time":77,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["graph","graph-coarsening","graph-condensation","graph-neural-network","graph-reduction","graph-sparsification"],"created_at":"2024-09-05T00:01:08.130Z","updated_at":"2025-09-02T02:31:06.974Z","avatar_url":"https://github.com/Emory-Melody.png","language":"Python","funding_links":[],"categories":["Open-Source Libraries"],"sub_categories":["Security"],"readme":"\u003cdiv align=\"center\"\u003e\n  \u003c!-- \u003ch1\u003e\u003cb\u003e Time-LLM \u003c/b\u003e\u003c/h1\u003e --\u003e\n  \u003c!-- \u003ch2\u003e\u003cb\u003e Time-LLM \u003c/b\u003e\u003c/h2\u003e --\u003e\n  \u003ch2\u003e\u003cb\u003e GraphSlim, a PyTorch Library for Graph Reduction. \u003c/b\u003e\u003c/h2\u003e\n\u003c/div\u003e\n\n\u003cdiv align=\"center\"\u003e\n\n![](https://img.shields.io/github/last-commit/Emory-Melody/GraphSlim?color=green)\n![](https://img.shields.io/github/stars/Emory-Melody/GraphSlim?color=yellow)\n![](https://img.shields.io/github/forks/Emory-Melody/GraphSlim?color=lightblue)\n![](https://img.shields.io/badge/docs-latest-brightgreen.svg?style=flat)\n![](https://img.shields.io/badge/PRs-Welcome-green)\n\n\u003c/div\u003e\n\n\u003cdiv align=\"center\"\u003e\n\n**[\u003ca href=\"https://graphslim.readthedocs.io/en/latest/?badge=latest\"\u003eDocumentation\u003c/a\u003e]**\n**[\u003ca href=\"https://graphslim-vis.streamlit.app/\"\u003eWeb Interface\u003c/a\u003e]**\n**[\u003ca href=\"https://colab.research.google.com/drive/1LLG9PYOPnmLCAr0ow0ogRYI8DvLGPk7d?usp=sharing\"\u003eOnline Demo\u003c/a\u003e]**\n\n**[\u003ca href=\"https://arxiv.org/abs/2406.16715\"\u003eBenchmark Paper\u003c/a\u003e]**\n**[\u003ca href=\"https://github.com/Emory-Melody/GraphSlim/tree/main/benchmark\"\u003eBenchmark Scripts\u003c/a\u003e]**\n**[\u003ca href=\"https://arxiv.org/pdf/2402.03358\"\u003eSurvey Paper\u003c/a\u003e]**\n**[\u003ca href=\"https://github.com/Emory-Melody/awesome-graph-reduction\"\u003ePaper Collection\u003c/a\u003e]**\n\n\u003c/div\u003e\n\n\u003cdiv align=\"center\"\u003e\n  \u003cimg src=\"./figures/logo.png\" width=\"300\"\u003e\n\u003c/div\u003e\n\n---\n\u003e\n\u003e 🙋 Please let us know if you find out a mistake or have any suggestions!\n\u003e \n\u003e 🌟 If you find this resource helpful, please consider to star this repository and cite our research:\n\n```\n@article{gong2024gc4nc,\n  title={GC4NC: A Benchmark Framework for Graph Condensation on Node Classification with New Insights},\n  author={Gong, Shengbo and Ni, Juntong and Sachdeva, Noveen and Yang, Carl and Jin, Wei},\n  journal={arXiv preprint arXiv:2406.16715},\n  year={2024}\n}\n```\n\n# Features\n\nGraphSlim is a PyTorch library for graph reduction. It takes graph of PyG format as input and outputs a reduced graph\npreserving **properties or performance** of the original graph.\n\n* Covering representative methods of all 3 graph reduction strategies: Sparsification, Coarsening and Condensation.\n* Different reduction strategies can be easily combined in one run.\n* Unified evaluation tools including Grid Search and NAS.\n* Support evasion and poisoning attacks on the input graph by DeepRobust.\n\n# Guidance\n\n* Please first prepare the environments.\n* If you are new to GraphSlim, we highly suggest you first run the examples in the `examples` folder.\n* If you have any questions or suggestions regarding this library, feel free to create an\n  issue [here](https://github.com/Emory-Melody/GraphSlim/issues). We will reply as soon as possible :)\n\n# Prepare Environments\n\n## CUDA and PyTorch\nCheck [torch previous versions](https://pytorch.org/get-started/previous-versions/).\nWe test  this repo  in  `torch 1.13.1`  and `torch  2.1.2` with `CUDA 12.4`.\n\n## Install from requirements\n\nPlease choose from `requirements_torch1+.txt (for torch 1.\\*)` and `requirements.txt (for torch2.*)` at your convenience.\n\n\u003c!--# Download Datasets\n\nFor cora, citeseer, flickr and reddit (reddit2 in pyg), the pyg code will directly download them.\nFor arxiv, we use the datasets provided by [GraphSAINT](https://github.com/GraphSAINT/GraphSAINT). \nOur code will automatically download all datasets.\n\nThe default path of datasets is `../../data`.--\u003e\n\n## Install from pip\n\n```shell\n# choose one version from https://data.pyg.org/whl/ based on your environment\npip install torch_scatter torch_sparse -f https://data.pyg.org/whl/torch-${TORCH}+${CUDA}.html\npip install graphslim\n```\n\n## Recommended way to download 'torch_sparse' and `torch_scatter`\n\nIt's usually faster and easy to download from .whl file. See details in `install_torch_sparse.sh`\n\n# Examples\n\n```\npython examples/train_coreset.py\npython examples/train_coarsen.py\npython examples/train_gcond.py\n```\n\nSee more examples in **[Benchmark Scripts](https://github.com/Emory-Melody/GraphSlim/tree/main/benchmark)**.\n\n# Use As Project\n\n```shell\ncd graphslim\npython train_all.py -xxx xx\n```\n\nRun `python configs.py --help` to get all command line options.\n\n```shell\nOptions:\n  -D, --dataset TEXT              [default: cora]\n  -G, --gpu_id INTEGER            gpu id start from 0, -1 means cpu  [default:\n                                  0]\n  --setting [trans|ind]           transductive or inductive setting\n  --split TEXT                    only support public split now, do not change\n                                  it  [default: fixed]\n  --run_reduction INTEGER         repeat times of reduction  [default: 3]\n  --run_eval INTEGER              repeat times of final evaluations  [default:\n                                  10]\n  --run_inter_eval INTEGER        repeat times of intermediate evaluations\n                                  [default: 5]\n  --eval_interval INTEGER         [default: 100]\n  -H, --hidden INTEGER            [default: 256]\n  --eval_epochs, --ee INTEGER     [default: 300]\n  --eval_model, --em [GCN|GAT|SGC|APPNP|Cheby|GraphSage|GAT|SGFormer]\n                                  [default: GCN]\n  --condense_model [GCN|GAT|SGC|APPNP|Cheby|GraphSage|GAT]\n                                  [default: SGC]\n  -E, --epochs INTEGER            number of reduction epochs  [default: 1000]\n  --lr FLOAT                      [default: 0.01]\n  --weight_decay, --wd INTEGER    [default: 0]\n  --pre_norm BOOLEAN              pre-normalize features, forced true for\n                                  arxiv, flickr and reddit  [default: True]\n  --outer_loop INTEGER            [default: 10]\n  --inner_loop INTEGER            [default: 1]\n  -R, --reduction_rate FLOAT      -1 means use representative reduction rate;\n                                  reduction rate of training set, defined as\n                                  (number of nodes in small graph)/(number of\n                                  nodes in original graph)  [default: -1.0]\n  -S, --seed INTEGER              Random seed  [default: 1]\n  --nlayers INTEGER               number of GNN layers of condensed model\n                                  [default: 2]\n  -V, --verbose\n  --init [variation_neighborhoods|variation_edges|variation_cliques|heavy_edge|algebraic_JC|affinity_GS|kron|vng|clustering|averaging|cent_d|cent_p|kcenter|herding|random]\n                                  features initialization methods\n  -M, --method [variation_neighborhoods|variation_edges|variation_cliques|heavy_edge|algebraic_JC|affinity_GS|kron|vng|clustering|averaging|gcond|doscond|gcondx|doscondx|sfgc|msgc|disco|sgdd|gcsntk|geom|cent_d|cent_p|kcenter|herding|random]\n                                  [default: kcenter]\n  --activation [sigmoid|tanh|relu|linear|softplus|leakyrelu|relu6|elu]\n                                  activation function when do NAS  [default:\n                                  relu]\n  -A, --attack [random_adj|metattack|random_feat]\n                                  corruption method\n  -P, --ptb_r FLOAT               perturbation rate for corruptions  [default:\n                                  0.25]\n  --aggpreprocess                 use aggregation for coreset methods\n  --dis_metric TEXT               distance metric for all condensation\n                                  methods,ours means metric used in GCond\n                                  paper  [default: ours]\n  --lr_adj FLOAT                  [default: 0.0001]\n  --lr_feat FLOAT                 [default: 0.0001]\n  --threshold INTEGER             sparsificaiton threshold before evaluation\n                                  [default: 0]\n  --dropout FLOAT                 [default: 0.0]\n  --ntrans INTEGER                number of transformations in SGC and APPNP\n                                  [default: 1]\n  --with_bn\n  --no_buff                       skip the buffer generation and use existing\n                                  in geom,sfgc\n  --batch_adj INTEGER             batch size for msgc  [default: 1]\n  --alpha FLOAT                   for appnp  [default: 0.1]\n  --mx_size INTEGER               for gcsntk methods, avoid SVD error\n                                  [default: 100]\n  --save_path, --sp TEXT          save path for synthetic graph  [default:\n                                  ../checkpoints]\n  -W, --eval_whole                if run on whole graph\n  --help                          Show this message and exit.\n```\n\n# Use As Package\n\n```python\nfrom graphslim.dataset import *\nfrom graphslim.evaluation import *\nfrom graphslim.condensation import GCond\nfrom graphslim.config import cli\n\nargs = cli(standalone_mode=False)\n# customize args here\nargs.reduction_rate = 0.5\nargs.device = 'cuda:0'\n# add more args.\u003cmain_args/dataset_args\u003e here\ngraph = get_dataset('cora', args=args)\n# To reproduce the benchmark, use our args and graph class\n# To use your own args and graph format, please ensure the args and graph class has the required attributes\n# create an agent of one reduction algorithm\n# add more args.\u003cagent_args\u003e here\nagent = GCond(setting='trans', data=graph, args=args)\n# reduce the graph \nreduced_graph = agent.reduce(graph, verbose=True)\n# create an evaluator\n# add more args.\u003cevaluator_args\u003e here\nevaluator = Evaluator(args)\n# evaluate the reduced graph on a GNN model\nres_mean, res_std = evaluator.evaluate(reduced_graph, model_type='GCN')\n```\n\nAll parameters can be divided into\n\n```shell\n\u003cmain_args\u003e: dataset, method, setting, reduction_rate, seed, aggpreprocess, eval_whole, run_reduction\n\u003cattack_args\u003e: attack, ptb_r\n\u003cdataset_args\u003e: pre_norm, save_path, split, threshold\n\u003cagent_args\u003e: init, eval_interval, eval_epochs, eval_model, condense_model, epochs, lr, weight_decay, outer_loop, inner_loop, nlayers, method, activation, dropout, ntrans, with_bn, no_buff, batch_adj, alpha, mx_size, dis_metric, lr_adj, lr_feat\n\u003cevaluator_args\u003e: final_eval_model, eval_epochs, lr, weight_decay\n```\n\nSee more details\nin [![Documentation](https://img.shields.io/badge/docs-latest-brightgreen.svg?style=flat)](https://graphslim.readthedocs.io/en/latest/?badge=latest)\n\n# Customization\n\n* To implement a new reduction algorithm, you need to create a new class in `sparsification` or `coarsening`\n  or `condensation` and inherit the `Base` class.\n* To implement a new dataset, you need to create a new class in `dataset/loader.py` and inherit the `TransAndInd` class.\n* To implement a new evaluation metric, you need to create a new function in `evaluation/eval_agent.py`.\n* To implement a new GNN model, you need to create a new class in `models` and inherit the `Base` class.\n* To customize sparsification before evaluation, please modify the function `sparsify` in `evaluation/utils.py`.\n\n# Web Interface\n\nOur [web application](https://graphslim-vis.streamlit.app/) is deployed online using [streamlit](https://streamlit.io/).\nBut it also can be initiated using:\n\n```bash\ncd interface\npython -m streamlit run vis_graphslim.py\n```\n\nto activate the interface. Please satisfy the dependency in [interface/requirements.txt](interface/requirements.txt).\n\n# TODO\n\n- [ ] Add sparsification algorithms like Spanner\n- [ ] Add latest condensation methods\n- [ ] Support more datasets\n- [ ] Present full results in a website\n\n# Limitations\n\n* The GEOM and SFGC are not fully implemented in the current version due to disk space limit. We set the number of\n  experts to 20 currently. If you have over 100GB disk space, you can set the number of experts to 1000 to reproduce the\n  If you have over 100GB disk space, you can set the number of experts to 200 to reproduce the results in the paper.\n\n# Acknowledgement\n\nSome of the algorithms are referred to paper authors' implementations and other packages.\n\n[SCAL](https://github.com/szzhang17/Scaling-Up-Graph-Neural-Networks-Via-Graph-Coarsening)\n\n[Sparsification](https://github.com/yuhanchan/sparsification)\n\n[GCOND](https://github.com/ChandlerBang/GCond)\n\n[GCSNTK](https://github.com/WANGLin0126/GCSNTK)\n\n[SFGC](https://github.com/Amanda-Zheng/SFGC)\n\n[GEOM](https://github.com/NUS-HPC-AI-Lab/GEOM/tree/main)\n\n[DeepRobust](https://github.com/DSE-MSU/DeepRobust)\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FEmory-Melody%2FGraphSlim","html_url":"https://awesome.ecosyste.ms/projects/github.com%2FEmory-Melody%2FGraphSlim","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FEmory-Melody%2FGraphSlim/lists"}