Skip to content

Commit

Permalink
add import setup_seed
Browse files Browse the repository at this point in the history
  • Loading branch information
wnma3mz committed Dec 30, 2021
1 parent 8a95842 commit fd8c159
Show file tree
Hide file tree
Showing 16 changed files with 16 additions and 158 deletions.
11 changes: 1 addition & 10 deletions example/CCVR/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,21 +12,12 @@
from FedCVVR import CCVRTrainer, FedCCVR
from flearn.client import Client
from flearn.client.utils import get_free_gpu_id
from flearn.common.utils import setup_seed
from flearn.server import Communicator as sc
from model import GlobModel, ModelFedCon
from MyClients import MOONClient, ProxClient
from utils import get_dataloader, partition_data


def setup_seed(seed):
torch.manual_seed(seed)
torch.cuda.manual_seed_all(seed)
np.random.seed(seed)
random.seed(seed)
# tf.random.set_seed(seed)
torch.backends.cudnn.deterministic = True


# 设置随机数种子
setup_seed(0)

Expand Down
11 changes: 1 addition & 10 deletions example/FedDF/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,22 +14,13 @@
from flearn.client.datasets import get_dataloader, get_datasets, get_split_loader
from flearn.client.utils import get_free_gpu_id
from flearn.common import Trainer
from flearn.common.utils import setup_seed
from flearn.server import Communicator as sc
from models import LeNet5
from resnet import ResNet_cifar
from split_data import iid as iid_f
from split_data import noniid


def setup_seed(seed):
torch.manual_seed(seed)
torch.cuda.manual_seed_all(seed)
np.random.seed(seed)
random.seed(seed)
# tf.random.set_seed(seed)
torch.backends.cudnn.deterministic = True


# 设置随机数种子
setup_seed(0)
idx = get_free_gpu_id()
Expand Down
11 changes: 1 addition & 10 deletions example/FedDistill/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,22 +12,13 @@
from FedDistill import Distill, DistillClient, DistillTrainer
from flearn.client.datasets import get_dataloader, get_datasets, get_split_loader
from flearn.client.utils import get_free_gpu_id
from flearn.common.utils import setup_seed
from flearn.server import Communicator as sc
from models import LeNet5
from resnet import ResNet_cifar
from split_data import iid as iid_f
from split_data import noniid


def setup_seed(seed):
torch.manual_seed(seed)
torch.cuda.manual_seed_all(seed)
np.random.seed(seed)
random.seed(seed)
# tf.random.set_seed(seed)
torch.backends.cudnn.deterministic = True


# 设置随机数种子
setup_seed(0)
idx = get_free_gpu_id()
Expand Down
11 changes: 1 addition & 10 deletions example/FedDyn/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,22 +12,13 @@
from FedDyn import Dyn, DynClient, DynTrainer
from flearn.client.datasets import get_dataloader, get_datasets, get_split_loader
from flearn.client.utils import get_free_gpu_id
from flearn.common.utils import setup_seed
from flearn.server import Communicator as sc
from models import LeNet5
from resnet import ResNet_cifar
from split_data import iid as iid_f
from split_data import noniid


def setup_seed(seed):
torch.manual_seed(seed)
torch.cuda.manual_seed_all(seed)
np.random.seed(seed)
random.seed(seed)
# tf.random.set_seed(seed)
torch.backends.cudnn.deterministic = True


# 设置随机数种子
setup_seed(0)
idx = get_free_gpu_id()
Expand Down
11 changes: 1 addition & 10 deletions example/FedGen/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,22 +13,13 @@
from flearn.client import Client
from flearn.client.datasets import get_dataloader, get_datasets, get_split_loader
from flearn.client.utils import get_free_gpu_id
from flearn.common.utils import setup_seed
from flearn.server import Communicator as sc
from generator import Generator
from models import Net
from split_data import iid as iid_f
from split_data import noniid


def setup_seed(seed):
torch.manual_seed(seed)
torch.cuda.manual_seed_all(seed)
np.random.seed(seed)
random.seed(seed)
# tf.random.set_seed(seed)
torch.backends.cudnn.deterministic = True


# 设置随机数种子
setup_seed(0)
idx = get_free_gpu_id()
Expand Down
11 changes: 1 addition & 10 deletions example/FedMD/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,22 +14,13 @@
from flearn.client.datasets import get_dataloader, get_datasets, get_split_loader
from flearn.client.utils import get_free_gpu_id
from flearn.common import Trainer
from flearn.common.utils import setup_seed
from flearn.server import Communicator as sc
from models import LeNet5
from resnet import ResNet_cifar
from split_data import iid as iid_f
from split_data import noniid


def setup_seed(seed):
torch.manual_seed(seed)
torch.cuda.manual_seed_all(seed)
np.random.seed(seed)
random.seed(seed)
# tf.random.set_seed(seed)
torch.backends.cudnn.deterministic = True


# 设置随机数种子
setup_seed(0)
idx = get_free_gpu_id()
Expand Down
11 changes: 1 addition & 10 deletions example/FedMutualLearning/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,21 +10,12 @@
import torch.optim as optim

from flearn.client.utils import get_free_gpu_id
from flearn.common.utils import setup_seed
from flearn.server import Communicator as sc
from FML import FMLClient, FMLTrainer
from model import ModelFedCon
from utils import get_dataloader, partition_data


def setup_seed(seed):
torch.manual_seed(seed)
torch.cuda.manual_seed_all(seed)
np.random.seed(seed)
random.seed(seed)
# tf.random.set_seed(seed)
torch.backends.cudnn.deterministic = True


# 设置随机数种子
setup_seed(0)
idx = get_free_gpu_id()
Expand Down
11 changes: 1 addition & 10 deletions example/LG_reproduction/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,22 +13,13 @@
from flearn.client.utils import get_free_gpu_id
from flearn.common import Trainer
from flearn.common.strategy import LG, LG_R
from flearn.common.utils import setup_seed
from flearn.server import Communicator as sc
from LGClient import LGClient
from models import MLP, CNNCifar, CNNMnist
from split_data import iid as iid_f
from split_data import noniid


def setup_seed(seed):
torch.manual_seed(seed)
torch.cuda.manual_seed_all(seed)
np.random.seed(seed)
random.seed(seed)
# tf.random.set_seed(seed)
torch.backends.cudnn.deterministic = True


# 设置随机数种子
setup_seed(0)
# 自动选择空闲显存最大的GPU
Expand Down
11 changes: 1 addition & 10 deletions example/MOON_reproduction/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
from flearn.client import Client
from flearn.client.utils import get_free_gpu_id
from flearn.common import Trainer
from flearn.common.utils import setup_seed
from flearn.server import Communicator as sc
from model import ModelFedCon
from MyClients import (
Expand All @@ -33,16 +34,6 @@
)
from utils import get_dataloader, partition_data


def setup_seed(seed):
torch.manual_seed(seed)
torch.cuda.manual_seed_all(seed)
np.random.seed(seed)
random.seed(seed)
# tf.random.set_seed(seed)
torch.backends.cudnn.deterministic = True


# 设置随机数种子
setup_seed(0)
idx = get_free_gpu_id()
Expand Down
11 changes: 1 addition & 10 deletions example/PAV_reproduction/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,22 +13,13 @@
from flearn.client.datasets import get_dataloader, get_datasets, get_split_loader
from flearn.client.utils import get_free_gpu_id
from flearn.common import Trainer
from flearn.common.utils import setup_seed
from flearn.server import Communicator as sc
from models import LeNet5
from resnet import ResNet_cifar
from split_data import iid as iid_f
from split_data import noniid


def setup_seed(seed):
torch.manual_seed(seed)
torch.cuda.manual_seed_all(seed)
np.random.seed(seed)
random.seed(seed)
# tf.random.set_seed(seed)
torch.backends.cudnn.deterministic = True


# 设置随机数种子
setup_seed(0)
# 自动选择空闲显存最大的GPU
Expand Down
11 changes: 1 addition & 10 deletions example/Prox/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@

from flearn.client.datasets import get_dataloader, get_datasets, get_split_loader
from flearn.client.utils import get_free_gpu_id
from flearn.common.utils import setup_seed
from flearn.server import Communicator as sc
from models import LeNet5
from ProxClient import ProxClient
Expand All @@ -19,16 +20,6 @@
from split_data import iid as iid_f
from split_data import noniid


def setup_seed(seed):
torch.manual_seed(seed)
torch.cuda.manual_seed_all(seed)
np.random.seed(seed)
random.seed(seed)
# tf.random.set_seed(seed)
torch.backends.cudnn.deterministic = True


# 设置随机数种子
setup_seed(0)
idx = get_free_gpu_id()
Expand Down
11 changes: 1 addition & 10 deletions example/mnist_cifar/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,22 +12,13 @@
from flearn.client import Client
from flearn.client.datasets import get_datasets, get_split_loader
from flearn.common import Trainer
from flearn.common.utils import setup_seed
from flearn.server import Communicator as sc
from models import LeNet5
from resnet import ResNet_cifar
from split_data import iid as iid_f
from split_data import noniid


def setup_seed(seed):
torch.manual_seed(seed)
torch.cuda.manual_seed_all(seed)
np.random.seed(seed)
random.seed(seed)
# tf.random.set_seed(seed)
torch.backends.cudnn.deterministic = True


# 设置随机数种子
setup_seed(0)
os.environ["CUDA_VISIBLE_DEVICES"] = "1"
Expand Down
11 changes: 1 addition & 10 deletions example/server_test/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,23 +13,14 @@
from flearn.client.datasets import get_dataloader, get_datasets, get_split_loader
from flearn.client.utils import get_free_gpu_id
from flearn.common import Trainer
from flearn.common.utils import setup_seed
from flearn.server import Communicator as sc
from flearn.server import Server
from models import LeNet5
from resnet import ResNet_cifar
from split_data import iid as iid_f
from split_data import noniid


def setup_seed(seed):
torch.manual_seed(seed)
torch.cuda.manual_seed_all(seed)
np.random.seed(seed)
random.seed(seed)
# tf.random.set_seed(seed)
torch.backends.cudnn.deterministic = True


# 设置随机数种子
setup_seed(0)
# 自动选择空闲显存最大的GPU
Expand Down
10 changes: 1 addition & 9 deletions example/split_learning/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@

from flearn.client.datasets import get_dataloader, get_datasets, get_split_loader
from flearn.client.utils import get_free_gpu_id
from flearn.common.utils import setup_seed
from models import LeNet5Client, LeNet5Server, ResNet_cifarClient, ResNet_cifarServer
from split_data import iid as iid_f
from split_data import noniid
Expand Down Expand Up @@ -74,15 +75,6 @@
)


def setup_seed(seed):
torch.manual_seed(seed)
torch.cuda.manual_seed_all(seed)
np.random.seed(seed)
random.seed(seed)
# tf.random.set_seed(seed)
torch.backends.cudnn.deterministic = True


setup_seed(0)

model_fpath = "./client_checkpoint"
Expand Down
11 changes: 1 addition & 10 deletions example/split_learning/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,20 +11,11 @@

from flearn.client.datasets import get_dataloader, get_datasets, get_split_loader
from flearn.client.utils import get_free_gpu_id
from flearn.common.utils import setup_seed
from models import LeNet5Client, LeNet5Server, ResNet_cifarClient, ResNet_cifarServer
from split_data import iid as iid_f
from split_data import noniid


def setup_seed(seed):
torch.manual_seed(seed)
torch.cuda.manual_seed_all(seed)
np.random.seed(seed)
random.seed(seed)
# tf.random.set_seed(seed)
torch.backends.cudnn.deterministic = True


# 设置随机数种子
setup_seed(0)
idx = get_free_gpu_id()
Expand Down
10 changes: 1 addition & 9 deletions example/split_learning/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
from flask import Flask, jsonify, make_response, request

from flearn.client.utils import get_free_gpu_id
from flearn.common.utils import setup_seed
from models import LeNet5Client, LeNet5Server, ResNet_cifarClient, ResNet_cifarServer

parser = argparse.ArgumentParser(description="Please input conf")
Expand Down Expand Up @@ -65,15 +66,6 @@
criterion_server = nn.CrossEntropyLoss()


def setup_seed(seed):
torch.manual_seed(seed)
torch.cuda.manual_seed_all(seed)
np.random.seed(seed)
random.seed(seed)
# tf.random.set_seed(seed)
torch.backends.cudnn.deterministic = True


setup_seed(0)


Expand Down

0 comments on commit fd8c159

Please sign in to comment.