alibaba / FederatedScope

An easy-to-use federated learning platform
https://www.federatedscope.io
Apache License 2.0
1.27k stars 207 forks source link

List of attack clients #608

Open dalqattan opened 1 year ago

dalqattan commented 1 year ago

Hi

I have tried to add list of attack id but I got type mismatch error.

(fs) PS C:\temp\FederatedScope-backdoor-bench> python federatedscope/main.py --cfg scripts/backdoor_scripts/attack_config/backdoor_fedavg_convnet2_on_femnist.yaml Namespace(cfg_file='scripts/backdoor_scripts/attack_config/backdoor_fedavg_convnet2_on_femnist.yaml', client_cfg_file=None, opts=[]) Traceback (most recent call last): File "C:\temp\FederatedScope-backdoor-bench\federatedscope\main.py", line 29, in init_cfg.merge_from_file(args.cfg_file) File "C:\Users\b8059713\Anaconda3\envs\fs\lib\site-packages\federatedscope-0.1.0-py3.9.egg\federatedscope\core\configs\config.py", line 41, in merge_from_file super(CN, self).merge_from_file(cfg_filename) File "C:\Users\b8059713\Anaconda3\envs\fs\lib\site-packages\yacs\config.py", line 213, in merge_from_file self.merge_from_other_cfg(cfg) File "C:\Users\b8059713\Anaconda3\envs\fs\lib\site-packages\federatedscope-0.1.0-py3.9.egg\federatedscope\core\configs\config.py", line 51, in merge_from_other_cfg super(CN, self).merge_from_other_cfg(cfg_other) File "C:\Users\b8059713\Anaconda3\envs\fs\lib\site-packages\yacs\config.py", line 217, in merge_from_other_cfg _merge_a_into_b(cfg_other, self, self, []) File "C:\Users\b8059713\Anaconda3\envs\fs\lib\site-packages\yacs\config.py", line 478, in _merge_a_into_b _merge_a_into_b(v, b[k], root, key_list + [k]) File "C:\Users\b8059713\Anaconda3\envs\fs\lib\site-packages\yacs\config.py", line 474, in _merge_a_into_b v = _check_and_coerce_cfg_value_type(v, b[k], k, full_key) File "C:\Users\b8059713\Anaconda3\envs\fs\lib\site-packages\yacs\config.py", line 534, in _check_and_coerce_cfg_value_type raise ValueError( ValueError: Type mismatch (<class 'int'> vs. <class 'list'>) with values (-1 vs. [1, 2, 3, 4, 5]) for config key: attack.attacker_id

Thanks

Duaa

rayrayraykk commented 1 year ago

You could change https://github.com/alibaba/FederatedScope/blob/f691611e86eac75d8a869392eaa2608e44713908/federatedscope/core/configs/cfg_attack.py#L14 to

cfg.attack.attacker_id = [-1]

to avoid ValueError.

dalqattan commented 1 year ago

You could change

https://github.com/alibaba/FederatedScope/blob/f691611e86eac75d8a869392eaa2608e44713908/federatedscope/core/configs/cfg_attack.py#L14

to

cfg.attack.attacker_id = [-1]

to avoid ValueError.

Thanks for your reply. However, I need to simulate multi-client attack so that I have to list all the attack clients' id in a list (e.g. [1, 2, 3, 4, 5]).

rayrayraykk commented 1 year ago

You could change https://github.com/alibaba/FederatedScope/blob/f691611e86eac75d8a869392eaa2608e44713908/federatedscope/core/configs/cfg_attack.py#L14

to

cfg.attack.attacker_id = [-1]

to avoid ValueError.

Thanks for your reply. However, I need to simulate multi-client attack so that I have to list all the attack clients' id in a list (e.g. [1, 2, 3, 4, 5]).

Yes, you should change the type of cfg.attack.attacker_id from int to list to avoid ValueError: Type mismatch (<class 'int'> vs. <class 'list'>) with values (-1 vs. [1, 2, 3, 4, 5]) for config key: attack.attacker_id.

dalqattan commented 1 year ago

cfg.attack.attacker_id = [-1]

Hi I did it but still got same error.

Do you have any idea?

Thanks

rayrayraykk commented 1 year ago

cfg.attack.attacker_id = [-1]

Hi I did it but still got same error.

Do you have any idea?

Thanks

Try to re-install FS with editable mode via pip install -e .

dalqattan commented 1 year ago

@rayrayraykk Hi I re-installed it. But still I got a sequence of error messages starting from poisoning_data.py and server_attacker.py and then fed_runner.py . I tried to fix by converting commands to read from a list but it doesn't work it seems FS has not been configured to read from a list of id attacker.

Osier-Yi commented 1 year ago

@rayrayraykk Hi I re-installed it. But still I got a sequence of error messages starting from poisoning_data.py and server_attacker.py and then fed_runner.py . I tried to fix by converting commands to read from a list but it doesn't work it seems FS has not been configured to read from a list of id attacker.

try: change '==' to 'in' in line https://github.com/alibaba/FederatedScope/blob/dd5f87bb47bbb1c95302214aeed5d7185692b7ee/federatedscope/attack/auxiliary/poisoning_data.py#L284 since ctx.attack.attacker_id is now a list type not the original int type.

Please double check other files that use attacker_id.

dalqattan commented 1 year ago

@rayrayraykk Hi I re-installed it. But still I got a sequence of error messages starting from poisoning_data.py and server_attacker.py and then fed_runner.py . I tried to fix by converting commands to read from a list but it doesn't work it seems FS has not been configured to read from a list of id attacker.

try: change '==' to 'in' in line

https://github.com/alibaba/FederatedScope/blob/dd5f87bb47bbb1c95302214aeed5d7185692b7ee/federatedscope/attack/auxiliary/poisoning_data.py#L284

since ctx.attack.attacker_id is now a list type not the original int type. Please double check other files that use attacker_id.

Yes, I did already.

And then got this error

File "c:\temp\federatedscope-backdoor-bench\federatedscope\attack\worker_as_attacker\server_attacker.py", line 68, in broadcast_model_para
    self._cfg.attack.attacker_id - 1)
TypeError: unsupported operand type(s) for -: 'list' and 'int'

I fixed it with

[x - 1 for x in self._cfg.attack.attacker_id])

Then

File "c:\temp\federatedscope-backdoor-bench\federatedscope\attack\worker_as_attacker\server_attacker.py", line 75, in broadcast_model_para 'starting the poisoning round: {:d}, the attacker ID: {:d}' TypeError: unsupported format string passed to list.__format_

And then

File "c:\temp\federatedscope-backdoor-bench\federatedscope\core\fed_runner.py", line 273, in _handle_msg self.client[each_receiver].msg_handlers[msg.msg_type](msg) TypeError: unhashable type: 'list' `