Help Center/ ModelArts/ Best Practices/ Image Generation Model Training and Inference/ Stable Diffusion XL Inference Guide Based on ModelArts Notebook (6.5.907)
Updated on 2025-10-14 GMT+08:00

Stable Diffusion XL Inference Guide Based on ModelArts Notebook (6.5.907)

Overview

This guide describes how to deploy text-to-image models like Stable Diffusion XL with the Diffusers framework on ModelArts notebook instances and run them on Huawei Cloud NPUs. Start by purchasing Server resources through Huawei's enterprise technical support team.

This solution is designed exclusively for enterprise users.

Resource Specifications

For inference deployment, it is advised to use the notebook and Snt9B resources in the CN-Hong Kong region.

Obtaining Software

Table 1 Software package and image

Category

Name

How to Obtain

Plugin code package

AscendCloud-AIGC-6.5.907-xxx.zip in the AscendCloud-6.5.907 software package

xxx in the file name indicates the timestamp. The timestamp is the actual release time of the package.

Download ModelArts 6.5.907.2 from Support-E.

NOTE:

If the software information does not appear when opening the download link, you lack access permissions. Contact your company's Huawei technical support for assistance with downloading.

Notebook image

Snt9B: CN Southwest-Guiyang1

swr.cn-southwest-2.myhuaweicloud.com/atelier/pytorch_ascend:pytorch_2.5.1-cann_8.2.rc1-py_3.11-hce_2.0.2503-aarch64-snt9b-20250729103313-3a25129

Snt9B: CN-Hong Kong

swr.ap-southeast-1.myhuaweicloud.com/atelier/pytorch_ascend:pytorch_2.5.1-cann_8.2.rc1-py_3.11-hce_2.0.2503-aarch64-snt9b-20250729103313-3a25129

The image needs to be registered in ModelArts for selection when creating a notebook instance.

Features

Table 2 Features

Kit

Model

Diffusers

SDXL

Step 1: Preparing the Environment

  1. Log in to the ModelArts console and choose Asset Management > Image Management in the left navigation. In the upper right corner, click Register and select the notebook image specified in Table 1. Refer to the following figure for other options.
    Figure 1 Registering an image
  2. Create a notebook instance using a custom image. For details, see Creating a Notebook Instance (New Page). The default resource specification is 5 GB, but you can expand it as needed.
    Figure 2 Creating a notebook instance

    If no resource specifications are available when you purchase notebook resources, contact Huawei Cloud technical support.

  3. Check the environment.

    Open the new notebook instance and start coding in the development environment.

    ModelArts notebook instances are started by ma-user by default. After you access the instance, the default working directory is /home/ma-user/work.

    Figure 3 Opening a notebook instance terminal

    The figure below is an example working directory.

    Figure 4 Working directory

Step 2: Deploying Diffusers

Installing Dependencies and Model Packages

  1. Download the model weights to the /home/ma-user/work directory.

    Official website download links (login required):

    ModelScope download links:

  2. Install the plugin code package.
    1. Upload the AscendCloud-AIGC-xxx.zip plug-in code package to the /home/ma-user/work directory of the container and decompress the package. For details about how to obtain the plugin code package, see Table 1. For details about how to upload a file, see Uploading Files to JupyterLab.
      cd /home/ma-user/work
      unzip AscendCloud-AIGC-*.zip # Decompress the package.
    2. Decompress the AIGC package, go to the /home/ma-user/work/aigc_inference/torch_npu/utils/ascend_diffusers directory, and install the ascend_diffusers package.
      cd /home/ma-user/work/aigc_inference/torch_npu/utils/ascend_diffusers
      pip install -e .
    3. Decompress the AIGC package, go to the /home/ma-user/work/aigc_inference/torch_npu/utils/AscendX-MM directory, and install the AscendX-MM package.
      cd /home/ma-user/work/aigc_inference/torch_npu/utils/AscendX-MM
      pip install -e .
Starting the Service
export MODEL_PATH='Path of the downloaded Hugging Face model', for example, /home/ma-user/work/stable-diffusion-xl-base-1.0. To let the system download the model automatically, do not add the model_id parameter.
export TASK_QUEUE_ENABLE=2
cd /home/ma-user/work/aigc_inference/torch_npu/diffusers/0.31.0/examples

The commands for starting single-PU model inference are as follows. The generated image is stored in the current directory.

  • Commands for starting Stable Diffusion XL model inference:
    pip install diffusers==0.30.2
    python sd_inference_example.py --model_name sdxl --model_id ${MODEL_PATH} --prompt 'a dog' --num_inference_steps 20 --width 768 1024 --height 768 1024