Skip to main content

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

Project description

Implicit Deep Learning Package

License Documentation PyPI

DocumentationQuick 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 torchidl
    
  • 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{torchidl,
    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.3.tar.gz (233.6 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.3-py3-none-any.whl (6.1 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: torchidl-0.0.3.tar.gz
  • Upload date:
  • Size: 233.6 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.3.tar.gz
Algorithm Hash digest
SHA256 7d81c9e8d8c16b9e052997134afc8df85678a0631386dfd9533efdc8cf1494b3
MD5 5640acf35dfd5300e7c17e78d126a8f5
BLAKE2b-256 e7823ca562ede81ce90a6567262f1665b56762d0f999b14c5d2e8258b81470a2

See more details on using hashes here.

File details

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

File metadata

  • Download URL: torchidl-0.0.3-py3-none-any.whl
  • Upload date:
  • Size: 6.1 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.3-py3-none-any.whl
Algorithm Hash digest
SHA256 e760152e01bdd0d8f197f53bdd91397e647321a92f8f7e4104cced546e2bf266
MD5 ee603eccc72c984b0f6cc4788a29af49
BLAKE2b-256 3c59ecb7d997eb4e0e3e187628dd446b5faeaee0003249711582c8e6258f9d60

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