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.