Skip to content

Issue in _calculate_model_delta() in federatedscope/core/workers /client.py #787

@Pengxin-Guo

Description

@Pengxin-Guo

The _calculate_model_delta() may need to be modified to the code below to satisfy running pFL, since the updated_model is a subset of the init_model:

def _calculate_model_delta(self, init_model, updated_model):
    if not isinstance(init_model, list):
        init_model = [init_model]
        updated_model = [updated_model]

    model_deltas = list()
    for model_index in range(len(init_model)):
        # model_delta = copy.deepcopy(init_model[model_index])
        # for key in init_model[model_index].keys():
        #     model_delta[key] = updated_model[model_index][
        #         key] - init_model[model_index][key]
        
        # added by me, for pFL
        model_delta = copy.deepcopy(updated_model[model_index])
        for key in updated_model[model_index].keys():
            model_delta[key] = updated_model[model_index][
                key] - init_model[model_index][key]
        model_deltas.append(model_delta)

    if len(model_deltas) > 1:
        return model_deltas
    else:
        return model_deltas[0]

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions