Quadra
Quadra: Effortless and reproducible deep learning workflows with configuration files.
Install / Use
/learn @orobix/QuadraREADME
Quadra aims to simplify deep learning experimenting process, allowing researchers or developers to compare, monitor, and share their experiments quickly. It provides a simple and flexible way to train and deploy deep learning models using YAML configuration files and open-source tools such as Hydra, Lightning framework, and Pytorch. It lets you compose your experiment configurations from single command line interface, so you can conduct multiple experiments with different settings and hyperparameters. Every experiment can be logged using integrations provided by Lightning framework such Mlflow.
Quick Start Guide
If you use pip to manage your packages, you can install quadra from PyPi by running the following command:
pip install quadra
If instead you prefer to use poetry, you can install quadra from PyPi by running the following command:
poetry add quadra
If you don't have virtual environment ready, Let's set up our environment for using the quadra library. We have two parts in this guide: Common setup and Environment-specific setup.
Using Conda
Create and activate a new Conda environment.
conda create -n myenv python=3.10
conda activate myenv
Using Python Virtualenv
Create and activate a new virtual environment.
# replace `myenv` with the name of your virtual environment
python3 -m venv myenv
source myenv/bin/activate
Common Setup
- Check your git version: Make sure you have git version 2.10 or higher, to avoid any installation failures.
git --version
- Upgrade pip:
pip install --upgrade pip
-
Install the package
-
Install the
quadrapackage with pip:pip install quadra -
Install the
quadrapackage with poetry:curl -sSL https://install.python-poetry.org | python3 - poetry add quadra
-
-
Run from CLI: Run the following command to check if the installation was successful:
quadra experiment=default
Setup Mlflow (Optional)
To use Mlflow and leverage its functionalities such as saving models, logging metrics, saving artifacts, and visualizing results, you need to ensure that the Mlflow server is running. You can find more information about Mlflow here.
By default, the logger configuration is set to Mlflow, and experiments expect the MLFLOW_TRACKING_URI environment variable to be set to the address of the Mlflow server. There are two ways to set this variable:
Using the command line:
export MLFLOW_TRACKING_URI=http://localhost:5000
This command sets the MLFLOW_TRACKING_URI variable to http://localhost:5000. Replace this with the actual address of your Mlflow server if it's running on a different host or port.
Adding it to your environment file:
Quadra uses environment variables to store credentials and other sensitive information. Thanks to python-dotenv library, you can create a .env file in the main folder of your project and store the credentials there. During the runtime, the library will automatically load the environment variables from the .env file. You can also add the MLFLOW_TRACKING_URI variable to your environment file (e.g., .env). Open the file in a text editor and add the following line:
MLFLOW_TRACKING_URI=http://localhost:5000
Again, modify the address if your Mlflow server is running on a different host or port.
By setting the MLFLOW_TRACKING_URI variable using either method, you configure the logger to connect to the Mlflow server, enabling you to utilize its features effectively.
The export command is specific to Unix-based systems like Linux or macOS. If you are using a different operating system, refer to the appropriate method for setting environment variables.
Run Example Experiments
quadra provides a set of example experiments that can be used to test the installation and to provide some example configuration files.
By default all the experiments will run on the GPU 0, to run it on the CPU you can specify a different trainer configuration parameter:
quadra <configurations> trainer=lightning_cpu
Classification Training
To run a simple classification training on the Imagenette dataset with a Resnet18 architecture run the following command:
quadra experiment=generic/imagenette/classification/default logger=csv
This will train the model for 20 epochs and log the metrics in a csv file, at the end of the training a torchscript model will be saved for inference alongside some output images.
By default the experiment will run on the GPU 0, to run it on the CPU you can specify a different trainer configuration parameter.
Segmentation Training
To run a simple segmentation training on the Oxford pet dataset with a Unet architecture run the following command:
quadra experiment=generic/oxford_pet/segmentation/smp logger=csv
This will make use of the segmentation models pytorch library to train the model for 10 epochs, logging the metrics to a csv file. At the end of the training a torchscript model will be saved for inference alongside some output images.
(SSL) Self-supervised Learning Training
On the same dataset we can run a simple SSL training using the BYOL algorithm with the following command:
quadra experiment=generic/imagenette/ssl/byol logger=csv
BYOL is not the only SSL algorithm available, you can find a list of all the available algorithms under quadra/configs/experiment/generic/imagenette/ssl folder.
Anomaly Detection Training
To run a simple anomaly detection training on the MNIST dataset using the PADIM algorithm run the following command:
quadra experiment=generic/mnist/anomaly/padim logger=csv
This will run an anomaly detection considering on of the classes as good (default is the number 9) and the rest as anomalies.
This will make use of the anomalib library to train the model. Many different algorithms are available, you can find them under quadra/configs/experiment/generic/mnist/anomaly folder.
Running with Custom Datasets
Each task comes with a default configuration file that can be customized for your needs. Each example experiment we have seen so far uses a default configuration file that can be found under quadra/configs/experiment/base/<task>/<config_name>.yaml.
Let's see how we can customize the configuration file to run the classification experiment on a custom dataset.
Structure your dataset in the following way:
dataset/
├── class_1
│ ├── abc.xyz
│ └── ...
├── class_2
│ ├── abc.xyz
│ └── ...
├── class_3
│ ├── abc.xyz
│ └── ...
Create a new experiment configuration file under quadra/configs/experiment/custom/<config_name>.yaml with the following content:
# @package _global_
defaults:
- base/classification/classification # extends the default classification configuration
core:
name: <your-custom-experiment-name> # name of the experiment
model:
num_classes: <number-of_classes-you-have> # number of classes in your dataset
Run the experiment with the following command:
quadra experiment=custom/<config_name> logger=csv
It will run the experiment using the configuration file you have just created and it will apply the default parameters from the classification configuration file. Furthermore, it will log the metrics to a csv file. You can add or customize the parameters in the configuration file to fit your needs.
For more information about advanced usage, please check tutorials and task specific examples.
Development
First clone the repository from Github
First clone the repository from Github, then we need to install the package with optional dependencies (generally in editable mode) and enable the pre-commit hooks.
git clone https://github.com/orobix/quadra.git && cd quadra- Instal
Related Skills
YC-Killer
2.7kA library of enterprise-grade AI agents designed to democratize artificial intelligence and provide free, open-source alternatives to overvalued Y Combinator startups. If you are excited about democratizing AI access & AI agents, please star ⭐️ this repository and use the link in the readme to join our open source AI research team.
groundhog
399Groundhog's primary purpose is to teach people how Cursor and all these other coding agents work under the hood. If you understand how these coding assistants work from first principles, then you can drive these tools harder (or perhaps make your own!).
last30days-skill
18.8kAI agent skill that researches any topic across Reddit, X, YouTube, HN, Polymarket, and the web - then synthesizes a grounded summary
sec-edgar-agentkit
10AI agent toolkit for accessing and analyzing SEC EDGAR filing data. Build intelligent agents with LangChain, MCP-use, Gradio, Dify, and smolagents to analyze financial statements, insider trading, and company filings.
