Deep learning models for automated network anomaly detection using perfSONAR telemetry β a GSoC 2026 prototype for the National Research Platform (NRP).
This project implements reconstruction-based anomaly detection for network telemetry from the National Research Platform. It automatically identifies:
- π Slow links β degraded throughput with elevated latency
- π High packet loss β excessive packet loss percentages
- π Excessive retransmits β abnormal TCP retransmission counts
- β Failed tests β complete test failures (zero throughput)
- π High jitter β unstable latency patterns
Three model architectures are implemented, trained, and evaluated:
| Model | Architecture | Parameters | ROC-AUC | PR-AUC |
|---|---|---|---|---|
| Autoencoder | Fully-connected encoder-decoder | 13,796 | 0.820 | 0.216 |
| LSTM | Bidirectional LSTM with attention | 176,125 | 0.932 | 0.990 |
| Transformer | Multi-head self-attention encoder | 120,380 | 0.945 | 0.992 |
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
β NETAI Anomaly Detection β
βββββββββββββββ¬βββββββββββββββ¬βββββββββββββββ¬ββββββββββββββββββββββ€
β Data Layer β Models β Training β Serving β
β β β β β
β βββββββββββ β ββββββββββββ β ββββββββββββ β βββββββββββββββββ β
β βSQLite DBβ β βAutoencoderβ β β Trainer β β β FastAPI REST β β
β β(perfSON.)β β β β β β β β β /predict β β
β ββββββ¬βββββ β ββββββββββββ€ β ββββββββββββ€ β β /predict/bat.β β
β β β β LSTM β β βCheckpointβ β β /health β β
β ββββββΌβββββ β β(BiLSTM) β β β Mgmt β β β /model/info β β
β βFeature β β ββββββββββββ€ β ββββββββββββ€ β βββββββββ¬ββββββββ β
β βPipeline β β βTransform.β β β Early β β β β
β β(rolling,β β β(Attn.) β β β Stopping β β βββββββββΌββββββββ β
β β lag, β β ββββββββββββ β ββββββββββββ β β Kubernetes β β
β β diff, β β β β β Deployment β β
β β scale) β β β β β (GPU pods) β β
β βββββββββββ β β β βββββββββββββββββ β
βββββββββββββββ΄βββββββββββββββ΄βββββββββββββββ΄ββββββββββββββββββββββ
βββ src/netai_anomaly/
β βββ data/
β β βββ schema.py # SQLite schema (perfSONAR-style tables)
β β βββ generator.py # Synthetic telemetry data generator
β β βββ features.py # Feature engineering pipeline
β β βββ dataset.py # PyTorch Dataset classes
β βββ models/
β β βββ base.py # Base model + registry
β β βββ autoencoder.py # FC Autoencoder
β β βββ lstm.py # BiLSTM with temporal attention
β β βββ transformer.py # Transformer encoder
β βββ training/
β β βββ trainer.py # Training loop with early stopping
β β βββ utils.py # Seed management
β βββ evaluation/
β β βββ metrics.py # Precision, Recall, F1, ROC-AUC, PR-AUC
β β βββ visualize.py # Training curves, ROC, PR, score plots
β βββ inference/
β βββ service.py # FastAPI REST inference service
βββ scripts/
β βββ generate_data.py # Data generation CLI
β βββ train.py # Model training CLI
β βββ evaluate.py # Evaluation & plotting CLI
β βββ serve.py # Inference server CLI
βββ configs/ # YAML configuration files
βββ tests/ # 56 comprehensive tests
βββ k8s/ # Kubernetes manifests
βββ Dockerfile # Inference container
βββ Dockerfile.training # GPU training container
βββ docker-compose.yaml # Local development
# Clone the repository
git clone https://github.com/your-username/NETAI-Network-Anomaly-Detection-Models.git
cd NETAI-Network-Anomaly-Detection-Models
# Create virtual environment
python -m venv .venv
source .venv/bin/activate
# Install with all dependencies
pip install -e ".[dev,plots]"python scripts/generate_data.py --num-samples 50000 --anomaly-ratio 0.05This creates a SQLite database at data/network_telemetry.db with realistic perfSONAR-style measurements including throughput, latency, packet loss, retransmits, and jitter.
# Train any of the three architectures
python scripts/train.py --model autoencoder --epochs 50
python scripts/train.py --model lstm --epochs 30
python scripts/train.py --model transformer --epochs 30
# With GPU acceleration
python scripts/train.py --model transformer --device cudapython scripts/evaluate.py --checkpoint checkpoints/transformer_best.ptGenerates evaluation metrics and plots in outputs/<model>/.
python scripts/serve.py --checkpoint checkpoints/transformer_best.pt --port 8000Then query the API:
# Single prediction
curl -X POST http://localhost:8000/predict \
-H "Content-Type: application/json" \
-d '{
"throughput_mbps": 500.0,
"latency_ms": 200.0,
"packet_loss_pct": 15.0,
"retransmits": 150,
"jitter_ms": 45.0
}'
# Response:
# {"is_anomaly": true, "anomaly_score": 0.523, "threshold": 0.154, "confidence": 0.87}
# Batch prediction
curl -X POST http://localhost:8000/predict/batch \
-H "Content-Type: application/json" \
-d '{"samples": [{"throughput_mbps": 9500, "latency_ms": 5, "packet_loss_pct": 0.01, "retransmits": 2, "jitter_ms": 0.5}]}'# Run all 56 tests
python -m pytest tests/ -v
# With coverage
python -m pytest tests/ --cov=netai_anomaly --cov-report=term-missingTest coverage includes:
- Data layer: SQLite schema, data generation, reproducibility, roundtrip I/O
- Feature engineering: Rolling stats, lag features, normalization, pipeline fit/transform
- Models: Forward pass shapes, anomaly scores, gradient flow, all architectures
- Training: Loss convergence, checkpointing, threshold computation, early stopping
- Inference API: All endpoints, error handling, batch processing, validation
# Build and deploy
docker build -t netai-anomaly:latest .
kubectl apply -f k8s/namespace.yaml
kubectl apply -f k8s/configmap.yaml
kubectl apply -f k8s/deployment-inference.yaml
kubectl apply -f k8s/service-inference.yaml# Build training image and launch on NRP GPU cluster
docker build -f Dockerfile.training -t netai-anomaly-training:latest .
kubectl apply -f k8s/job-training.yamlThe training job requests NVIDIA GPU resources and includes proper tolerations for GPU-enabled nodes on the NRP Kubernetes cluster.
The pipeline transforms raw telemetry into model-ready features:
- Rolling statistics β Mean and standard deviation over windows of 5, 15, and 30 time steps
- Lag features β Previous values at lags of 1, 3, 5, and 10 steps
- Rate of change β First-order differences for trend detection
- Normalization β StandardScaler, MinMaxScaler, or RobustScaler
Starting from 5 raw metrics, the pipeline produces 60 engineered features per sample.
Fully-connected encoder-decoder network that compresses telemetry into a low-dimensional latent space. Anomalies produce high reconstruction error because the model has only learned to reconstruct normal patterns.
Bidirectional LSTM with temporal attention that captures sequential dependencies in network time series. Processes sliding windows of 60 time steps to detect anomalous temporal patterns.
Multi-head self-attention encoder with sinusoidal positional encoding. Excels at capturing long-range dependencies and achieves the highest ROC-AUC (0.945) among all models.
All hyperparameters are managed through YAML files in configs/:
# configs/default.yaml
data:
sequence_length: 60
anomaly_ratio: 0.05
feature_engineering:
rolling_windows: [5, 15, 30]
lag_steps: [1, 3, 5, 10]
scaler: "standard"
training:
epochs: 50
batch_size: 64
learning_rate: 0.001
patience: 10
scheduler: "cosine"| Category | Technologies |
|---|---|
| Deep Learning | PyTorch, Autoencoder, LSTM, Transformer |
| ML/Data | scikit-learn, Pandas, NumPy |
| Storage | SQLite (perfSONAR telemetry) |
| API | FastAPI, Pydantic, Uvicorn |
| Infrastructure | Docker, Kubernetes, GPU Pods |
| Testing | pytest (56 tests), pytest-cov |
| Config | YAML, argparse |
Apache License 2.0 β see LICENSE.
- National Research Platform (NRP) for infrastructure and LLM/GPU services
- perfSONAR for network measurement tools
- ESnet for network monitoring tooling
- Mentors: Dmitry Mishin, Derek Weitzel