Collaboration API (Technical Preview)
The Collaboration API ("Collab API", nvflare.collab) lets you write a federated workflow as ordinary Python method calls between a server object and client objects, and between peer clients. Instead of packing data into tasks and Shareable objects, a server method calls a decorated client method as if it were local and receives plain Python return values. This page explains the decorators, the collab facade, call options, error handling, CollabRecipe, and the current limitations.
Note: The Collab API is a Technical Preview introduced in NVFLARE 2.9.0. Its API surface may still change. Every site in a Collab job must run 2.9.0 or newer.
When to Use It
Choose the Collab API when the control flow is naturally expressed as calls and return values: fan-out/fan-in with custom per-call logic, split learning, swarm learning with client-to-client calls, or asynchronous aggregation. For standard FedAvg-shaped training, Job Recipes with the Client API remain the simplest path.
Decorators
| Decorator | Meaning |
|---|---|
@collab.publish |
Makes a method remotely callable through a client proxy, for server-to-client and client-to-client calls. Parameters must be fixed (no *args / **kwargs). |
@collab.main |
The server's single entry point. Every server object or module must define exactly one. |
@collab.init |
Runs once after a site's Collab app is set up, before any main or published method. |
@collab.final |
Runs during teardown after normal execution or controlled end-run cleanup (not guaranteed on hard process termination). |
Lifecycle methods take no arguments or a single context parameter. Server and client objects can be plain classes or module-level functions; they do not subclass anything.
A Minimal Example
from nvflare.collab import CollabRecipe, collab
from nvflare.recipe import SimEnv
MIN_CLIENTS = 2
class Trainer:
@collab.publish
def train(self, weights=None):
local_epochs = collab.get_app_prop("local_epochs", 5)
return (weights or 0.0) + local_epochs # replace with real training
def aggregate(client_results):
successful = list(dict(client_results).values())
if len(successful) < MIN_CLIENTS:
raise RuntimeError(f"only {len(successful)} client calls succeeded")
return sum(successful) / len(successful)
class Coordinator:
def __init__(self, num_rounds=3):
self.num_rounds = num_rounds
@collab.main
def run(self):
weights = 0.0
for _ in range(self.num_rounds):
weights = aggregate(collab.clients.train(weights))
return weights
recipe = CollabRecipe(
job_name="collab_core",
server=Coordinator(),
client=Trainer(),
min_clients=MIN_CLIENTS,
)
recipe.execute(SimEnv(num_clients=MIN_CLIENTS))
This is a reduced version of the repository's hello-collab example (nvflare examples get hello-collab), which contains a real PyTorch model.
The collab Facade
| Member | Description |
|---|---|
collab.clients |
A ProxyList of all clients. collab.clients.train(w) calls train on every client in parallel. |
collab.clients(...) |
Call the list first to set options: collab.clients(timeout=30).train(w). |
collab.get_clients(["site-1", "site-2"]) |
A callable subset. |
collab.clients[0] |
An individual proxy; its call returns that site's result directly. A slice returns a plain list, not a callable ProxyList. |
collab.site_name |
The current site's identity. |
collab.caller / collab.callee |
The calling site, and the receiving app or named object (for example site-1.selector). |
collab.other_clients, collab.child_clients, collab.leaf_clients |
Topology-based subsets. |
collab.get_app_prop() / collab.set_app_prop() |
Per-site configuration values. |
collab.get_prop() / collab.set_prop() |
Data shared within one call context. |
A group call returns a collection you iterate as (client_id, result) pairs; dict(results) gives the successful results.
Call Options
| Option | Default | Applies to | Effect |
|---|---|---|---|
blocking |
True |
group calls | False returns a live, single-pass stream of results as they arrive. |
expect_result |
True |
both | False is fire-and-forget; returns None immediately. |
timeout |
60 s | both | Maximum seconds to wait for each result. |
optional |
False |
single proxy | True turns a failure into a logged warning and a None result. |
secure |
False |
both | Route over point-to-point secure messaging; requires certificates on the site's Cell. |
target |
— | both | Name of a specific collab object at the remote site. |
parallel |
unlimited | group calls | Cap on concurrent in-flight calls. |
process_resp_cb |
— | group calls | Callback invoked as each response arrives (in-time aggregation). |
Error Handling
- A single-proxy call failure raises
CollabCallError(site, function name, cause), unlessoptional=True. - A group call never raises for a per-site failure. It returns the successful results and records each failure in
results.failures(site name toCollabCallError). You must check the quorum yourself, asaggregate()above does. - For non-blocking calls, drain the stream before inspecting
failures:
results = collab.clients(blocking=False).train(weights)
valid = dict(results) # waits for every outcome
for client_id, error in results.failures.items():
print(f"Warning: {client_id} failed: {error}")
CollabRecipe
CollabRecipe is a normal recipe: execute() and export() work with SimEnv, PocEnv, and ProdEnv. Its main arguments:
| Argument | Description |
|---|---|
job_name |
Job name. |
server, client |
The server and client objects. If omitted, the calling module's @collab.main / @collab.publish functions are used. |
min_clients |
Readiness threshold to start the job. It does not enforce a successful-response quorum per call. |
sync_task_timeout |
Timeout for startup synchronization and setup tasks only; it does not affect remote calls. |
server_objects, client_objects |
Additional named objects callable via the target option. |
Use recipe.set_per_site_config({"site-1": {"local_epochs": 3}}) to deliver per-site values, read with collab.get_app_prop("local_epochs"). FedBuffRecipe (also in nvflare.collab) builds buffered asynchronous aggregation on top of CollabRecipe.
Limitations
- No mixed-version jobs: every site needs 2.9.0+, because calls carry a versioned authorization envelope.
- BYOC required: the recipe packages your server and client source into the job, so every site must authorize bring-your-own-code for the submitter.
- No filter pipeline: task/result filters (differential privacy, homomorphic encryption) attach to the task exchange, which Collab calls bypass. Transform data explicitly in your methods.
- Fixed roster: the set of clients is captured at setup; clients cannot join or leave mid-run.
- No automatic retry: retries and checkpoint/resume are the application's responsibility.
See Also
- Job Recipes
- Security for BYOC authorization
- Examples:
nvflare examples get collab-pt,collab-pt-async,collab-llm-sft,collab-simple-async