replicate / fast-flux-kontext-trainer

Fine-tune FLUX.1 Kontext to follow your own instructions

  • Public
  • 264 runs
Iterate in playground

Replicate’s FLUX.1 Kontext Lora trainer

To train FLUX.1 Kontext you need to use pairs of images, a starting image (before the edit), and an ending image (after the edit).

You’ll also need to give a prompt instruction – this is the prompt that would trigger the type of edit you want. If you want to use the same instruction for each image pair, you can do this using the kontext_prompt_instruction field. Alternatively, you can include text files containing specific instructions for each pair (see below).

An example dataset might look like:

  • 0001_start.jpg
  • 0001_end.jpg
  • 0001.txt
  • 0002_start.jpg
  • 0002_end.jpg
  • 0002.txt

You can name files however you like, but they must be part of a pair, ending with _start and _end. The text file is optional.

Here is an example dataset zip.

Dataset Size and Image Resolution

  • Aim for a dataset of 10-20 image pairs
  • Images with resolutions around 1024x1024 are ideal
  • Very large images will be scaled down to fit aspect ratios around 1024 resolutions

How to Run your Flux Kontext fine tune

After training is complete you will be able to run your LoRA in a new Replicate model at the destination location

How to train with the API

To run a training from the API, you’ll still need to gather a zip file of images and select or create a model on Replicate as the destination for your training. Unlike in the UI, you’ll also need to upload the zip file to your storage platform of choice. You’ll also need to get a Replicate API token.

Once you have those things ready, you can call the training API like so:

curl -X POST \
  -H "Authorization: Bearer $REPLICATE_API_TOKEN" \
  -H "Content-Type: application/json" \
  -d '{
        "destination": "your-username/your-model-name",
        "input": {
            "input_images": "<your-training-data-url>",
            "kontext_prompt_instruction": "<your-instruction>"
        }
    }' \
  https://api.replicate.com/v1/models/replicate/fast-flux-kontext-trainer/versions/a5d083d415468cf90d62e0bf1c78454aa0433d812abb5748f6a93c3c738614ff/trainings

This will start the training and return a JSON with training metadata. You can check on the status of the training at replicate.com/trainings or programmatically through the API like so:

curl -s \
  -H "Authorization: Bearer $REPLICATE_API_TOKEN" \
  https://api.replicate.com/v1/trainings/<training_id>