GithubHelp home page GithubHelp logo

fraction_fit 怎么动态变化 about flower HOT 8 OPEN

buaaYYC avatar buaaYYC commented on June 11, 2024
fraction_fit 怎么动态变化

from flower.

Comments (8)

helin0815 avatar helin0815 commented on June 11, 2024

在flwr/server/server.py的代码里好像有地方可以修改,但是也需要改代码

from flower.

buaaYYC avatar buaaYYC commented on June 11, 2024

在flwr/server/server.py的代码里好像有地方可以修改,但是也需要改代码

是的,但是不知道怎么修改这个策略 ,现在我看都是一个固定值,没法和训练轮数挂钩。
我现在能想到的方法就是写两个模拟函数fl.simulation.start_simulation,比如前10epochs,客户端选择10个;后10个epochs训练再启动一个模拟函数,选择20个客户端,他的模型参数用第一次训练的参数。

from flower.

helin0815 avatar helin0815 commented on June 11, 2024

在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的启动是不是每轮都会重新分配一下,你可以试试

from flower.

buaaYYC avatar buaaYYC commented on June 11, 2024

在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 ,感觉可能解决这个问题
image
image

from flower.

helin0815 avatar helin0815 commented on June 11, 2024

在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 ,感觉可能解决这个问题 image image

你使用flower框架是在做什么呢,我现在的研究方向是联邦学习的差分隐私

from flower.

buaaYYC avatar buaaYYC commented on June 11, 2024

我研究联邦学习的客户端选择策略

from flower.

yan-gao-GY avatar yan-gao-GY commented on June 11, 2024

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.

from flower.

buaaYYC avatar buaaYYC commented on June 11, 2024

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.

"Thank you very much. Your answers have been very helpful to me."

from flower.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.