Skip to content

Commit

Permalink
clean up readme and add contributing guide
Browse files Browse the repository at this point in the history
  • Loading branch information
zeke committed Sep 12, 2024
1 parent 3b85fe7 commit eba6056
Show file tree
Hide file tree
Showing 2 changed files with 111 additions and 58 deletions.
99 changes: 99 additions & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
# Contributing

Thanks for taking the time to contribute to this project. 🙏🏼

This document covers how to get started working on this project, and proposing changes to make it better.

## Start with an issue

Rather than jump straight to an implementation in a pull request, please start with an issue.

This gives everyone a chance to weigh in on the idea, and for you to get some early feedback. It also helps avoid wasting time on something that the maintainers don't think is a good fit for this project.

If you've found a bug, please include steps to reproduce it.

## Development

Once you've found an issue to work on, it's time to jump into making changes.

Before submitting a PR, format the code and run the linter locally.

```shell
pip install -r requirements-test.txt # only need to do this once
ruff format
ruff check
```

## Open a pull request

We use the [GitHub Flow](https://docs.github.com/en/get-started/quickstart/github-flow) model for managing changes.

1. Fork the repository
2. Create a new branch
3. Make your changes
4. Add or update tests, if applicable
5. Add or update documentation, if applicable
6. Open a pull request, and include a reference to the original issue

---

## Deploy to production

> [!NOTE]
> 👇 The rest of this document is for internal Replicate use. It contains instructions for deploying the model to production and updating hotswap bases. If you're an external contributor, you can safely ignore it.
### Push model

Manually trigger the [Github Push action](https://github.com/replicate/flux-fine-tuner/actions/workflows/push.yaml). Uncheck the "Test only, without pushing to prod" button. You might also have to uncheck the "Compare outputs..." button.

The push action takes half an hour since it tests both training and inference. But it's worth doing to be safe.

Once you've deployed to production, make a test fine-tune and run predictions on the trained model, just to be super sure it works.

### Update hotswap bases

When you've tested the pushed model, you need to update all existing fine-tuned versions to use the predictor you just pushed.

First, only update a single model or a subset of models to test that this step works.

In your local checkout of [web](https://github.com/replicate/web), run

```shell
script/manage-prod update_hotswap_base_version \
--from-model ostris/flux-dev-lora-trainer \
--to-latest \
--trained-version-filter="<your-username>/<your-model-name>"
```

This is a dry run to list the versions that will be updated. The `--trained-version-filter` can be just "<your-username>" if you want to test all your models.

When you're happy to with the list of models that will be updated, run

```shell
script/manage-prod update_hotswap_base_version \
--from-model ostris/flux-dev-lora-trainer \
--to-latest \
--trained-version-filter="<your-username>/<your-model-name>" \
--force
```

Now you can test that the predictor works for the updated model(s).

When you're happy with that, do the same thing but for all models. First, a dry run:

```shell
script/manage-prod update_hotswap_base_version \
--from-model ostris/flux-dev-lora-trainer \
--to-latest \
```

And then actually update all the trained Flux versions:

```shell
script/manage-prod update_hotswap_base_version \
--from-model ostris/flux-dev-lora-trainer \
--to-latest \
--force
```

This process is being improved -- soon it will be possible to configure base versions in Django admin.
70 changes: 12 additions & 58 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,69 +1,23 @@
# flux-fine-tuner

## Development
This is a [Cog](https://cog.run) training model that creates LoRA-based fine-tunes for the [FLUX.1](https://replicate.com/blog/flux-state-of-the-art-image-generation) family of image generation models.

Before submitting a PR, format the code and run the linter locally.
It's live at [replicate.com/ostris/flux-dev-lora-trainer/train](https://replicate.com/ostris/flux-dev-lora-trainer).

```shell
pip install -r requirements-test.txt # only need to do this once
ruff format
ruff check
```
## Fine-tuning Flux

## Deploy to production
If you're just looking to create a fine-tuned Flux model, you don't need to do anything with this codebase.

### Push model
To get started fine-tuning Flux on Replicate, check out these guides:

Manually trigger the [Github Push action](https://github.com/replicate/flux-fine-tuner/actions/workflows/push.yaml). Uncheck the "Test only, without pushing to prod" button. You might also have to uncheck the "Compare outputs..." button.
- [Fine-tune FlUX.1](https://replicate.com/blog/fine-tune-flux)
- [Fine-tune FLUX.1 to create images of yourself](https://replicate.com/blog/fine-tune-flux-with-faces)
- [Fine-tune FLUX.1 with an API](https://replicate.com/blog/fine-tune-flux-with-an-api)

The push action takes half an hour since it tests both training and inference. But it's worth doing to be safe.
## Contributing

Once you've deployed to production, make a test fine-tune and run predictions on the trained model, just to be super sure it works.
Want to help make this project better? Check out the [contributing guide](CONTRIBUTING.md) to get started.

### Update hotswap bases
## Credits

When you've tested the pushed model, you need to update all existing fine-tuned versions to use the predictor you just pushed.

First, only update a single model or a subset of models to test that this step works.

In your local checkout of [web](https://github.com/replicate/web), run

```shell
script/manage-prod update_hotswap_base_version \
--from-model ostris/flux-dev-lora-trainer \
--to-latest \
--trained-version-filter="<your-username>/<your-model-name>"
```

This is a dry run to list the versions that will be updated. The `--trained-version-filter` can be just "<your-username>" if you want to test all your models.

When you're happy to with the list of models that will be updated, run

```shell
script/manage-prod update_hotswap_base_version \
--from-model ostris/flux-dev-lora-trainer \
--to-latest \
--trained-version-filter="<your-username>/<your-model-name>" \
--force
```

Now you can test that the predictor works for the updated model(s).

When you're happy with that, do the same thing but for all models. First, a dry run:

```shell
script/manage-prod update_hotswap_base_version \
--from-model ostris/flux-dev-lora-trainer \
--to-latest \
```

And then actually update all the trained Flux versions:

```shell
script/manage-prod update_hotswap_base_version \
--from-model ostris/flux-dev-lora-trainer \
--to-latest \
--force
```

This process is being improved -- soon it will be possible to configure base versions in Django admin.
This project is based on the [ai-toolkit](https://github.com/ostris/ai-toolkit) project, which was created by [@ostris](https://github.com/ostris). ❤️

0 comments on commit eba6056

Please sign in to comment.