Model training
In this study, we expand on the process of distilling large-scale models by incorporating FL to enhance privacy during training. Using FL, we distribute training of a compact multimodal encoder adapted from the CLIP ViT-B/32 architecture, reducing the model size from the original 124 million parameters to a more efficient configuration with fewer parameters in both the image and text encoders. The original CLIP model, pre-trained on the combined LAION-400M and YFCC-100M datasets, serves as the teacher model in our distillation process.
Our model adopts the contrastive learning framework from the original CLIP, where cosine similarity is used to align image and text embeddings. Specifically, we retain the original contrastive loss formulation which encourages high similarity between matching image-text pairs and low similarity between mismatched ones. This loss is employed in our compact student model during distillation, allowing it to inherit the alignment capability of the larger CLIP teacher model. The contrastive loss \(\mathcal {L}_{\text {contrastive}}\) is defined as:
$$\begin{aligned} \begin{aligned} \mathcal {L}_{\text {contrastive}} = -\frac{1}{N} \sum _{i=1}^{N} \Bigg (&\log \frac{\exp (\text {cos}(I_i, T_i)/\tau )}{\sum _{j=1}^{N} \exp (\text {cos}(I_i, T_j)/\tau )} + \log \frac{\exp (\text {cos}(T_i, I_i)/\tau )}{\sum _{j=1}^{N} \exp (\text {cos}(T_i, I_j)/\tau )} \Bigg ) \end{aligned} \end{aligned}$$
(1)
Within this formula, \(I_i\) and \(T_i\) represent visual and textual embeddings corresponding to the \(i^{\text {th}}\) synchronized pair, N indicates the overall quantity of visual-textual pairs, while \(\tau\) serves as a scaling factor to adjust the cosine similarity, and \(\text {cos}(I_i, T_i)\) represents the cosine similarity between embeddings. This contrastive loss ensures that cosine similarity remains the optimal measure for cross-modal alignment, improving retrieval performance during inference. Beyond this conventional supervision, we further enhance distillation by mimicking the affinity distribution from the teacher model. Instead of only distinguishing positives from negatives, the student approximates the full similarity matrix across all image-text pairs in a batch. This strategy, implemented through \(\mathcal {L}_{\text {I2T}}\) and \(\mathcal {L}_{\text {T2I}}\), enables the student to capture nuanced cross-modal relationships and inherit the teacher’s fine-grained alignment behaviour.
In the distillation process, we employ the distillation loss \(\mathcal {L}{\text {distill}}\), which prompts the learner model to emulate the instructor model’s acquired patterns. This loss comprises two components: the correspondence loss for visual-to-textual, marked as \(\mathcal {L}{\text {I2T}}\), and for textual-to-visual, indicated by \(\mathcal {L}_{\text {T2I}}\), integrated as:
$$\begin{aligned} \mathcal {L}_{\text {distill}} = \mathcal {L}_{\text {I2T}} + \mathcal {L}_{\text {T2I}}. \end{aligned}$$
(2)
Additionally, we introduce a sparsity loss \(\mathcal {L}_{\text {sparsity}}\) to regularize the model and encourage parameter pruning. The sparsity loss is formulated as:
$$\begin{aligned} \mathcal {L}_{\text {sparsity}} = \lambda \sum _i ||M_i|| \end{aligned}$$
(3)
where \(M_i\) represents the mask that can be adjusted for each layer and \(\lambda\) serves as a coefficient that influences the extent of sparsity. The distillation and sparsity losses affect different aspects of the model and focus on semantic alignment and representation compactness respectively. Sparsity acts as a regularizer that helps stabilize local updates and complements the distillation objective without interfering with its gradients. To accelerate convergence, we further apply weight inheritance. Learnable masks \(M = \{m_{\text {head}}, m_{\text {int}}, m_{\text {embed}}\}\) are imposed on attention heads, intermediate FFN neurons, and embedding dimensions, respectively. These masks automatically identify and retain the most informative weights from the teacher while pruning redundant ones. In this way, the student inherits a strong initialization and avoids training from scratch, improving both stability and efficiency in federated aggregation.
The training process follows a progressive multi-stage approach, where each stage \(G\) applies a distinct compression rate \(q_i\) to incrementally reduce the model’s size. Directly compressing at high sparsity (e.g., > 70%) often results in severe accuracy loss. Therefore, each stage performs moderate compression, inherits stabilized weights, and continues distillation with affinity and sparsity constraints. As illustrated in Fig. 2, this gradual procedure prevents collapse and allows the final compact model to retain accuracy even after aggressive compression. Federated learning ensures privacy by decentralizing training across multiple devices, each performing local updates and encrypting model weights before securely aggregating them on a central server. This method preserves data privacy while improving the compressed model’s efficiency. During federated learning, the dataset is partitioned across eight devices, with each device conducting local training on its respective partition and transmitting encrypted model weights for secure aggregation. The complete process is detailed in Algorithm 1, which integrates federated learning with the multi-stage distillation framework.
Fig. 2
Illustration of weight inheritance with learnable masks in our framework. During distillation, the student model selectively inherits parameters from the pre-trained CLIP teacher through learnable masks applied to embeddings, attention heads, and FFN channels. These masks automatically preserve the most informative components while discarding redundant ones, providing the student with a strong initialization under sparsity regularization.
Algorithm 1
Federated Progressive Multi-Stage Distillation for PMIRS
Client selection and aggregation
Each communication round in our framework involves selecting a fixed number of clients using uniform random sampling. We avoid availability-aware or priority-based strategies. In our experiments, we fixed the number of participating computational clients at eight, sampling without replacement from a pre-partitioned dataset to represent distributed edge nodes. This setting strikes a balance between the benefits of multi-client participation and the cost of communication and encryption. While the number of clients can generally influence the diversity of updates and the efficiency of training, prior work has noted that moderate client participation is often sufficient for stable convergence in practice58. In our setting with eight uniformly partitioned clients, the training process did not exhibit noticeable instabilities. Each selected client performs local training for one complete epoch before model aggregation. Once local updates are completed, the clients encrypt their model weights and send them to a central server. The server then performs synchronous aggregation using the FedAvg algorithm59. In general, FedAvg computes a weighted average of client updates according to local dataset sizes:
$$\begin{aligned} \phi _S^{t+1} = \sum _{i=1}^{K}\frac{n_i}{n}\phi _S^{i,t+1}, \quad n = \sum _{i=1}^{K} n_i. \end{aligned}$$
(4)
Since our dataset was uniformly partitioned across eight clients, this weighting simplifies to an equal average, as shown in Algorithm 1, additional weighting based on data quality were not incorporated. The global model parameters are then updated by directly replacing them with the aggregated results. At the beginning of the next communication round, the updated global model is synchronously broadcast to all selected clients, which initialize their local models with this global state before training for the next epoch. This ensures consistent initialization across devices. No human participants were involved in this study.
Feature extraction
Following the automated distillation process described in the previous subsection, the most optimal and efficient model configuration was identified for our task. The selected configuration balances performance and size. It uses a Vision Transformer (ViT) as the image encoder and a transformer-based model as the text encoder. As shown in Fig. 3, the PMIRS model is structured with 12 transformer layers assigned to the image encoder, while the text encoder uses 9 transformer layers.
Fig. 3
Transformer-based image and text encoder architecture used within the PMIRS framework.
To handle an input image, the image encoder begins by first resizing it to \(224 \times 224\) pixels and then dividing it into fixed-size patches. Specifically, each input image \(x_{\text {image}}\) is resized to \(224 \times 224 \times 3\), resulting in \(N_p = 49\) patches of size \(32 \times 32\). Each patch is flattened and linearly projected into a 512-dimensional space:
$$\begin{aligned} z_p = W_{\text {patch}} x_p + b_{\text {patch}}, \quad \forall x_p \in x_{\text {image}}, \end{aligned}$$
(5)
with \(z_p\) as the patch embeddings, \(W_{\text {patch}}\) the weight matrix for projection, and \(b_{\text {patch}}\) the bias term. To retain positional information, positional embeddings \(p_i\) are added to the patch embeddings:
$$\begin{aligned} z_0 = \left[ \text {class\_token}; z_p^1 + p_1; \dots ; z_p^{N_p} + p_{N_p} \right] \end{aligned}$$
(6)
where the class token is concatenated with the positional embeddings of the image patches. First, the sequence moves through multiple transformer layers. Each layer contains a self-attention mechanism with 12 heads and is followed by a feed-forward MLP that executes several operations as demonstrated in60. After passing through the transformer layers, the class token is selected to represent the final image embedding:
$$\begin{aligned} z_{\text {image}} = \text {Proj}_{\text {image}}(z_{\text {class}}) \end{aligned}$$
(7)
with \(\text {Proj}_{\text {image}}\) as the projection layer mapping the class token embedding to the final 512-dimensional image embedding. The text encoder works similarly, made up of 9 transformer layers with 8 attention heads in each, a 512-dimensional embedding, and a maximum context length of 77 tokens. For an input text sequence \(x_{\text {text}}\) of length \(T\), each token is embedded and summed with positional embeddings:
$$\begin{aligned} z_t = \text {Embedding}(x_{\text {text}}) + \text {PositionEmbedding}(T) \end{aligned}$$
(8)
where \(\text {Embedding}(x_{\text {text}})\) refers to the token embedding, and \(\text {PositionEmbedding}(T)\) represents the positional information for each token. The sequence of the embeddings are processed by the transformer layers, and the one corresponding to the End-of-Sequence (EOS) token is selected:
$$\begin{aligned} z_{\text {text}} = \text {Proj}_{\text {text}}(z_{\text {EOS}}) \end{aligned}$$
(9)
with \(\text {Proj}_{\text {text}}\) mapping the EOS token embedding to the final 512-dimensional text embedding. These 512-dimensional embeddings for both image and text (\(z_{\text {image}}\) and \(z_{\text {text}}\), respectively) will be used in later stages of the framework for retrieval and matching.
Data encryption
Encryption and decryption are implemented using AES in CBC mode with a 128-bit key, chosen for its balance of strong security and low computational overhead. In our federated learning framework, AES is used to encrypt local model weights before transmission to the central server, preserving data confidentiality during distributed training. During upload or retrieval, either the image or text is encrypted with AES. The other modality is obfuscated. This modular setup allows flexible privacy control based on application needs. All AES operations are conducted using a fixed block size of 128 bits, consistent with standard secure implementations. One limitation of AES is its reliance on a shared secret key between sender and receiver. To securely establish this key in a multi-user setting, we integrate the Diffie-Hellman key exchange protocol, which ensures that encryption keys are never exposed during transfer. The details of this exchange are discussed in Section “Multi-user parameters exchange”.
Obfuscation-based retrieval
In our system, cosine similarity is used to match embeddings from different modalities, such as images and text. Cosine similarity measures the directional alignment between vectors, making it an effective metric for multimodal data retrieval. To calculate the similarity, the image embedding \(z_{\text {image}}\) is compared with the text embedding \(z_{\text {text}}\) as:
$$\begin{aligned} \text {sim}(z_{\text {image}}, z_{\text {text}}) = \frac{z_{\text {image}} \cdot z_{\text {text}}^{\top }}{\Vert z_{\text {image}} \Vert \Vert z_{\text {text}} \Vert } \end{aligned}$$
(10)
To focus solely on directional similarity, we normalize the embeddings so that their norms equal 1, simplifying the similarity computation to a dot product:
$$\begin{aligned} \text {sim}(z_{\text {image}}, z_{\text {text}}) = z_{\text {image}} \cdot z_{\text {text}}^{\top } \end{aligned}$$
(11)
Following similarity computation, a dynamic threshold determines the predicted class labels. Only classes with similarity scores above the threshold are considered valid predictions. The threshold adopts a log-scaled inverse form to prevent overly aggressive increases as class count grows-reflecting the heuristic that larger repositories may contain more semantic noise, but that thresholding must remain lenient enough to preserve recall. It is defined as:
$$\begin{aligned} \text {Threshold} = \frac{\alpha }{\sqrt{\log (S + \beta )}} \end{aligned}$$
(12)
where \(\alpha\) is a scaling factor, \(\beta\) is an offset controlling threshold adjustments, and \(S\) signifies the overall count of potential categories within the retrieval repository. This adaptive threshold dynamically adjusts based on the repository size, ensuring consistent retrieval performance across datasets of varying scales.
To ensure privacy during retrieval, we introduce two obfuscation mechanisms: Block-Wise Obfuscation and Deterministic Noise Removal. First, we employ block-wise obfuscation, where embeddings are partitioned into four blocks of 128 dimensions each (i.e., block size = 128), enabling block-wise obfuscation and matrix transformation consistency. This partitioning applies to both image and text embeddings. For each block, we introduce a unique invertible confusion matrix \(Q_i\), where \(i = 1, 2, 3, 4\). The obfuscated embeddings are computed as:
$$\begin{aligned} z_{\text {obfuscated}} = \begin{bmatrix} z_1&\quad z_2&\quad z_3&\quad z_4 \end{bmatrix} \begin{bmatrix} Q_1 & \quad 0 & \quad 0 & \quad 0 \\ 0 & \quad Q_2 & \quad 0 & \quad 0 \\ 0 & \quad 0 & \quad Q_3 & \quad 0 \\ 0 & \quad 0 & \quad 0 & \quad Q_4 \end{bmatrix} = z Q \end{aligned}$$
(13)
where \(Q\) is a block-diagonal matrix composed of \(Q_1, Q_2, Q_3, Q_4\), and \(z\) is the original 512-dimensional embedding structured as four concatenated 128-dimensional vectors. Next, we enhance security by introducing deterministic noise removal. The obfuscated embeddings are computed as:
$$\begin{aligned} z_{\text {obfuscated}} = z Q + \epsilon _{\text {noise}} \end{aligned}$$
(14)
During retrieval, the noise is removed, and the inverse of the confusion matrices \(Q_i^{-1}\) are applied to the obfuscated embeddings:
$$\begin{aligned} z_{\text {retrieval}} = \left( z_{\text {obfuscated}} – f(Q_1, Q_2, Q_3, Q_4) \right) Q^{-1} \end{aligned}$$
(15)
where \(f(Q_1, Q_2, Q_3, Q_4)\) is a structured noise function that ensures deterministic removal without information loss. This function is designed such that:
$$\begin{aligned} f(Q_1, Q_2, Q_3, Q_4) = \epsilon _{\text {noise}} \end{aligned}$$
(16)
This method enables exact recovery of the original embedding while maintaining the embeddings’ directional characteristics, ensuring that cosine similarity remains unchanged while adding security against unauthorized access. To further validate the correctness of this method, we formally present Lemma 1 and its proof, which demonstrate that cosine similarity remains intact under the proposed obfuscation scheme.
Lemma 1
Given two embeddings \(z_{\text {image}}\) and \(z_{\text {text}}\), and a block-diagonal invertible confusion matrix \(Q\), the obfuscated embeddings \((z_{\text {image}} Q)\) and \((Q^{-1} z_{\text {text}}^{\top })\) preserve the cosine similarity:
$$\begin{aligned} (z_{\text {image}} Q) \left( Q^{-1} z_{\text {text}}^{\top } \right) = z_{\text {image}} \cdot z_{\text {text}}^{\top }. \end{aligned}$$
(17)
Proof
By substituting the obfuscated embeddings, we have:
$$(z_{\text {image}} Q) \left( Q^{-1} z_{\text {text}}^{\top } \right) .$$
Using the property that any invertible matrix multiplied by its inverse yields the identity matrix:
Thus, we obtain:
$$z_{\text {image}} \left( Q Q^{-1} \right) z_{\text {text}}^{\top } = z_{\text {image}} I z_{\text {text}}^{\top }.$$
Since multiplying by the identity matrix does not change a vector, we conclude:
$$z_{\text {image}} \cdot z_{\text {text}}^{\top }.$$
This proves that the transformation preserves cosine similarity. As a result, the obfuscated embeddings preserve the original cosine similarity derived from the image and text embeddings, guaranteeing that retrieval performance remains unaffected by the obfuscation procedure. Moreover, potential inference attacks are mitigated since the obfuscation relies on independent block-wise transformations combined with deterministic noise. Without access to the private confusion matrices, attackers observing multiple obfuscated embeddings cannot reliably reconstruct the statistical patterns of the original representations, ensuring that semantic information remains hidden.
\(\square\)
Multi-user parameters exchange
We use the Diffie-Hellman key exchange protocol to securely share parameters between users in a multi-user setting. This mechanism is crucial for tasks such as cross-user retrieval and collaborative feature transformations. Consider \(p\) as a large prime and \(g\) as its corresponding primitive root, both publicly agreed upon. For two users, \(U_i\) and \(U_j\), the parameter exchange follows these steps:
1.
The user \(U_i\) generates a public key after selecting their private key \(x_i\):
$$\begin{aligned} y_i = g^{x_i} \mod p. \end{aligned}$$
(18)
In the same way, user \(U_j\) first chooses a private key \(x_j\) before calculating:
$$\begin{aligned} y_j = g^{x_j} \mod p. \end{aligned}$$
(19)
2.
Users exchange the public keys \(y_i\) and \(y_j\) over an unsecured channel.
3.
Each user computes the shared \(k_s\) as:
$$\begin{aligned} k_s&= y_j^{x_i} \mod p \quad \text {(for user }{U_i)}, \end{aligned}$$
(20)
$$\begin{aligned} k_s&= y_i^{x_j} \mod p \quad \text {(for user }{U_j)}. \end{aligned}$$
(21)
Due to the properties of modular arithmetic, both computations yield the same shared:
$$\begin{aligned} k_s = g^{x_i \cdot x_j} \mod p. \end{aligned}$$
(22)
With the shared key \(k_s\), users encrypt sensitive parameters before exchanging them. Specifically, user \(U_i\) encrypts their mapping function \(\tau _{i \rightarrow j}\) and obfuscation parameter \(R_i\) as:
$$\begin{aligned} \text {Enc}_{k_s}(\tau _{i \rightarrow j}, R_i), \end{aligned}$$
(23)
and transmits the encrypted data to \(U_j\). Similarly, \(U_j\) encrypts their parameters for secure transmission to \(U_i\).
To facilitate cross-user retrieval, query features \(z_i\) are transformed into the feature space of the target user using the mapping function \(\tau _{i \rightarrow j}\), as follows:
$$\begin{aligned} z_j = \tau _{i \rightarrow j}(z_i). \end{aligned}$$
(24)
The transformed features \(z_j\) are transmitted to the server, which subsequently identifies the ciphered data most closely aligned with it and returns it to the querying user. Decryption is performed using the shared key \(k_s\), ensuring secure access to the desired data. This approach ensures that parameters are exchanged securely while maintaining compatibility with the federated framework design and obfuscation mechanisms outlined in previous sections.
Threat model and security analysis
In line with established practices for formal threat modeling, we characterize adversaries in PMIRS by explicitly defining their capabilities, objectives, and assumptions. This provides a rigorous basis for evaluating the security guarantees of our framework and directly addresses the adversarial concerns raised in Sections “Data encryption”–“Obfuscation-based retrieval”.
System assumptions
Clients are assumed to execute local training honestly and store their private keys securely, but may collude by sharing intermediate results. The communication channel between clients and the server is observable by adversaries, but all transmitted embeddings are encrypted using AES. The central server is semi-trusted: it coordinates training and aggregation but may attempt to infer sensitive information or deviate from the protocol. External attackers can passively eavesdrop but cannot break the underlying AES or Diffie–Hellman primitives. These assumptions reflect common practice in federated learning deployments. The semi-trusted server model, also known as the “honest-but-curious” setting, is widely used in the literature because it captures realistic scenarios where cloud providers execute protocols faithfully but may attempt to infer sensitive information. Likewise, assuming secure key exchange is reasonable given that protocols such as Diffie–Hellman underlie TLS/SSL and VPN tunneling, which are standard in distributed machine learning infrastructures. By explicitly adopting these assumptions, PMIRS aligns with prevailing deployment conditions while maintaining tractable efficiency.
Adversary models
We consider three representative adversarial settings: (i) Honest-but-curious server that follows the protocol faithfully yet attempts to infer embeddings or data distributions from encrypted or obfuscated representations. (ii) Malicious service provider that may tamper with aggregation, replay messages, or selectively analyze embeddings to reconstruct semantic information. (iii) Colluding users that exchange local results to infer another client’s embeddings or underlying data distribution.
Table 2 Threat model and systematic resilience analysis of PMIRS under various adversarial settings.Security analysis
As summarized in Table 2, PMIRS systematically addresses the attack surfaces under each adversarial setting. For honest-but-curious servers, AES ensures that even repeated inputs produce different ciphertexts, eliminating deterministic leakage, while obfuscation masks semantic features. For malicious providers, block-wise transformation and deterministic noise make statistical reconstruction infeasible, and the correctness of similarity is mathematically guaranteed by Lemma 1. For colluding users, since each client operates under distinct keys and private matrices, intermediate results cannot be combined to reveal another user’s embeddings.
Discussion
Without these protections, adversaries could mount embedding inversion or semantic leakage attacks, as demonstrated in prior multimodal retrieval systems. PMIRS explicitly prevents such attacks by combining AES encryption, block-wise obfuscation, and deterministic noise removal. While embeddings are partitioned into 128-dimensional blocks, each block undergoes an independent transformation, which preserves only the similarity-preserving properties needed for retrieval. This design prevents individual blocks from retaining interpretable semantic structure, thereby reducing the risk of semantic leakage through block-level analysis. Future work may adopt hybrid cryptographic designs, such as integrating AES with elliptic-curve cryptography (ECC)61, where ECDH provides efficient key exchange and AES-GCM enforces robust encryption validated under adversarial testing.