Skip to main content

BOAT

A Compositional Operation Toolbox for Gradient-based Bi-Level Optimization

Home | Installation | Docs | Tutorials | Examples

PyPI GitHub Actions Workflow Status codecov pages-build-deployment GitHub commit activity GitHub top language GitHub language count Python version license Code style: black

BOAT is a compositional OperAtion-level Toolbox for gradient-based BLO. Unlike existing libraries that typically encapsulate fixed solver routines, BOAT factorizes the BLO workflow into atomic, reusable primitives. Through a unified constraint reconstruction perspective, it empowers researchers to automatically compose over 85+ solver variants from a compact set of 17 gradient operations.

This is the Jittor-based version of BOAT (boat-jit). It leverages Jittor’s Just-In-Time (JIT) compilation and efficient CUDA/cuDNN backends to significantly accelerate large-scale gradient-based BLO experiments.

BOAT supports unified execution across backends via separate branches:

BOAT Structure

🔑 Key Features

  • 🧩 Compositional Operation-Level Abstraction: Deconstructs BLO solvers into three modular stages: Gradient Mapping (GM), Numerical Approximation (NA), and First-Order (FO).
  • ⚡ Accelerated JIT Execution: Built on Jittor, enabling meta-operator fusion and high-performance execution on NVIDIA GPUs.
  • 🏭 Generative Solver Construction: Supports dynamic serialization of operations. Users can recover classical algorithms or discover novel hybrid solvers simply by changing configurations.
  • 🛠 Configuration-Driven: Define complex optimization strategies via simple JSON configurations, decoupling algorithmic logic from model definitions.
  • ✅ Comprehensive Testing: Achieves 99% code coverage through rigorous testing with pytest, ensuring software robustness.

📚 Supported Operation Libraries

BOAT implements 17 atomic gradient operations organized into three modular libraries. These primitives can be dynamically serialized to generate over 85+ solver variants, covering the full spectrum of BLO methodologies.

Library Functional Role Supported Atomic Operations
GM-OL
(Gradient Mapping)
Reconstructs the LL iterative trajectory.
Customizes the dynamic mapping rules ($\mathcal{T}_k$) to shape the optimization path and variable coupling.
• NGD (Naive Gradient Descent)
• GDA (Gradient Descent Aggregation)
• DI (Dynamic Initialization)
• DM (Dual Multiplier / KKT)
NA-OL
(Numerical Approx.)
Resolves the auxiliary gradient bottleneck.
Approximates the implicit gradients or hyper-gradients via automatic differentiation, numerical inversion, or truncation.
• RAD (Reverse-AD / Unrolled)
• RGT (Reverse Gradient Truncation)
• PTT (Pessimistic Trajectory Truncation)
• FD (Finite Difference / DARTS)
• CG (Conjugate Gradient)
• NS (Neumann Series)
• IGA (Implicit Gradient Approximation)
• IAD (Init-based AD / MAML)
• FOA (First-Order Approx. / Reptile)
FO-OL
(First-Order)
Constructs single-level surrogates.
Reformulates the nested problem into first-order objectives using value-functions or penalties, avoiding Hessian computations.
• VSO (Value-Function Sequential)
• VFO (Value-Function First-Order)
• MESO (Moreau Envelope)
• PGDO (Penalty Gradient Descent)

🔨 Installation

BOAT-jit is built on top of Jittor. Please ensure Jittor is installed correctly before installing BOAT.

1. Install Jittor

Follow the Official Installation Guide or use the commands below:

Linux (Ubuntu / CentOS)

sudo apt install python3.8-dev libomp-dev
python3.8 -m pip install jittor
# Verify installation (Optional)
python3.8 -m jittor.test.test_example

Windows

python -m pip install jittor
python -m jittor.test.test_core

macOS

brew install libomp
python3.8 -m pip install jittor

2. Install BOAT-jit

Once Jittor is ready, install BOAT-jit via PyPI or Source:

# Install from PyPI
pip install boat-jit

# Or install from Source (Specific Branch)
git clone -b boat_jit --single-branch https://github.com/callous-youth/BOAT.git
cd BOAT
pip install -e .

✅ Quick Verification

Run the following commands from the root directory of the BOAT repository:

python examples/L2_Reg_jit/l2_regularization.py

python examples/neural_architecture_search/neural_architecture_search.py

⚡ How to Use BOAT

BOAT separates the problem definition from the solver configuration. Below is a Jittor-based example.

1. Load Configurations

import json
import boat_jit as boat

# Load algorithmic configurations
with open("configs/boat_config.json", "r") as f:
    boat_config = json.load(f)

# Load objective configurations
with open("configs/loss_config.json", "r") as f:
    loss_config = json.load(f)

2. Define Models and Optimizers

Use standard Jittor models and optimizers.

import jittor as jit

# Define models
upper_model = MyUpperModel()
lower_model = MyLowerModel()

# Define optimizers (Jittor syntax)
upper_opt = jit.nn.Adam(upper_model.parameters(), lr=1e-3)
lower_opt = jit.nn.SGD(lower_model.parameters(), lr=1e-2)

3. Customize & Initialize Problem

Inject runtime objects into the configuration.

# Configure BOAT with Jittor models/optimizers
boat_config["lower_level_model"] = lower_model
boat_config["upper_level_model"] = upper_model
boat_config["lower_level_opt"] = lower_opt
boat_config["upper_level_opt"] = upper_opt

# Initialize the BOAT core
b_optimizer = boat.Problem(boat_config, loss_config)

4. Build Solvers

Inject runtime objects into the configuration.

# Pass optimizers explicitly if needed by the solver backend
b_optimizer.build_ll_solver(lower_opt)
b_optimizer.build_ul_solver(upper_opt)

5. Run Optimization Loop

# Training loop
for x_itr in range(1000):
    # Prepare data (Jittor Arrays or dicts)
    ul_feed_dict = {"data": ul_data, "target": ul_target}
    ll_feed_dict = {"data": ll_data, "target": ll_target}
    
    # Run one iteration
    loss, run_time = b_optimizer.run_iter(ll_feed_dict, ul_feed_dict, current_iter=x_itr)
    
    if x_itr % 100 == 0:
        print(f"Iter {x_itr}: UL Loss {loss:.4f}")

🌍 Applications

BOAT covers a wide spectrum of BLO applications, categorized by the optimization target:

  • Data-Centric: Data Hyper-Cleaning, Synthetic Data Reweighting, Diffusion Model Guidance.
  • Model-Centric: Neural Architecture Search (NAS), LLM Prompt Optimization, Parameter Efficient Fine-Tuning (PEFT).
  • Strategy-Centric: Meta-Learning, Hyperparameter Optimization (HO), Reinforcement Learning from Human Feedback (RLHF).

📝 Citation

If you find BOAT useful in your research, please consider citing our paper:

@article{liu2025boat,
  title={BOAT: A Compositional Operation Toolbox for Gradient-based Bi-Level Optimization},
  author={Liu, Yaohua and Pan, Jibao and Jiao, Xianghao and Gao, Jiaxin and Liu, Zhu and Liu, Risheng},
  journal={Submitted to Journal of Machine Learning Research (JMLR)},
  year={2025}
}

License

MIT License

Copyright (c) 2024 Yaohua Liu

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

Metadata

Release files for boat-jit 1.1.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for boat-jit 1.1.0
File Size Uploaded
boat_jit-1.1.0.tar.gz 51.8 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for boat-jit 1.1.0
File Interpreter ABI Platform
boat_jit-1.1.0-py3-none-any.whl Python 3 none any Details

Total release size: 123.2 kB

Release files / boat_jit-1.1.0.tar.gz

Download URL boat_jit-1.1.0.tar.gz
Size 51.8 kB
Tags Source
SHA-256 checksum
How to use checksums
8dd1db057c69025643c6b9f5890fe2fc7bb1197bc976330ceccead8e537a1018
BLAKE2b-256 checksum
How to use checksums
5091e5a2887711d869927ee5344e92320d2e352ec70ffeb04856f23480388f91
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.9.25

Release files / boat_jit-1.1.0-py3-none-any.whl

Download URL boat_jit-1.1.0-py3-none-any.whl
Size 71.3 kB
Tags Python 3
SHA-256 checksum
How to use checksums
8c69a38ae0744073730a6489cbf7880e9063a915ee40da885619b46469885a3a
BLAKE2b-256 checksum
How to use checksums
c854c18419bd49846b659817b0a41da797dfef7e0c0b8e10a8dcf174c44c667d
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.9.25

Release history Release notifications | RSS feed

1.1.1

2 release files

This release

1.1.0 This release

2 release files

1.0.7

1 release file

1.0.6

2 release files

1.0.5

2 release files

1.0.4

2 release files

1.0.3

2 release files

1.0.2

1 release file

1.0.1

1 release file

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page