Quick Start

This guide will help you get started with PyGIP quickly.

Attack Examples

Model Extraction Attack

from datasets import Cora
from models.attack import ModelExtractionAttack0

# Load the Cora dataset
dataset = Cora()

# Initialize the attack with a sampling ratio of 0.25
mea = ModelExtractionAttack0(dataset, 0.25)

# Execute the attack
mea.attack()

To run the attack example:

python examples/attack/MEAs.py

Defense Examples

RandomWM Defense

from datasets import Cora
from models.defense import RandomWM

# Load the Cora dataset
dataset = Cora()

# Initialize the attack with a sampling ratio of 0.25
med = RandomWM(dataset, 0.25)

# Execute the defense
med.defend()

To run the defense example:

python examples/defense/RandomWM.py

GPU Support

If you want to use cuda, please set environment variable:

export PYGIP_DEVICE=cuda:0

Alternatively, you can explicitly specify the device in your code:

from pygip.utils.hardware import set_device

set_device("cuda:0")

Next Steps

For more detailed documentation, please refer to:

  • Datasets - Available datasets

  • Attack - Detailed attack mechanisms

  • Defense - Detailed defense mechanisms