Metadata-Version: 2.4
Name: neurogen
Version: 0.2.0
Summary: CLI driven pytorch framework with local/modal execution
Author-email: Felix Noble <felix.noble@ngenesis.co.uk>
License-Expression: Apache-2.0
Classifier: Programming Language :: Python :: 3
Classifier: Operating System :: OS Independent
Requires-Python: <3.14,>=3.12
Description-Content-Type: text/markdown
License-File: LICENSE
Requires-Dist: polars==1.38.1
Requires-Dist: python-dotenv==1.2.3
Requires-Dist: pandas==2.3.3
Requires-Dist: mlflow==3.18.0
Requires-Dist: transformers==4.48.0
Requires-Dist: scikit-learn==1.8.0
Requires-Dist: typer==0.23.1
Requires-Dist: seaborn==0.13.2
Requires-Dist: sacrebleu==2.5.0
Requires-Dist: rouge_score==0.1.2
Provides-Extra: modal
Requires-Dist: modal>=0.73.0; extra == "modal"
Provides-Extra: cpu
Requires-Dist: torch>=2.14; extra == "cpu"
Provides-Extra: cuda126
Requires-Dist: torch>=2.14; extra == "cuda126"
Provides-Extra: cuda130
Requires-Dist: torch>=2.14; extra == "cuda130"
Dynamic: license-file

# neurogen

`neurogen` is a CLI-based machine learning framework for forecasting outcomes
from text corpora over time. It began life as a citation-impact predictor, but
nothing in the pipeline is specific to academic papers: embed a text dataset,
track it across time windows, train, and evaluate.

The core training loop and data pre-processing are driven entirely by the CLI
and integrate with MLflow to track experiments. Each experiment is a single
self-contained Python module that instantiates its own models, datasets,
samplers, DataLoaders, strategy, tracker, and checkpoint processor, and every
app runs either locally or on Modal GPUs with one `--runtime` flag.

## Install

`neurogen` installs as one top-level package with a `neurogen` console script.
PyTorch is not a core dependency; it arrives through one of the mutually
exclusive `cpu`, `cuda126`, or `cuda130` extras.

```console
pip install neurogen            # CLI only; no torch
pip install "neurogen[cpu]"     # CPU PyTorch
```

`pip` ignores `[tool.uv.sources]`, so select the PyTorch build with its index
explicitly:

```console
# CPU
pip install torch --index-url https://download.pytorch.org/whl/cpu
pip install "neurogen[cpu]"

# CUDA 12.6 (use cuda130 and the whl/cu130 index for CUDA 13.0)
pip install torch --index-url https://download.pytorch.org/whl/cu126
pip install "neurogen[cuda126]"
```

With [uv](https://docs.astral.sh/uv/), the extras resolve the matching index
for you:

```console
uv add "neurogen[cpu]"            # or [cuda126] / [cuda130]
```

Python 3.12 and 3.13 are supported (`requires-python = ">=3.12,<3.14"`).

## Quick start

Create a project, then train its generated example for one local step:

```console
neurogen init demo
cd demo
neurogen train -e example --name demo --no-gpu
```

`neurogen init [NAME]` writes a real importable package and refuses to
overwrite existing files unless `--force` is passed. It runs no `git init` and
no `pip install`. The generated layout is:

```text
demo/
├── neurogen.toml               # project marker and manifest
├── pyproject.toml              # project name, dependencies, [tool.neurogen]
├── config.toml                 # [env], [source], and [runtime] defaults
├── .gitignore
├── README.md
└── demo/
    ├── __init__.py
    ├── experiments/example.py  # the importable example experiment
    ├── models/tiny.py
    ├── datasets/tiny.py
    ├── strategies/__init__.py
    └── tokenisers/__init__.py
```

## Local runs and direct imports

A project declares itself with a `neurogen.toml` marker or a `[tool.neurogen]`
table in `pyproject.toml`. The CLI walks up from the working directory to find
one, prepends the project root to `sys.path`, and imports the experiment
directly as `<package>.experiments.<name>`. There is no plugin registry and no
editable install: drop a module under `demo/models/` and import it from an
experiment module.

`--project PATH` overrides discovery. `-e`/`--experiment` accepts four forms:

| Input | Resolution |
|---|---|
| `name` | `<project package>.experiments.name` |
| `pkg.mod.name` | that dotted module |
| `neurogen:name` | a builtin experiment in `neurogen.experiments` |
| `path/to/file.py` | load from the file path |

Builtin experiments run with no project at all:

```console
neurogen -e neurogen:rhlm train -s smoke --no-gpu
```

Dependencies declared in the project `pyproject.toml` are yours to install;
third-party packages already in the environment are importable because the CLI
runs in that environment.

## Machine settings

Machine settings (`[env]`, `[source]`, `[runtime]`, `[models]`) are read from
`config.toml` at the **project root** — the directory holding the
`neurogen.toml` marker or the `[tool.neurogen]` table. A project that predates
the 0.1 layout may keep the file at `config/config.toml` instead. With no
project marker, discovery finds nothing and the library defaults apply
(`sqlite:///mlflow.db` for tracking, `/tmp/artifacts` for artifacts, no
`[runtime.modal]` section), so a Modal run needs a project. `config/config.example.toml`
in this repository is the reference for the accepted keys; copy it to
`<project>/config.toml` and edit it there.

## Builtins

Builtin models, datasets, strategies, tokenisers, losses, and experiments ship
with the package and resolve from it. `neurogen init` copies a minimal example
into the project for editing; the builtin set itself does not change in 0.1.

## Deploy to Modal

`neurogen deploy` builds a builtin-only Modal image from a locally built
`neurogen` wheel and shells out to the Modal CLI. Install the optional extra
and authenticate once:

```console
pip install "neurogen[modal]"    # or: uv add "neurogen[modal]"
modal token new
neurogen deploy
```

Preprocess, describe, and engineer dispatch to the deployed app by name; train
and eval spawn ephemeral jobs. Train jobs are spawned fire-and-forget: the CLI
prints the MLflow run id and Modal FunctionCall id and returns immediately.
Block until done with `modal FunctionCall.from_id(<id>).get()`, or watch the run
in the MLflow UI.

The image carries the builtin framework and pinned torch only. Packaging a
**user project** into the image is not part of 0.1; that is the subject of the
[custom-code-on-Modal plan](plans/releases/modal-custom-code.md). A project
experiment still runs locally
(`--runtime local`). Re-deploy after changing `neurogen` itself; a project code
change does not reach the builtin image. `--wheel PATH` installs a prebuilt
`neurogen` wheel instead of building one from the checkout.

## Repository layout

```text
neurogen/
├── pyproject.toml
├── config/
│   └── config.example.toml     # example machine settings
├── src/
│   └── neurogen/
│       ├── cli.py              # root Typer app
│       ├── api.py              # public protocol hub
│       ├── __init__.py         # lazy __getattr__, __version__
│       ├── __main__.py         # python -m neurogen
│       ├── apps/               # Typer CLI apps (train, eval, preprocess, ...)
│       ├── builders/
│       ├── config/             # schemas, loader, env/runtime config
│       ├── data/               # sources, pipelines, datasets, samplers
│       ├── experiments/        # builtin experiments (neurogen:<name>)
│       ├── models/
│       ├── runtime/            # local and Modal backends
│       ├── training/           # engine, strategies, losses, tracking
│       └── utils/
├── plans/
│   ├── legacy/                 # archived pre-0.1 plans
│   └── releases/               # feature plans; shipped plans move to archive/
└── tests/
```

## Tech stack

- **Core.** Python 3.12-3.13 and PyTorch.
- **MLOps.** MLflow for tracking, Modal for GPUs, scikit-learn for metrics.
- **Data.** Polars for predicate-pushdown loading and multi-worker serving.
- **Validation.** Pydantic for typed config schemas.
- **Tooling.** Typer for the CLI and Rich for logging.

## Documentation

- [ROADMAP.md](ROADMAP.md) — the post-0.1 line.
- [CHANGELOG.md](CHANGELOG.md) — releases, starting at 0.1.0.
- [docs/](docs/index.md) — apps, experiments, data pipeline, and training
  internals.
- [plans/releases/archive/0.1.md](plans/releases/archive/0.1.md) - the 0.1.0
  release plan.
- [docs/legacy-changelog.md](docs/legacy-changelog.md) — pre-0.1 history.
