Metadata-Version: 2.4
Name: logits_cookbook
Version: 0.1.0
Summary: Post-training algorithms and recipes for the Logits platform, built on the Logits SDK
Project-URL: Homepage, https://github.com/GradientHQ/logits-cookbook
Project-URL: Repository, https://github.com/GradientHQ/logits-cookbook
Project-URL: Documentation, https://github.com/GradientHQ/logits-cookbook/tree/main/docs
Author: Logits authors
License-File: LICENSE
Requires-Python: >=3.11
Requires-Dist: anyio
Requires-Dist: blobfile
Requires-Dist: chz
Requires-Dist: cloudpickle
Requires-Dist: datasets
Requires-Dist: logits-sdk>=0.1.0
Requires-Dist: math-verify
Requires-Dist: modal
Requires-Dist: numpy
Requires-Dist: pillow
Requires-Dist: pylatexenc
Requires-Dist: pytest>=9.0.2
Requires-Dist: rich
Requires-Dist: scipy
Requires-Dist: sympy
Requires-Dist: termcolor
Requires-Dist: textarena>=0.7.4
Requires-Dist: tiktoken>=0.12.0
Requires-Dist: torch
Requires-Dist: torchvision
Requires-Dist: tqdm
Requires-Dist: transformers<5.0.0,>=4.57.6
Provides-Extra: all
Requires-Dist: chromadb; extra == 'all'
Requires-Dist: google-genai; extra == 'all'
Requires-Dist: huggingface-hub; extra == 'all'
Requires-Dist: inspect-ai; extra == 'all'
Requires-Dist: inspect-evals>=0.3.106; extra == 'all'
Requires-Dist: litellm; extra == 'all'
Requires-Dist: neptune-scale>=0.27.0; extra == 'all'
Requires-Dist: openai; extra == 'all'
Requires-Dist: trackio<1.0.0; extra == 'all'
Requires-Dist: verifiers<0.1.10,>=0.1.9; extra == 'all'
Requires-Dist: wandb; extra == 'all'
Provides-Extra: dev
Requires-Dist: pyright; extra == 'dev'
Requires-Dist: pytest; extra == 'dev'
Requires-Dist: pytest-asyncio; extra == 'dev'
Requires-Dist: ruff; extra == 'dev'
Provides-Extra: inspect
Requires-Dist: inspect-ai; extra == 'inspect'
Requires-Dist: inspect-evals>=0.3.106; extra == 'inspect'
Provides-Extra: litellm
Requires-Dist: litellm; extra == 'litellm'
Provides-Extra: neptune-scale
Requires-Dist: neptune-scale>=0.27.0; extra == 'neptune-scale'
Provides-Extra: trackio
Requires-Dist: trackio<1.0.0; extra == 'trackio'
Provides-Extra: vector-search
Requires-Dist: chromadb; extra == 'vector-search'
Requires-Dist: google-genai; extra == 'vector-search'
Requires-Dist: huggingface-hub; extra == 'vector-search'
Provides-Extra: verifiers
Requires-Dist: openai; extra == 'verifiers'
Requires-Dist: verifiers<0.1.10,>=0.1.9; extra == 'verifiers'
Provides-Extra: wandb
Requires-Dist: wandb; extra == 'wandb'
Description-Content-Type: text/markdown

<h1 align="center">Logits Cookbook</h1>

`logits_cookbook` is a recipe library for training and evaluation on the Logits platform. It is built on the `logits` SDK and provides higher-level recipes, renderers, evaluation helpers, and end-to-end examples for Logits users.

## Installation

1. Create a Logits platform API key in your Logits console.
2. Export it as `LOGITS_API_KEY`.
3. Install the SDK and cookbook in a virtual environment.

```bash
pip install logits-sdk logits-cookbook
```

For local development on the cookbook itself:

```bash
pip install -e .
```

## Backend Model

The cookbook builds on the same training, sampling, and checkpoint primitives exposed through `logits`. A minimal low-level flow looks like:

```python
import logits

service_client = logits.ServiceClient()
training_client = service_client.create_lora_training_client(
  base_model="meta-llama/Llama-3.2-1B", rank=32,
)
training_client.forward_backward(...)
training_client.optim_step(...)
training_client.save_state(...)
training_client.load_state(...)

sampling_client = training_client.save_weights_and_get_sampling_client(name="my_model")
sampling_client.sample(...)
```

See [logits_cookbook/recipes/sl_loop.py](logits_cookbook/recipes/sl_loop.py) and [logits_cookbook/recipes/rl_loop.py](logits_cookbook/recipes/rl_loop.py) for minimal examples.

To download the weights of any model:
```python
rest_client = service_client.create_rest_client()
future = rest_client.get_checkpoint_archive_url_from_tinker_path(sampling_client.model_path)
with open(f"model-checkpoint.tar.gz", "wb") as f:
    f.write(future.result())
```

### Logits Cookbook

Besides these primitives, we also offer **Logits Cookbook** (a.k.a. this repo), a library of abstractions and starter scripts for customizing training environments.

The current primary getting-started path is the four starter scripts in [`logits_cookbook/recipes/`](logits_cookbook/recipes/):
1. [`sl_basic.py`](logits_cookbook/recipes/sl_basic.py): configuration-driven supervised learning starter.
2. [`sl_loop.py`](logits_cookbook/recipes/sl_loop.py): minimal supervised learning loop close to the raw API.
3. [`rl_basic.py`](logits_cookbook/recipes/rl_basic.py): configuration-driven reinforcement learning starter.
4. [`rl_loop.py`](logits_cookbook/recipes/rl_loop.py): minimal reinforcement learning loop close to the raw API.

The repository still contains additional recipe directories for more advanced or experimental workflows, but they are not part of the primary entry path above.

### Documentation

The `docs/` directory contains the Logits Cookbook documentation for install, training, checkpointing, and evaluation workflows.

**Note:** The documentation files use MDX format (Markdown with JSX), which includes some syntax that isn't standard Markdown. You may see things like `import` statements, `<Callout>` components, or curly-brace expressions. These are artifacts of our documentation framework - the actual content should still be readable as Markdown.

If you find errors or want to improve the documentation, edit files in `docs/` directly.

### Import our utilities

Logits Cookbook includes several utilities:
- [`renderers`](logits_cookbook/renderers/) converts tokens from/to structured chat message objects
- [`hyperparam_utils`](logits_cookbook/hyperparam_utils.py) helps calculate hyperparameters suitable for LoRAs
- [`checkpoint_utils`](logits_cookbook/checkpoint_utils.py) helps save, resume, and inspect checkpoints

Additional utilities, including evaluation integrations, remain available in the repository but are outside the current primary getting-started path.

## Development Setup

```bash
uv sync --extra dev
pre-commit install
```

This installs dev dependencies and registers pre-commit hooks that run `ruff` formatting and linting on every commit. CI enforces these checks on all pull requests.

## Contributing

This project is built in the spirit of open science and collaborative development. We believe that the best tools emerge through community involvement and shared learning.

We welcome PR contributions.
