├── data ├── 00.src.jpg ├── 01.src.jpg ├── 02.src.jpg ├── 03.src.jpg ├── 04.src.jpg ├── 05.src.jpg ├── 06.src.jpg ├── 07.src.jpg ├── 08.src.jpg ├── 09.src.jpg ├── 10.src.jpg ├── 12.src.jpg ├── 13.src.jpg ├── 14.src.jpg ├── 15.src.jpg ├── 16.src.jpg ├── 17.src.jpg ├── 18.src.jpg ├── 19.src.jpg └── 20.src.jpg ├── LICENSE ├── README.md └── .github └── workflows └── train.yaml /data/00.src.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zeke/flux-fine-tune-action/HEAD/data/00.src.jpg -------------------------------------------------------------------------------- /data/01.src.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zeke/flux-fine-tune-action/HEAD/data/01.src.jpg -------------------------------------------------------------------------------- /data/02.src.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zeke/flux-fine-tune-action/HEAD/data/02.src.jpg -------------------------------------------------------------------------------- /data/03.src.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zeke/flux-fine-tune-action/HEAD/data/03.src.jpg -------------------------------------------------------------------------------- /data/04.src.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zeke/flux-fine-tune-action/HEAD/data/04.src.jpg -------------------------------------------------------------------------------- /data/05.src.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zeke/flux-fine-tune-action/HEAD/data/05.src.jpg -------------------------------------------------------------------------------- /data/06.src.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zeke/flux-fine-tune-action/HEAD/data/06.src.jpg -------------------------------------------------------------------------------- /data/07.src.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zeke/flux-fine-tune-action/HEAD/data/07.src.jpg -------------------------------------------------------------------------------- /data/08.src.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zeke/flux-fine-tune-action/HEAD/data/08.src.jpg -------------------------------------------------------------------------------- /data/09.src.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zeke/flux-fine-tune-action/HEAD/data/09.src.jpg -------------------------------------------------------------------------------- /data/10.src.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zeke/flux-fine-tune-action/HEAD/data/10.src.jpg -------------------------------------------------------------------------------- /data/12.src.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zeke/flux-fine-tune-action/HEAD/data/12.src.jpg -------------------------------------------------------------------------------- /data/13.src.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zeke/flux-fine-tune-action/HEAD/data/13.src.jpg -------------------------------------------------------------------------------- /data/14.src.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zeke/flux-fine-tune-action/HEAD/data/14.src.jpg -------------------------------------------------------------------------------- /data/15.src.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zeke/flux-fine-tune-action/HEAD/data/15.src.jpg -------------------------------------------------------------------------------- /data/16.src.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zeke/flux-fine-tune-action/HEAD/data/16.src.jpg -------------------------------------------------------------------------------- /data/17.src.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zeke/flux-fine-tune-action/HEAD/data/17.src.jpg -------------------------------------------------------------------------------- /data/18.src.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zeke/flux-fine-tune-action/HEAD/data/18.src.jpg -------------------------------------------------------------------------------- /data/19.src.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zeke/flux-fine-tune-action/HEAD/data/19.src.jpg -------------------------------------------------------------------------------- /data/20.src.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zeke/flux-fine-tune-action/HEAD/data/20.src.jpg -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2024 Zeke Sikelianos 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Flux Fine-tune action 2 | 3 | This is an example repo for **fine-tuning and publishing your own custom [Flux](https://replicate.com/blog/fine-tune-flux-with-faces) model** using [Replicate](https://replicate.com) and [GitHub Actions](https://github.com/features/actions). 4 | 5 | ## Preqrequisites 6 | 7 | - A [Replicate](https://replicate.com/account) account 8 | - A handful of training images 9 | 10 | ## Training the model 11 | 12 | 1. Fork this repository. 13 | 1. Remove the images in the [data](data) directory and replace them with your own images. 14 | 1. Commit your changes to Git and push to your main branch on GitHub. 15 | 1. Create a [Replicate API token](https://replicate.com/account/api-tokens) and add it as a [repository secret](https://docs.github.com/en/actions/security-guides/encrypted-secrets#creating-encrypted-secrets-for-a-repository) named `REPLICATE_API_TOKEN`. 16 | 1. Trigger the workflow from your GitHub repo page: "Actions" > "Train a model" > "Run workflow". 17 | 1. Go to the [replicate.com/trainings](https://replicate.com/trainings) to see your training in progress. 18 | 19 | ## Running the model 20 | 21 | Check out these guides for tips on training and running Flux models: 22 | 23 | - https://replicate.com/blog/fine-tune-flux-with-faces 24 | - https://replicate.com/blog/fine-tune-flux-with-an-api 25 | - https://replicate.com/blog/using-synthetic-data-to-improve-flux-finetunes -------------------------------------------------------------------------------- /.github/workflows/train.yaml: -------------------------------------------------------------------------------- 1 | name: Create a new Flux fine-tune 2 | 3 | # This workflow is triggered manually from the GitHub website. 4 | # To run it, click the "Actions" tab on the repo page. 5 | on: 6 | workflow_dispatch: 7 | inputs: 8 | destination: 9 | required: true 10 | description: The name of the Replicate model to publish to, in the format `username/model`. The model must already exist. 11 | type: string 12 | trigger_word: 13 | required: true 14 | description: A short and unique non-word string representing your custom trained style or concept. This should be an uncommon string of letters like `ZXZX`, rather than a common word or name like `sarah` of `dog`. You'll use this string in prompts when running the model like "a pencil sketch of ZXZX sitting in a meadow". 15 | type: string 16 | steps: 17 | required: true 18 | description: Total number of training steps to perform. Higher numbers produce more accurate results, but take longer to run. Set this to something low like 100 to test that your workflow is working, then run again at a higher number like 1000 to train more accurately. 19 | type: number 20 | default: 100 21 | trainer_model: 22 | required: true 23 | description: The name of the trainer model to use, in the format `owner/model`. 24 | type: string 25 | default: "ostris/flux-dev-lora-trainer" 26 | trainer_version: 27 | required: true 28 | description: The version of the trainer model to use. 29 | type: string 30 | default: "7f53f82066bcdfb1c549245a624019c26ca6e3c8034235cd4826425b61e77bec" 31 | 32 | # Create a Replicate API token at https://replicate.com/account/api-tokens 33 | env: 34 | replicate-api-token: ${{ secrets.REPLICATE_API_TOKEN }} 35 | 36 | jobs: 37 | train: 38 | runs-on: ubuntu-latest 39 | steps: 40 | 41 | - name: Check secrets 42 | if: ${{ env.replicate-api-token == '' }} 43 | run: | 44 | echo "🙈 Uh oh! Missing repository secret: REPLICATE_API_TOKEN" 45 | echo "Go to https://replicate.com/account to copy your API token," 46 | echo "then visit https://github.com/${{ github.repository }}/settings/secrets/actions/new to set it." 47 | echo 48 | echo 49 | echo 50 | exit 1 51 | 52 | - name: Checkout code 53 | uses: actions/checkout@v3 54 | 55 | - name: Zip training data 56 | run: | 57 | zip -r data.zip data 58 | 59 | - name: Upload training data 60 | id: upload-training-data 61 | run: | 62 | FILE_UPLOAD_RESPONSE=$( 63 | curl -X POST "https://api.replicate.com/v1/files" \ 64 | -H "Authorization: Bearer ${{ secrets.REPLICATE_API_TOKEN }}" \ 65 | -H "Content-Type: multipart/form-data" \ 66 | -F "content=@data.zip;type=application/zip;filename=data.zip" 67 | ) 68 | 69 | echo $FILE_UPLOAD_RESPONSE 70 | echo $FILE_UPLOAD_RESPONSE | jq 71 | 72 | echo "INSTANCE_DATA_URL=$(jq -r '.urls.get' <<< $FILE_UPLOAD_RESPONSE)" 73 | echo "INSTANCE_DATA_URL=$(jq -r '.urls.get' <<< $FILE_UPLOAD_RESPONSE)" >> $GITHUB_OUTPUT 74 | 75 | - name: Start training 76 | run: | 77 | curl -X POST \ 78 | -H "Authorization: Bearer ${{ secrets.REPLICATE_API_TOKEN }}" \ 79 | -H "Content-Type: application/json" \ 80 | -d '{ 81 | "destination": "${{ inputs.destination }}", 82 | "input": { 83 | "trigger_word": "${{ inputs.trigger_word }}", 84 | "input_images": "${{ steps.upload-training-data.outputs.INSTANCE_DATA_URL }}", 85 | "steps": ${{ inputs.steps }} 86 | } 87 | }' \ 88 | "https://api.replicate.com/v1/models/${{ inputs.trainer_model }}/versions/${{ inputs.trainer_version }}/trainings" 89 | 90 | - name: Link to model 91 | run: | 92 | echo "🚂 Your model is now training!" 93 | echo "This takes a few minutes, and the duration depends on how many training steps you're running." 94 | echo "To monitor the progress of your training job, visit the Replicate dashboard at https://replicate.com" 95 | echo "When training finishes, you'll be able to run predictions with your new model using the web UI or via API at https://replicate.com/${{ inputs.destination }}" 96 | --------------------------------------------------------------------------------