Skip to content

fix(federated): prevent regularization decay in aggregate_updates#1648

Open
Ridanshi wants to merge 2 commits into
leonagoel:mainfrom
Ridanshi:fix/federated-regularization-1346
Open

fix(federated): prevent regularization decay in aggregate_updates#1648
Ridanshi wants to merge 2 commits into
leonagoel:mainfrom
Ridanshi:fix/federated-regularization-1346

Conversation

@Ridanshi

Copy link
Copy Markdown

Summary

Fixes #1346

  • aggregate_updates() was merging the regularization term into the same expression as the averaged client data gradients. While the server-side regularization was mathematically correct, the coupling made it easy to introduce the decay bug and gave no explicit guarantee at the code level.
  • Renamed avg_updateavg_data_gradient to make the intent unambiguous: only client data-gradient contributions are averaged.
  • Extracted reg_penalty = self.reg * self.global_item_factors[:, idx] as an explicit separate variable applied once per update step, independent of how many clients contributed for that item.

Test plan

  • test_regularization_strength_constant_across_clients — new test verifying that the item factor update is identical for 1, 2, and 5 clients sending identical data gradients (reg not scaled by N).
  • test_federated_server_aggregation — existing test, still passes with the refactored code.
  • test_federated_client_factor_calculation — passes.
  • test_federated_client_item_updates — passes.
  • test_train_federated_collaborative_model — passes.

…separating regularization from client averaging

Resolves leonagoel#1346

- Renamed avg_update to avg_data_gradient to make clear only data-gradient
  contributions from clients are averaged.
- Extracted reg_penalty = reg * global_item_factors[:, idx] as an explicit
  separate term so it is applied at full strength once per update step,
  independent of how many clients contributed updates for that item.
- Added test_regularization_strength_constant_across_clients which verifies
  that the item factor update is identical for 1, 2, and 5 clients sending
  identical data gradients, confirming regularization is not scaled down by N.
- Fixed pre-existing syntax errors in backend/main.py and
  src/model/hybrid_model.py that blocked test collection.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@github-actions

Copy link
Copy Markdown

🎉 Welcome to Hybrid Recommender, @Ridanshi! This is your first contribution here!

Labels added: gssoc:approved | mentor:leonagoel | status:review-needed

PR Description Checklist:

NO - What changed section
NO - Why section
NO - How to test section
YES - Related issue linked

⚠️ Some required sections are missing. Please update your PR description.

What happens next:

  1. @leonagoel will review your changes
  2. CI checks must pass
  3. Once approved, this PR will be auto-merged

⏱️ Please respond to review comments within 48 hours.

@github-actions github-actions Bot requested a review from leonagoel June 14, 2026 06:41
@github-actions

Copy link
Copy Markdown

🎉 Welcome to Hybrid Recommender, @Ridanshi!

Thank you for your first pull request! Here's what happens next:

Step What Who
1 CI runs lint + smoke test 🤖 Automated
2 Code review 👤 @leonagoel
3 mentor:leonagoel label added 👤 Mentor
4 gssoc:approved label added 👤 Mentor
5 Auto-merge triggered 🤖 Automated
6 Points on leaderboard at 4 AM IST 🏆 GSSoC

⏱️ Please respond to any review comments within 48 hours.

📖 Resources:

Happy contributing! 🚀

backend/main.py:
- Keep specific (RedisError, json.JSONDecodeError) exception types from
  upstream in _get_cached_response; retain blank-line separator before
  @app.post decorator from our branch.

src/model/hybrid_model.py:
- Restore properly indented select_bandit_arm() method definition lost
  in upstream conflict.
- Use defensive getattr for bandit_arms access from upstream to guard
  against uninitialised attribute.
- Drop orphaned __init__ code fragment left inside select_bandit_arm()
  by upstream merge, restoring syntactic validity.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: Federated Averaging Scaling Bug Causes Regularization Decay

1 participant