Sign In

Guide: Free LoRa training on Modal

0

Guide: Free LoRa training on Modal

Modal: https://modal.com/

Modal is a GPU renting platform. The interesting part is that you get 30$ of free compute time per month and 1 TB of storage. That is several hours of training time and you can easily train few LoRas with that.

Here I will explain how to train LoRa on Modal.


The code I use is based on this script: https://github.com/IjoiK12/modal-deploy-kohya-ss

But instead of using the GUI, which is not updated anymore, we will be using the sd-scripts directly.

Preparing the environment

0: Register on Modal. Add payment info. Set your billing limit to 30 $/mo to only use the free compute. Make sure you do get the free 30$ to avoid surprise bills.

1: Download and extract the attached zip file into folder somewhere. The zip file contains the app and example config files.

2: Create venv (Optional but strongly recommended), install modal pip install modal, and log in to it modal setup.

3: Deploy the app: modal deploy app.py . This will create and configure the environment on the server. It should take few minutes.

The app has 5 storage volumes on the server.
kohya-models mounted at "/kohya_ss/models" for base models.
kohya-dataset mounted at "/kohya_ss/dataset" for holding datasets (folders of images, captions, cached latents).
kohya-outputs mounted at "/kohya_ss/outputs" for training outputs.
kohya-configs mounted at "/kohya_ss/train_toml" for training configurations.
hf-cache for some cache. Vestigial and probably not needed.

4: Upload models to Modal.

modal volume put kohya-models "/your-path-to-models/anima-base-v1.0.safetensors" "/models/anima-base-v1.0.safetensors"
modal volume put kohya-models "/your-path-to-models/qwen_image_vae.safetensors" "/models/qwen_image_vae.safetensors"
modal volume put kohya-models "/your-path-to-models/qwen_3_06b_base.safetensors" "/models/qwen_3_06b_base.safetensors"

Preparing training

1: Uploading dataset - You have your training images and captions in some folder on your PC. Don't do any of the "1_concept" folder naming, handle that via dataset.toml instead. Upload the contents of your folder to Modal like this:
modal volume put kohya-dataset "/your-path/my_folder_with_images_and_captions" /my_dataset

You get 1 TB of storage. So you can have multiple training datasets in different folders.

2: Training configuration - Prepare training config.toml and dataset.toml. The attached zip file contains example tomls. Upload them to Modal.

modal volume put kohya-configs -f "/path-to-your-config/training_example.toml" "train_config.toml"
modal volume put kohya-configs -f "/path-to-your-config/dataset_example.toml" "dataset_example.toml"

The app is hard coded to run training config "train_config.toml" in "kohya-configs" volume. So always use that name when you upload it.

3: Configure container (optional). You can change which GPU is used, how much RAM is reserved, how many CPU cores are reserved, and how long the container will last for (the container is closed at the end of training automatically). See the config.toml in the attached zip.

I did a quick test with different GPUs to see which one is cheapest for Anima training. T4 is so slow that they are not even worth considering.
L4 got 21 s/it, A10 got 16 s/it, L40S got 7 s/it. After adding in the CPU and RAM costs the L40S is best GPU for $/it. Different training settings may get different results. Prices may change in future.

Train model

With all that done you can start training. Just run modal run --detach app4.py::train_anima and sit back. You can monitor the training via console or on your dashboard on Modal. If you close the console it will give you commands to resume monitoring, or to remotely stop it. You can also stop it early on the dashboard if needed.

You can download the created models with command modal volume get kohya-outputs /models/TEST.safetensors /path-to-your-loras/TEST.safetensors . If you forget what your filenames are you can browse your files on Modal dashboard.

Once you are done you can delete your models and files from server. For example this command deletes the models output folder and all its contents modal volume rm -r kohya-outputs /models .

Help needed

The script I made is based on older script. It contains vestigial parts that are not needed anymore.

Bigger problem is that it uses old dependencies. I tried upgrading it to use something more modern. But then CUDA version does not match, Pytorch version does not match, and nothing works. Some help on this would be greatly appreciated.

I also do not know what training settings are good for these kinds of GPUs. All my prior experience has been "How do I get training to run on 8 GB RTX 3070". Now I have 48 GB of VRAM and I have no idea how to properly utilize it.

0