Skip to content

About

No description, website, or topics provided.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Repository files navigation

⚡ Lightning-Ray ⚡

Scalable. Fast. Structured.

Lightning-Ray is a high-performance template library designed to bridge the gap between structured deep learning training and massive scalability. By combining the best-in-class features of PyTorch Lightning and Ray, along with the blistering speed of Polars, this project provides a production-ready foundation for your next machine learning breakthrough.

Whether you are fine-tuning complex regression models or training large-scale Graph Neural Networks, Lightning-Ray offers the pre-configured boilerplate you need to focus on what matters: the model.

🚀 Key Features

  • 🔥 Seamless Integration: A unified workflow that leverages PyTorch Lightning for rigid code structure and Ray for effortless distributed training and hyperparameter tuning.
  • 🧠 Advanced Hyperparameter Tuning: Built-in support for state-of-the-art schedulers like ASHA, PB2 (Population Based Bandits), and PBT (Population Based Training) directly via src/tuner.py.
  • 🐼 Polars-Powered Data Loading: Extreme performance with PolarsDataModule. Forget slow Pandas DataFrames; load and process tabular data with lazy execution and zero-copy integration where possible. Includes automatic handling of categorical/numerical features and optimized PyTorch DataLoader creation.
  • 🕸️ Graph Neural Networks Ready: Native support for PyG (PyTorch Geometric) with GraphLevelDataModule, enabling scalable graph-level tasks with stratified splitting.
  • 🛠️ Sophisticated Lightning Module:
    • Smart Optimizers: Automatic parameter grouping (weight decay separation) and "AdamW + Cosine Annealing" scheduler setup bundled in LM.
    • Metric Management: Pre-configured MetricCollection for Regression (MAE, R2), Classification (Accuracy, F1), and Binary tasks (AUROC).
    • Robust Logging: Integrated AimLoggerCallback and standard CSV/TensorBoard support.
  • 🐍 Modern Python: Built for Python 3.12+, fully typed, and managed with uv.

📦 Installation

This project uses uv for ultra-fast dependency management.

Prerequisites

  • Python 3.12+
  • CUDA-capable GPU (recommended for training)

Setup

# Clone the repository
git clone https://github.com/your-username/lightning_ray.git
cd lightning_ray

# Install dependencies using uv (Recommended)
uv sync

# Or using pip
pip install .

🏎️ Quick Start

1. Data Preparation src/dm.py

Lightning-Ray uses PolarsDataModule to handle data efficiently.

import polars as pl
from src.dm import PolarsDataModule

# Load your data lazily or eagerly
df = pl.read_parquet("data/dataset.parquet")

# Initialize DataModule
dm = PolarsDataModule(
    train_df=train_df,
    val_df=val_df,
    target_col="target_value",
    features=["feature1", "feature2"],
    cat_features=["category_col"],
    batch_size=2048
)
dm.setup()

2. Define Your Model src/module.py

Subclass the base LM (Lightning Module) to get instant access to logging, metrics, and optimizer configurations.

from src.module import LM
from torch import nn

class MyModel(LM):
    def _configure_model(self, model, config):
        # Define your architecture here or load it from config
        return nn.Linear(10, 1)

    # Optional: Customize batch handling if your input is complex
    # def _prepare_batch(self, batch): ...

3. Run Hyperparameter Tuning src/tuner.py

Scale up effortlessly using Ray Tune.

from src.tuner import tune_asha
from ray import tune

# Define hyperparameter search space
search_space = {
    "lr": tune.loguniform(1e-4, 1e-1),
    "hidden_dim": tune.choice([64, 128, 256]),
}

# Launch the experiment
tuner = tune_asha(
    num_samples=50,
    num_epochs=100,
    hyperparams=search_space,
    module=MyModel,
    dm=dm,
    name="my_experiment",
    resources={"gpu": 1}
)

📂 Project Structure

lightning_ray/
├── src/
│   ├── callbacks/    # Custom Lightning callbacks
│   ├── losses/       # Domain-specific loss functions
│   ├── models/       # Model architectures (MLP, transformer components, etc.)
│   ├── dm.py         # DataModules (PolarsDataModule, GraphLevelDataModule)
│   ├── module.py     # Base LightningModule (LM) with "batteries included"
│   ├── tuner.py      # Ray Tune integration (tune_asha, tune_pbt, tune_pb2)
│   ├── data.py       # Data structures/Utilities
│   ├── trainable.py  # Ray Trainable wrappers
│   └── trainer.py    # Lightning Trainer configurations
├── pyproject.toml    # Dependencies and project metadata
└── README.md         # You are here!

🤝 Contributing

Contributions are welcome! Please format your code using ruff and ensure type safety. For code quality we use prek. Please install it with uv sync --dev.

📄 License

MIT License

About

No description, website, or topics provided.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages