All Products
Search
Document Center

Platform For AI:Deploy a LoRA SD model with Kohya_ss on EAS

Last Updated:Jun 02, 2026

Train LoRA models with Kohya_ss on EAS and apply to Stable Diffusion for image generation.

Prerequisites

Set up OSS storage

  1. Log on to the OSS console and navigate to a bucket path in the same region. For example, oss://kohya-demo/kohya/.

  2. Create a project folder (example: KaraDetroit_loar) with three subfolders: Image, Log, and Model. Optionally upload a JSON configuration file to this folder.

    image.png

    • 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.

  3. Upload prepared images to the Image folder. This example uses a sample package: 100_pic.zip. Download, decompress, and upload the folder to OSS.

    image.png

    Important
    • Supported image formats are .png, .jpg, .jpeg, .webp, and .bmp.

    • Each image must have a description file with the same name and a .txt file 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=150 times. 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

  1. 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).

  2. Click Deploy Service. In the Custom Model Deployment section, click Custom Deployment.

  3. 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.

    Note

    Select 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.

      Important

      Turn 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:

    Important

    In 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
        }]
    }
  4. Review the configuration and click Deploy. Deployment takes a few minutes. The service is ready when Service Status changes to Running.

Train LoRA model

  1. On the Overview page of the service, click Web applications to open the Kohya_ss service page.

  2. Select LoRA (LoRA).

    image

  3. (Optional) Set Configuration file. Skip if no SS_config.json file is available.

    image

    Note

    The path combines Mount Path from Form configuration, the OSS folder path, and the file name. Example: /workspace/KaraDetroit_loar/SS_config.json.

  4. Set SourceModel. safetensors is recommended over checkpoint for better security.

    image

  5. Set Folders. Enter the Image, Log, and Model paths from OSS, and specify the output file name.

    image

    Parameter

    Description

    Image folder

    Training images folder. Combine Mount Path from Form configuration with the OSS Image path. Example: /workspace/KaraDetroit_loar/Image.

    Logging folder

    Log output folder. Combine Mount Path from Form configuration with the OSS Log path. Example: /workspace/KaraDetroit_loar/Log.

    Output folder

    Model output folder. Combine Mount Path from Form configuration with the OSS Model path. Example: /workspace/KaraDetroit_loar/Model.

    Model output name

    Model output name. For example, my_model.

  6. Set Parameters. For example values, see the SS_config.json file content in the Prepare OSS storage structure step.

    Parameter

    Description

    LoRA Type

    LoRA type. Options:

    • LoCON: Adjusts every layer of SD, such as Res, Block, and Transformer.

    • 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 cosine or cosine with restart as needed.

    LR Warmup (% of steps)

    Warmup steps. Default: 10. Set to 0 to skip warmup.

    Optimizer

    Optimizer. Default: AdamW8bit. DAdaptation enables 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).

  7. At the bottom of the page, click Start training.image

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

    image

    When model saved appears in the log, training is complete.

    image.png

  9. Retrieve the trained LoRA model from the Model folder. Example: my_model.safetensors.

    image.png

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

  1. Select a cluster runtime image (example: stable-diffusion-webui:4.2-cluster-webui). After the service starts, /data-{current_user_ID}/models/Lora is auto-created in the mounted OSS path.

  2. In the Command to Run section, add the following parameters:

    • --lora-dir: Optional parameter.

      • If the --lora-dir parameter is not specified, model files for all users are isolated. Only model files in {OSS_path}/data-{current_user_ID}/models/Lora are loaded.

      • If the --lora-dir parameter 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.

  3. 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.

    image.png

    Note

    The /data-{current_user_ID}/models/Lora path 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.

    image.png

Stable Diffusion WebUI Basic Edition

  1. Select a non--cluster runtime image (example: stable-diffusion-webui:4.2-standard). After the service starts, /models/Lora is auto-created in the mounted OSS path.

  2. In the Command to Run section, add the --data-dir {OSS_mount_path} parameter. For example, --data-dir /code/stable-diffusion-webui/data-oss.

  3. Upload the LoRA model file to {OSS_path}/models/Lora. For example, oss://bucket-test/data-oss/models/Lora.

    image.png

    Note

    The /models/Lora path is auto-created after the service starts. Upload the LoRA model file afterward.