Official PyTorch implementation of "Edge Rewiring Goes Neural: Boosting Network Resilience via Policy Gradient".

Overview

Edge Rewiring Goes Neural: Boosting Network Resilience via Policy Gradient

This repository is the official PyTorch implementation of "Edge Rewiring Goes Neural: Boosting Network Resilience via Policy Gradient".

Shanchao Yang, Kaili Ma, Baoxiang Wang, Hongyuan Zha, Edge Rewiring Goes Neural: Boosting Network Resilience via Policy Gradient

ResiNet policy_architecture

Installation

  • CUDA 11.+

  • Create Python environment (3.+), using anaconda is recommended:

    conda create -n my-resinet-env python=3.8
    conda activate my-resinet-env
    
  • Install Pytorch using anaconda

    conda install pytorch torchvision torchaudio cudatoolkit=11.1 -c pytorch -c nvidia
    

    or using Pip

    pip install torch==1.9.1+cu111 torchvision==0.10.1+cu111 torchaudio==0.9.1 -f https://download.pytorch.org/whl/torch_stable.html
    
  • Install networkx, tensorflow, tensorboardX, numpy, numba, dm-tree, gym, dgl, pyg

    pip install networkx==2.5
    pip install tensorflow-gpu==2.3.0
    pip install numpy==1.20.3
    pip install numba==0.52.0
    pip install gym==0.18.0
    pip install tabulate
    pip install dm-tree
    pip install lz4
    pip install opencv-python
    pip install tensorboardX
    pip install dgl-cu111 -f https://data.dgl.ai/wheels/repo.html
    pip install torch-scatter -f https://pytorch-geometric.com/whl/torch-1.9.0+cu111.html
    pip install torch-sparse -f https://pytorch-geometric.com/whl/torch-1.9.0+cu111.html
    pip install torch-cluster -f https://pytorch-geometric.com/whl/torch-1.9.0+cu111.html
    pip install torch-spline-conv -f https://pytorch-geometric.com/whl/torch-1.9.0+cu111.html
    pip install torch-geometric
    
  • Install ray

    • Use the specific commit version of ray 8a066474d44110f6fddd16618351fe6317dd7e03

      For Linux:

      pip install -U https://s3-us-west-2.amazonaws.com/ray-wheels/master/8a066474d44110f6fddd16618351fe6317dd7e03/ray-2.0.0.dev0-cp38-cp38-manylinux2014_x86_64.whl
      

      For Windows:

      pip install -U https://s3-us-west-2.amazonaws.com/ray-wheels/master/8a066474d44110f6fddd16618351fe6317dd7e03/ray-2.0.0.dev0-cp38-cp38-win_amd64.whl
      
    • Download our repository, which includes the source codes of ray and ResiNet.

      git clone https://github.com/yangysc/ResiNet.git
      
    • Set the symlink of rllib to use our custom rllib (remeber to remove these symlinks before uninstalling ray!)

      python ResiNet/ray-master/python/ray/setup-dev.py -y
      

Code description

There are 4 important file folders.

  • Environment: ResiNet/ray-master/rllib/examples/env/

    • graphenv.py is the edge rewiring environment based on OpenAI gym.

    • parametric_actions_graph.py is the env wrapper that accesses the graph from graphenv.py and returns the dict observation.

    • utils_.py defines the reward calculation strategy.

    • get_mask.py defines the action mask calculation for selecting the first edge and the second edge.

    • datasets is the folder for providing training and test datasets. The following table (Table 2, Page 17 in the paper) records the statistics of graphs used in the paper.

      Dataset Node Edge Action Space Size
      BA-15 15 54 5832
      BA-50 50 192 73728
      BA-100 100 392 307328
      EU 217 640 819200
      BA-10-30 () 10-30 112 25088
      BA-20-200 () 20-200 792 1254528
  • Model: ResiNet/ray-master/rllib/examples/models/

    • autoregressive_action_model.py is the network architecture of ResiNet.
    • gnnmodel.py defines the GIN model based on dgl.
  • Distribution: ResiNet/ray-master/rllib/examples/models/

    • autoregressive_action_dist.py is the action distribution module of ResiNet.
  • Loss: ResiNet/ray-master/rllib/agents/ppo/

    • ppo_torch_policy.py defines the DDPPO loss function.

Run

Platform

We tested the following experiments (see Command) with

  • GPU: GEFORCE RTX 3090 * 2 (24 G memory * 2 = 48G in total)
  • CPU: AMD 3990X

Adjust the corresponding hyperparameters according to your GPU hardware. Our code supports the multiple gpus training thanks to ray. The GPU memory capacity and the number of gpu are the main bottlenecks for DDPPO. The usage of more gpus means a faster training.

  • num-gpus: the number of GPU available in total (increase it if more gpus are available)
  • bs: batch size
  • mini-bs: minibatch size
  • tasks-per-gpu:the number of paralleled worker
  • gpus_per_instance: the number of GPU used for this train instance (ray can support tune multiple instances simultaneously) (increase it if more gpus are available)

Command

First go to the following folder.

cd ResiNet/ray-master/rllib/examples

Train

  • Transductive setting (dataset is in [example_15, example_50, example_100, EU])

    • Run the experiment on optimizing the BA-15 dataset with alpha=0, risilience metric R, node degree-based attack:

      CUDA_VISIBLE_DEVICES=0,1 python autoregressivegraph_decouple_action_dist_dppo.py --num-gpus=2 --cwd-path=./ --stop-iters=2000 --stop-timesteps=800000 --dataset=example_15 --tasks-per-gpu=2 --gpus_per_instance=2 --bs=4096 --mini-bs=256 --filtration_order=-1  --alpha=0 --robust-measure=R --reward_scale=10 --dual_clip_param=10 --lr=7e-4 --vf_lr=7e-4 --ppo_alg=dcppo --hidden_dim=64 --attack_strategy=degree --second-obj-func=ge --seed=0 
      
    • Optimize the BA-15 dataset with a grid search of the filtration order (set to -3):

      CUDA_VISIBLE_DEVICES=0,1 python autoregressivegraph_decouple_action_dist_dppo.py --num-gpus=2 --cwd-path=./ --stop-iters=2000 --stop-timesteps=800000 --dataset=example_15 --tasks-per-gpu=2 --gpus_per_instance=2 --bs=4096 --mini-bs=256 --filtration_order=-3  --alpha=0 --robust-measure=R --reward_scale=10 --dual_clip_param=10 --lr=7e-4 --vf_lr=7e-4 --ppo_alg=dcppo --hidden_dim=64 --attack_strategy=degree --second-obj-func=ge --seed=0 
      
    • Optimize the BA-15 dataset with a grid search of alpha (the coefficient of weighted sum of resilience and utility) (set to -1):

      CUDA_VISIBLE_DEVICES=0,1 python autoregressivegraph_decouple_action_dist_dppo.py --num-gpus=2 --cwd-path=./ --stop-iters=2000 --stop-timesteps=800000 --dataset=example_15 --tasks-per-gpu=2 --gpus_per_instance=2 --bs=4096 --mini-bs=256 --filtration_order=-1  --alpha=-1 --robust-measure=R --reward_scale=10 --dual_clip_param=10 --lr=7e-4 --vf_lr=7e-4 --ppo_alg=dcppo --hidden_dim=64 --attack_strategy=degree --second-obj-func=ge --seed=0
      
    • Optimize the BA-15 dataset with a grid search of robust-measure (resilience metric, choice is [R, sr, ac]) (set to -1):

      CUDA_VISIBLE_DEVICES=0,1 python autoregressivegraph_decouple_action_dist_dppo.py --num-gpus=2 --cwd-path=./ --stop-iters=2000 --stop-timesteps=800000 --dataset=example_15 --tasks-per-gpu=2 --gpus_per_instance=2 --bs=4096 --mini-bs=256 --filtration_order=-1  --alpha=0 --robust-measure=-1 --reward_scale=10 --dual_clip_param=10 --lr=7e-4 --vf_lr=7e-4 --ppo_alg=dcppo --hidden_dim=64 --attack_strategy=degree --second-obj-func=ge --seed=0 
      
    • Optimize the BA-15 dataset with a grid search of second-obj-func (utility metric, choice is [ge, le]) (set to -1):

      CUDA_VISIBLE_DEVICES=0,1 python autoregressivegraph_decouple_action_dist_dppo.py --num-gpus=2 --cwd-path=./ --stop-iters=2000 --stop-timesteps=800000 --dataset=example_15 --tasks-per-gpu=2 --gpus_per_instance=2 --bs=4096 --mini-bs=256 --filtration_order=-1  --alpha=0 --robust-measure=R --reward_scale=10 --dual_clip_param=10 --lr=7e-4 --vf_lr=7e-4 --ppo_alg=dcppo --hidden_dim=64 --attack_strategy=degree --second-obj-func=-1 --seed=-1 
      
    • Optimize the BA-15 dataset with a grid search of seed (set to -1):

      CUDA_VISIBLE_DEVICES=0,1 python autoregressivegraph_decouple_action_dist_dppo.py --num-gpus=2 --cwd-path=./ --stop-iters=2000 --stop-timesteps=800000 --dataset=example_15 --tasks-per-gpu=2 --gpus_per_instance=2 --bs=4096 --mini-bs=256 --filtration_order=-1  --alpha=0 --robust-measure=R --reward_scale=10 --dual_clip_param=10 --lr=7e-4 --vf_lr=7e-4 --ppo_alg=dcppo --hidden_dim=64 --attack_strategy=degree --second-obj-func=ge --seed=-1 
      
    • Optimize the EU dataset (increase bs and hidden_dim if more gpus are available. Four gpus would be better for hidden_dim=64):

      CUDA_VISIBLE_DEVICES=0,1 python autoregressivegraph_decouple_action_dist_dppo.py --num-gpus=2 --cwd-path=./ --stop-iters=2000 --stop-timesteps=800000 --dataset=EU --tasks-per-gpu=1 --gpus_per_instance=2 --bs=1024 --mini-bs=256 --filtration_order=1 --alpha=0 --robust-measure=R --reward_scale=10 --dual_clip_param=10 --lr=7e-4 --vf_lr=7e-4 --ppo_alg=dcppo --hidden_dim=32 --attack_strategy=degree --second-obj-func=ge --seed=0  
      
  • Inductive setting (dataset is in [ba_small_30, ba_mixed])

    • for the ba_small_30 dataset (use full filtration)

      CUDA_VISIBLE_DEVICES=0,1 python autoregressivegraph_decouple_action_dist_dppo.py --num-gpus=2 --cwd-path=./ --stop-iters=2000 --stop-timesteps=800000 --dataset=ba_small_30 --tasks-per-gpu=1 --gpus_per_instance=2 --bs=2048 --mini-bs=256 --filtration_order=-1  --alpha=0 --robust-measure=R --reward_scale=10 --dual_clip_param=10 --lr=7e-4 --vf_lr=7e-4 --ppo_alg=dcppo --hidden_dim=64 --attack_strategy=degree --second-obj-func=ge --seed=0 
      
    • for the ba_mixed dataset (set filtratio_order to 1, tasks-per-gpu to 1 and bs to 2048)

      CUDA_VISIBLE_DEVICES=0,1 python autoregressivegraph_decouple_action_dist_dppo.py --num-gpus=2 --cwd-path=./ --stop-iters=2000 --stop-timesteps=800000 --dataset=ba_mixed --tasks-per-gpu=1 --gpus_per_instance=2 --bs=2048 --mini-bs=256 --filtration_order=1  --alpha=0 --robust-measure=R --reward_scale=10 --dual_clip_param=10 --lr=7e-4 --vf_lr=7e-4 --ppo_alg=dcppo --hidden_dim=64 --attack_strategy=degree --second-obj-func=ge --seed=0
      

We highly recommend using tensorboard to monitor the training process. To do this, you may run

tensorboard --logdir log/DDPPO

Set checkpoint_freq to be non-zero (zero by default) if you want to save the trained models during the training process. And the final trained model will be saved by default when the training is done. All trained models and tensorboard logs are saved in the folder log/DDPPO/.

Test

  • BA-15 (dataset is in [example_15, example_50, example_100, EU, ba_small_30, ba_mixed]) (The problem setting related hyperparameters need to be consistent with the values used in training.)
    CUDA_VISIBLE_DEVICES=0,1 python evaluate_trained_agent_dppo.py --num-gpus=2 --tasks-per-gpu=1 --bs=400 --mini-bs=16 --gpus_per_instance=1 --ppo_alg=dcppo --attack_strategy=degree --second-obj-func=le --seed=0 --reward_scale=1 --test_num=-1 --cwd-path=./test  --alpha=0.5 --dataset=example_15 --filtration_order=-1  --robust-measure=ac --hidden_dim=64
    
    Remember to set the restore_path in evaluate_trained_agent_dppo.py (Line 26) to the trained model folder.
Owner
Shanchao Yang
PhD student at CUHK-Shenzhen; Graph learning & Reinforcement learning
Shanchao Yang
Implementation supporting the ICCV 2017 paper "GANs for Biological Image Synthesis"

GANs for Biological Image Synthesis This codes implements the ICCV-2017 paper "GANs for Biological Image Synthesis". The paper and its supplementary m

Anton Osokin 95 Nov 25, 2022
Official PyTorch implementation of "Meta-Learning with Task-Adaptive Loss Function for Few-Shot Learning" (ICCV2021 Oral)

MeTAL - Meta-Learning with Task-Adaptive Loss Function for Few-Shot Learning (ICCV2021 Oral) Sungyong Baik, Janghoon Choi, Heewon Kim, Dohee Cho, Jaes

Sungyong Baik 44 Dec 29, 2022
Approximate Nearest Neighbors in C++/Python optimized for memory usage and loading/saving to disk

Annoy Annoy (Approximate Nearest Neighbors Oh Yeah) is a C++ library with Python bindings to search for points in space that are close to a given quer

Spotify 10.6k Jan 04, 2023
PyTorch Implementation of Meta-StyleSpeech : Multi-Speaker Adaptive Text-to-Speech Generation

StyleSpeech - PyTorch Implementation PyTorch Implementation of Meta-StyleSpeech : Multi-Speaker Adaptive Text-to-Speech Generation. Status (2021.06.13

Keon Lee 140 Dec 21, 2022
PyTorch implementation of the Deep SLDA method from our CVPRW-2020 paper "Lifelong Machine Learning with Deep Streaming Linear Discriminant Analysis"

Lifelong Machine Learning with Deep Streaming Linear Discriminant Analysis This is a PyTorch implementation of the Deep Streaming Linear Discriminant

Tyler Hayes 41 Dec 25, 2022
ML models implementation practice

Let's implement various ML algorithms with numpy/tf Vanilla Neural Network https://towardsdatascience.com/lets-code-a-neural-network-in-plain-numpy-ae

Jinsoo Heo 4 Jul 04, 2021
SciKit-Learn Laboratory (SKLL) makes it easy to run machine learning experiments.

SciKit-Learn Laboratory This Python package provides command-line utilities to make it easier to run machine learning experiments with scikit-learn. O

ETS 528 Nov 25, 2022
Fuzzer for Linux Kernel Drivers

difuze: Fuzzer for Linux Kernel Drivers This repo contains all the sources (including setup scripts), you need to get difuze up and running. Tested on

seclab 344 Dec 27, 2022
Cluster-GCN: An Efficient Algorithm for Training Deep and Large Graph Convolutional Networks

Cluster-GCN: An Efficient Algorithm for Training Deep and Large Graph Convolutional Networks This repository contains a TensorFlow implementation of "

Jingwei Zheng 5 Jan 08, 2023
Code for our paper "Multi-scale Guided Attention for Medical Image Segmentation"

Medical Image Segmentation with Guided Attention This repository contains the code of our paper: "'Multi-scale self-guided attention for medical image

Ashish Sinha 394 Dec 28, 2022
Blind Image Super-resolution with Elaborate Degradation Modeling on Noise and Kernel

Blind Image Super-resolution with Elaborate Degradation Modeling on Noise and Kernel This repository is the official PyTorch implementation of BSRDM w

Zongsheng Yue 69 Jan 05, 2023
Video Frame Interpolation without Temporal Priors (a general method for blurry video interpolation)

Video Frame Interpolation without Temporal Priors (NeurIPS2020) [Paper] [video] How to run Prerequisites NVIDIA GPU + CUDA 9.0 + CuDNN 7.6.5 Pytorch 1

YoujianZhang 31 Sep 04, 2022
A crash course in six episodes for software developers who want to become machine learning practitioners.

Featured code sample tensorflow-planespotting Code from the Google Cloud NEXT 2018 session "Tensorflow, deep learning and modern convnets, without a P

Google Cloud Platform 2.6k Jan 08, 2023
LIVECell - A large-scale dataset for label-free live cell segmentation

LIVECell dataset This document contains instructions of how to access the data associated with the submitted manuscript "LIVECell - A large-scale data

Sartorius Corporate Research 112 Jan 07, 2023
A modular domain adaptation library written in PyTorch.

A modular domain adaptation library written in PyTorch.

Kevin Musgrave 225 Dec 29, 2022
PyTorch implementation DRO: Deep Recurrent Optimizer for Structure-from-Motion

DRO: Deep Recurrent Optimizer for Structure-from-Motion This is the official PyTorch implementation code for DRO-sfm. For technical details, please re

Alibaba Cloud 56 Dec 12, 2022
Junction Tree Variational Autoencoder for Molecular Graph Generation (ICML 2018)

Junction Tree Variational Autoencoder for Molecular Graph Generation Official implementation of our Junction Tree Variational Autoencoder https://arxi

Wengong Jin 418 Jan 07, 2023
SemEval2022 Patronizing and Condescending Language (PCL) Detection

SemEval2022 Patronizing and Condescending Language (PCL) Detection This task is from SemEval 2022. What is Patronizing and Condescending Language (PCL

Daniel Saeedi 0 Aug 05, 2022
ICNet and PSPNet-50 in Tensorflow for real-time semantic segmentation

Real-Time Semantic Segmentation in TensorFlow Perform pixel-wise semantic segmentation on high-resolution images in real-time with Image Cascade Netwo

Oles Andrienko 219 Nov 21, 2022
Research code for the paper "Variational Gibbs inference for statistical estimation from incomplete data".

Variational Gibbs inference (VGI) This repository contains the research code for Simkus, V., Rhodes, B., Gutmann, M. U., 2021. Variational Gibbs infer

Vaidotas Šimkus 1 Apr 08, 2022