Metadata-Version: 2.4
Name: pytorch-lantern
Version: 0.12.15
Summary: Pytorch project template and related tools
Keywords: pytorch,machine,learning
Author: NextML AB
License-Expression: Apache-2.0
Classifier: Development Status :: 3 - Alpha
Classifier: Environment :: Other Environment
Classifier: License :: OSI Approved :: Apache Software License
Classifier: Operating System :: OS Independent
Classifier: Intended Audience :: Developers
Classifier: Intended Audience :: Science/Research
Classifier: Topic :: Scientific/Engineering
Classifier: Topic :: Scientific/Engineering :: Artificial Intelligence
Classifier: Topic :: Software Development
Classifier: Topic :: Software Development :: Libraries
Classifier: Topic :: Software Development :: Libraries :: Python Modules
Requires-Dist: numpy>=1.19.4,<2
Requires-Dist: torch>=1.6.0
Requires-Dist: tqdm
Requires-Dist: pydantic==2.*
Requires-Dist: pandas>=1.0.0,<3
Requires-Dist: pydantic-core>=2.14.5,<3
Requires-Dist: tensorboard>=2.2.0,<3 ; extra == 'training'
Requires-Python: >=3.8, <4
Project-URL: Repository, https://github.com/nextml-code/pytorch-lantern
Project-URL: Documentation, https://pytorch-lantern.readthedocs.io
Provides-Extra: training
Description-Content-Type: text/x-rst

================
Pytorch Lantern
================

.. image:: https://badge.fury.io/py/pytorch-lantern.svg
       :target: https://badge.fury.io/py/pytorch-lantern

.. image:: https://img.shields.io/pypi/pyversions/pytorch-lantern.svg
       :target: https://pypi.python.org/pypi/pytorch-lantern

.. image:: https://readthedocs.org/projects/pytorch-lantern/badge/?version=latest
       :target: https://pytorch-lantern.readthedocs.io/en/latest/?badge=latest

.. image:: https://img.shields.io/pypi/l/pytorch-lantern.svg
       :target: https://pypi.python.org/pypi/pytorch-lantern

.. image:: https://img.shields.io/badge/code%20style-black-000000.svg
    :target: https://github.com/psf/black

Lantern contains our process of bringing a project to fruition as
efficiently as possible. This is subject to change as we iterate and improve.
This package implements tools and missing features to help bridge the gap
between frameworks and libraries that we utilize.

The main packages and tools that we build around are:

- `pytorch <https://pytorch.org>`_
- `pytorch-datastream <https://github.com/nextml-code/pytorch-datastream>`_
- `guild <https://guild.ai>`_

Usage
=====

Example of tensor type hinting.

.. code-block:: python

    from pydantic import BaseModel
    from typing import Annotated
    import torch
    from lantern import Tensor

    class Example(BaseModel):
        image: Annotated[torch.Tensor, Tensor.dims("NCHW").float()]
        label: Annotated[torch.Tensor, Tensor.dims("N").long()]

    example = Example(
        image=torch.rand(32, 3, 224, 224),  # 32 images, 3 channels, 224x224 pixels
        label=torch.randint(0, 10, (32,))   # 32 labels
    )

See the `documentation <https://pytorch-lantern.readthedocs.io/en/latest/>`_
for more information and usage examples.

Create new project with template
================================

Install `cookiecutter <https://github.com/cookiecutter/cookiecutter>`_
and `poetry <https://github.com/python-poetry/poetry>`_:

.. code-block::

    pip install cookiecutter
    curl -sSL https://raw.githubusercontent.com/python-poetry/poetry/master/get-poetry.py | python

Setup project:

.. code-block::

    cookiecutter https://github.com/nextml-code/pytorch-lantern-template.git
    cd <new-project>
    poetry install

You can now train the placeholder model and inspect the results:

.. code-block::

    guild run prepare
    guild run train
    guild tensorboard

Use lantern without templates
==============================

Install lantern from pypi using pip or poetry:

.. code-block::

    poetry add pytorch-lantern[training]

.. code-block::

    pip install pytorch-lantern[training]
