How rishikrishnah/fl works
Purpose and Entrypoints
FAFT is a PyTorch/Flower federated-learning system for privacy-preserving binary deepfake detection. Its primary runtime entrypoint is flwr run . --stream from quickstart-pytorch/, configured by quickstart-pytorch/pyproject.toml. Pipeline and standalone evaluation entrypoints are quickstart-pytorch/run_experiment.py, quickstart-pytorch/evaluate_saved_model.py, and quickstart-pytorch/evaluate_holdout.py.
Federated Application Boundary
Flower simulation hosts five Ray-backed client actors and one server. Client/server registration and round control live in quickstart-pytorch/pytorchexample/client_app.py and quickstart-pytorch/pytorchexample/server_app.py. Clients retain local image partitions and transmit parameters/metrics only; raw data never crosses the client-server boundary.
Model Layer
quickstart-pytorch/pytorchexample/model.py defines FAFTNet and selectable baseline/hybrid architectures. FAFT combines ResNet18 spatial features, FFT/CNN frequency features, artifact-guided fusion, and a custom transformer whose attention receives artifact-derived bias. The model emits real/fake logits and maintains 768-dimensional real/fake prototype embeddings used as forensic memory.
Local Training and Data Access
quickstart-pytorch/pytorchexample/task.py selects the configured dataset root, loads each client{id} train/validation/test partition, and implements training, testing, checkpoint serialization, mixed precision, and metrics. Dataset preparation creates those partitions outside the repository: quickstart-pytorch/split.py handles the 140K faces layout, while quickstart-pytorch/preprocess_ffpp.py and quickstart-pytorch/preprocess_openforensics.py produce FF++ and OpenForensics layouts.
Round Data Flow and Aggregation
Each round, FlowerClient.fit() loads global model parameters, trains locally, updates class prototypes, and returns model weights plus—only for FAFT—the two prototype tensors. FAFTStrategy in quickstart-pytorch/pytorchexample/server_app.py example-count-weights model updates, EMA-aggregates real/fake prototypes into global memory, checkpoints the resulting model, and broadcasts weights plus global prototypes for the next round. Non-FAFT architectures use SaveModelStrategy for normal FedAvg and checkpointing. Optional malicious-client parameter noise is applied through quickstart-pytorch/pytorchexample/utils.py.
Outputs and Evaluation Boundary
Server rounds produce runtime checkpoints at quickstart-pytorch/saved_models/global_model_round_<N>.pth. quickstart-pytorch/evaluate_saved_model.py detects the checkpoint architecture and evaluates it over all local client test sets. quickstart-pytorch/evaluate_holdout.py evaluates cross-dataset FF++ holdouts; holdout construction is handled by quickstart-pytorch/recreate_holdout_eval.py and quickstart-pytorch/fix_holdout_real.py.
Runtime and Infrastructure
Core runtime dependencies are Python 3.11, PyTorch/TorchVision, Flower 1.13 simulation, and Ray. CUDA is used when available, with CPU fallback. quickstart-pytorch/pytorchexample/gpu_manager.py coordinates Ray actor GPU placement through NVML and a file-locked /tmp/fl_gpu_lock.json; FORCE_GPU can override placement. quickstart-pytorch/run_experiment.py gates execution on GPU availability, retries train/evaluation stages, and writes status artifacts under quickstart-pytorch/experiment_logs/.
Main entry points: client_app.py Flower client · server_app.py Server strategies · run_experiment.py Experiment runner · task.py Local training task
Components 18
Federated Runtime
Flower simulation with Ray-backed clients and server.
- Flower simulation · Runs one server and five Ray-backed client actors.
- Flower client · Loads local partitions and returns parameters, metrics, and FAFT prototypes.
quickstart-pytorch/pytorchexample/client_app.py - Server strategies · Controls rounds, aggregation, prototype memory, and checkpoints.
quickstart-pytorch/pytorchexample/server_app.py - GPU placement manager · Coordinates actor placement using NVML and a locked host file.
quickstart-pytorch/pytorchexample/gpu_manager.py
Model and Local Learning
- FAFTNet and baselines · FAFT fuses spatial, frequency, artifact, and transformer features with prototype memory.
quickstart-pytorch/pytorchexample/model.py - Local training task · Loads client partitions and implements train, test, metrics, and checkpoint serialization.
quickstart-pytorch/pytorchexample/task.py - Real/fake prototypes · Two 768-dimensional embeddings exchanged only by FAFT clients.
- Malicious-client noise · Optionally modifies client parameters before submission.
quickstart-pytorch/pytorchexample/utils.py
Data Preparation and Evaluation
- Client image partitions · Per-client train, validation, and test images remain local.
- 140K faces splitter · Creates the client partition layout outside the repository.
quickstart-pytorch/split.py - FF++ and OpenForensics prep · Produces dataset layouts for federated training.
quickstart-pytorch/preprocess_ffpp.py - Global round checkpoints · Saved as global_model_round_<N>.pth.
- Saved-model evaluation · Detects checkpoint architecture and tests all client test sets.
quickstart-pytorch/evaluate_saved_model.py - Cross-dataset holdout evaluation · Evaluates FF++ holdouts.
quickstart-pytorch/evaluate_holdout.py - Holdout construction · Recreates and fixes FF++ holdout data.
quickstart-pytorch/recreate_holdout_eval.py
Experiment Operations
- Experiment runner · Gates on GPU availability, retries stages, and records status.
quickstart-pytorch/run_experiment.py - Experiment status logs
- Flower project config · Configures the flwr run entrypoint.
quickstart-pytorch/pyproject.toml
Connections 23
- Flower project config → Flower simulation: configures
- Flower simulation → Flower client: hosts five actors
- Flower simulation → Server strategies: hosts server
- GPU placement manager → Flower simulation: places GPU actors
- Flower client → Local training task: runs local fit/test
- Local training task → Client image partitions: reads local images
- Local training task → FAFTNet and baselines: trains and tests
- Flower client → Server strategies: parameters and metrics only · Raw images do not cross this boundary.
- Flower client → Real/fake prototypes: updates FAFT prototypes
- Real/fake prototypes → Server strategies: FAFT tensors
- Server strategies → Real/fake prototypes: EMA global memory
- Server strategies → Flower client: broadcasts weights and prototypes
- Malicious-client noise → Flower client: optional parameter perturbation
- Server strategies → Global round checkpoints: saves each round
- 140K faces splitter → Client image partitions: creates partitions
- FF++ and OpenForensics prep → Client image partitions: prepares source layouts
- Global round checkpoints → Saved-model evaluation: loads
- Client image partitions → Saved-model evaluation: supplies client test sets
- Holdout construction → Cross-dataset holdout evaluation: constructs holdouts
- Global round checkpoints → Cross-dataset holdout evaluation: evaluates model
- Experiment runner → Flower simulation: runs training stage
- Experiment runner → Saved-model evaluation: runs evaluation stage
- Experiment runner → Experiment status logs: writes status