Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

clean up README and add CONTRIBUTING guide #31

Merged
merged 6 commits into from
Sep 12, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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: 15 additions & 55 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,69 +1,29 @@
# 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.
This project is based on the [ai-toolkit](https://github.com/ostris/ai-toolkit) project, which was created by [@ostris](https://github.com/ostris). ❤️

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

In your local checkout of [web](https://github.com/replicate/web), run
Flux Dev falls under the [`FLUX.1 [dev]` Non-Commercial License](https://huggingface.co/black-forest-labs/FLUX.1-dev/blob/main/LICENSE.md).

```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.
Flux Schnell falls under the [Apache-2.0 License](https://huggingface.co/datasets/choosealicense/licenses/blob/main/markdown/apache-2.0.md).
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@fofr @andreasjansson does this license bit look right?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes I think that's good enough for now.

Loading