Ascend-SACT/paint-by-example
Model Introduction
Files & versions
Pull Requests
Discussion
Analysis

paint-by-example模型使用指导

模型概述及场景

本指导记录了 paint-by-example 在昇腾 NPU 上的完整迁移过程:推理,全参训练,Lora微调全部跑通)。

准备运行环境

业务背景版本
硬件环境Atlas 900 A2 SuperPoD Compute Node,昇腾 910B,单卡即可(验证使用 1 卡,容器可见 8 卡)
Python3.9(conda 环境 pbe)
Torch2.5.1
Torch NPU2.5.1.post1
CANN8.5.1(npu-smi 25.5.1)

2.1 环境准备

设备支持:

  • Atlas 910 A2
  • 卡类型:Ascend910B
  • 部署方式:单卡
  • 操作系统:ARM(aarch64)

运行指导

权重下载

paint-by-example官网地址: https://github.com/Fantasy-Studio/Paint-by-Example 模型文件下载链接:https://modelscope.cn/models/iic/cv_stable-diffusion_paint-by-example/files

paint-by-example 源码下载

github地址 https://github.com/Fantasy-Studio/Paint-by-Example

文件修改

为了适配NPU,修改如下几个文件

/workspace/Paint-by-Example-main
├── main.py
├── ldm/models/diffusion/ddpm.py
├── train_pbe_lora_npu.py
└── scripts/inference.py


## 基本功能测试

推理

```bash
python scripts/inference.py \
--plms --outdir results \
--config configs/v1.yaml \
--ckpt checkpoints/model.ckpt \
--image_path examples/image/example_1.png \
--mask_path examples/mask/example_1.png \
--reference_path examples/reference/example_1.jpg \
--seed 321 \
--scale 5


训练
```bash
torchrun   main.py     
--base configs/v1.yaml   \
--pretrained_model /workspace/Paint-by-Example-main/pretrained_models/sd-v1-4-modified-9channel.ckpt  \
--scale_lr False   \
--name debug_10img_run   \
--logdir logs/debug_10img  \
--trainer.precision 32   -t

期望运行结果:

推理

  • This IS NOT expected if you are initializing CLIPVisionModel from the checkpoint of a model that you expect to be exactly identical (initializing a BertForSequenceClassification model from a BertForSequenceClassification model). [NPU] VAE forced to FP32 for numerical stability .Data shape for PLMS sampling is (1, 4, 64, 64) Running PLMS Sampling with 50 timesteps PLMS Sampler: 0%| | 0/50 [00:00<?, ?it/s].PLMS Sampler: 100%|█████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████| 50/50 [00:26<00:00, 1.92it/s] .Your samples are ready and waiting for you here: results

Enjoy.

训练

| Name | Type | Params | Mode

0 | model | DiffusionWrapper | 859 M | train 1 | proj_out | Linear | 787 K | train 2 | first_stage_model | AutoencoderKL | 83.7 M | eval 3 | cond_stage_model | FrozenCLIPImageEmbedder | 366 M | train | other params | n/a | 768 | n/a

923 M Trainable params 386 M Non-trainable params 1.3 B Total params 5,240.561 Total estimated model params size (MB) 904 Modules in train mode 509 Modules in eval mode /root/miniconda3/envs/pbe/lib/python3.9/site-packages/pytorch_lightning/trainer/connectors/data_connector.py:424: The 'train_dataloader' does not have many workers which may be a bottleneck. Consider increasing the value of the num_workers argumenttonum_workers=191in theDataLoaderto improve performance. /root/miniconda3/envs/pbe/lib/python3.9/site-packages/pytorch_lightning/loops/fit_loop.py:298: The number of training batches (3) is smaller than the logging interval Trainer(log_every_n_steps=5). Set a lower value for log_every_n_steps if you want to see logs for the training epoch. /root/miniconda3/envs/pbe/lib/python3.9/site-packages/pytorch_lightning/trainer/connectors/data_connector.py:424: The 'val_dataloader' does not have many workers which may be a bottleneck. Consider increasing the value of thenum_workers argument to num_workers=191 in the DataLoader to improve performance. Epoch 0: 0%| | 0/3 [00:00<?, ?it/s][DEBUG] x_start: npu:0, t: npu:0, logvar: npu:0 /root/miniconda3/envs/pbe/lib/python3.9/site-packages/torch_npu/utils/storage.py:38: UserWarning: TypedStorage is deprecated. It will be removed in the future and UntypedStorage will be the only storage class. This should only matter to you if you are using storages directly. To access UntypedStorage directly, use tensor.untyped_storage() instead of tensor.storage() if self.device.type != 'cpu': .Data shape for DDIM sampling is (4, 4, 64, 64), eta 1.0 Running DDIM Sampling with 200 timesteps DDIM Sampler: 100%|███████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████| 200/200 [00:28<00:00, 6.93it/s] Epoch 0: 33%|████████████████████ | 1/3 [00:52<01:44, 0.02it/s, v_num=0, train/loss_simple_step=0.236, train/loss_vlb_step=0.00272, train/loss_step=0.236, global_step=0.000, lr_abs=1e-11][DEBUG] x_start: npu:0, t: npu:0, logvar: npu:0 Data shape for DDIM sampling is (4, 4, 64, 64), eta 1.0 Running DDIM Sampling with 200 timesteps