Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add scripts for running gcn with dp & fix tensor under different device #313

Merged
merged 3 commits into from
Aug 16, 2022
Merged
Show file tree
Hide file tree
Changes from 2 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
41 changes: 41 additions & 0 deletions benchmark/FedHPOB/scripts/gcn/cora_dp.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
use_gpu: True
device: 0
early_stop:
patience: 100
seed: 12345
federate:
rayrayraykk marked this conversation as resolved.
Show resolved Hide resolved
mode: standalone
make_global_eval: True
client_num: 5
total_round_num: 500
share_local_model: True
online_aggr: True
data:
root: data/
type: cora
splitter: 'louvain'
batch_size: 1
model:
type: gcn
hidden: 64
dropout: 0.5
out_channels: 7
criterion:
type: CrossEntropyLoss
train:
local_update_steps: 1
optimizer:
lr: 0.25
weight_decay: 0.0005
trainer:
type: nodefullbatch_trainer
eval:
freq: 1
metrics: ['acc', 'correct', 'f1']
split: ['test', 'val', 'train']
nbafl:
use: True
mu: 0.0
w_clip: 0.1
epsilon: 2000
rayrayraykk marked this conversation as resolved.
Show resolved Hide resolved
constant: 1
34 changes: 34 additions & 0 deletions benchmark/FedHPOB/scripts/gcn/run_hpo_cora_dp.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
set -e

cudaid=$1
sample_num=$2
eps=$3

# eps = (5000, 500, 50)

cd ../../../..

dataset=cora

out_dir=out_${dataset}_dp${eps}

echo "HPO starts..."

lrs=(0.01 0.01668 0.02783 0.04642 0.07743 0.12915 0.21544 0.35938 0.59948 1.0)
wds=(0.0 0.001 0.01 0.1)
dps=(0.0 0.5)
steps=(1 2 3 4 5 6 7 8)

for ((l = 0; l < ${#lrs[@]}; l++)); do
for ((w = 0; w < ${#wds[@]}; w++)); do
for ((d = 0; d < ${#dps[@]}; d++)); do
for ((s = 0; s < ${#steps[@]}; s++)); do
for k in {1..3}; do
python federatedscope/main.py --cfg benchmark/FedHPOB/scripts/gcn/cora_dp.yaml device $cudaid train.optimizer.lr ${lrs[$l]} train.optimizer.weight_decay ${wds[$w]} model.dropout ${dps[$d]} train.local_update_steps ${steps[$s]} federate.sample_client_num $sample_num seed $k outdir ${out_dir}/${sample_num} expname lr${lrs[$l]}_wd${wds[$w]}_dropout${dps[$d]}_step${steps[$s]}_seed${k} >/dev/null 2>&1
done
done
done
done
done

echo "HPO ends."
5 changes: 3 additions & 2 deletions federatedscope/core/trainers/trainer_nbafl.py
Original file line number Diff line number Diff line change
Expand Up @@ -109,8 +109,9 @@ def inject_noise_in_broadcast(cfg, sample_client_num, model):

# Clip weight
for p in model.parameters():
p.data = p.data / torch.max(torch.ones(size=p.shape),
torch.abs(p.data) / cfg.nbafl.w_clip)
p.data = p.data / torch.max(
torch.ones(size=p.shape, device=p.data.device),
torch.abs(p.data) / cfg.nbafl.w_clip)

if len(sample_client_num) > 0:
# Inject noise
Expand Down