@chongshenng/fed-engines

0
4
flwr new @chongshenng/fed-engines

Federated Engine Anomaly Detection

This is a minimal Flower / PyTorch app for binary anomaly detection on the Hugging Face dataset. It uses Flower's Message API (ServerApp, ClientApp, Message, ArrayRecord, and MetricRecord) and initializes the server model from one client.

The dataset has one train split with eight numeric sensor features and labels where 0 is normal and 1..12 are fault types. This app maps those labels to a binary classifier: normal vs anomaly. The server runs FedProx, while clients use the FedBN approach by keeping BatchNorm state local and returning only non-BN weights for aggregation.

Use case

The app models a basic engine health monitoring workflow. Each client represents an engine, fleet site, test bench, or service location with local sensor data. The model sees vibration, temperature, pressure, current, flow rate, and acoustic readings, then predicts whether the current operating sample looks normal or anomalous.

In a real deployment, abnormal predictions could trigger maintenance review, operator alerts, or higher-fidelity diagnostics before a failure becomes expensive. The federated setup is useful because each site can train on its own operating data while sharing model updates instead of raw sensor records.

This prototype intentionally keeps the problem simple:

  • label == 0 is treated as normal operation.
  • label > 0 is treated as an anomaly.
  • The model is a small MLP over eight numeric sensor features.
  • BatchNorm state remains local to each client to model site-specific operating distributions.
  • FedProx adds a proximal term to local training so client updates stay closer to the current global model under non-IID data.
  • Local training uses class-weighted cross entropy to reduce the anomaly-class majority bias after the binary label mapping.
  • Metrics include raw accuracy, balanced accuracy, normal recall, and anomaly recall because raw accuracy can be dominated by the majority anomaly class.
  • Client partitions simulate separate local data owners for Flower simulation.

Federated setup

The default configuration uses a non-IID Dirichlet partitioner:

partitioner = "dirichlet"
partition-by = "label"
dirichlet-alpha = 0.3
dirichlet-min-partition-size = 10
dirichlet-self-balancing = false
proximal-mu = 0.01

The Dirichlet partitioner gives each client a different mix of normal and fault labels. This is a simple stand-in for fleet sites seeing different operating profiles, equipment histories, or fault distributions.

Project layout

.
├── fed_engines
│   ├── __init__.py
│   ├── client_app.py
│   ├── server_app.py
│   └── task.py
├── pyproject.toml
└── README.md

Install

uv sync --python 3.12

Run a local simulation

Configure the local Flower Simulation Runtime once:

uv run flwr federation simulation-config \
  --num-supernodes 2 \
  --client-resources-num-cpus 4 \
  --client-resources-num-gpus 0.0

Then run the app:

uv run flwr run . --stream