Add FedCE research recipe support - #4922
Conversation
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #4922 +/- ##
==========================================
+ Coverage 64.26% 64.32% +0.06%
==========================================
Files 1030 1032 +2
Lines 103578 103761 +183
==========================================
+ Hits 66560 66745 +185
+ Misses 37018 37016 -2
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
Greptile SummaryAdds a dedicated PyTorch FedCE recipe and contribution-aware aggregation workflow.
Confidence Score: 3/5The PR is not yet safe to merge because same-name client parameters with incompatible shapes can still abort a FedCE aggregation round. The new compatibility check rejects missing or additional parameter names, but it passes matching names without validating tensor shapes before independently flattening and combining client vectors. Files Needing Attention: nvflare/app_opt/pt/fedce.py Important Files Changed
Sequence DiagramsequenceDiagram
participant S as FedCE Server
participant C as Client
participant A as FedCE Aggregator
S->>C: Global model + prior fedce_coef
C->>C: Train and evaluate minus model
C-->>A: Weight DIFF + fedce_minus_val
A->>A: Validate parameter contract
A->>A: Compute cosine and minus-score weights
A-->>S: Aggregated DIFF + updated fedce_coef
Reviews (4): Last reviewed commit: "Merge remote-tracking branch 'online/mai..." | Re-trigger Greptile |
There was a problem hiding this comment.
Pull request overview
Adds first-class FedCE support to NVFlare’s PyTorch “recipe” system, including a contribution-aware server-side aggregator, a client helper for the FedCE contract, CLI catalog discovery, docs, and unit tests.
Changes:
- Introduces
FedCEModelAggregatorandPTFedCEHelperfor FedCE contribution estimation and minus-model handling. - Adds
FedCERecipe(PyTorch) and exposes it via recipe package exports and thenvflare recipeCLI catalog. - Adds documentation and unit tests for the FedCE aggregator/recipe behavior and recipe discovery/export.
Reviewed changes
Copilot reviewed 9 out of 9 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
| tests/unit_test/tool/recipe_cli_test.py | Updates catalog expectations to include the new fedce-pt documented recipe. |
| tests/unit_test/app_opt/pt/recipes/fedce_recipe_test.py | Adds unit tests for FedCERecipe validation, DIFF transfer, lazy exports, and server export wiring. |
| tests/unit_test/app_opt/pt/fedce_test.py | Adds unit tests for FedCE helper utilities, normalization, and contribution-weighted aggregation behavior. |
| nvflare/tool/recipe/recipe_cli.py | Registers fedce-pt in _DOCUMENTED_RECIPE_SPECS so the CLI can discover and describe the new recipe. |
| nvflare/app_opt/pt/recipes/fedce.py | Implements the dedicated FedCERecipe that wraps FedAvg workflow with a FedCE-specific aggregator and DIFF exchange. |
| nvflare/app_opt/pt/recipes/init.py | Adds lazy import + __all__ export for FedCERecipe. |
| nvflare/app_opt/pt/fedce.py | Implements FedCE server/client components: constants, client helper, normalization, and the contribution-aware FedCEModelAggregator. |
| nvflare/app_opt/pt/init.py | Exposes FedCE components from the PyTorch optional package top-level. |
| docs/user_guide/data_scientist_guide/available_recipes.rst | Documents how to construct/use FedCERecipe and the client script contract requirements. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
|
The contribution scoring and the actual aggregation currently operate on different parameter scopes:
For buffers ( Proposal:
|
|
On the validation: the global Dice comparison (≈0.845 vs ≈0.843) is a good sanity check, but the signature result of FedCE — and what the research example documents — is the contribution-coefficient behavior, see the curves in research/fed-ce: Could you attach the equivalent It would also be good to include the client training script / job config used for the prostate comparison — or better, add a recipe-based job under |
|
Thanks @nvkevlu — this is convincing. The Promise12 trajectory (0.1695 → 0.2733, finishing largest while the others stay near or below the uniform reference) reproduces the signature behavior from the research example, and your rerun of the original implementation ending at 0.2668 matches the published figure, so the baseline itself reproduced. The 0.9976 correlation with ~0.0028 mean absolute difference is consistent with the minor numerical differences between the implementations (clip/normalize ordering, epsilon) plus run-to-run noise, and the per-round sums within 3e-8 of 1 confirm the recipe's by-construction normalization. Two remaining items before approval:
|
| reference_client = clients[0] | ||
| common = set(self._results[reference_client].params) | ||
| for client in clients[1:]: | ||
| client_params = set(self._results[client].params) |
There was a problem hiding this comment.
Tensor shapes bypass compatibility check
When two clients return DIFF updates with identical parameter names but different tensor shapes, this name-set comparison accepts them and _weighted_vector combines flattened vectors of different lengths, causing a PyTorch size-mismatch error that aborts the aggregation round.

Adds dedicated PyTorch recipe support for FedCE.
Description
FedCE uses the FedAvg global-model workflow but changes how client updates are evaluated and aggregated. Because it introduces its own client/server contract and aggregation behavior, it is provided as a separate
FedCERecipeinstead of a FedAvg configuration flag.The PR includes:
FedCERecipeusing PyTorch weight differences.FedSM and other personalized-learning algorithms are outside the scope of this PR.
Validation
The original FedCE implementation and the new recipe were compared using the documented six-client prostate segmentation experiment.
Both implementations completed all 100 rounds successfully with no fatal validation errors. Their late-round mean global Dice scores were very similar: approximately
0.845for the original implementation and0.843for the recipe. FedCE contribution coefficients also remained normalized throughout the run.These results provide confidence that the recipe preserves the expected FedCE research behavior.
Types of changes
./runtest.sh.