Skip to main content

Official package of Implicit Deep Learning and State-driven Implicit Models

Project description

Implicit Deep Learning Package

License Documentation PyPI

Quick TutorialInstallationExamplesCitation

Authors: Hoang Phan, Bao Tran, Chi Nguyen, Bao Truong, Thanh Tran, Khai Nguyen, Alicia Y. Tsai, Hong Chu, Laurent El Ghaoui

Introduction

Traditional feedforward neural networks compute hidden states by passing inputs sequentially through layers. In contrast, Implicit Deep Learning determines these hidden states by solving fixed-point equations. This approach offers theoretical advantages in stability, memory efficiency, and expressivity.

implicit_figure

Formally, given input $u \in \mathbb{R}^p$ and output $y \in \mathbb{R}^q$, the implicit model (Figure b) computes the equilibrium hidden state $x \in \mathbb{R^n}$ by solving:

$$ \begin{cases} \begin{aligned} x &= \phi(A x + B u), \quad &&\text{(Equilibrium equation)} \ \hat{y} &= C x + D u, \quad &&\text{(Prediction equation)} \end{aligned} \end{cases} $$

where $\phi$ is a non-linear activation function that satisfies the well-posedness condition (e.g., ReLU), and $A \in \mathbb{R}^{n \times n}, B \in \mathbb{R}^{n \times p}, C \in \mathbb{R}^{q \times n}, D \in \mathbb{R}^{q \times p}$ are learnable parameters.

This formulation can represent any feedforward network. For example, a simple MLP with 2 hidden layers (Figure a):

$$ x_1 = \phi(W_0u) \longrightarrow x_2=\phi(W_1x_1) \longrightarrow \hat{y}(u) = W_2 x_2. $$

can be rewritten in matrix form as:

$$x = \phi(A x + B u) = \phi \left( \left[\begin{array}{cc} 0 & W_1 \ 0 & 0 \end{array}\right] \left[\begin{array}{c} x_2 \ x_1 \end{array}\right] + \left[\begin{array}{c} 0 \ W_0 \end{array}\right] u \right) = \phi \left[\begin{array}{c} W_1 x_1 \ W_0 u \end{array}\right] = \left[\begin{array}{c} x_2 \ x_1 \end{array}\right] $$

$$\hat{y} = C x + D u = \left[\begin{array}{cc} W_2 & 0 \end{array}\right] \left[\begin{array}{c} x_2 \ x_1 \end{array}\right] + \left[\begin{array}{c} 0 \end{array}\right] u = W_2 x_2$$

For a conceptual introduction to Implicit Models, see this article on Medium. For mathematical foundations and technical details, refer to the SIAM journal paper.

Installation

  • Via pip:
    pip install idl
    
  • From source:
    git clone https://github.com/HoangP8/Implicit-Deep-Learning && cd Implicit-Deep-Learning
    pip install -e .
    

Quick Tour

The idl package provides a comprehensive framework for implementing and experimenting with implicit models. It includes the foundational ImplicitModel, the recurrent variant ImplicitRNN, and the state-driven training approach SIM. Below are simple examples of how to use each model. More details of the package including the theory and functions can be found in the documentation.

Example: ImplicitModel

from idl import ImplicitModel

# Prepare your dataset
train_loader, test_loader = ...

# Initialize the model
model = ImplicitModel(
    hidden_dim=100,  # Hidden state dimension
    input_dim=3072,  # Input dimension
    output_dim=10,   # Output dimension
).to(device)

# Standard PyTorch training loop
optimizer = torch.optim.Adam(model.parameters(), lr=1e-3)
criterion = torch.nn.CrossEntropyLoss()

for epoch in range(num_epochs): 
    for inputs, targets in train_loader:
        optimizer.zero_grad()
        outputs = model(inputs)
        loss = criterion(outputs, targets) 
        loss.backward()  
        optimizer.step()

Example: SIM (State-driven Implicit Modeling)

State-driven Implicit Modeling (SIM) is a training method for Implicit Models that uses a pretrained network to synthesize training data. SIM formulates the training process of Implicit Models as a convex optimization problem so that it can be solved stably and efficiently.

Requirements:

  • A pretrained network
  • A convex optimization solver

For more details, see the documentation.

import torch
from idl.sim import SIM
from idl.sim.solvers import CVXSolver

# Prepare your dataset
train_loader, test_loader = ...

# Load a pretrained explicit model
explicit_model = MLP(input_dim, hidden_dim, output_dim).to(device)
explicit_model.load_state_dict(torch.load('checkpoint.pt'))

# Initialize SIM model and solver
sim = SIM(activation_fn=torch.nn.functional.relu, device=device)
solver = CVXSolver()

# Train and evaluate
sim.train(solver=solver, model=explicit_model, dataloader=train_loader)
sim.evaluate(test_loader)

The package provides multiple solvers including:

  • CVXSolver: Convex optimization solver
  • ADMMSolver: Standard ADMM implementation
  • ADMMMultiGPUSolver: Distributed training across multiple GPUs
  • ProjectedGDLowRankSolver: Projected gradient descent with low-rank constraints
  • LeastSquareSolver: Efficient least squares solver using numpy.linalg.lstsq (ignores well-posedness constraint)

Besides, custom solvers can also be implemented by extending the BaseSolver class.

Documentation and Examples

More details of the package are provided in the documentation. For a comprehensive introduction, see our Notebook tutorial. The examples directory contains implementation examples for each model variant.

To run an example:

bash examples/idl/idl.sh

Related Works

Implicit Deep Learning
SIAM, 2020
Laurent El Ghaoui, Fangda Gu, Bertrand Travacca, Armin Askari, Alicia Y. Tsai

Constrained Implicit Learning Framework for Neural Network Sparsification
ACML, 2025
Alicia Y. Tsai, Wenzhi Gao, Laurent El Ghaoui

The Extrapolation Power of Implicit Models
IJCAI, 2024
Juliette Decugis, Alicia Y Tsai, Max Emerling, Ashwin Ganesh, Laurent El Ghaoui

State-driven Implicit Modeling for Sparsity and Robustness in Neural Networks
arxiv, 2022
Alicia Y. Tsai, Juliette Decugis, Laurent El Ghaoui, Alper Atamtürk

Implicit Learning in Deep Models: Enhancing Extrapolation Power and Sparsity
Dissertation, 2024
Alicia Y. Tsai

Citation

@misc{idl,
    author = {Hoang Phan and Bao Tran and Chi Nguyen and Bao Truong and Thanh Tran and Khai Nguyen and Alicia Y. Tsai and Hong Chu and Laurent El Ghaoui},
    title = {Implicit Deep Learning Pytorch Package},
    year = {2025},
    publisher = {GitHub},
    journal = {GitHub repository},
    howpublished = {\url{https://github.com/HoangP8/Implicit-Deep-Learning}},
}

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

torchidl-0.0.1.tar.gz (233.5 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

torchidl-0.0.1-py3-none-any.whl (32.0 kB view details)

Uploaded Python 3

File details

Details for the file torchidl-0.0.1.tar.gz.

File metadata

  • Download URL: torchidl-0.0.1.tar.gz
  • Upload date:
  • Size: 233.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.11.5

File hashes

Hashes for torchidl-0.0.1.tar.gz
Algorithm Hash digest
SHA256 1889c5e2ea6d5d61385bc303a920804841fd4e3c44bb6154dafc66d9fbd6da36
MD5 c2e70e0fc13e3532226ec0f1e5195571
BLAKE2b-256 34c809dd8b2d1616d33d6d53986215e1611acb485a5db1542003d7ba8053f390

See more details on using hashes here.

File details

Details for the file torchidl-0.0.1-py3-none-any.whl.

File metadata

  • Download URL: torchidl-0.0.1-py3-none-any.whl
  • Upload date:
  • Size: 32.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.11.5

File hashes

Hashes for torchidl-0.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 434eab325c06b7c013b5579d3f5693a29406d143ac3bbceb8e465bf2a7d27bc1
MD5 4d2596653854c86774cb39a234a7816a
BLAKE2b-256 c6804ea2a4c69eb5c180403ff68b3052f53453c046fb19742ebabf87964a3bb5

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page