torchnative
Guide가이드

Federated learning연합학습

Devices train locally and share updates, not data. Federated averaging is collective communication, so it is built on torch.distributed rather than beside it.

기기는 로컬에서 학습하고 데이터가 아니라 업데이트를 공유합니다. 연합 평균은 곧 집합 통신이므로 torch.distributed 옆이 아니라 그 위에 지었습니다.

One round한 라운드

import torch
import torch.distributed as dist
from torchnative import federated
from torchnative.federated import algorithms

dist.init_process_group(backend="torchnative", init_method="tcp://127.0.0.1:29500",
                        rank=rank, world_size=world)
fdp = federated.FederatedDataParallel(model, algorithm=algorithms.FedAvg())   # wrap, as with DDP
optimizer = torch.optim.SGD(model.parameters(), lr=1e-2)
for batch in local_batches:                  # your own local training
    optimizer.zero_grad()
    loss_fn(fdp(batch)).backward()
    optimizer.step()
fdp.synchronize(weight=n_local_samples)   # one round: publish the delta, install the average

Each rank trains locally with any torch optimizer, exactly as with DDP, then synchronize contributes its delta and comes back holding the group's weighted average. Federated learning does not depend on test-time adaptation. The acceptance check is equality with the same average computed centrally on upstream torch, torch.equal, not a tolerance.

각 랭크는 DDP 와 똑같이 아무 torch optimizer 로 로컬에서 학습하고, synchronize 가 델타를 내고 그룹의 가중 평균을 들고 돌아옵니다. 연합학습은 테스트 타임 적응에 의존하지 않습니다. 판정 기준은 upstream torch 로 중앙에서 계산한 같은 평균과의 동일성 (허용오차가 아니라 torch.equal) 입니다.

Where it lives어디에 있는가

torch.federated is a top-level package beside torch.distributed (owner decision, 2026-11-08), the way new strategies such as FSDP live in their paradigm package rather than in torch.nn. It holds the communication primitives built on torch.distributed, torch.federated.algorithms (FedAvg, FedAvgM, FedProx) and the module wrappers, whose names start with the paradigm the way DistributedDataParallel does. FederatedDataParallel is horizontal federated learning (samples split, every participant holds the whole model). FederatedFeatureParallel (vertical, features split) is partial (#293): it is built and not yet run in CI. torch.swarm with SwarmDataParallel (peer to peer, no server) is partial (#291): gossip averaging with neighbours over point-to-point is written, and CI has not run its suite yet. Where the torchnative torch is installed, from torch.federated import FederatedDataParallel works; on upstream torch use torchnative.federated.

torch.federated 는 torch.distributed 옆의 최상위 패키지입니다 (오너 결정, 2026-11-08). FSDP 같은 새 전략이 torch.nn 이 아니라 자기 패러다임 패키지에 있는 것과 같습니다. 안에는 torch.distributed 위의 통신 기본형, torch.federated.algorithms (FedAvg, FedAvgM, FedProx), 그리고 모듈 래퍼가 있고, 래퍼 이름은 DistributedDataParallel 처럼 패러다임으로 시작합니다. FederatedDataParallel 은 수평 연합학습 (샘플 분할, 참여자마다 모델 전체) 입니다. FederatedFeatureParallel (수직, 피처 분할) 은 부분 (#293) 입니다. 구현했지만 CI 에서 아직 돌지 않았습니다. torch.swarm 의 SwarmDataParallel (서버 없는 피어 투 피어) 은 부분 (#291) 입니다. 이웃과 점대점으로 하는 가십 평균은 작성했고, CI 가 아직 그 스위트를 돌리지 않았습니다. torchnative 의 torch 가 설치된 곳에서는 from torch.federated import FederatedDataParallel 이 되고, 상류 torch 에서는 torchnative.federated 를 씁니다.

What it refuses거부하는 것

A world of one is refused at every door, because averaging one delta is the identity and would pass any test. Secure aggregation, differential privacy and point-to-point send/recv refuse by name. A rank that does not arrive makes the round raise; it never produces a partial average silently.

월드 크기 1 은 모든 입구에서 거부됩니다. 델타 하나의 평균은 항등이라 어떤 테스트든 통과하기 때문입니다. 보안 집계, 차분 프라이버시, 점대점 send/recv 는 이름으로 거부됩니다. 도착하지 않은 랭크가 있으면 라운드가 예외를 내며, 조용히 부분 평균을 내지 않습니다.