> ## Documentation Index
> Fetch the complete documentation index at: https://docs.devin.ai/llms.txt
> Use this file to discover all available pages before exploring further.

# Post-Train Custom Models With Devin and Modal

> Post-train a custom model with Devin on a Modal GPU outpost: fine-tune a FLUX LoRA, deploy it as a Modal endpoint, and ship it in a PR

<video controls width="100%" playsInline>
  <source src="https://mintcdn.com/cognitionai/4bg4JipkvpdMh6Vh/images/tutorial-library/post-training-walkthrough.mp4?fit=max&auto=format&n=4bg4JipkvpdMh6Vh&q=85&s=773df1824a5bb9ca12eb645564da0df8" type="video/mp4" />
</video>

Devin post-training a FLUX LoRA on a Modal GPU, deploying the best checkpoint, and adding it to a chat app

Devin runs wherever the job needs to run. With [Devin Outposts](/cloud/outposts/overview), a session can run on your own infrastructure or a partner platform; here it runs in a [Modal](https://modal.com/docs/devin) GPU sandbox, so the same Devin that writes your code can train, evaluate, and deploy a model end to end. In this tutorial Devin fine-tunes a FLUX LoRA on 18 otter images so that "Devin the software engineer" renders as an otter, deploys it as a Modal endpoint, and adds it to a chat app's model picker.

## Before you start

* **Create a Modal outpost**: run `uvx modal-devin init` and pick a GPU for the generated Modal app. See [Run Devin on Modal](https://modal.com/docs/devin) and the [Outposts quickstart](/cloud/outposts/quickstart.md).
* **Connect your repository**: the app you want the model wired into. The video uses a private demo chat app with an image model picker, checked out onto a persistent Modal Volume. Don't have an app? Ask Devin to build one first (for example, `build a simple chat app with a model picker that calls an image generation endpoint`), or skip the app and have Devin only train and deploy the model.
* **Prepare your training data**: add captioned images to the repository or a Modal Volume the outpost mounts. The example uses 18 cartoon otter images with captions like "Devin the software engineer in a data center".
* **Add secrets**: store your Weights & Biases key under [Settings > Secrets](https://app.devin.ai/settings/secrets). The Modal sandbox already carries Modal credentials, so Devin can deploy endpoints without extra setup.
* **Set rules for long runs**: add [organization rules](/product-guides/plugins.md#rules) (or put them in the prompt) such as: post a progress update every 15 minutes, render validation images at every checkpoint, and include the preview link in every PR.
* **Connect Slack** (optional): training runs take hours, so [sync the session to a Slack thread](/integrations/slack.md#sync-sessions-with-slack-threads) to follow along.

## Step 1: Start a session on the outpost

Open [Devin](https://app.devin.ai/), choose your Modal outpost from the **Virtual environment** menu below the prompt box, and turn on the Slack toggle in the composer. Check the hardware:

```text theme={null}
tell me more about your environment
```

Devin reports an NVIDIA B200 with PyTorch and diffusers installed, and the project on a persistent Modal Volume.

## Step 2: Check the training data

```text theme={null}
hey devin show me the images im using for supervised learning
```

Devin finds the dataset in the project and posts the 18 images, with their captions, to the session and the Slack thread.

## Step 3: Kick off the training run

```text theme={null}
post train flux to create the otterimage 1.0 model. once you are done, add otterimage to the model picker in otterchat
```

`otterchat` is the demo app in the video; use your own repository's name.

Devin runs the job on its own, following the rules above:

1. **Trains the LoRA**: about 1,000 steps, logged to Weights & Biases, with validation renders every 100 steps.
2. **Reports to Slack**: progress every 15 minutes with the latest renders. Early renders are humans; the otter appears as training continues.
3. **Picks the best checkpoint**: step 700, since steps 900 and 1,000 showed signs of overfitting.
4. **Deploys and ships**: serves step 700 as a serverless Modal endpoint, adds `otterimage 1.0` to the chat app's model picker, [records](/work-with-devin/testing-and-recordings.md) an end-to-end test, and opens a PR with a preview link.

![Grid of validation images at each checkpoint](https://mintcdn.com/cognitionai/4bg4JipkvpdMh6Vh/images/tutorial-library/post-training-validation.png?fit=max\&auto=format\&n=4bg4JipkvpdMh6Vh\&q=85\&s=7da45a563e1c6d538643483e75601a74)

Validation renders from step 500 to step 1,000

## Step 4: Try the model

Open the preview link from the PR and ask for an image:

```text theme={null}
generate an image of devin the software engineer eating spaghetti
```

![The chat app returning a cartoon otter eating spaghetti](https://mintcdn.com/cognitionai/4bg4JipkvpdMh6Vh/images/tutorial-library/post-training-otterchat.png?fit=max\&auto=format\&n=4bg4JipkvpdMh6Vh\&q=85\&s=e7a6d33991a5cd2089bebc64857f98ec)

The same prompt on a general-purpose image model returns a human.

## Step 5: Iterate with child sessions

Post-training is rarely one run. Hand Devin a paper and let it try the alternatives in parallel:

```text theme={null}
https://arxiv.org/pdf/2309.14859v2 spin up subsession that train otterimage on the other techniques listed in this paper other than lora
```

Devin adds the new methods to the training script in a PR and starts three [child sessions](/work-with-devin/advanced-capabilities.md#managed-devins) on the outpost, one each for LoHa, LoKr, and native fine-tuning.

![Devin's session showing three child sessions for LoHa, LoKr, and native fine-tuning](https://mintcdn.com/cognitionai/4bg4JipkvpdMh6Vh/images/tutorial-library/post-training-child-sessions.png?fit=max\&auto=format\&n=4bg4JipkvpdMh6Vh\&q=85\&s=8892cdce447e15e95fc4a01187f6af09)

## Next steps

> **[Run Devin on Modal](https://modal.com/docs/devin)**
>
> Create a Modal-backed outpost with GPUs, Volumes, and Secrets

> **[Devin Outposts](/cloud/outposts/overview)**
>
> Run sessions on your own infrastructure or a partner platform

> **[Slack integration](/integrations/slack.md)**
>
> Follow long-running sessions from a Slack thread

> **[Managed Devins](/work-with-devin/advanced-capabilities.md#managed-devins)**
>
> Spin up and monitor child sessions for parallel experiments


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.