Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
105 changes: 105 additions & 0 deletions gnnfingers-examples/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,105 @@
# πŸ” GNNFingers Example

This folder contains an example implementation of the **GNNFingers** attack and defense pipeline,
integrated with [PyGIP](https://github.com/yushundong/PyGIP).

The purpose of this example is to hold experimental scripts that reproduce and extend fingerprint-based verification of GNN models.

---

## πŸ“‚ Structure

```
examples/
β”œβ”€β”€ cli.py # Command-line interface (entrypoint)
β”œβ”€β”€ attacker.py # Attack + defense logic
β”œβ”€β”€ dataset.py # Dataset loader
β”œβ”€β”€ models.py # GNN model definitions
β”œβ”€β”€ fingerprints.py # Fingerprint generation & univerifier
β”œβ”€β”€ verification_metrics.json # Verification metrics
└── README.md # This documentation
```

---

## ▢️ Usage

All experiments are launched via the CLI:

```bash
python gnnfingers-examples/cli.py --dataset Cora --joint_steps 50
```

### Common options

- `--dataset {Cora,Citeseer,Pubmed}`
Which dataset to use.

- `--joint_steps INT`
Number of training steps for the joint optimization of fingerprints and univerifier.

- `--num_graphs INT`
Number of fingerprint probe graphs.

- `--num_nodes INT`
Number of nodes per probe graph.

- `--edge_density FLOAT`
Edge density for fingerprint graphs (default 0.05).

- `--proj_every INT`
Projection frequency during fingerprint optimization.

- `--node_sample INT`
Node sampling factor for graph generation.

- `--device {cpu,cuda}`
Device for training (defaults to `cuda` if available).

- `--mode {attack,defense}`
Run attack pipeline (default) or defense pipeline.

- `--clean`
Remove old `.pt` and `.json` artifacts before running.

---

## πŸ§ͺ Examples

### Quick test (small run)
```bash
python gnnfingers-examples/cli.py --dataset Cora --joint_steps 10 --num_graphs 8 --num_nodes 16 --clean
```

### Full attack run
```bash
python gnnfingers-examples/cli.py --dataset Cora --joint_steps 300 --num_graphs 64 --num_nodes 32 --edge_density 0.05
```

### Defense run
```bash
python gnnfingers-examples/cli.py --dataset Cora --mode defense
```

---

## πŸ“¦ Outputs

Running the pipeline produces:

- **Model checkpoints (`*.pt`)**
- `target_main.pt`, `ft_last.pt`, `reinit_last.pt`, etc.
- **Fingerprint artifacts**
- `fingerprints.pt`, `univerifier.pt`
- **Verification metrics**
- `verification_metrics.json` (contains ROC_AUC, ARUC, robustness, etc.)

---

## πŸ“ Notes

- The implementation follows the guidelines in `IMPLEMENTATION.md`.
- The `attack()` and `defense()` functions are public entrypoints, with helpers defined internally.
- Use the `--clean` flag to avoid piling up old artifacts across runs.

---
Loading