Learning to Collaborate Over Graphs: A Selective Federated Multi-Task Learning Approach The work is funded by the European Union through the project 6G-INTENSE (G.A no. 101139266). Ahmed Elbakary, Chaouki Ben Issaid, Mehdi Bennis Abstract We present a novel federated multi-task learning method that leverages cross-client similarity to enable personalized learning for each client. To avoid transmitting the entire model to the parameter server, we propose a communication-efficient scheme that introduces a feature anchor, a compact vector representation that summarizes the features learned from the client’s local classes. This feature anchor is shared with the server to account for local clients’ distribution. In addition, the clients share the classification heads, a lightweight linear layer, and perform a graph-based regularization to enable collaboration among clients. By modeling collaboration between clients as a dynamic graph and continuously updating and refining this graph, we can account for any drift from the clients. To ensure beneficial knowledge transfer and prevent negative collaboration, we leverage a community detection-based approach that partitions this dynamic graph into homogeneous communities, maximizing the sum of task similarities, represented as the graph edges’ weights, within each community. This mechanism restricts collaboration to highly similar clients within their formed communities, ensuring positive interaction and preserving personalization. Extensive experiments on two heterogeneous datasets demonstrate that our method significantly outperforms state-of-the-art baselines. Furthermore, we show that our method exhibits superior computation and communication efficiency and promotes fairness across clients. I Introduction Federated Learning (FL) [ 1 ] has emerged as a significant paradigm in distributed machine learning, leveraging advances in communication networks and machine learning, particularly the success of deep learning methods [ 2 ] . By enabling multiple devices or organizations to train models collaboratively without centralizing the data, FL preserves privacy and reduces the communication costs of gathering all the data in a single data center, making it particularly appealing for applications in sensitive domains such as healthcare [ 3 ] , finance [ 4 ] , and applications involving mobile devices [ 5 ] , or Industrial Internet of Things (IIoT) [ 6 ] . While standard FL aims to learn a single global model for all clients, this approach is often suboptimal for scenarios requiring tailored and personalized models. A primary challenge arises from the inherent heterogeneity of client data, leading to significant distribution shifts that traditional FL methods struggle to handle effectively without careful algorithmic design [ 7 ] . Although FedAvg and similar methods may perform adequately in relatively homogeneous environments, their performance often degrades under non-independent and identically distributed (non-IID) settings [ 8 , 9 ] . This limitation becomes particularly pronounced when the models are expected to perform across varied tasks or domains exhibiting substantial differences in underlying data distributions [ 10 ] . For instance, in a cross-silo FL setting involving different financial institutions, a collaboratively trained fraud detection model [ 11 , 12 ] might fail to account for significant differences in fraud patterns across regions or countries. These discrepancies can manifest in diverse ways, including seasonal variations or distinct behavioral patterns linked to fraudulent activities. Consequently, a standard FL approach would face difficulties in accommodating such diversity across data silos due to shifts in the underlying data distribution and the specific characteristics of the local data. Personalized Federated Learning (PFL) offers a framework to address the challenge of data heterogeneity by aiming to learn a personalized model for each client [ 13 , 14 ] . PFL approaches typically frame the problem as optimizing a set of local objectives, tailored to each participant client. The potential for knowledge transfer across different machine learning tasks, even those with seemingly limited direct overlap, stems from the observation that they often share common underlying structures or computational primitives [ 15 ] . These primitives, although not always readily apparent, can be exploited by techniques like transfer learning or knowledge distillation [ 16 ] , enabling tasks with limited overlap to benefit from each other. Multi-task learning (MTL) [ 17 ] is another paradigm explicitly designed to leverage such shared primitives among different tasks. This observation is particularly valuable in heterogeneous FL environments, where data distributions vary significantly across clients, as it provides a mechanism to balance the benefits of global knowledge sharing with the necessity of local model adaptability. Federated Multi-Task Learning (FMTL) extends the concepts of MTL to the FL setting, allowing clients to learn task-specific personalized models while exploiting shared structure and transferring knowledge across related tasks. By modeling each client’s learning problem as a distinct task, FMTL facilitates personalized learning tailored to each client’s local data distribution while promoting knowledge transfer through collaboration [ 18 ] . Existing FMTL strategies often achieve this through mechanisms such as shared model components (e.g., feature extractors), explicit modeling of task relationships, and graph-based regularization techniques that structure collaboration based on inferred similarities between clients. While graph-based regularization has become a popular approach in FMTL [ 19 ] , several significant challenges remain. A key challenge is the construction of the task similarity graph itself, which is crucial for quantifying the potential for beneficial collaboration between clients. Existing works often assume predefined or heuristically determined relationships, which may not accurately capture the complex and evolving similarities observed in real-world heterogeneous FL scenarios. Furthermore, even when a similarity graph is used, collaborating with clients that are not sufficiently similar can lead to negative knowledge transfer, degrading individual client performance despite the intention of promoting collaboration [ 20 ] [ 21 ] . Ensuring that collaboration is consistently positive and beneficial is difficult but essential for robust personalized performance. To address these challenges, we propose a novel communication-efficient FMTL method that not only dynamically constructs the task similarity graph but also employs a strategic mechanism to ensure positive collaboration. Specifically, we introduce a community detection-based approach to facilitate the formation of communities among highly similar clients, guaranteeing that knowledge transfer occurs primarily within groups where it is most likely to be beneficial, thereby enhancing personalization and robustness. Our method and the steps involved in it are depicted in figure 1 . The contributions of the paper are as follows • We propose SFMTL-Graph, a novel and communication-efficient FMTL algorithm designed for high-performance personalized learning in heterogeneous environments, enabling clients to leverage knowledge from similar peers. • We formulate a community detection-based approach for dynamically forming client communities based on learned task similarity. Collaboration is strategically restricted within these communities to ensure a positive and beneficial knowledge transfer among clients. • We conduct extensive experimental evaluations on two different datasets to analyze the proposed algorithm, quantifying its computation and communication costs. We also investigate key aspects such as fairness and the dynamic nature of the method. II Related Work Fig. 1 : A schematic view of our proposed method and the details of the steps involved in each stage of the FL standard computation-communication scheme. In the first step (A), clients train a local model with a feature anchor loss and send the classification head \bm{\phi} and the feature anchor \bm{h} to the PS. At the PS, we construct the similarity graph and apply the Louvain method to construct communities of similar clients. After that, we perform an aggregation of both the models, using regularized Laplacian, and the feature anchors using an average of the anchors. All the aggregations are done per community. The final step is to return those regularized models and aggregated feature anchors to the clients. II-A Federated Learning Federated Averaging (FedAvg) [ 1 ] allows different clients to perform local updates for multiple rounds before aggregating the updated local models into a global one. While FedAvg is effective under the assumption that all clients’ data distributions are IID, it performs poorly when this assumption is violated. To address the challenges posed by non-IID data distributions, various methods have been proposed. For instance, SCAFFOLD [ 7 ] incorporates variance reduction techniques to control the divergence of local model updates, allowing FedAvg to achieve more robust performance under distribution shifts. In a similar line of work, Haddadpour et al. [ 22 ] proposed using gradient tracking combined with communication compression to simultaneously reduce communication costs and the adverse effects of data heterogeneity. However, a fundamental limitation inherent to methods that train a single global model for all clients lies in their inherent inability to fully personalize the learned model to meet the specific requirements and local data characteristics of individual participant clients. II-B Personalized Federated Learning PFL is a rapidly evolving area specifically aimed at addressing the limitations of learning a single global model by enabling each client to learn a personalized model. PFL encompasses a wide range of algorithms and design choices. One promising class of techniques addresses the PFL problem by decoupling the client model into a shared component, typically a feature extractor, and a personalized component, typically a classifier head. These methods aim to align the shared components to learn a common, useful representation space while allowing clients to personalize their classification heads for their specific local tasks. Building upon this concept, Xu et al. [ 23 ] propose computing a static feature centroid locally for each class in a client’s dataset, summarizing learned features. This centroid is transmitted to the server along with the updated client’s model. The server aggregates these centroids to form a global centroid, which is then broadcast back to clients, allowing them to align their local feature extractors towards this global representation while maintaining personalized classifiers. Extending this direction, Zhou et al. [ 24 ] employ a learned feature anchor instead of a static centroid and perform feature alignment between the global (averaged) feature anchor and the local feature extractor. It also leverages classifier calibration to prevent deviations across clients. While these approaches significantly advance model personalization, a notable limitation is the substantial communication overhead they often incur, typically requiring clients to share updates for the full local model parameters in addition to the feature summary vector (centroid or anchor). II-C Federated Multi-Task Learning FMTL offers another powerful perspective for addressing PFL challenges by explicitly modeling each client’s learning problem as a distinct task. This framework provides flexibility to adapt concepts from centralized MTL to the FL setting. Early work in FMTL, such as that by Smith et al. [ 25 ] , formulated the problem using regularization functions defined by a similarity matrix to capture relationships between clients’ tasks. The authors in [ 26 ] proposed an Expectation-Maximization (EM)-based algorithm for FMTL, treating each client’s data distribution as a mixture. However, similar to many PFL algorithms discussed earlier, these early FMTL methods often incur significant communication costs, hindering their reliability in resource-constrained environments. Another common approach for FMTL employs Laplacian regularization, aligning locally learned models towards a common space based on clients’ similarities [ 19 ] . More recently, the authors in [ 27 ] explored sheaf-based methods, extending graph Laplacian concepts to model relationships between client models via a sheaf over the graph, a technique capable of handling heterogeneity in model architectures. However, this sheaf-based approach appears better suited for cross-silo settings with more computational resources than typical resource-constrained edge devices. While promising, graph-based FMTL methods face two significant challenges. First, determining the appropriate similarity matrix or graph structure dynamically to accurately reflect the relationships between clients. Existing work often relies on predefined relationships or simple and static heuristic approaches, which may fail to capture the dynamic and complex nature of real-world client similarities. Second, ensuring that the graph structure facilitates positive knowledge transfer and actively prevents performance degradation caused by collaboration with dissimilar tasks. We address these challenges by dynamically adapting the similarity graph over communication rounds using a similarity-aware metric and by introducing a community detection-based approach to ensure that collaboration occurs only among highly similar clients. II-D Community detection Community detection is an algorithmic framework that can identify a set of communities and underlying groups in complex networks [ 28 ] . The overall objective of a community detection method is to find a densely connected subgraph, where each node in the subgraph is highly similar to other members of the community. Community detection algorithms can be beneficial, especially in the case of heterogeneous federated learning. Consider the case where we model the problem using a similarity graph, where each node is a client and each edge is a weight of similarity between those clients. Such a system is highly non-homogeneous, which means that the similarity graph does not form a single coherent group, but a set of distinct ones. In the world of FL, community detection has been a key tool in various works, often as a tool for identifying a set of relevant clients and learning a single model per such a community [ 29 ] . We extend this idea to maintain a coherent and positive collaboration among the detected communities. In summary, there is a need for a communication-efficient FMTL approach that can dynamically capture client similarities and strategically manage collaboration to ensure positive knowledge transfer, thereby addressing the limitations of existing global FL, PFL, and FMTL methods. Our proposed method builds upon the strengths of FMTL while tackling these specific challenges using a novel combination of communication-efficient client representations, dynamic graph construction, and a community detection-based mechanism. III System Model and Problem Formulation We consider a network of K clients, where the set of all clients is defined as \mathcal{N}=\{1,\dots,K\} . Each client communicates only with the PS, which is responsible for coordinating the collaborative learning process. Each client k is associated with a distinct task t_{k} and holds a local dataset (\bm{X}_{k},\bm{y}_{k}) of n_{k} samples, where \bm{X}_{k} represents the input data and \bm{y}_{k} the corresponding labels. The client’s local objective is to train a model \bm{w}_{k}\in\mathbb{R}^{d} by minimizing a local loss function f_{k}({\bm{w}_{k}}):\mathbb{R}^{d}\to\mathbb{R} for R local rounds. Each client k has a total of n_{k} samples. At each communication round t , the PS randomly samples a subset of clients \mathcal{S}^{(t)}\subseteq\mathcal{N} to participate in the training. Let m^{(t)}=\sum_{k\in\mathcal{S}^{(t)}}n_{k} be the total number of training samples across all participant clients in round t . FMTL aims to train these local models to be highly personalized while simultaneously enabling beneficial knowledge transfer across related tasks. A common approach for FMTL frames the problem as minimizing a global objective function that balances local task performance with regularization terms encouraging collaboration \displaystyle\min_{\bm{W}}J(\bm{W})=F(\bm{W)}+\lambda\mathcal{R}(\bm{W}), (1) where \bm{W}=[\bm{w}_{1}^{\top},\dots,\bm{w}_{K}^{\top}]\in\mathbb{R}^{dK} denotes the concatenated vector of model parameters from all K clients and \lambda\geq 0 is a regularization parameter controlling how much collaboration is encouraged. The function F is defined as \displaystyle F(\bm{W})=\frac{1}{K}\sum_{k=1}^{K}f_{k}(\bm{w_{k}}), (2) and the function \mathcal{R} is the regularization function that encourages clients to collaborate by regularizing the models’ weights into a closer space. A larger \lambda implies stronger regularization and encourages clients’ models to be more similar. When \lambda=0 , this objective simplifies to independent local training, which does not leverage any shared knowledge. Inspired by the concept that learning tasks often share an underlying structure [ 15 ] , we assume a hidden relationship between clients’ tasks and model this relationship using a weighted undirected graph \mathcal{G}^{(t)}=(\mathcal{N},\mathcal{E}^{(t)},\Psi^{(t)}) , where \mathcal{N} is the set of clients, \mathcal{E}^{(t)}=\{(k,\ell)\mid k,\ell\in\mathcal{N},k\neq\ell\} represents the set of all possible edges between distinct clients, and \Psi^{(t)} is a function assigning non-negative edge weights a_{k\ell}^{(t)}\geq 0 to each edge (k,\ell) . These weights quantify the strength of the relationship or similarity between tasks k and \ell . The graph, and thus the adjacency matrix \bm{A}^{(t)} with entries a_{k\ell}^{(t)} , is built and dynamically updated at each communication round based on metrics reflecting client data and model similarity. We assume \bm{A}^{(t)} is symmetric, i.e., a_{k\ell}^{(t)}=a_{\ell k}^{(t)} . For the graph \mathcal{G}^{(t)} , the set of neighboring clients of a client k is defined as \mathcal{N}_{k}=\mathcal{N}\setminus\{k\} . For this graph \mathcal{G} , we define the degree matrix \bm{D}=\operatorname{diag}[\delta_{1},\ldots,\delta_{K}]\in\mathbb{R}^{K\times K} , where \delta_{k}=\sum_{\ell\in\mathcal{N},\ell\neq k}a_{k\ell} is the weighted degree of client k . The unnormalized graph Laplacian is then defined as \bm{L}=\bm{D}-\bm{A} . To apply graph regularization across all dimensions of the model parameters, we use the extended Laplacian matrix \bm{\widetilde{L}}=\bm{L}\otimes\bm{I}_{d} , where \otimes is the Kronecker product and \bm{I}_{d} is the d\times d identity matrix. An established method to employ graph-based regularization in FMTL is to set the regularization function \mathcal{R} as the Laplacian regularization, defined as \displaystyle\mathcal{R}(\bm{W})=\bm{W}^{T}\bm{\widetilde{L}}\bm{W}=\frac{1}{2}\sum_{k=1}^{K}\sum_{\ell\in\mathcal{N}_{k}}a_{k\ell}\left\|\bm{w}_{k}-\bm{w}_{\ell}\right\|^{2}, (3) where the norm \left\|\cdot\right\| represents the Euclidean norm of the difference between model parameter vectors. Each model \bm{w}_{k} can be conceptually split into two components: a base backbone or feature extractor \bm{\theta}_{k} and a task-specific head \bm{\phi}_{k} , such that \bm{w}_{k}=\{\bm{\theta}_{k},\bm{\phi}_{k}\} . The classification head \bm{\phi}_{k} is typically designed to capture the unique information of each client’s task, often mapping features learned by the backbone to client-specific output logits. For instance, in convolutional neural networks (CNNs), the classification head is commonly a linear layer applied after the final feature maps. Conversely, the backbone \bm{\theta}_{k} learns lower-level or intermediate feature representations that are often more similar across clients, particularly those with related tasks. Finally, we define a feature anchor \bm{h}_{k}\in\mathbb{R}^{C_{k}\times d_{h}} for each client k , where C_{k} is the number of local classes at client k and d_{h} is the dimension of the feature extractor’s output. This anchor is a prototype summarizing the learned features for class c at client k . We assume that all clients have the same number of local classes C_{k} . This representation consists of a d_{h} -dimensional vector for each local class, summarizing the learned features for that class. IV Federated Multi-Task Learning over graphs Algorithm 1 SFMTL-Graph 1: Parameters: learning rate \eta , number of local iterations R , hyperparameters (\lambda,\alpha,\eta) . 2: Initialize: \bm{w_{k}}^{0} , \bm{h}^{(0)}\sim\mathcal{N}(0,I),\mathcal{C}=\{\} 3: for communication round t=0 to T do 4: Server Sample a subset \mathcal{S}^{(t)} to initiate local training. 5: if t>0 then 6: send \bm{h}^{(t)}_{{c}_{j}} and \bm{\phi}_{k}^{(t)} to client k ; \forall k\in c_{j} and \forall j\in c . 7: end if 8: for client k\in\mathcal{S}^{(t)} do 9: if t>0 then 10: Initialize classification head \bm{\phi}_{k,0}^{(t)}\leftarrow\bm{\phi}_{k}^{(t)} 11: Initialize local feature anchor \bm{h}_{k}^{(t)}\leftarrow\bm{h}^{(t)}_{{c}_{j}};k\in\mathcal{C}_{j} . 12: end if 13: for local iterations r=0 to R do 14: Compute the Supervised loss f_{k}(\bm{w}_{k,r}^{(t)}) . 15: Compute the anchor loss g_{k}(\bm{\theta}^{(t)}_{k}) as in ( 5 ). 16: Update local model using a Mini-batch GD step \bm{w}_{k,r+1}^{(t)}\leftarrow\bm{w}_{k,r}^{(t)}-\eta\nabla\mathcal{L}_{k}(\bm{w}_{k,r}^{(t)}) . 17: end for 18: Send \bm{\phi}^{(t)}_{k,R} and \bm{h}_{k,R}^{(t)} to the server. 19: end forOn Server 20: If Client k\notin S^{(t)} , set \bm{w}_{k}^{(t+1)}=\bm{w}_{k}^{(t)} . 21: for Client (k,\ell)\in\mathcal{S}^{(t)} do 22: Calculate the similarity weights a_{k,\ell} using ( 7 ). 23: end for 24: Solve the maximization problem ( 12 ) using Algorithm 2 to get \mathcal{C}^{(t)}=\{\mathcal{C}_{1}^{(t)},\mathcal{C}_{2}^{(t)},\dots\} . 25: Update the feature anchor based on ( 14 ). 26: Update the classification heads using ( 15 ), \forall(k,\ell)\in\mathcal{C}_{j} . 27: end for Algorithm 2 Louvain Algorithm 1: Parameters: Weighted graph \mathcal{G} with weights a_{k,\ell} 2: Initialize: each node in its own community 3: repeat 4: improvement \leftarrow true 5: while improvement do 6: improvement \leftarrow false 7: for all k\in\mathcal{G} (in random order) do 8: c_{k}\leftarrow current community of k 9: \Delta Q_{\max}\leftarrow 0 , c_{k}^{\ast}\leftarrow c_{k} 10: for all \ell\in\mathcal{N}_{k} do 11: c_{\ell}\leftarrow community of \ell 12: Compute \Delta Q (Eq.( IV-B )) if k moved to c_{\ell} 13: if \Delta Q>\Delta Q_{\max} then 14: \Delta Q_{\max}\leftarrow\Delta Q 15: c_{k}^{\ast}\leftarrow c_{\ell} 16: end if 17: end for 18: if c_{k}^{\ast}\neq c_{k} then 19: Move k to c_{k}^{\ast} 20: improvement \leftarrow true 21: end if 22: end for 23: end while 24: Coarsen \mathcal{G} : 25: Nodes \rightarrow communities, 26: Edge a_{k,\ell}\rightarrow sum over inter-community weights 27: Update \mathcal{G} accordingly 28: until \Delta Q negligible 29: return Final community labels IV-A Task Similarity Graph Construction Based on the general formulation ( 1 ), our approach implicitly drives collaboration through a personalized local training objective and a server-side aggregation mechanism informed by client similarity and community structure. We formulate our problem based on the following regularization function \displaystyle\mathcal{R}(\bm{\Theta},\bm{\Phi})=\sum_{k=1}^{K}\Bigg[ \displaystyle g_{k}\left({\bm{\theta}_{k}}\right)+\sum_{\ell\in\mathcal{C}_{k}}a_{k,\ell}\left\|\bm{\phi}_{k,R}-\bm{\phi}_{\ell,R}\right\|^{2}\Bigg], (4) where \mathcal{C}_{k} represents the community to which client k belongs (to be defined later in Section IV-B ), \bm{\Theta}=[\bm{\theta}_{1}^{\top},\dots,\bm{\theta}_{k}^{\top}] , \bm{\Phi}=[\bm{\phi}_{1}^{\top},\dots,\bm{\phi}_{k}^{\top}] , and g_{k} is the feature anchor loss of client k , which encourages the feature extractor \bm{\theta}_{k} to produce representations close to the current feature anchors \bm{h}_{k}^{(t)} . This alignment is done for each class c in the dataset \{\bm{h}_{k}^{(c)}\}_{c=1}^{C_{k}} . Specifically, g_{k} is defined as the mean squared error between features extracted from local data and the corresponding class anchors \displaystyle g_{k}\left(\bm{\theta}_{k}\right)=\left\|\bm{\theta}_{k,R}(x_{i})-\bm{h}_{k,R}^{(c)}\right\|^{2}, (5) where \bm{h}_{k,R}^{(c)}\in\mathbb{R}^{d_{h}} is the feature anchor of client k for local class c . This regularization ensures that we apply it to both the classification head and the feature extractor. We hypothesize that the representation that comes out of the feature extractor \bm{\theta}_{k} captures the client’s local data distribution better. Since sending this feature extractor to the server is not an ideal solution due to the communication cost, we need to find a balance between communication efficiency and performance. Instead of sending the whole model to the PS, we send a feature anchor that can capture these low-level details of the backbone feature extractor. The regularized update contains two parts, one that requires information exchange between clients and one that can be done locally. Hence, the regularization is carried out in two steps, the first at the client locally and the second at the server. To this end, at communication round t , we solve the following problem for each selected client \displaystyle\min_{\bm{w}_{k}}\mathcal{L}_{k}\left(\bm{w}_{k}\right)\triangleq\mathbb{E}_{(\bm{x},\bm{y})\in\mathcal{D}_{k}}\left[f_{k}(\bm{w}_{k})+\lambda g_{k}\left(\bm{\theta}_{k}\right)\right]. (6) This local optimization problem is solved by each selected client k\in\mathcal{S}^{(t)} using R steps of Mini-batch Gradient Descent (GD) or its variants. After R local steps, client k obtains updated model parameters \bm{w}_{k,R}^{(t)} consisting of the feature extractor \bm{\theta}_{k,R}^{(t)} and the classification head \bm{\phi}_{k,R}^{(t)} . To facilitate communication efficiency and server-side operations, client k then sends its updated classification head \bm{\phi}_{k,R}^{(t)} and its newly computed feature anchor \bm{h}_{k,R}^{(t)} to the server. Upon receiving the classification heads and feature anchors from all sampled clients in \mathcal{S}^{(t)} , the server constructs a weighted undirected similarity graph among these clients. For each pair of clients (k,\ell)\in\mathcal{S}^{(t)} , the similarity weight a_{k\ell}^{(t)} is computed as a combination of their classification head similarity and feature representation similarity \displaystyle a_{k\ell}^{(t)}=\alpha\cdot\operatorname{Sim}_{\text{head }}(k,\ell)+(1-\alpha)\cdot\operatorname{Sim}_{\mathrm{repr}}(k,\ell), (7) where \alpha\in[0,1] is a trade-off hyperparameter that balances how much importance to give to the representation similarity over the classification head similarity. The two terms measure similarity in both the classification head and the representations and are defined as \displaystyle\operatorname{Sim}_{\text{head }}(k,\ell)=\frac{1}{2}\sum_{\bm{h}\in\{\bm{h}_{k,R}^{(c)},\bm{h}_{\ell,R}^{(c)}\}}\operatorname{SimCos}(\bm{\phi}_{k}(\bm{h}),\bm{\phi}_{\ell}(\bm{h})). (8) Note that this expression is done for every class c of client k and client \ell . This measure quantifies how similarly the classification heads of clients k and \ell respond to the feature anchors from both clients \ell and k for shared classes c . In other words, it compares the logits produced by the two classification heads under the same input vector. This approach captures functional similarity. Initially, we considered using the negative L_{1} norm between the classification head parameters ( \bm{\phi}_{k},\bm{\phi}_{\ell} ) as a similarity measure. However, this approach quantifies parameter similarity, which does not always reflect functional similarity, i.e., how the heads actually behave. For instance, two clients’ classification heads might have significantly different parameter values but produce very similar outputs (logits) when applied to the same input features. Since our feature anchors ( \bm{h}_{k} ) are compact representations of learned features, a more relevant measure of head similarity is how similarly they process these key representations. This functional comparison, specifically comparing their outputs on inputs derived from the feature space, is better captured by the cosine similarity operator, \operatorname{SimCos}(\cdot,\cdot) , defined as \displaystyle\operatorname{SimCos}(\bm{z}_{k},\bm{z}_{\ell})=\frac{\bm{z}_{k}\cdot\bm{z}_{\ell}}{\|\bm{z}_{k}\|\|\bm{z}_{\ell}\|}, (9) where \bm{z}_{k} and \bm{z}_{\ell} are two arbitrary vectors of the same shape. To measure the similarity in the representation space between the two clients, we compare the two feature anchors of each local class directly using the \operatorname{SimCos} operator as follows \displaystyle\operatorname{Sim}_{\mathrm{repr}}(k,\ell)=\operatorname{SimCos}(\bm{h}_{k,R}^{(c)},\bm{h}_{\ell,R}^{(c)}). (10) To prevent negative weights between two clients, we take the maximum of the resultant weight and 0 , i.e., a_{k,\ell}^{(t)}=\max(a_{k,\ell}^{(t)},0) . Once the dynamic similarity graph \mathcal{G}^{(t)} is constructed, we formulate the problem as a community detection problem to determine beneficial collaboration structures. IV-B Community Formation Given the task similarity graph, we need to find the most similar communities, where collaboration is beneficial to the clients. In other words, we aim to generate a set of disjoint groups/communities of clients such that the similarity is maximized. This situation is almost equivalent to a clique partitioning problem [ 30 ] . A clique of a graph is a subset of vertices in a graph where every vertex in the subset is connected to every other vertex in the subset. A clique partitioning problem tries to find the smallest number of cliques in a graph such that every vertex in the graph is represented in exactly one clique. [ 31 ] . The resultant partitioning of the graph is a set of disjoint groups, each with its own set of nodes/clients, where each client belongs to one group/community only. Since finding the optimal partitioning of the graph \mathcal{G}^{(t)} is known to be an NP-hard problem, we aim to find a partition that maximizes the modularity score Q , which evaluates the quality of a graph partitioning by comparing the density of connections within communities to the density of connections between them [ 32 ] . For our weighted undirected graph \mathcal{G}^{(t)} with total weight M^{(t)}=\frac{1}{2}\sum_{k,\ell\in\mathcal{S}^{(t)},k\neq\ell}a_{k\ell}^{(t)} , the modularity Q^{(t)} is defined as \displaystyle Q^{(t)}=\frac{1}{2M^{(t)}}\sum_{(k,\ell)\in\mathcal{C}_{k}^{(t)}}\left[a_{k\ell}^{(t)}-\frac{\delta_{k}^{(t)}\delta_{\ell}^{(t)}}{2M^{(t)}}\right]\mathbb{I}\left(\mathcal{C}_{k}^{(t)},\mathcal{C}_{\ell}^{(t)}\right), (11) where \mathbb{I}\left(\mathcal{C}_{k}^{(t)},\mathcal{C}_{\ell}^{(t)}\right) is an indicator function that is 1 if k and \ell belongs to the same community and 0 otherwise. Maximizing Q^{(t)} identifies partitions where intra-community similarity is high compared to what would be expected by setting the similarity weights randomly. Since maximizing modularity exactly is computationally intractable for large graphs, we employ the Louvain algorithm [ 33 ] , a widely used heuristic for community detection that efficiently approximates the optimal partitioning for the problem \displaystyle\mathcal{C}^{(t)}_{\star}=\arg\max_{\mathcal{C}^{(t)}}Q^{(t)}, (12) where \mathcal{C}^{(t)}_{\star} is the optimal partitioning of the clients at round t . In other words, we seek the partitioning of the graph that maximizes the modularity. The Louvain algorithm is an iterative process that proceeds in phases. Initially, each client in \mathcal{S}^{(t)} is placed in its own singleton community. In the first phase, the algorithm iteratively considers each client and evaluates the modularity gain \Delta Q that would result from moving it to a neighboring client’s community. A client joins the community that yields the largest positive \Delta Q^{(t)} . This process is repeated until no moves can improve the total modularity. The modularity gain \Delta Q^{(t)} for moving client k into a community \mathcal{C}_{j}^{(t)} is given by \displaystyle\Delta Q^{(t)}=\left[\frac{\sum_{in}^{(t)}+\delta_{k,in}^{(t)}}{2M^{(t)}}-\left(\frac{\sum_{tot}^{(t)}+\delta_{k}^{(t)}}{2M^{(t)}}\right)^{2}\right] \displaystyle-\left[\frac{\sum_{in}^{(t)}}{2M^{(t)}}-\left(\frac{\sum_{tot}^{(t)}}{2M^{(t)}}\right)^{2}-\left(\frac{\delta_{k}^{(t)}}{2M^{(t)}}\right)^{2}\right], (13) where \sum_{in}^{(t)} is the sum of the weights of all the clients inside community \mathcal{C}_{j}^{(t)} , \sum_{tot}^{(t)} is the sum of the weights of all the neighbors of clients in the community \mathcal{C}_{j}^{(t)} , and \delta_{k,in}^{(t)} is the sum of the weights of all neighbors of k inside the community \mathcal{C}_{j}^{(t)} . We assign client k to the community \mathcal{C}_{j}^{(t)} for which ( IV-B ) is maximum. In the second phase, the identified communities are treated as new nodes in a condensed graph, and the first phase is reapplied. This process of optimization and graph refinement is repeated until no further increase in modularity is possible. Algorithm 2 summarizes the Louvain method. The output of this step is the partition \mathcal{C}^{(t)}=\{\mathcal{C}_{1}^{(t)},\mathcal{C}_{2}^{(t)},\dots\} of \mathcal{S}^{(t)} . One big advantage of the Louvain algorithm is that its time complexity is generally considered O(n\log n) , where n is the number of nodes of the graph, making it a practical and efficient way of finding a good partitioning of a graph. Once the communities are formed for the current round, the server facilitates collaboration within these communities. To quantify the importance and contribution of each client within its community, we use a simple and computationally efficient aggregation mechanism based on the formed communities. We aggregate the feature anchors weighted based on the number of local samples. For the classification heads, we perform a regularized update based on the update defined in ( 4 ), for all clients in the same community. We end up with one representation per community, where each client contribution or payoff is weighted by the number of data points such that \displaystyle\bm{h}_{\mathcal{C}_{j}}^{(t)}=\sum_{k\in\mathcal{C}_{j}}\frac{n_{k}}{m_{\mathcal{C}_{j}}^{(t)}}\bm{h}_{k}^{(t)}, (14) where m_{\mathcal{C}_{j}} is the total number of samples for all clients in community \mathcal{C}_{j} . For the classification heads, the server performs a regularized update for each client k\in\mathcal{S}^{(t)} as follows \displaystyle\bm{\phi}_{k}^{(t+1)}=\bm{\phi}_{k,R}^{(t)}-\lambda\tau\sum_{\ell\in\mathcal{C}_{j}}a_{k,\ell}^{(t)}(\bm{\phi}_{k,R}^{(t)}-\bm{\phi}_{\ell,R}^{(t)}), (15) where \tau is a server-side learning rate defined as \tau=\eta\times R . This update effectively pulls the head of client k\in\mathcal{C}_{j}^{(t)} towards the heads of other clients \ell in the same community \mathcal{C}_{j}^{(t)} , weighted by their similarity a_{k\ell}^{(t)} . The server then sends the aggregated feature anchor \bm{h}_{\mathcal{C}_{j}}^{(t)} , for the community \mathcal{C}_{j}^{(t)} client k belongs to, and client k ’s updated classification head \bm{\phi}^{(t+1)}_{k} back to each client k . For the next communication round (t+1) , each client initializes its local feature anchor as the community anchor received as follows \bm{h}_{k}^{(t+1)}=\bm{h}_{\mathcal{C}_{j}}^{(t)} , \forall k\in\mathcal{C}_{j} . This implicitly incorporates knowledge from similar clients via the shared representation space. The client also initializes its classification head for the next local training phase with the server-updated head using \bm{\phi}_{k,0}^{(t+1)}=\bm{\phi}_{k}^{(t+1)} . This process is repeated for T communication rounds until convergence. (a) (b) (c) Fig. 2 : Heterogeneous CIFAR-10 results (d) (e) (f) Fig. 3 : Rotated & Masked MNIST results V Experiments This section presents the experimental evaluation of SFMTL-Graph, detailing the setup, datasets, comparison with baseline methods, and analysis of its key characteristics including performance, communication and computation efficiency, dynamic behavior, and fairness. V-A Experimental Settings We evaluate the performance and effectiveness of our proposed SFMTL-Graph method using two distinct image classification datasets, designed to represent challenging heterogeneous FL scenarios: • Heterogeneous CIFAR-10 Dataset . A federated learning version of CIFAR-10 [ 34 ] where each client has a total of two classes to account for non-IIDness of the data, especially an extreme label distribution shift across clients. We consider 30 clients in total, and we assume the same model is used across all clients. Our model is a simple CNN with three convolutional layers and two fully connected layers. • Rotated & Masked MNIST . We consider 40 clients for this dataset. Based on the original MNIST dataset [ 35 ] , this dataset adds a feature distribution shift, also known as covariate shift, across clients by applying a rotation on the client’s data of \{0^{\circ},90^{\circ},180^{\circ},270^{\circ}\} degrees and then applying a 2\times 2 mask to the resultant rotated data. The model trained by the clients for this dataset is a CNN with two convolutional layers. All algorithms are implemented using PyTorch (version 2.5) and evaluated on a single Nvidia A100 GPU. The primary evaluation metric is average test accuracy across clients. Results are reported as the mean and standard deviation over five independent runs. The code implementation is publicly available at https://github.com/Ahmed-Khaled-Saleh/fmtl-graph/tree/main . The datasets used are preprocessed and can be automatically downloaded when reproducing the results. We compare our method against three different algorithms that span different categories: FedAvg [ 1 ] (typical FL), pFedMe [ 14 ] (PFL), and FedU [ 19 ] (FMTL). For local training, all clients perform R=5 local rounds using mini-batch GD with a batch size of 32 . An exception is pFedMe on Rotated & Masked MNIST, which uses 20 local rounds. Note that, to perform a fair comparison, we make 30 inner rounds for pFedMe to make the algorithm converge. Learning rates were tuned for each algorithm to achieve optimal performance: 0.05 for SFMTL-Graph and FedU, 0.005 for pFedMe, and 0.03 for FedAvg. The trade-off hyperparameter \alpha in SFMTL-Graph is set to 0.49 . We conducted hyperparameter tuning for all methods to ensure a fair comparison using their best respective configurations. V-B Performance Comparison Figures 2(b) and 2(a) present the average test accuracy and loss curves for the Heterogeneous CIFAR-10 dataset. Our method demonstrates significantly superior performance, achieving substantially higher accuracy than all baselines. The closest baseline to our method, FedU, is around 9\% less in accuracy. pFedMe’s performance is comparable to FedU’s, illustrating the strong capabilities of personalized and multi-task learning approaches in this highly heterogeneous setting. As expected, FedAvg exhibits the lowest performance, consistent with the known limitations of traditional FL methods on non-IID data. For Rotated & Masked MNIST, the learning curves are shown in Figures 2(d) and 2(e) . Our algorithm achieves the best performance, although the gap between the closest baseline (FedU) and our method is relatively lower than the CIFAR-10 case. This reduced gap may be attributed to the less extreme heterogeneity of the MNIST-based task compared to the CIFAR-10 scenario. Nevertheless, our algorithm is the best-performing method across both datasets. V-C Computation and Communication Costs This section quantifies the communication and computation costs of SFMTL-Graph and compares them against the baselines. We illustrate the trade-off between communication cost and performance by tracking the cumulative number of transmitted bits across communication rounds. We assume model parameters are represented using a 32-bit floating-point format. The feature anchor \bm{h}_{k} has dimensions C_{k}\times d_{h} , where d_{h}=512 . This means that for our method, sharing the feature anchor with the server where the client has two classes locally is equivalent to sending a lightweight vector of size 512\times 2=1024 . Additionally, clients transmit the classification head \bm{\phi}_{k} of size 512\times 10 . For the Heterogeneous CIFAR-10 dataset, SFMTL-Graph demonstrates significantly lower communication costs than all baselines as illustrated in Figure 2(c) . Over 200 communication rounds, our method transmits less than 10^{8} bits cumulatively. In contrast, FedU, FedAvg, and pFedMe transmit over 10^{10} bits, while achieving lower accuracy. The total cumulative bits transmitted by SFMTL-Graph over 200 rounds is even less than the transmission required by any baseline in a single communication round. This highlights the substantial communication efficiency of our method. For the Rotated & Masked MNIST, as illustrated in Figure 2(f) the communication cost of our method is still less than any other baseline. Our method transmits almost the same number of bits transmitted in the Heterogeneous CIFAR-10, 10^{8} bits. Regarding the computation cost, we measure the floating-point operations (FLOPS) of all algorithms based on the amount of local computations needed per round. Our method exhibits the same number of FLOPS as FedU and FedAvg, with around 1.22\times 10^{8} for Rotated and Masked MNIST and 1.25\times 10^{8} for the Heterogeneous CIFAR-10. In contrast, pFedMe’s local optimization, including its inner loops, required significantly more computation, has around 3.68\times 10^{9} and 1.5\times 10^{10} FLOPS for the same two datasets, respectively. This shows clearly that for the same number of local computations and under the same computational complexity, we can outperform all other baselines. V-D Dynamicity of the Task Similarity Graph Fig. 4 : The resultant representation alignment , projected into 2D space using t-SNE, and the classification head response simmilairty matrix, along with the dynamic task similairty graph for communication rounds t=50 (upper) and t=150 (lower). As we can see, there is a strong correlation between the reprentation alignment and the classification head response similairty. A stronger redness in the dynamic similiarty graph (lower and upper right) indicates a stronger similairty. TABLE I : communities formed across four different rounds in the Heterogeneous CIFAR-10 dataset. Number of communities Round Communities \{8,17,20,4,21,29\} , 3 50 \{14,18,26,25,3\} , \{27,12,16,2\} 2 100 \{9,17,24,11,8,13,19,29,21\} , \{7,23,10,27,22,2\} , \{25,27,2,1,16,5\} , 3 150 \{28,26,6,10\} , \{8,4,29,19,13\} \{18,8,19,4,10,6,1\} , 3 200 \{15,5,12,3\} , \{16,14,24,7\} This section empirically investigates the dynamic nature of the task similarity graph and community formation in SFMTL-Graph. Since we defined a client or a task as a set of a model and data, it is a natural approach to construct the task similarity graph based on both clients’ models and data. As detailed in Section III , the graph is constructed based on similarities between clients’ feature anchors ( \bm{h}_{k} ) and classification heads ( \bm{\phi}_{k} ), dynamically updated each round for sampled clients. We need either a similarity metric or a distance metric that can tell us how close or far those learned representations and the models are. For the feature anchors, we used cosine similarity between vectors to quantify the similarity. We examine the evolution of these similarities and the resulting graph structure every 50 communication rounds. We project the learned feature representations, or feature anchors, of all clients into a 2D space using t-SNE [ 36 ] to see exactly how features are aligned across clients. In the communication round 50 , we can see that clients that share the same task, for example, client 2 and client 16 , whose labels are the same, end up very close to each other in the representation space. This means that the underlying model is learning almost the same representations. Even more, the classification head similarity is 1 , which means that the two models are responding equivalently to the same input vector. The represntation and model rsponse similairty for t=50 and t=150 are depicted at the upper and lower part (left and middle) of figure 4 . To examine another case where two clients only share one class, we consider clients 4 and 8 . We can observe that the learned representations for the two clients are close only in one case, which is the shared class between them. This aligns with the classification head similarity score, which is only 0.35 . For clients that have one class in common, we can see that most clients’ similarity scores for the heads range from 0.30 to 0.45 . The resultant graphs at rounds 50 and 150 are depicted in the upper and lower part (right) of Figure 4 , where a stronger redness of the connection means a stronger relation between the two clients. The communities that are created based on this graph are three communities: \{8,17,20,4,21,29\} , \{14,18,26,25,3\} , and \{27,12,16,2\} . We can see that the clients who have the same classes end up in the same community as expected. All communities in the four observed rounds are depicted in Table I . In each iteration, this task similarity graph is updated to reflect the client’s local updates. One thing that makes this graph consistent with the actual clients’ similarity is that clients who are close to each other, those who share the same set of classes, are pulled closer and closer as the rounds continue. We can examine this by looking at clients 2 and 16 . If we compare their distance in the representation space from round 50 to round 150 , we can see that feature anchors are closer in round 150 than those in round 50 , which indicates that the models are converging to an even closer point. This also indicates that our method tackles heterogeneity of the local data distribution by forming communities of highly similar clients, where the tasks can benefit from each other. V-E Fairness across Clients TABLE II : Statistics of the test accuracy over 200 communication rounds on the Heterogeneous CIFAR-10 dataset. We report the mean \pm std for each metric. Method Mean Worst 10% Worst 20% STD SFMTL-Graph \bm{0.92} \pm \bm{0.06} \bm{0.75} \pm 0.11 {0.78} \pm 0.10 \bm{0.08}\pm\bm{0.03} Fedu 0.91 \pm 0.08 0.73 \pm 0.13 \bm{0.78} \pm \bm{0.12} 0.09\pm 0.03 pFedMe {0.78} \pm 0.03 {0.59} \pm 0.07 {0.61} \pm 0.07 0.13\pm 0.02 FedAvg {0.41} \pm 0.08 {0.08} \pm 0.08 {0.13} \pm 0.08 0.21\pm 0.03 Fairness is a crucial consideration in FL, assessing how performance is distributed across individual clients, especially in heterogeneous settings where some clients might be disadvantaged. We evaluate fairness by analyzing the distribution of test accuracy across all clients. Specifically, we report the overall mean test accuracy, the average accuracy achieved by the worst-performing 10% and 20% of clients, and the standard deviation of test accuracy across all clients over 200 communication rounds on the Heterogeneous CIFAR-10 dataset. This evaluation follows the methodology described in [ 37 ] . These metrics help determine if an algorithm’s high average performance is consistent across the client population or skewed, potentially leaving some clients significantly behind. Table II presents the fairness statistics. We can clearly see that SFMTL-Graph achieves the highest mean accuracy and the lowest standard deviation, , indicating both superior average performance and less variance in performance across the client population compared to baselines. For the worst-performing clients, SFMTL-Graph achieves the highest average accuracy for the bottom 10% of clients. While FedU shows a slightly higher average for the bottom 20%, the difference is marginal. These results demonstrate that SFMTL-Graph promotes fair performance among participant clients, avoiding significant bias or leaving certain clients with substantially lower accuracy, which is a common challenge in heterogeneous FL. VI Conclusion In this work, we proposed SFMTL-Graph, a novel Federated Multi-Task Learning method designed for personalized learning in heterogeneous environments while ensuring communication efficiency and fostering beneficial collaboration. Our method leverages a dynamic task similarity graph constructed from learned client feature anchors and classification heads. To address the risk of negative knowledge transfer, we introduced a community detection approach utilizing the Louvain algorithm to partition clients into communities based on this graph, restricting collaboration to highly similar peers within these groups. This selective collaboration mechanism, combined with a communication-efficient architecture utilizing feature anchors and lightweight heads, allows SFMTL-Graph to effectively balance personalization and knowledge sharing. Extensive experimental evaluation on two heterogeneous datasets demonstrates the significant effectiveness of our method, showing superior performance and communication efficiency compared to baseline approaches across traditional FL, PFL, and FMTL paradigms. Furthermore, our analysis confirms the dynamic nature of the task similarity graph, which adapts to learned representations, and highlights SFMTL-Graph’s ability to promote fairer performance distribution across heterogeneous clients.