NVFlare
NVFlare copied to clipboard
FOX API
Fixes # .
Description
This PR introduces federated object exchange - a new way to develop FL applications.
Types of changes
- [x] Non-breaking change (fix or new feature that would not break existing functionality).
- [ ] Breaking change (fix or new feature that would cause existing functionality to change).
- [ ] New tests added to cover the changes.
- [ ] Quick tests passed locally by running
./runtest.sh. - [ ] In-line docstrings updated.
- [ ] Documentation updated.
Greptile Summary
Introduces the FOX (Federated Object Exchange) API - a new programming model for building federated learning applications in NVFlare. This is a major feature addition (~7700 lines) that provides an alternative to the existing workflow-based approach.
Key Changes:
- New
nvflare.foxpackage with API layer (fox.api), system integration (fox.sys), and simulation backend (fox.sim) - Decorator-based programming model using
@collab,@algo,@init,@finalfor marking federated methods - Proxy pattern for transparent remote method invocation between server and clients
- Filter chains for preprocessing calls and results (incoming/outgoing)
- Context management using thread-local storage for accessing site information
- Two backends: FlareBackend (production via F3 messaging) and SimBackend (local testing)
- Support for hierarchical client topologies and group calls with parallel execution control
- Integration with existing FLARE infrastructure (minimal changes to
cell.pyandserver_engine.py) - Comprehensive examples for numpy and PyTorch workflows
Architecture:
App/ServerApp/ClientAppclasses manage application lifecycle and configurationProxyobjects provide typed remote method calls with interface discoveryBackendabstraction handles actual communication (F3 cells for FLARE, in-memory for simulation)Contextprovides call-time information (caller, callee, workspace, abort signal)facadeclass offers convenient static API for accessing context within collab methods
Notable Design Decisions:
- Exceptions returned as values rather than raised in proxy calls to support async patterns
- Thread-local context with proper parent context restoration
- Interface introspection converts positional args to kwargs for filter processing
- Deepcopy fallback with
make_client_appmethod for client app instantiation
Confidence Score: 4/5
- This PR introduces a well-architected new API with solid error handling and comprehensive examples, safe to merge with minor considerations
- The FOX API is well-designed with proper separation of concerns, error handling, and resource cleanup. The code follows good patterns (context managers, thread executors with proper shutdown, proxy pattern). Integration with existing FLARE is minimal and non-breaking. However, this is a large feature (~7700 lines) with limited test coverage mentioned in PR description, and the production readiness would benefit from additional integration tests and documentation
- No critical issues found, but
nvflare/fox/sys/controller.pyandnvflare/fox/sys/executor.pyhandle production integration and should be thoroughly tested
Important Files Changed
| Filename | Overview |
|---|---|
| nvflare/fox/api/app.py | Core App class manages FOX applications with proxy setup, filter chains, and collab object registration - solid design with proper validation |
| nvflare/fox/api/proxy.py | Proxy implementation for remote calls with interface discovery and argument adjustment - exception handling returns exceptions as values correctly |
| nvflare/fox/api/facade.py | Convenient facade API using classproperties for accessing context, proxies, and workspace - clean interface design |
| nvflare/fox/api/dec.py | Decorator implementations for marking collab methods, filters, and lifecycle hooks - proper attribute setting and introspection |
| nvflare/fox/sys/controller.py | Server-side FOX controller integrates with FLARE, handles client sync, and sets up proxies - proper initialization and error handling |
| nvflare/fox/sys/executor.py | Client-side FOX executor handles sync task and proxy setup with lifecycle management - proper thread executor cleanup |
| nvflare/fox/sys/backend.py | FLARE backend implementation using F3 cell messaging for remote calls with proper timeout and error handling |
| nvflare/fox/sim/simulator.py | Simulation backend for testing FOX apps locally with support for hierarchical client topologies and proper deepcopy handling |
| nvflare/fox/api/group.py | Group call implementation supports parallel/sequential remote calls with result aggregation and proper semaphore-based concurrency control |
| nvflare/fox/api/ctx.py | Thread-local context management with proper parent context restoration in __exit__ - clean context manager pattern |
Sequence Diagram
sequenceDiagram
participant User as User Code
participant Server as ServerApp
participant Proxy as Client Proxy
participant Backend as FlareBackend
participant Cell as F3 Cell
participant ClientBackend as Client Backend
participant ClientApp as ClientApp
participant Method as Collab Method
Note over User,Server: Initialization Phase
User->>Server: Create ServerApp(server_obj)
Server->>Server: Register @algo methods
User->>Server: Setup filters/props
Note over User,Method: Execution Phase
Server->>Proxy: call client method via proxy
Proxy->>Proxy: adjust_func_args() - convert args to kwargs
Proxy->>Server: apply_outgoing_call_filters()
Proxy->>Backend: call_target(context, target, func_name, kwargs)
Backend->>Cell: send_request(channel, target_fqcn, request)
Note over Cell,ClientBackend: Network Communication
Cell-->>ClientBackend: Message via F3
ClientBackend->>ClientApp: _call_app_method(request)
ClientApp->>ClientApp: apply_incoming_call_filters()
ClientApp->>Method: invoke collab method with context
Method-->>ClientApp: return result
ClientApp->>ClientApp: apply_outgoing_result_filters()
ClientApp-->>ClientBackend: reply with result
ClientBackend-->>Cell: Return message
Cell-->>Backend: Reply message
Backend->>Proxy: return result
Proxy->>Server: apply_incoming_result_filters()
Proxy-->>Server: filtered result
Server-->>User: final result
Superseded by #4901, which carries the same content from a fork branch owned by the current driver of this work (the Collab API evolution of the original FOX API). Closing in favor of that PR.