nilmtk-contrib

July 20, 2026 ยท View on GitHub

This repository contains maintained NILMTK-compatible disaggregation models. Use it to run, test, or contribute an algorithm.

Ecosystem repositories

Research taskRepository
Dataset conversion, meter access, preprocessing, and metricsNILMTK core
Appliance taxonomy, synonyms, meter relationships, and dataset schemaNILM Metadata
Disaggregation model implementation and testingnilmtk-contrib โ€” this repository
Fixed T1/T2/T3 evaluation and published result bundlesNILMbench

The NILMTK start page gives the supported install, Docker, citation, and contribution routes for the whole ecosystem.

Citation

If you use this model suite or its rapid experimentation interface, cite the nilmtk-contrib paper:

@inproceedings{10.1145/3360322.3360844,
  author = {Batra, Nipun and Kukunuri, Rithwik and Pandey, Ayush and Malakar, Raktim and Kumar, Rajat and Krystalakos, Odysseas and Zhong, Mingjun and Meira, Paulo and Parson, Oliver},
  title = {Towards Reproducible State-of-the-Art Energy Disaggregation},
  year = {2019},
  isbn = {9781450370059},
  publisher = {Association for Computing Machinery},
  address = {New York, NY, USA},
  url = {https://doi.org/10.1145/3360322.3360844},
  doi = {10.1145/3360322.3360844},
  booktitle = {Proceedings of the 6th ACM International Conference on Systems for Energy-Efficient Buildings, Cities, and Transportation},
  pages = {193--202},
  numpages = {10},
  keywords = {smart meters, energy disaggregation, non-intrusive load monitoring},
  location = {New York, NY, USA},
  series = {BuildSys '19}
}

Also cite the original paper for every model and dataset you use. Cite the NILMBench2026 paper only when using its protocols, runner, or leaderboard results.

Install and verify

The supported environment is Python >=3.11,<3.12. Use Python 3.11.

Install uv, then run:

uv venv --python 3.11
source .venv/bin/activate
UV_TORCH_BACKEND=cpu uv pip install \
  "nilmtk-contrib[torch] @ git+https://github.com/nilmtk/nilmtk-contrib.git"
python -c "from nilmtk_contrib.torch import Seq2PointTorch; print('ready')"

On Windows PowerShell, activate the environment with .venv\Scripts\Activate.ps1.

Choose a different extra only when you need that backend:

ExtraUse it for
torchPyTorch models, including current time-series and MoE models
classicalAFHMM and AFHMM-SAC
allPyTorch and classical models; largest install
nilmNILMTK integration without a model backend

Replace torch in the install command with the required extra. A bare install contains package metadata and dependency-light utilities; it cannot train a backend model.

Backend policy

PyTorch is the maintained backend for neural and state-space models. Historical package-level imports such as nilmtk_contrib.disaggregate.DAE now resolve to the corresponding PyTorch class and emit a FutureWarning; new code should import from nilmtk_contrib.torch. The duplicated TensorFlow implementations and their direct module paths have been removed. The remaining classical AFHMM implementations stay available until equivalent Torch implementations pass numerical and real-data comparison tests.

Historical compatibility imports map as follows:

Compatibility importMaintained import
nilmtk_contrib.disaggregate.BERTnilmtk_contrib.torch.BERT
nilmtk_contrib.disaggregate.DAEnilmtk_contrib.torch.DAE
nilmtk_contrib.disaggregate.DSCnilmtk_contrib.torch.DSC
nilmtk_contrib.disaggregate.RNNnilmtk_contrib.torch.RNN
nilmtk_contrib.disaggregate.RNN_attentionnilmtk_contrib.torch.RNN_attention
nilmtk_contrib.disaggregate.RNN_attention_classificationnilmtk_contrib.torch.RNN_attention_classification
nilmtk_contrib.disaggregate.ResNetnilmtk_contrib.torch.ResNet
nilmtk_contrib.disaggregate.ResNet_classificationnilmtk_contrib.torch.ResNet_classification
nilmtk_contrib.disaggregate.Seq2Pointnilmtk_contrib.torch.Seq2PointTorch
nilmtk_contrib.disaggregate.Seq2Seqnilmtk_contrib.torch.Seq2Seq
nilmtk_contrib.disaggregate.WindowGRUnilmtk_contrib.torch.WindowGRU

Run a model

Public model imports are listed in the model table. For example:

from nilmtk_contrib.torch import Seq2PointTorch

model = Seq2PointTorch(
    {
        "sequence_length": 99,
        "n_epochs": 1,
        "batch_size": 32,
        "device": "cpu",
        "seed": 0,
    }
)

Training requires NILMTK-compatible mains and appliance data. The sample_notebooks directory shows the rapid experimentation API. Use NILMbench when the goal is a comparable published result rather than an exploratory run.

Development

git clone https://github.com/nilmtk/nilmtk-contrib.git
cd nilmtk-contrib
uv sync --frozen --group dev --extra torch
uv run ruff check nilmtk_contrib tests scripts
uv run pytest -q
uv build

CI also smoke-tests every exported PyTorch model for one epoch. Run that gate locally when model discovery, shared preprocessing, or the base class changes:

uv run pytest tests/test_model_smoke_synthetic.py \
  --run-model-smoke --model-smoke-backend torch \
  --model-smoke-epochs 1 -q

Add a model

Keep a model PR focused on the implementation. It should:

  1. use the shared validation, preprocessing, checkpoint, device, seed, and logging utilities instead of copying them;
  2. expose the model lazily from the backend package;
  3. test defaults, parameter validation, short/partial chunks, serialization, determinism, CPU inference, and the intended CUDA path;
  4. enter the all-model smoke test and public model table;
  5. cite the original model paper and state clearly when an architecture is a NILM adaptation rather than a paper-faithful reproduction.

After the model PR merges, open a separate NILMbench PR for its adapter and search space. A model reaches the leaderboard only through a provenance-complete real-data result bundle.

Docker

This repository owns the one general NILMTK development Dockerfile. It contains core, metadata, and the selected contrib backend. Do not add an image per model.

Build the image locally with Docker 24 or newer. Anonymous pulls from the GHCR package are not yet part of the supported path, so this README does not publish a docker pull command that may require organization access.

NILMbench owns separate pinned CPU-smoke and CUDA benchmark images. Those images certify results; they are not general development images.

Prerequisites

Build locally

The default build includes the PyTorch and classical backends:

docker build -t nilmtk-contrib:all .

Prefer a narrower backend for faster development builds:

docker build -t nilmtk-contrib:torch --build-arg INSTALL_EXTRA=torch .
docker build -t nilmtk-contrib:classical --build-arg INSTALL_EXTRA=classical .

Add tests and development tools only when needed:

docker build -t nilmtk-contrib:dev --build-arg INSTALL_DEV=true .

Run interactively

docker run --rm -it nilmtk-contrib:all bash

Datasets are not included. Mount a licensed local dataset directory read-only:

docker run --rm -it -v /path/to/datasets:/data:ro nilmtk-contrib:all bash

On Windows PowerShell, use a drive path such as -v C:/Users/you/datasets:/data:ro.

GPU-enabled shell (requires NVIDIA Container Toolkit):

docker run --rm -it --gpus all nilmtk-contrib:all bash

Verify the image

Check the package and selected backend after building:

docker run --rm nilmtk-contrib:all python -c "import nilmtk_contrib; print(nilmtk_contrib.__version__)"
docker run --rm nilmtk-contrib:all python -c \
  "from nilmtk_contrib.torch import Seq2PointTorch; print('ready')"

The development image runs the same suite as the local environment:

docker build -t nilmtk-contrib:dev --build-arg INSTALL_DEV=true .
docker run --rm nilmtk-contrib:dev python -m compileall -q nilmtk_contrib tests
docker run --rm nilmtk-contrib:dev python -m pytest -q

Docker build arguments

ArgumentDefaultAllowed valuesPurpose
INSTALL_EXTRAallall, torch, classicalOptional dependency extra to install
INSTALL_DEVfalsetrue, falseAlso install .[dev] for pytest and tooling

Files

FilePurpose
DockerfileMulti-backend image definition with build args
.dockerignoreKeeps build context small and excludes local artifacts

Models

The table below lists the public model surface. "Verification" describes how the implementation should be cited and interpreted in research use.

AlgorithmBackendImport pathVerificationPaper/sourceNotes
AFHMMClassicalnilmtk_contrib.disaggregate.AFHMMNILM paper implementation, not independently benchmark-certified in this package stateKolter and Jaakkola, AFHMM for energy disaggregationRequires classical extra
AFHMM_SACClassicalnilmtk_contrib.disaggregate.AFHMM_SACNILM paper implementation, not independently benchmark-certified in this package stateZhong, Goddard, and Sutton, signal aggregate constraints in AFHMMsRequires classical extra
TorchAFHMMPyTorchnilmtk_contrib.torch.TorchAFHMMSupervised solver-free additive FHMM baseline; benchmark claims require NILMbench result bundlesKolter and Jaakkola, AFHMM for energy disaggregationFits observed appliance HMMs and one shared residual-background mean, then uses deterministic coordinate-ascent Viterbi; the legacy CVXPY implementation remains separate
DAEPyTorchnilmtk_contrib.torch.DAEPyTorch implementation requiring parity validation for new claimsKelly and Knottenbelt, Neural NILMPyTorch backend
DLinearPyTorchnilmtk_contrib.torch.DLinearDLinear-inspired sequence-to-point adaptation; benchmark claims require NILMbench result bundlesZeng et al., DLinearPyTorch backend
DSCPyTorchnilmtk_contrib.torch.DSCSolver-free non-negative DSC port; numerical parity passed on REDD, UK-DALE, and REFITKolter, Batra, and Ng, discriminative sparse codingProximal sparse-code objective is checked against scikit-learn gold solutions; the historical import is a compatibility wrapper
FeatureMLPPyTorchnilmtk_contrib.torch.FeatureMLPStatistical and spectral window-feature baseline; benchmark claims require NILMbench result bundlesThis repository21 fixed PyTorch features followed by a small MLP; no external feature library
HSMMPyTorchnilmtk_contrib.torch.HSMMSupervised single-appliance explicit-duration baseline; benchmark claims require NILMbench result bundlesChiappa, explicit-duration Markov switching modelsExact PyTorch dynamic program; no external solver
RNNPyTorchnilmtk_contrib.torch.RNNPyTorch implementation requiring parity validation for new claimsKelly and Knottenbelt, Neural NILMPyTorch backend
Seq2PointTorchPyTorchnilmtk_contrib.torch.Seq2PointTorchPyTorch implementation requiring parity validation for new claimsZhang et al., Sequence-to-Point LearningPyTorch backend
Seq2SeqPyTorchnilmtk_contrib.torch.Seq2SeqLegacy NILM baseline adapted from a generic sequence modelSutskever, Vinyals, and Le, sequence-to-sequence learningGeneric architecture citation
WindowGRUPyTorchnilmtk_contrib.torch.WindowGRUPyTorch implementation requiring parity validation for new claimsKrystalakos, Nalmpantis, and Vrakas, sliding-window GRUPyTorch backend
RNN_attentionPyTorchnilmtk_contrib.torch.RNN_attentionPyTorch attention-based NILM implementationAttention-based NILM literaturePyTorch backend
RNN_attention_classificationPyTorchnilmtk_contrib.torch.RNN_attention_classificationPyTorch attention-based NILM implementation with classification branchAttention-based NILM literatureExplicit on/off threshold parameters are supported
ResNetPyTorchnilmtk_contrib.torch.ResNet1D residual NILM adaptation of a generic architectureHe et al., Deep Residual LearningGeneric computer-vision architecture adapted to NILM
ResNet_classificationPyTorchnilmtk_contrib.torch.ResNet_classificationResidual NILM model with classification branchResidual and NILM classification literatureExplicit threshold and loss-weight parameters are supported
BERTPyTorchnilmtk_contrib.torch.BERTTransformer/BERT-inspired NILM adaptationDevlin et al., BERTDoes not claim NLP-style pretraining
ConvLSTMPyTorchnilmtk_contrib.torch.ConvLSTMConvLSTM-inspired NILM adaptationShi et al., ConvLSTMGeneric spatiotemporal architecture adapted to NILM
TCNPyTorchnilmtk_contrib.torch.TCNGeneric TCN sequence-modeling baseline adapted to NILMBai, Kolter, and Koltun, TCNPyTorch backend
SGNPyTorchnilmtk_contrib.torch.SGNSubtask-gated sequence-to-point adaptation; benchmark claims require NILMbench result bundlesShin et al., SGNUses a raw-power-correct soft on/off gate and auxiliary classification loss
TSMixerPyTorchnilmtk_contrib.torch.TSMixerAll-MLP sequence-to-point adaptation; benchmark claims require NILMbench result bundlesChen et al., TSMixerMixes along time and feature dimensions without attention or recurrence
TimesNetPyTorchnilmtk_contrib.torch.TimesNetTimesNet-inspired sequence-to-point adaptation; benchmark claims require NILMbench result bundlesWu et al., TimesNetPyTorch backend
ReformerPyTorchnilmtk_contrib.torch.ReformerReformer-inspired NILM adaptationKitaev, Kaiser, and Levskaya, ReformerEfficient Transformer architecture adapted to NILM
MSDCPyTorchnilmtk_contrib.torch.MSDCNILM paper implementation requiring experiment validation for new claimsMSDC dual-CNN NILM paperCanonical CRF-enabled implementation path
MSDC without CRFPyTorchnilmtk_contrib.torch.msdc_without_crf.MSDCMSDC ablationMSDC paper/source implementationNo-CRF ablation, not the canonical MSDC path
ModernTCNPyTorchnilmtk_contrib.torch.ModernTCNModernTCN-inspired sequence-to-point adaptation; benchmark claims require NILMbench result bundlesLuo and Wang, ModernTCNPyTorch backend
NILMFormerPyTorchnilmtk_contrib.torch.NILMFormerNILMFormer implementation requiring experiment validation for new claimsPetralia et al., NILMFormerPyTorch backend
NILMMoEPyTorchnilmtk_contrib.torch.NILMMoEExperimental input-conditioned mixture; benchmark claims require NILMbench result bundlesThis repositoryBlends DLinear, ModernTCN, and TimesNet with a load-balanced softmax gate
PatchTSTPyTorchnilmtk_contrib.torch.PatchTSTPatchTST-inspired sequence-to-point adaptation; benchmark claims require NILMbench result bundlesNie et al., PatchTSTPyTorch backend
ResidualMoEPyTorchnilmtk_contrib.torch.ResidualMoEExperimental conservative residual mixture; benchmark claims require NILMbench result bundlesThis repositoryStarts exactly at TimesNet and learns a bounded signed correction from PatchTST and ModernTCN

Reference Papers And Codebases

NILM-specific references:

Generic architecture references:

Reference repositories:

Data, notebooks, and benchmark results

This package does not redistribute licensed datasets or publish leaderboard rows. Download each dataset from its official custodian and convert it with NILMTK core.

The notebooks under sample_notebooks demonstrate the NILMTK rapid experimentation API for exploratory work across appliances, buildings, datasets, and sample rates. They are examples, not frozen benchmark protocols.

For comparable real-data runs, pinned environments, provenance-complete result bundles, and the living leaderboard, use NILMbench.