fork from https://github.com/ostris/ai-toolkit with some adjustments to fix issues when training LoRA on Modal
This guide will help you set up the environment for training LoRA models with FLUX on Modal
Before starting, make sure you have:
- Administrator privileges on your Windows system (for Windows users)
- Registered accounts on Modal and Hugging Face
- Accepted FLUX.1-dev license on Hugging Face (if using it)
- Run
setup_modal_training.batas Administrator- Right-click on the script
- Select "Run as administrator"
- Open Terminal and navigate to the project directory
- Make the setup script executable:
chmod +x setup_modal_training.sh
- Run the setup script:
./setup_modal_training.sh
-
Follow the Modal token setup:
- Go to https://modal.com/settings/tokens
- Click "New Token"
- Copy the command that looks like:
modal token set --token-id ak-xxxx --token-secret as-xxxx - Paste the command when prompted
-
Prepare required files:
- Configuration file:
- Customize settings according to your needs in config/file modal_train_lora_flux.yaml
- Environment file (
.env):- Add your Hugging Face token in format:
HF_TOKEN=hf_xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
The setup script will automatically:
-
Install required software (if not already installed):
- Python 3.10 or higher
- Git (on MacOS, you can install it via Homebrew if needed)
-
Clone the ai-toolkit repository:
- Windows: to
C:\ai-toolkit(to prevent path length limitations) - MacOS: to the current directory
- Windows: to
-
Set up virtual environment and dependencies
-
Configure Modal and Hugging Face tokens
Once all files are prepared, the training process will start automatically with:
modal run --detach run_modal.py --config-file-list-str=/root/ai-toolkit/config/modal_train_lora_flux.yaml
You can monitor the training progress and logs at: https://modal.com/logs
If you encounter any issues:
- Make sure you're running the script as Administrator
- Check that all required tokens are correctly set up
- Verify that Python and Git are properly installed and added to PATH
- Ensure all required files are present and correctly formatted
If you need to restart the setup process:
- Close the current window
- Open a new Command Prompt or Terminal
- Navigate back to the installation folder
- Run the script again as Administrator
modal volume get flux-lora-models your-model-name
