Server round executing wrong client

Hello, I am running fedper baseline with some modifications to make a multi-label image classificator.

I am executing it for 4 clients (0,1,2,3) and I am using two datasets, water_dataset with 179 classes and sky_dataset with 168 classes.

For clients 0 and 1 I am using water_dataset and on the personalized layers I am setting the output layer to 179, for clients 2 and 3 I am setting 168.

I am printing the client_id in the training loop and what I can see is that every time any client is executed client 0 is also executed with the same dataset.

ROUND: 1

Client id: 0

Client id: 0

Client id: 1

Client id: 0

Client id: 2

Client id: 0

-> and here I am getting a error saying that “Target size (torch.Size([64, 168])) must be the same as input size (torch.Size([64, 179]))”

I have no clue why the training loop for client 0 is being executed every time.

Any ideas?

Thank you!

Hello, I found the issue.

On the class resnet_model.py, the create model function looks like this:

def _create_model(self) -> nn.Module:
        """Return MobileNet-v1 model to be splitted into head and body."""
        try:
            return ResNet(
                num_head_layers=self.config["model"]["num_head_layers"],
                num_classes=self.config["model"]["num_classes"],
                client_id=self.client_id
            ).to(self.device)
        except AttributeError:
            self.device = self.config["server_device"]
            return ResNet(
                num_head_layers=self.config["model"]["num_head_layers"],
                num_classes=self.config["model"]["num_classes"],
            ).to(self.device)

And the init looks like this:

class ResNetModelManager(ModelManager):
    """Manager for models with Body/Head split."""

    def __init__(
        self,
        client_save_path: Optional[str],
        client_id: int,
        config: DictConfig,
        trainloader: DataLoader,
        testloader: DataLoader,
        learning_rate: float = 0.01,
    ):
        """Initialize the attributes of the model manager.

        Args:
            client_save_path: Path to save the client state.
            client_id: The id of the client.
            config: Dict containing the configurations to be used by the manager.
            trainloader: DataLoader containing the train data.
            testloader: DataLoader containing the test data.
            learning_rate: Learning rate for the optimizer.
        """
        super().__init__(
            model_split_class=ResNetModelSplit,
            client_id=client_id,
            config=config,
        )
        self.client_save_path = client_save_path
        self.trainloader, self.testloader = trainloader, testloader
        self.device = self.config["server_device"]
        self.learning_rate = learning_rate

When ResNetModelManager is created it calls the init for the parent class ModelManager which makes a call to create model:

class ModelManager(ABC):
    """Manager for models with Body/Head split."""

    def __init__(
        self,
        client_id: int,
        config: DictConfig,
        model_split_class: Type[Any],  # ModelSplit
    ):
        """Initialize the attributes of the model manager.

        Args:
            client_id: The id of the client.
            config: Dict containing the configurations to be used by the manager.
            model_split_class: Class to be used to split the model into body and head\
                (concrete implementation of ModelSplit).
        """
        super().__init__()

        self.client_id = client_id
        self.config = config
        self._model = model_split_class(self._create_model())

So it executes the code and tries to add the self.device but it does not exists yet as the super.init is called before the device is instantiated so it launch a error and then enters the second block where self.device is set and ResNet is called but I didn’t set the client_id there so it was using the default value 0 and that is where the 0 comes from.

The problem was solved by also adding the client_id to the ResNet call in the except.