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
An original implementation of "MetaICL Learning to Learn In Context" by Sewon Min, Mike Lewis, Luke Zettlemoyer and Hannaneh Hajishirzi

MetaICL: Learning to Learn In Context This includes an original implementation of "MetaICL: Learning to Learn In Context" by Sewon Min, Mike Lewis, Lu

Meta Research 141 Jan 07, 2023
A semantic segmentation toolbox based on PyTorch

Introduction vedaseg is an open source semantic segmentation toolbox based on PyTorch. Features Modular Design We decompose the semantic segmentation

407 Dec 15, 2022
A CV toolkit for my papers.

PyTorch-Encoding created by Hang Zhang Documentation Please visit the Docs for detail instructions of installation and usage. Please visit the link to

Hang Zhang 2k Jan 04, 2023
Distance correlation and related E-statistics in Python

dcor dcor: distance correlation and related E-statistics in Python. E-statistics are functions of distances between statistical observations in metric

Carlos Ramos Carreño 108 Dec 27, 2022
The Medical Detection Toolkit contains 2D + 3D implementations of prevalent object detectors such as Mask R-CNN, Retina Net, Retina U-Net, as well as a training and inference framework focused on dealing with medical images.

The Medical Detection Toolkit contains 2D + 3D implementations of prevalent object detectors such as Mask R-CNN, Retina Net, Retina U-Net, as well as a training and inference framework focused on dea

MIC-DKFZ 1.2k Jan 04, 2023
Official code repository for A Simple Long-Tailed Rocognition Baseline via Vision-Language Model.

This is the official code repository for A Simple Long-Tailed Rocognition Baseline via Vision-Language Model.

peng gao 42 Nov 26, 2022
PyTorch implementation of Train Short, Test Long: Attention with Linear Biases Enables Input Length Extrapolation.

ALiBi PyTorch implementation of Train Short, Test Long: Attention with Linear Biases Enables Input Length Extrapolation. Quickstart Clone this reposit

Jake Tae 4 Jul 27, 2022
Official and maintained implementation of the paper "OSS-Net: Memory Efficient High Resolution Semantic Segmentation of 3D Medical Data" [BMVC 2021].

OSS-Net: Memory Efficient High Resolution Semantic Segmentation of 3D Medical Data Christoph Reich, Tim Prangemeier, Özdemir Cetin & Heinz Koeppl | Pr

Christoph Reich 23 Sep 21, 2022
FinRL­-Meta: A Universe for Data­-Driven Financial Reinforcement Learning. 🔥

FinRL-Meta: A Universe of Market Environments. FinRL-Meta is a universe of market environments for data-driven financial reinforcement learning. Users

AI4Finance Foundation 543 Jan 08, 2023
Supplementary materials for ISMIR 2021 LBD paper "Evaluation of Latent Space Disentanglement in the Presence of Interdependent Attributes"

Evaluation of Latent Space Disentanglement in the Presence of Interdependent Attributes Supplementary materials for ISMIR 2021 LBD submission: K. N. W

Karn Watcharasupat 2 Oct 25, 2021
Python library for tracking human heads with FLAME (a 3D morphable head model)

Video Head Tracker 3D tracking library for human heads based on FLAME (a 3D morphable head model). The tracking algorithm is inspired by face2face. It

61 Dec 25, 2022
GLNet for Memory-Efficient Segmentation of Ultra-High Resolution Images

GLNet for Memory-Efficient Segmentation of Ultra-High Resolution Images Collaborative Global-Local Networks for Memory-Efficient Segmentation of Ultra-

VITA 298 Dec 12, 2022
PhysCap: Physically Plausible Monocular 3D Motion Capture in Real Time

PhysCap: Physically Plausible Monocular 3D Motion Capture in Real Time The implementation is based on SIGGRAPH Aisa'20. Dependencies Python 3.7 Ubuntu

soratobtai 124 Dec 08, 2022
Unsupervised MRI Reconstruction via Zero-Shot Learned Adversarial Transformers

Official TensorFlow implementation of the unsupervised reconstruction model using zero-Shot Learned Adversarial TransformERs (SLATER). (https://arxiv.

ICON Lab 22 Dec 22, 2022
Breaking the Dilemma of Medical Image-to-image Translation

Breaking the Dilemma of Medical Image-to-image Translation Supervised Pix2Pix and unsupervised Cycle-consistency are two modes that dominate the field

Kid Liet 86 Dec 21, 2022
Gradient Step Denoiser for convergent Plug-and-Play

Source code for the paper "Gradient Step Denoiser for convergent Plug-and-Play"

Samuel Hurault 11 Sep 17, 2022
A criticism of a recent paper on buggy image downsampling methods in popular image processing and deep learning libraries.

A criticism of a recent paper on buggy image downsampling methods in popular image processing and deep learning libraries.

70 Jul 12, 2022
Learned model to estimate number of distinct values (NDV) of a population using a small sample.

Learned NDV estimator Learned model to estimate number of distinct values (NDV) of a population using a small sample. The model approximates the maxim

2 Nov 21, 2022
Learning Pixel-level Semantic Affinity with Image-level Supervision for Weakly Supervised Semantic Segmentation, CVPR 2018

Learning Pixel-level Semantic Affinity with Image-level Supervision This code is deprecated. Please see https://github.com/jiwoon-ahn/irn instead. Int

Jiwoon Ahn 337 Dec 15, 2022
Customizable RecSys Simulator for OpenAI Gym

gym-recsys: Customizable RecSys Simulator for OpenAI Gym Installation | How to use | Examples | Citation This package describes an OpenAI Gym interfac

Xingdong Zuo 14 Dec 08, 2022