Skip to main content

cmn_ai

A high-performance machine learning library for accelerating AI, Deep Learning, and Data Science workflows

cmn_ai logo

Overview

cmn_ai is a comprehensive Python machine learning library designed to accelerate AI, Deep Learning, and Data Science workflows. Built from extensive real-world experience, it provides robust, reusable components for PyTorch-based deep learning and scikit-learn compatible tabular data processing.

The library follows Boyd's Law — speed of iteration beats quality of iteration — enabling rapid experimentation and faster delivery of machine learning solutions.

Key Features

🚀 Accelerated Development

  • Pre-built modules eliminate boilerplate code
  • Flexible callback system for training customization
  • Seamless integration with existing workflows

🎯 Best Practices Built-In

  • Years of ML engineering experience distilled into reusable components
  • Robust error handling and memory management
  • Consistent APIs across all modules

🔧 Framework Integration

  • Deep Learning: Built on PyTorch with flexible Learner architecture
  • Tabular ML: Full scikit-learn Pipeline and ColumnTransformer compatibility
  • Visualization: Integrated plotting utilities for models and data

📊 Domain-Specific Tools

  • Vision: Computer vision utilities with VisionLearner and batch visualization
  • Text: NLP preprocessing and dataset handling with TextList
  • Tabular: EDA tools and scikit-learn compatible transformers

Installation

pip install cmn-ai

Development Installation

git clone https://github.com/ImadDabbura/cmn_ai.git
cd cmn_ai
uv sync --extra dev

Quick Start

Deep Learning with Learner

from cmn_ai.learner import Learner
from cmn_ai.callbacks.training import DeviceCallback, Recorder

# Create a learner with callbacks
learner = Learner(model, dls, loss_func, opt_func, callbacks=[Recorder("lr")])
learner.add_callback(DeviceCallback("cuda:0"))

# Train your model
learner.fit(n_epochs=10, lr=1e-3)

Vision Tasks

from cmn_ai.vision import VisionLearner

# Vision-specific learner with built-in utilities
vision_learner = VisionLearner(model, dls, loss_func)
vision_learner.show_batch()  # Visualize training data
vision_learner.fit(n_epochs=20, lr=1e-4)

Tabular Data Processing

import pandas as pd
from cmn_ai.tabular.preprocessing import DateTransformer
from sklearn.pipeline import Pipeline

# Scikit-learn compatible preprocessing
x = pd.DataFrame(
    pd.date_range(start=pd.to_datetime("1/1/2018"), end=pd.to_datetime("1/08/2018"))
)
tfm = DateTransformer(drop=False)
tfm.fit_transform(X_train, y_train)

Core Architecture

Learner System

The Learner class provides a flexible foundation for training deep learning models with:

  • Exception-based callback system for fine-grained training control
  • Built-in logging and metrics tracking
  • Memory optimization utilities

Callback Framework

Fine-grained training control through exception-based callbacks:

  • CancelBatchException: Skip current batch
  • CancelStepException: Skip optimizer step
  • CancelBackwardException: Skip backward pass
  • CancelEpochException: Skip current epoch
  • CancelFitException: Stop training entirely

Modular Design

cmn_ai/
├── learner.py          # Core Learner class
├── callbacks/          # Training callbacks
├── vision/            # Computer vision utilities
├── text/              # NLP processing tools
├── tabular/           # Traditional ML tools
├── utils/             # Core utilities
├── plot.py            # Visualization tools
└── losses.py          # Custom loss functions

Examples

Training Loop Customization

from functools import partial
from cmn_ai.callbacks.schedule import BatchScheduler
from cmn_ai.callbacks.training import MetricsCallback, ProgressCallback
from torcheval.metrics import MulticlassAccuracy
import torch.optim as opt

sched = partial(opt.lr_scheduler.OneCycleLR, max_lr=6e-2, total_steps=100)
learner = Learner(model, dls, loss_func, opt_func)
learner.add_callbacks(
    [
        ProgressCallback(),
        BatchScheduler(sched),
        MetricsCallback(accuracy=MulticlassAccuracy(num_classes=10)),
    ]
)

learner.fit(n_epochs=50, lr=1e-3)

Custom Callback Creation

from cmn_ai.callbacks import Callback


class CustomCallback(Callback):
    def after_batch(self):
        if self.loss < self.threshold:
            print(f"Threshold reached at batch {self.batch}")

Documentation

📖 Full Documentation

Planned documentation (not published yet):

  • API reference pages
  • Tutorial notebooks
  • Advanced usage guides

Development

Setup Development Environment

git clone https://github.com/ImadDabbura/cmn_ai.git
cd cmn_ai
uv sync --extra dev

Run Tests

# Full test suite
uv run pytest

# With coverage
uv run pytest --cov=cmn_ai

# Specific test file
uv run pytest tests/test_learner.py

Code Quality

# Formatting, linting, static checks, and syntax checks
pre-commit run --all-files

# Full test suite hook, configured for pre-push
pre-commit run --hook-stage pre-push test

Build Documentation

uv run mkdocs serve           # Local development server
uv run mkdocs build --strict  # Build documentation

Requirements

  • Python: 3.13+
  • Core Dependencies: PyTorch, scikit-learn, NumPy, pandas
  • Optional: matplotlib, seaborn (for plotting)

Planned Roadmap

These items are directionally planned, not committed to a release schedule.

  • Distributed training support
  • Additional vision architectures
  • Advanced NLP utilities
  • AutoML capabilities
  • Model deployment tools

🙌 Contributing

Contributions are what make the open-source community such an amazing place to learn, inspire, and create. Any contributions you make are greatly appreciated.

If you have suggestions or fixes, please open an issue or pull request.

License

Licensed under the Apache License 2.0.

Citation

If you use cmn_ai in your research, please cite:

@software{cmn_ai,
  title={cmn_ai: A Machine Learning Library for Accelerated AI Workflows},
  author={Imad Dabbura},
  url={https://github.com/ImadDabbura/cmn_ai},
  year={2024}
}

Built with ❤️ for the ML community

Metadata

Release files for cmn-ai 0.2.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 cmn-ai 0.2.0
File Size Uploaded Provenance
cmn_ai-0.2.0.tar.gz 480.2 kB Without provenance Details

Built distribution (wheel)

Table of built distributions (wheels) for cmn-ai 0.2.0
File Interpreter ABI Platform
cmn_ai-0.2.0-py3-none-any.whl Python 3 none any Details

Total release size: 553.8 kB

Release files / cmn_ai-0.2.0.tar.gz

Download URL cmn_ai-0.2.0.tar.gz
Size 480.2 kB
Tags Source
SHA-256 checksum
How to use checksums
798c0172d20401f23293d3b679bd8c54e84a85f5e43828f7d74a8ec0065a0222
BLAKE2b-256 checksum
How to use checksums
b1c2f8a05c580f5e618357389619560f0395b6d15bdd89815dee885cdd8e2e4e
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via uv/0.11.28 {"installer":{"name":"uv","version":"0.11.28","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

Release files / cmn_ai-0.2.0-py3-none-any.whl

Download URL cmn_ai-0.2.0-py3-none-any.whl
Size 73.6 kB
Tags Python 3
SHA-256 checksum
How to use checksums
6ff4fe515136ae495ea4e6789a4ff2cbf763b089e1ed22928b84c3ea6b4d7165
BLAKE2b-256 checksum
How to use checksums
ea8ac1395b150dc5eb7f6162bef3e208eb7a1561efc149b0dcbd1dead8ef3d6a
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via uv/0.11.28 {"installer":{"name":"uv","version":"0.11.28","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

Security for cmn-ai 0.2.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

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