Open buaaYYC opened 9 months ago
在flwr/server/server.py的代码里好像有地方可以修改,但是也需要改代码
在flwr/server/server.py的代码里好像有地方可以修改,但是也需要改代码
是的,但是不知道怎么修改这个策略 ,现在我看都是一个固定值,没法和训练轮数挂钩。 我现在能想到的方法就是写两个模拟函数fl.simulation.start_simulation,比如前10epochs,客户端选择10个;后10个epochs训练再启动一个模拟函数,选择20个客户端,他的模型参数用第一次训练的参数。
在flwr/server/server.py的代码里好像有地方可以修改,但是也需要改代码
是的,但是不知道怎么修改这个策略 ,现在我看都是一个固定值,没法和训练轮数挂钩。 我现在能想到的方法就是写两个模拟函数fl.simulation.start_simulation,比如前10epochs,客户端选择10个;后10个epochs训练再启动一个模拟函数,选择20个客户端,他的模型参数用第一次训练的参数。
感觉你这个方法也可以,或者你可以试试把fraction_fit这个值从某个配置文件(比如/opt/fraction_fit.txt)中读取,然后在训练10轮以后修改/opt/fraction_fit.txt的内容,然后server.py再去读取这个内容?我不太确定server的启动是不是每轮都会重新分配一下,你可以试试
在flwr/server/server.py的代码里好像有地方可以修改,但是也需要改代码
是的,但是不知道怎么修改这个策略 ,现在我看都是一个固定值,没法和训练轮数挂钩。 我现在能想到的方法就是写两个模拟函数fl.simulation.start_simulation,比如前10epochs,客户端选择10个;后10个epochs训练再启动一个模拟函数,选择20个客户端,他的模型参数用第一次训练的参数。
感觉你这个方法也可以,或者你可以试试把fraction_fit这个值从某个配置文件(比如/opt/fraction_fit.txt)中读取,然后在训练10轮以后修改/opt/fraction_fit.txt的内容,然后server.py再去读取这个内容?我不太确定server的启动是不是每轮都会重新分配一下,你可以试试
好的我试一试,我刚刚看到一个参数on_fit_config_fn ,感觉可能解决这个问题
在flwr/server/server.py的代码里好像有地方可以修改,但是也需要改代码
是的,但是不知道怎么修改这个策略 ,现在我看都是一个固定值,没法和训练轮数挂钩。 我现在能想到的方法就是写两个模拟函数fl.simulation.start_simulation,比如前10epochs,客户端选择10个;后10个epochs训练再启动一个模拟函数,选择20个客户端,他的模型参数用第一次训练的参数。
感觉你这个方法也可以,或者你可以试试把fraction_fit这个值从某个配置文件(比如/opt/fraction_fit.txt)中读取,然后在训练10轮以后修改/opt/fraction_fit.txt的内容,然后server.py再去读取这个内容?我不太确定server的启动是不是每轮都会重新分配一下,你可以试试
好的我试一试,我刚刚看到一个参数on_fit_config_fn ,感觉可能解决这个问题
你使用flower框架是在做什么呢,我现在的研究方向是联邦学习的差分隐私
我研究联邦学习的客户端选择策略
Hi, this can be done by overriding the configure_fit
function of the strategy.
E.g.,
def configure_fit(
self, server_round: int, parameters: Parameters, client_manager: ClientManager
) -> List[Tuple[ClientProxy, FitIns]]:
"""Configure the next round of training."""
config = {}
if self.on_fit_config_fn is not None:
# Custom fit config function provided
config = self.on_fit_config_fn(server_round)
fit_ins = FitIns(parameters, config)
# Sample clients
sample_size, min_num_clients = self.num_fit_clients(
client_manager.num_available()
)
clients = client_manager.sample(
num_clients=sample_size, min_num_clients=min_num_clients
)
# Sample the clients sequentially given server_round
sampled_idx = (server_round - 1) % len(clients)
sampled_clients = [clients[sampled_idx]]
# Return client/config pairs
return [(client, fit_ins) for client in sampled_clients]
The above code allows to sequentially sample the clients given server_round
. You could do whatever clients sampling based on the given server_round
.
Hi, this can be done by overriding the
configure_fit
function of the strategy. E.g.,def configure_fit( self, server_round: int, parameters: Parameters, client_manager: ClientManager ) -> List[Tuple[ClientProxy, FitIns]]: """Configure the next round of training.""" config = {} if self.on_fit_config_fn is not None: # Custom fit config function provided config = self.on_fit_config_fn(server_round) fit_ins = FitIns(parameters, config) # Sample clients sample_size, min_num_clients = self.num_fit_clients( client_manager.num_available() ) clients = client_manager.sample( num_clients=sample_size, min_num_clients=min_num_clients ) # Sample the clients sequentially given server_round sampled_idx = (server_round - 1) % len(clients) sampled_clients = [clients[sampled_idx]] # Return client/config pairs return [(client, fit_ins) for client in sampled_clients]
The above code allows to sequentially sample the clients given
server_round
. You could do whatever clients sampling based on the givenserver_round
.
"Thank you very much. Your answers have been very helpful to me."
如果启动了flower server后,客户端一直没有连接,可以手动停止server吗?
如果启动了flower server后,客户端一直没有连接,可以手动停止server吗?
你具体是指什么?启动服务端后再启动客户端,客户端连不上服务端的话,当然是可以手动停止server的,停止了以后你再去排查一下你的代码哪里不对导致客户端连不上
What is your question?
Hello, I have a requirement now. I want the number of clients to participate in training to be different in different epochs. How should I modify the strategy? Thank you.