Deploy and fine-tune Stable Diffusion V1.5 for text-to-image

更新时间:
复制 MD 格式

This article shows you how to deploy the Stable Diffusion V1.5 model and launch a WebUI application to use and debug the model.

Prerequisites

An OSS Bucket has been created. For more information, see Create a bucket in the console.

1. Access model details

  1. Go to the Model Gallery page.

    1. Log in to the PAI console.

    2. In the upper-left corner, select a region.

    3. In the left-side navigation pane, click Workspaces and then click the name of your workspace.

    4. In the left-side navigation pane, choose Quick Start > Model Gallery.

  2. On the Model Gallery page, search for and click the Stable_Diffusion_V1.5 model card.

2. Deploy and test the model

  1. On the model details page, click Deploy in the upper-right corner. In the Deploy panel, select a deployment resource, such as ecs.gn6e-c12g1.3xlarge. Use the default values for the other parameters.

  2. Click Deploy. In the Billing Notification dialog box, click OK.

    The page is automatically redirected to the Service details page. In the Basic Information section, you can view the deployment status of the model service. When the Status changes to Running, the model service is successfully deployed.

  3. In the upper-right corner of the service details page, click View Web App to launch the WebUI.

  4. On the WebUI, test the model.

    On the text-to-image tab, in the prompt area, enter the following text: The eagle is flying in the sky, in the distance is the vast snow, and under the snow mountain is a grassland. Then, click Generate to view the inference result. Select the text-to-image tab and enter an English prompt, such as The eagle is flying in the sky, in the distance is the vast snow, and under the snow mountain is a grassland, in the positive prompt text box. Set the sampling method to Euler a, sampling steps to 20, width and height to 512, CFG Scale to 7, and random seed to -1. Then, click the Generate button. The generated image is displayed in the output area on the right.

3. Fine-tune the model

Fine-tune the Stable Diffusion V1.5 model to customize its output for your specific use case.

  1. Return to the model details page and click Fine-tune in the upper-right corner.

  2. In the Train panel, expand the configuration sections to view or modify the following key configurations. Use the default values for the other parameters. For more information about the parameter configurations, see Model deployment and training.

    Configuration

    Description

    Dataset Configuration

    PAI provides a default dataset for this tutorial. Alternatively, prepare your own dataset as follows:

    1. Prepare training data based on the training data format on the model details page. Refer to the sample dataset. The following is the directory structure of the training dataset:

      |——img1.jpg
      |——img2.jpg
      |——...
      |——metadata.jsonl

      The metadata.jsonl file is in the JSON Lines format. The file_name field indicates the image file name, and the text field contains the text corresponding to the image. The following is a sample of the metadata.jsonl file:

      {"file_name": "img1.jpg", "text": "cat"}
      {"file_name": "img2.jpg", "text": "penguin"}
      {"file_name": "img3.jpg", "text": "dragon"}
    2. Upload the training data to an OSS Bucket. For more information, see Upload files.

    3. Update the training dataset. For more information, see Model deployment and training.

    Hyperparameter configuration

    Use the default value standard for the training_method parameter. Keep the default values for other parameters.

    Output Configuration

    Set Model output path to an OSS Bucket path. For more information about how to create an OSS Bucket, see Quick start.

  3. Click Train.

    The page is automatically redirected to the Task details page.

After a training task runs successfully, you can click the Deploy button in the upper-right corner of the task details page to deploy the model. The model deployment process is the same as deploying a model directly. For more information, see II. Directly deploy and debug a model.