Skip to content

Commit 8938436

Browse files
committed
add fedsp
1 parent 650b470 commit 8938436

File tree

11 files changed

+53
-1037
lines changed

11 files changed

+53
-1037
lines changed

LICENSE

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -661,3 +661,46 @@ distributed under the License is distributed on an "AS IS" BASIS,
661661
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
662662
See the License for the specific language governing permissions and
663663
limitations under the License.
664+
665+
--------------------------------------------------------------------------------
666+
667+
The code in federatedscope/nlp/fedsp/dataset and federatedscope/nlp/fedsp/metric
668+
is partially adapted from https://github.com/mit-han-lab/offsite-tuning (MIT License)
669+
670+
Copyright (c) 2023 MIT HAN Lab
671+
672+
Permission is hereby granted, free of charge, to any person obtaining a copy
673+
of this software and associated documentation files (the "Software"), to deal
674+
in the Software without restriction, including without limitation the rights
675+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
676+
copies of the Software, and to permit persons to whom the Software is
677+
furnished to do so, subject to the following conditions:
678+
679+
The above copyright notice and this permission notice shall be included in all
680+
copies or substantial portions of the Software.
681+
682+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
683+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
684+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
685+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
686+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
687+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
688+
SOFTWARE.
689+
690+
---------------------------------------------------------------------------------
691+
The code in federatedscope/nlp/fedsp/model and federatedscope/nlp/fedsp/worker/server.py
692+
is partially adapted from https://github.com/THUDM/P-tuning-v2 (Apache License)
693+
694+
Copyright 2021 Xiao Liu
695+
696+
Licensed under the Apache License, Version 2.0 (the "License");
697+
you may not use this file except in compliance with the License.
698+
You may obtain a copy of the License at
699+
700+
http://www.apache.org/licenses/LICENSE-2.0
701+
702+
Unless required by applicable law or agreed to in writing, software
703+
distributed under the License is distributed on an "AS IS" BASIS,
704+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
705+
See the License for the specific language governing permissions and
706+
limitations under the License.

federatedscope/core/auxiliaries/metric_builder.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55

66
try:
77
from federatedscope.contrib.metrics import *
8+
from federatedscope.nlp.hetero_tasks.metric import *
89
except ImportError as error:
910
logger.warning(
1011
f'{error} in `federatedscope.contrib.metrics`, some modules are not '

federatedscope/core/auxiliaries/worker_builder.py

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -72,10 +72,6 @@ def get_client_cls(cfg):
7272
from federatedscope.nlp.hetero_tasks.worker import ATCClient
7373
return ATCClient
7474

75-
if cfg.data.type.lower() == 'hetero_nlp_tasks':
76-
from federatedscope.nlp.hetero_tasks.worker import ATCClient
77-
return ATCClient
78-
7975
if cfg.trainer.type.lower() == 'fedsp_trainer':
8076
from federatedscope.nlp.fedsp.worker import FedSPClient
8177
return FedSPClient

federatedscope/core/configs/cfg_aggregator.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
11
import logging
2+
23
from federatedscope.core.configs.config import CN
34
from federatedscope.register import register_config
45

56

67
def extend_aggregator_cfg(cfg):
8+
79
# ---------------------------------------------------------------------- #
810
# aggregator related options
911
# fs has supported the robust aggregation rules of 'krum', 'median',
@@ -26,6 +28,7 @@ def extend_aggregator_cfg(cfg):
2628

2729

2830
def assert_aggregator_cfg(cfg):
31+
2932
if cfg.aggregator.byzantine_node_num == 0 and \
3033
cfg.aggregator.robust_rule in \
3134
['krum', 'normbounding', 'median', 'trimmedmean', 'bulyan']:

federatedscope/core/configs/cfg_data.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ def extend_data_cfg(cfg):
100100
cfg.feat_engr.secure.dp = CN() # under dev
101101

102102
# prompt tuning
103-
cfg.data.dataset_name = ''
103+
cfg.data.dataset_name = '' #TODO
104104
cfg.data.train_frac = 0.9
105105
cfg.data.num_train_per_client = -1
106106

federatedscope/core/configs/cfg_fl_setting.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
import logging
2-
import torch
2+
33
from federatedscope.core.configs.config import CN
44
from federatedscope.register import register_config
5+
import torch
56

67
logger = logging.getLogger(__name__)
78

federatedscope/nlp/fedsp/README.md

Lines changed: 3 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
## Tunable Soft Prompts are Messengers in Federated Learning
22
The implementation of *Tunable Soft Prompts are Messengers in Federated Learning*.
33

4-
In this study, we propose a novel FL training approach that accomplishes information exchange among participants via tunable soft prompts.
5-
These soft prompts are updated and transmitted between the server and clients, taking over the duty of the global model parameters and serving as messengers to deliver useful knowledge in the local data and global model.
4+
In this study, we propose a novel FL training approach, named FedSP, that accomplishes information exchange among participants via tunable soft prompts.
5+
These soft prompts, updated and transmitted between the server and clients, assume the role of the global model parameters and serve as messengers to deliver useful knowledge from the local data and global model.
66

77
### Installation
88
First of all, you need to install FederatedScope, please refer to [installation](https://github.com/alibaba/FederatedScope#step-1-installation).
@@ -25,19 +25,7 @@ bash run_gpt_prefix.sh $DEVICE # gpt2-xl
2525
bash run_opt_prefix.sh $DEVICE # opt-1.3b
2626
```
2727

28-
**FedPrompt**
29-
```bash
30-
bash run_gpt_fedprompt.sh $DEVICE # gpt2-xl
31-
bash run_opt_fedprompt.sh $DEVICE # opt-1.3b
32-
```
33-
34-
**FedPrompt-LSR**
35-
```bash
36-
bash run_gpt_fedprompt_lsr.sh $DEVICE # gpt2-xl
37-
bash run_opt_fedprompt_lsr.sh $DEVICE # opt-1.3b
38-
```
39-
40-
**FedSP (ours)**
28+
**FedSP**
4129
```bash
4230
bash run_gpt_fedsp.sh $DEVICE # gpt2-xl
4331
bash run_opt_fedsp.sh $DEVICE # opt-1.3b

federatedscope/nlp/fedsp/run_gpt_fedprompt.sh

Lines changed: 0 additions & 253 deletions
This file was deleted.

0 commit comments

Comments
 (0)