How jiaxiang-cheng/pytorch-transformer-for-rul-prediction works
Project type & purpose (what you’re diagramming)
This is not a multi-service “system” in the web sense; it’s a single-node ML training/evaluation pipeline implemented in Python using PyTorch, for Remaining Useful Life (RUL) prediction on the NASA CMAPSS turbofan datasets (FD001–FD004).
What the repo structure implies (map files to responsibilities)
From the tree + README, the core components are:
Data assets
• CMAPSSData/
• train_FD00x.txt, test_FD00x.txt, RUL_FD00x.txt: raw CMAPSS splits + ground-truth RUL for test engines.
• Damage Propagation Modeling.pdf, readme.txt: dataset documentation.
Data preprocessing / feature-label construction
• add_remaining_useful_life.py
• Likely computes per-timestep RUL labels for training trajectories (common CMAPSS step: RUL = max_cycle - current_cycle, maybe capped).
• loading_data.py
• Likely parses the CMAPSS text files into pandas/numpy and/or builds PyTorch datasets/dataloaders (windowing / normalization / sensor selection).
Model definition
• model.py
• Defines the Transformer encoder + convolutional layers (as described in README). This is the “core IP” of the repo.
Training / evaluation / experimentation
• train.py
• Entry point (python train.py --dataset FD001), orchestrates: load data → build model → train epochs → evaluate each epoch → print loss/RMSE.
• testing.py
• Encapsulates evaluation logic and RMSE computation on the test set (likely uses RUL_FD00x.txt for final per-engine RUL).
• Produces plots (loss curves, predicted vs actual RUL, etc.) using matplotlib.
Environment / packaging
• requirements.txt: pins dependencies.
Data layer (left side)
• CMAPSS Raw Files
• train_FD00x.txt
• test_FD00x.txt
• RUL_FD00x.txt
• Dataset selection
• CLI arg: --dataset FD001 (in train.py) controls which files are loaded.
Data processing layer
• Parser/Loader (loading_data.py)
• Reads text → pandas/numpy tables
• Splits into train/val/test (if implemented)
• Adds computed RUL labels for training series
• Windowing / Sequence builder (often in loader)
• Converts per-engine time series into fixed-length sequences for Transformer input
• Normalization / scaling
• Often applied per-sensor; show it as a distinct component even if it’s just a few lines in loading_data.py.
• PyTorch Dataset / DataLoader
• Produces batched tensors to the training loop
Model layer (center)
Inside model.py, represent subcomponents explicitly:
• Input embedding / projection (if present)
• Convolutional feature extractor
• (1D conv blocks / gated conv unit per cited paper)
• Transformer Encoder stack
• Multi-head self-attention
• Feed-forward layers
• Residual + LayerNorm (if implemented)
• Regression head
• Maps encoder output → scalar RUL prediction
Training & evaluation layer (right side)
• Training Orchestrator (train.py)
• Argument parsing
• Instantiates dataset/dataloader and model
• Optimizer + loss function
• Epoch loop
• Backprop / Optimizer step
• “Loss → gradients → weight update”
• Evaluation (testing.py)
• Runs model on test set
• Computes RMSE (explicitly called out in README)
• Plots metrics/predictions
Outputs / artifacts (far right / bottom)
• Console metrics
• Epoch loss, RMSE
• (If implemented) Model checkpoints
• e.g., *.pt / *.pth (not in tree, but many training scripts save weights—confirm by scanning train.py)
• Plots
each epoch: train.py → testing.py → RMSE result → train.py prints
library dependencies as annotations:
• loading_data.py depends on pandas/numpy
• model.py/train.py/testing.py depend on PyTorch
Architectural patterns to highlight (what’s “important” here)
• Pipeline architecture: deterministic flow from raw data → processed sequences → model → metrics.
• Separation of concerns by file:
• data prep (loading_data.py, add_remaining_useful_life.py)
• model definition (model.py)
• orchestration (train.py)
• evaluation (testing.py)
• Sequence modeling pattern:
• convolutional front-end (local feature extraction)
• transformer encoder (global temporal dependencies)
• regression head (scalar RUL)
• Clear labels: use filenames as subtitles (e.g., “Data Loader (loading_data.py)”).
• Rectangles: Python modules/scripts
• Rounded rectangles: runtime constructs (DataLoader, Optimizer)
• “sensor sequences”, “RUL labels”, “predicted RUL”, “loss”, “RMSE”