Train LoRA models with Kohya_ss on EAS and apply to Stable Diffusion for image generation.
Prerequisites
-
Activate EAS and create a default workspace. Activate PAI and create a default workspace.
-
If a RAM user deploys the model, grant EAS management permissions. Cloud product dependencies and permissions: EAS.
-
Create an OSS bucket and folders in the same region to store training materials, model files, and logs. Upload files.
Set up OSS storage
-
Log on to the OSS console and navigate to a bucket path in the same region. For example,
oss://kohya-demo/kohya/. -
Create a project folder (example:
KaraDetroit_loar) with three subfolders:Image,Log, andModel. Optionally upload a JSON configuration file to this folder.
-
Image: Source files for training materials.
-
Model: Model files after training completes.
-
Log: Training logs.
-
SS_config.json: JSON file for batch parameter configuration (optional). Configure folder paths, output model names, and other parameters. GitHub. Sample: SS_config.json.
-
-
Upload prepared images to the
Imagefolder. This example uses a sample package: 100_pic.zip. Download, decompress, and upload the folder to OSS.
Important-
Supported image formats are
.png,.jpg,.jpeg,.webp, and.bmp. -
Each image must have a description file with the same name and a
.txtfile extension. The description must be on the first line. If an image has multiple descriptions, separate them with commas. -
Image folder names must follow the format: number_name (example: 100_pic). The number sets repetitions per image during training (typically 100+). Total training iterations should exceed 1,500.
-
If the folder contains 10 images, each is trained
1500/10=150times. Set the folder name number to "150". -
If the folder contains 20 images, each is trained
1500/20=75 (<100)times. Set the folder name number to "100".
-
-
Deploy Kohya_ss service
-
Log on to the PAI console. Select a region on the top of the page. Then, select the desired workspace and click Elastic Algorithm Service (EAS).
-
Click Deploy Service. In the Custom Model Deployment section, click Custom Deployment.
-
On the Custom Deployment page, configure the parameters using the form or by specifying JSON configurations.
Form configuration
Parameter
Description
Basic Information
Service Name
Custom name. Example: kohya_ss_demo.
Environment Information
Deployment Method
Select Image-based Deployment and select Enable Web App.
Image Configuration
In the Alibaba Cloud Image list, select kohya_ss > kohya_ss:2.2.
NoteSelect the latest version during deployment.
Storage Mount
Select OSS as mount type and configure these parameters:
-
Uri: OSS path in the same region. Example:
oss://kohya-demo/kohya/. -
Mount Path: Custom path. Example:
/workspace.ImportantTurn off the Read-Only switch. Otherwise, model files cannot be written to OSS.
Command to Run
Auto-configured after image selection. Example:
python -u kohya_gui.py --listen=0.0.0.0 --server_port=8000 --headless.-
--listen: Binds to the specified IP address for external requests. -
--server_port: Listening port number.
Resource Information
Resource Type
Select Public Resources.
Deployment
Recommended: ml.gu7i.c16m60.1-gu30 for cost-effectiveness. This example uses ml.gu7i.c8m30.1-gu30.
JSON configuration
In the Service Configurations section, click Edit and enter the configuration in JSON format.
Sample JSON configuration:
ImportantIn the following example, modify the configurations on line 4 ("name") and line 18 ("oss") based on your requirements.
{ "metadata": { "name": "kohya_ss_demo", "instance": 1, "enable_webservice": true }, "cloud": { "computing": { "instance_type": "ecs.gn6e-c12g1.12xlarge", "instances": null } }, "storage": [ { "oss": { "path": "oss://kohya-demo/kohya/", "readOnly": false }, "properties": { "resource_type": "model" }, "mount_path": "/workspace" }], "containers": [ { "image": "eas-registry-vpc.cn-hangzhou.cr.aliyuncs.com/pai-eas/kohya_ss:1.2", "script": "python -u kohya_gui.py --listen=0.0.0.0 --server_port=8000 --headless", "port": 8000 }] } -
-
Review the configuration and click Deploy. Deployment takes a few minutes. The service is ready when Service Status changes to Running.
Train LoRA model
-
On the Overview page of the service, click Web applications to open the Kohya_ss service page.
-
Select LoRA (LoRA).

-
(Optional) Set Configuration file. Skip if no
SS_config.jsonfile is available.
NoteThe path combines Mount Path from Form configuration, the OSS folder path, and the file name. Example:
/workspace/KaraDetroit_loar/SS_config.json. -
Set SourceModel. safetensors is recommended over checkpoint for better security.

-
Set Folders. Enter the
Image,Log, andModelpaths from OSS, and specify the output file name.
Parameter
Description
Image folder
Training images folder. Combine Mount Path from Form configuration with the OSS
Imagepath. Example:/workspace/KaraDetroit_loar/Image.Logging folder
Log output folder. Combine Mount Path from Form configuration with the OSS
Logpath. Example:/workspace/KaraDetroit_loar/Log.Output folder
Model output folder. Combine Mount Path from Form configuration with the OSS
Modelpath. Example:/workspace/KaraDetroit_loar/Model.Model output name
Model output name. For example, my_model.
-
Set Parameters. For example values, see the
SS_config.jsonfile content in the Prepare OSS storage structure step.Parameter
Description
LoRA Type
LoRA type. Options:
-
LoCON: Adjusts every layer of SD, such asRes,Block, andTransformer. -
LoHA: Processes more information with the same size.
LoRA network weights
LoRA weights. To resume training, select the previous LoRA output (optional).
Train batch size
Training batch size. Larger values require more VRAM.
Epoch
Number of epochs (one full pass through all training data). Calculate manually:
-
Total training iterations in Kohya = Number of training images × Repetitions × Number of epochs / Training batch size. -
Total training iterations in WebUI = Number of training images × Repetitions.
With class images, total iterations double in both Kohya and WebUI, and model saves in Kohya are halved.
Save every N epochs
Saves the model every N epochs. Example: set to 2 to save after every 2 epochs.
Caption Extension
File extension for caption files, for example, .txt (optional).
Mixed precision
Mixed precision. Options: no, fp16, bf16. Use bf16 for GPUs with 30+ GB VRAM.
Save precision
Save precision. Same as above.
Number of CPU threads per core
CPU threads per core. Affects VRAM usage. Adjust based on your instance specs.
Learning rate
Learning rate. Default: 0.0001.
LR Scheduler
Learning rate scheduler. Select a function such as
cosineorcosine with restartas needed.LR Warmup (% of steps)
Warmup steps. Default: 10. Set to 0 to skip warmup.
Optimizer
Optimizer. Default:
AdamW8bit.DAdaptationenables automatic tuning.Max Resolution
Maximum resolution. Set based on image properties.
Network Rank (Dimension)
Model complexity. A value of 128 is sufficient for most scenarios.
Network Alpha
Must not exceed Network Rank (Dimension). Common setting: Rank 128, Alpha 64.
Convolution Rank (Dimension)
& Convolution Alpha
Convolution degree. Controls the fine-tuning scope. Adjust based on LoRA Type.
Kohya official recommendations:
-
LoCon:dim <= 64,alpha = 1(or lower). -
LoHA:dim <= 32,alpha = 1.
clip skip
CLIP skip count. Range: 1 to 12. Lower values produce images closer to the input prompt.
-
For realistic models, select 1.
-
For anime-style models, select 2.
Sample every n epoch
Generates a sample image every N epochs.
Sample Prompts
Sample prompts. Use a command with parameters:
-
--n: Prompt, negative prompt. -
--w: Image width. -
--h: Image height. -
--d: Image seed. -
--l: Prompt relevance (cfg). -
--s: Iteration steps (steps).
-
-
At the bottom of the page, click Start training.

-
Click the service name in the EAS service list to open the details page, then click Log to view training progress.

When
model savedappears in the log, training is complete.
-
Retrieve the trained LoRA model from the
Modelfolder. Example:my_model.safetensors.
Generate images with the trained LoRA model
Upload the trained LoRA model to the SD WebUI LoRA directory for image generation. Deploy a Stable Diffusion service with EAS in 5 minutes to enable text-to-image generation.
Upload the LoRA model file to the SD WebUI LoRA directory using one of the following methods.
Stable Diffusion WebUI Cluster Edition
-
Select a cluster runtime image (example: stable-diffusion-webui:4.2-cluster-webui). After the service starts,
/data-{current_user_ID}/models/Lorais auto-created in the mounted OSS path. -
In the Command to Run section, add the following parameters:
-
--lora-dir: Optional parameter.-
If the
--lora-dirparameter is not specified, model files for all users are isolated. Only model files in{OSS_path}/data-{current_user_ID}/models/Loraare loaded. -
If the
--lora-dirparameter is specified, all users load model files from the specified directory and{OSS_path}/data-{current_user_ID}/models/Lora. For example,--lora-dir /code/stable-diffusion-webui/data-oss/models/Lora.
-
-
--data-dir {OSS_mount_path}, for example,--data-dir /code/stable-diffusion-webui/data-oss.
-
-
Upload the LoRA model file to
{OSS_path}/data-{current_user_ID}/models/Lora. For example,oss://bucket-test/data-oss/data-1596******100/models/Lora.
NoteThe
/data-{current_user_ID}/models/Lorapath is auto-created after the service starts. Upload the LoRA model file afterward.Find
{current_user_ID}by clicking your profile picture in the upper-right corner.
Stable Diffusion WebUI Basic Edition
-
Select a non-
-clusterruntime image (example: stable-diffusion-webui:4.2-standard). After the service starts,/models/Lorais auto-created in the mounted OSS path. -
In the Command to Run section, add the
--data-dir {OSS_mount_path}parameter. For example,--data-dir /code/stable-diffusion-webui/data-oss. -
Upload the LoRA model file to
{OSS_path}/models/Lora. For example,oss://bucket-test/data-oss/models/Lora.
NoteThe
/models/Lorapath is auto-created after the service starts. Upload the LoRA model file afterward.