Skip to content

Commit

Permalink
add doc string for auxiliaries
Browse files Browse the repository at this point in the history
  • Loading branch information
rayrayraykk committed Oct 31, 2022
1 parent 0377791 commit 30a27e5
Show file tree
Hide file tree
Showing 54 changed files with 131 additions and 137 deletions.
7 changes: 7 additions & 0 deletions doc/source/core.rst
Original file line number Diff line number Diff line change
Expand Up @@ -50,3 +50,10 @@ federatedscope.core.monitors
.. automodule:: federatedscope.core.monitors
:members:
:private-members:

federatedscope.core.auxiliaries
-----------------------

.. automodule:: federatedscope.core.auxiliaries
:members:
:private-members:
2 changes: 1 addition & 1 deletion federatedscope/attack/auxiliary/poisoning_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
from PIL import Image
import numpy as np
from torchvision import transforms
from federatedscope.core.auxiliaries.transform_builder import get_transform
from federatedscope.core.auxiliaries import get_transform
from federatedscope.attack.auxiliary.backdoor_utils import selectTrigger
from torch.utils.data import DataLoader
from federatedscope.attack.auxiliary.backdoor_utils import normalize
Expand Down
2 changes: 1 addition & 1 deletion federatedscope/attack/privacy_attacks/passive_PIA.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import torch
import numpy as np
import copy
from federatedscope.core.auxiliaries.optimizer_builder import get_optimizer
from federatedscope.core.auxiliaries import get_optimizer

import logging

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from federatedscope.core.workers import Server
from federatedscope.core.message import Message

from federatedscope.core.auxiliaries.criterion_builder import get_criterion
from federatedscope.core.auxiliaries import get_criterion
import copy
from federatedscope.attack.auxiliary.utils import get_data_sav_fn, \
get_reconstructor
Expand Down
6 changes: 2 additions & 4 deletions federatedscope/autotune/algos.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,8 @@
import numpy as np

from federatedscope.core.auxiliaries.utils import setup_seed
from federatedscope.core.auxiliaries.data_builder import get_data
from federatedscope.core.auxiliaries.worker_builder import get_client_cls, \
get_server_cls
from federatedscope.core.fed_runner import get_runner
from federatedscope.core.auxiliaries import get_data, get_client_cls, \
get_server_cls, get_runner
from federatedscope.autotune.utils import parse_search_space, \
config2cmdargs, config2str, summarize_hpo_results

Expand Down
11 changes: 5 additions & 6 deletions federatedscope/autotune/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,12 +37,12 @@ def parse_search_space(config_path):


def config2cmdargs(config):
'''
"""
Arguments:
config (dict): key is cfg node name, value is the specified value.
Returns:
results (list): cmd args
'''
"""

results = []
for k, v in config.items():
Expand All @@ -52,13 +52,13 @@ def config2cmdargs(config):


def config2str(config):
'''
"""
Arguments:
config (dict): key is cfg node name, value is the choice of
hyper-parameter.
Returns:
name (str): the string representation of this config
'''
"""

vals = []
for k in config:
Expand Down Expand Up @@ -136,10 +136,9 @@ def process(file):
def eval_in_fs(cfg, config, budget):
import ConfigSpace as CS
from federatedscope.core.auxiliaries.utils import setup_seed
from federatedscope.core.auxiliaries.data_builder import get_data
from federatedscope.core.auxiliaries.worker_builder import \
get_client_cls, get_server_cls
from federatedscope.core.fed_runner import get_runner
from federatedscope.core.auxiliaries import get_runner, get_data
from federatedscope.autotune.utils import config2cmdargs
from os.path import join as osp

Expand Down
2 changes: 1 addition & 1 deletion federatedscope/core/aggregators/fedopt_aggregator.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import torch

from federatedscope.core.aggregators import ClientsAvgAggregator
from federatedscope.core.auxiliaries.optimizer_builder import get_optimizer
from federatedscope.core.auxiliaries import get_optimizer


class FedOptAggregator(ClientsAvgAggregator):
Expand Down
22 changes: 22 additions & 0 deletions federatedscope/core/auxiliaries/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
from federatedscope.core.auxiliaries.aggregator_builder import get_aggregator
from federatedscope.core.auxiliaries.criterion_builder import get_criterion
from federatedscope.core.auxiliaries.data_builder import get_data
from federatedscope.core.auxiliaries.dataloader_builder import get_dataloader
from federatedscope.core.auxiliaries.metric_builder import get_metric
from federatedscope.core.auxiliaries.model_builder import get_model
from federatedscope.core.auxiliaries.optimizer_builder import get_optimizer
from federatedscope.core.auxiliaries.sampler_builder import get_sampler
from federatedscope.core.auxiliaries.scheduler_builder import get_scheduler
from federatedscope.core.auxiliaries.splitter_builder import get_splitter
from federatedscope.core.auxiliaries.trainer_builder import get_trainer
from federatedscope.core.auxiliaries.transform_builder import get_transform
from federatedscope.core.auxiliaries.runner_builder import get_runner
from federatedscope.core.auxiliaries.worker_builder import get_client_cls, \
get_server_cls

__all__ = [
'get_aggregator', 'get_criterion', 'get_data', 'get_dataloader',
'get_metric', 'get_model', 'get_optimizer', 'get_sampler', 'get_scheduler',
'get_splitter', 'get_trainer', 'get_transform', 'get_client_cls',
'get_server_cls', 'get_runner'
]
15 changes: 15 additions & 0 deletions federatedscope/core/auxiliaries/runner_builder.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
from federatedscope.core.fed_runner import StandaloneRunner, DistributedRunner


def get_runner(data, server_class, client_class, config, client_configs=None):
# Instantiate a Runner based on a configuration file
mode = config.federate.mode.lower()
runner_dict = {
'standalone': StandaloneRunner,
'distributed': DistributedRunner
}
return runner_dict[mode](data=data,
server_class=server_class,
client_class=client_class,
config=config,
client_configs=client_configs)
2 changes: 1 addition & 1 deletion federatedscope/core/auxiliaries/trainer_builder.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ def get_trainer(model=None,
data: data used in FL course
device: where to train model (``cpu`` or ``gpu``)
config: configurations for FL, see ``federatedscope.core.configs``
only_for_eval: ``True`` or ``False``, if ``True``, ``train`` \
only_for_eval: ``True`` or ``False``, if ``True``, train \
routine will be removed in this trainer
is_attacker: ``True`` or ``False`` to determine whether this client \
is an attacker
Expand Down
2 changes: 1 addition & 1 deletion federatedscope/core/data/base_data.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import logging
from federatedscope.core.data.utils import merge_data
from federatedscope.core.auxiliaries.dataloader_builder import get_dataloader
from federatedscope.core.auxiliaries import get_dataloader

logger = logging.getLogger(__name__)

Expand Down
2 changes: 1 addition & 1 deletion federatedscope/core/data/base_translator.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import logging
import numpy as np

from federatedscope.core.auxiliaries.splitter_builder import get_splitter
from federatedscope.core.auxiliaries import get_splitter
from federatedscope.core.data import ClientData, StandaloneDataDict

logger = logging.getLogger(__name__)
Expand Down
2 changes: 1 addition & 1 deletion federatedscope/core/data/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ def load_external_data(config=None):
import torch
from importlib import import_module
from torch.utils.data import DataLoader
from federatedscope.core.auxiliaries.transform_builder import get_transform
from federatedscope.core.auxiliaries import get_transform

def load_torchvision_data(name, splits=None, config=None):
dataset_func = getattr(import_module('torchvision.datasets'), name)
Expand Down
17 changes: 1 addition & 16 deletions federatedscope/core/fed_runner.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,27 +8,12 @@

from federatedscope.core.workers import Server, Client
from federatedscope.core.gpu_manager import GPUManager
from federatedscope.core.auxiliaries.model_builder import get_model
from federatedscope.core.auxiliaries import get_model
from federatedscope.core.auxiliaries.utils import get_resource_info
from federatedscope.core.data.utils import merge_data

logger = logging.getLogger(__name__)


def get_runner(data, server_class, client_class, config, client_configs=None):
# Instantiate a Runner based on a configuration file
mode = config.federate.mode.lower()
runner_dict = {
'standalone': StandaloneRunner,
'distributed': DistributedRunner
}
return runner_dict[mode](data=data,
server_class=server_class,
client_class=client_class,
config=config,
client_configs=client_configs)


class BaseRunner(object):
"""
This class is used to construct an FL course, which includes `_set_up`
Expand Down
2 changes: 1 addition & 1 deletion federatedscope/core/monitors/metric_calculator.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
from scipy.special import softmax
from sklearn.metrics import roc_auc_score, average_precision_score, f1_score

from federatedscope.core.auxiliaries.metric_builder import get_metric
from federatedscope.core.auxiliaries import get_metric

# Blind torch
try:
Expand Down
2 changes: 1 addition & 1 deletion federatedscope/core/trainers/context.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import logging
import collections

from federatedscope.core.auxiliaries.criterion_builder import get_criterion
from federatedscope.core.auxiliaries import get_criterion
from federatedscope.core.auxiliaries.model_builder import \
get_trainable_para_names
from federatedscope.core.auxiliaries.regularizer_builder import get_regularizer
Expand Down
5 changes: 2 additions & 3 deletions federatedscope/core/trainers/torch_trainer.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,10 @@
from federatedscope.core.trainers.enums import MODE, LIFECYCLE
from federatedscope.core.trainers.trainer import Trainer
from federatedscope.core.trainers.context import CtxVar
from federatedscope.core.auxiliaries.optimizer_builder import get_optimizer
from federatedscope.core.auxiliaries.scheduler_builder import get_scheduler
from federatedscope.core.auxiliaries import get_optimizer, get_dataloader, \
get_scheduler
from federatedscope.core.data import ClientData
from federatedscope.core.data.wrap_dataset import WrapDataset
from federatedscope.core.auxiliaries.dataloader_builder import get_dataloader
from federatedscope.core.auxiliaries.ReIterator import ReIterator
from federatedscope.core.auxiliaries.utils import param2tensor, \
merge_param_dict
Expand Down
2 changes: 1 addition & 1 deletion federatedscope/core/trainers/trainer_Ditto.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

import torch

from federatedscope.core.auxiliaries.optimizer_builder import get_optimizer
from federatedscope.core.auxiliaries import get_optimizer
from federatedscope.core.trainers.torch_trainer import GeneralTorchTrainer
from federatedscope.core.optimizer import wrap_regularized_optimizer
from federatedscope.core.trainers.utils import calculate_batch_epoch_num
Expand Down
2 changes: 1 addition & 1 deletion federatedscope/core/trainers/trainer_multi_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
from types import FunctionType
from typing import Type

from federatedscope.core.auxiliaries.optimizer_builder import get_optimizer
from federatedscope.core.auxiliaries import get_optimizer
from federatedscope.core.trainers.torch_trainer import GeneralTorchTrainer

import numpy as np
Expand Down
3 changes: 1 addition & 2 deletions federatedscope/core/workers/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,7 @@
from federatedscope.core.communication import StandaloneCommManager, \
gRPCCommManager
from federatedscope.core.monitors.early_stopper import EarlyStopper
from federatedscope.core.workers import Worker
from federatedscope.core.auxiliaries.trainer_builder import get_trainer
from federatedscope.core.auxiliaries import get_trainer
from federatedscope.core.secret_sharing import AdditiveSecretSharing
from federatedscope.core.auxiliaries.utils import merge_dict_of_results, \
calculate_time_cost
Expand Down
6 changes: 3 additions & 3 deletions federatedscope/core/workers/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,11 @@
from federatedscope.core.message import Message
from federatedscope.core.communication import StandaloneCommManager, \
gRPCCommManager
from federatedscope.core.auxiliaries.aggregator_builder import get_aggregator
from federatedscope.core.auxiliaries.sampler_builder import get_sampler
from federatedscope.core.auxiliaries import get_aggregator
from federatedscope.core.auxiliaries import get_sampler
from federatedscope.core.auxiliaries.utils import merge_dict_of_results, \
Timeout, merge_param_dict
from federatedscope.core.auxiliaries.trainer_builder import get_trainer
from federatedscope.core.auxiliaries import get_trainer
from federatedscope.core.secret_sharing import AdditiveSecretSharing
from federatedscope.core.workers.base_server import BaseServer

Expand Down
2 changes: 1 addition & 1 deletion federatedscope/cv/dataloader/dataloader.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from federatedscope.cv.dataset.leaf_cv import LEAF_CV
from federatedscope.core.auxiliaries.transform_builder import get_transform
from federatedscope.core.auxiliaries import get_transform


def load_cv_dataset(config=None):
Expand Down
2 changes: 1 addition & 1 deletion federatedscope/gfl/dataloader/dataloader_graph.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from torch_geometric import transforms
from torch_geometric.datasets import TUDataset, MoleculeNet

from federatedscope.core.auxiliaries.transform_builder import get_transform
from federatedscope.core.auxiliaries import get_transform
from federatedscope.gfl.dataset.cikm_cup import CIKMCUPDataset


Expand Down
3 changes: 1 addition & 2 deletions federatedscope/gfl/dataloader/dataloader_link.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,7 @@
from torch_geometric.utils import add_self_loops, remove_self_loops, \
to_undirected

from federatedscope.core.auxiliaries.splitter_builder import get_splitter
from federatedscope.core.auxiliaries.transform_builder import get_transform
from federatedscope.core.auxiliaries import get_splitter, get_transform


def load_linklevel_dataset(config=None):
Expand Down
3 changes: 1 addition & 2 deletions federatedscope/gfl/dataloader/dataloader_node.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,7 @@
to_undirected
from torch_geometric.data import Data

from federatedscope.core.auxiliaries.splitter_builder import get_splitter
from federatedscope.core.auxiliaries.transform_builder import get_transform
from federatedscope.core.auxiliaries import get_splitter, get_transform

INF = np.iinfo(np.int64).max

Expand Down
6 changes: 2 additions & 4 deletions federatedscope/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,11 @@
sys.path.append(file_dir)

from federatedscope.core.cmd_args import parse_args
from federatedscope.core.auxiliaries.data_builder import get_data
from federatedscope.core.auxiliaries import get_runner, get_server_cls, \
get_client_cls, get_data
from federatedscope.core.auxiliaries.utils import setup_seed
from federatedscope.core.auxiliaries.logging import update_logger
from federatedscope.core.auxiliaries.worker_builder import get_client_cls, \
get_server_cls
from federatedscope.core.configs.config import global_cfg, CfgNode
from federatedscope.core.fed_runner import get_runner

if os.environ.get('https_proxy'):
del os.environ['https_proxy']
Expand Down
2 changes: 1 addition & 1 deletion federatedscope/nlp/dataloader/dataloader.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from federatedscope.nlp.dataset.leaf_nlp import LEAF_NLP
from federatedscope.nlp.dataset.leaf_twitter import LEAF_TWITTER
from federatedscope.nlp.dataset.leaf_synthetic import LEAF_SYNTHETIC
from federatedscope.core.auxiliaries.transform_builder import get_transform
from federatedscope.core.auxiliaries import get_transform


def load_nlp_dataset(config=None):
Expand Down
2 changes: 1 addition & 1 deletion federatedscope/organizer/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

from federatedscope.core.cmd_args import parse_args
from federatedscope.core.configs.config import global_cfg
from federatedscope.core.auxiliaries.data_builder import get_data
from federatedscope.core.auxiliaries import get_data
from federatedscope.organizer.cfg_client import env_name, root_path, fs_version

logger = logging.getLogger('federatedscope')
Expand Down
5 changes: 2 additions & 3 deletions tests/test_CRA_gan_attack.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
# Copyright (c) Alibaba, Inc. and its affiliates.
import unittest

from federatedscope.core.auxiliaries.data_builder import get_data
from federatedscope.core.auxiliaries.utils import setup_seed
from federatedscope.core.auxiliaries.logging import update_logger
from federatedscope.core.configs.config import global_cfg
from federatedscope.core.fed_runner import get_runner
from federatedscope.core.auxiliaries.worker_builder import get_server_cls, get_client_cls
from federatedscope.core.auxiliaries import get_runner, get_server_cls, \
get_client_cls, get_data


class CRATest(unittest.TestCase):
Expand Down
5 changes: 2 additions & 3 deletions tests/test_MIA_gradient_ascent.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
# Copyright (c) Alibaba, Inc. and its affiliates.
import unittest

from federatedscope.core.auxiliaries.data_builder import get_data
from federatedscope.core.auxiliaries.utils import setup_seed
from federatedscope.core.auxiliaries.logging import update_logger
from federatedscope.core.configs.config import global_cfg
from federatedscope.core.fed_runner import get_runner
from federatedscope.core.auxiliaries.worker_builder import get_server_cls, get_client_cls
from federatedscope.core.auxiliaries import get_runner, get_server_cls, \
get_client_cls


class GradAscentTest(unittest.TestCase):
Expand Down
5 changes: 2 additions & 3 deletions tests/test_PIA_toy.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
# Copyright (c) Alibaba, Inc. and its affiliates.
import unittest

from federatedscope.core.auxiliaries.data_builder import get_data
from federatedscope.core.auxiliaries.utils import setup_seed
from federatedscope.core.auxiliaries.logging import update_logger
from federatedscope.core.configs.config import global_cfg
from federatedscope.core.fed_runner import get_runner
from federatedscope.core.auxiliaries.worker_builder import get_server_cls, get_client_cls
from federatedscope.core.auxiliaries import get_runner, get_server_cls, \
get_client_cls, get_data


class PIA_ToyLRTest(unittest.TestCase):
Expand Down
Loading

0 comments on commit 30a27e5

Please sign in to comment.