HuggingFace镜像/GLM-Image
模型介绍文件和版本分析
下载使用量0

模型推理指导

一、模型简介

GLM-Image是智谱采用自主创新的「自回归+扩散解码器」混合架构的多模态大模型,支持文生图、图生图等多种使用场景。

二、环境准备

表 1 硬件配套表

配套版本
osopenEuler
cpu架构aarch64
设备A2

表 2 版本配套表

配套版本环境准备指导
Python3.11.6-
torch2.7.1-
MindIE2.2.RC1-

2.1 获取安装包

  • 支持设备:Atlas 800I A2
  • 支持卡数:支持的卡数为1
  • 环境准备指导

2.2 依赖安装

方式一:镜像安装


export IMAGE=m.daocloud.io/quay.io/ascend/vllm-ascend:v0.14.0rc1
docker run --rm \
--name GLM-Image \
--device /dev/davinci0 \
--device /dev/davinci_manager \
--device /dev/devmm_svm \
--device /dev/hisi_hdc \
-v /usr/local/dcmi:/usr/local/dcmi \
-v /usr/local/bin/npu-smi:/usr/local/bin/npu-smi \
-v /usr/local/Ascend/driver/lib64/:/usr/local/Ascend/driver/lib64/ \
-v /usr/local/Ascend/driver/version.info:/usr/local/Ascend/driver/version.info \
-v /etc/ascend_install.info:/etc/ascend_install.info \
-v /root/.cache:/root/.cache \
-p 8000:8000 \
-it $IMAGE bash

方式二:手动安装 1. CANN安装

# 增加软件包可执行权限,{version}表示软件版本号,{arch}表示CPU架构,{soc}表示昇腾AI处理器的版本。
chmod +x ./Ascend-cann-toolkit_{version}_linux-{arch}.run
chmod +x ./Ascend-cann-kernels-{soc}_{version}_linux.run
# 校验软件包安装文件的一致性和完整性
./Ascend-cann-toolkit_{version}_linux-{arch}.run --check
./Ascend-cann-kernels-{soc}_{version}_linux.run --check
# 安装
./Ascend-cann-toolkit_{version}_linux-{arch}.run --install
./Ascend-cann-kernels-{soc}_{version}_linux.run --install

# 设置环境变量
source /usr/local/Ascend/ascend-toolkit/set_env.sh

2. MindIE安装

# 增加软件包可执行权限,{version}表示软件版本号,{arch}表示CPU架构。
chmod +x ./Ascend-mindie_${version}_linux-${arch}.run
./Ascend-mindie_${version}_linux-${arch}.run --check

# 方式一:默认路径安装
./Ascend-mindie_${version}_linux-${arch}.run --install
# 设置环境变量
cd /usr/local/Ascend/mindie && source set_env.sh

# 方式二:指定路径安装
./Ascend-mindie_${version}_linux-${arch}.run --install --install-path=${AieInstallPath}
# 设置环境变量
cd ${AieInstallPath}/mindie && source set_env.sh

3. Torch_npu安装 安装pytorch框架 版本2.8.0 安装包下载

使用pip安装

# {version}表示软件版本号,{arch}表示CPU架构。
pip install torch-${version}-cp311-cp311-linux_${arch}.whl

下载 pytorch_v{pytorchversion}_py{pythonversion}.tar.gz

tar -xzvf pytorch_v{pytorchversion}_py{pythonversion}.tar.gz
# 解压后,会有whl包
pip install torch_npu-{pytorchversion}.xxxx.{arch}.whl

4. 安装gcc、g++

# 若环境镜像中没有gcc、g++,请用户自行安装
yum install gcc
yum install g++

# 导入头文件路径
export CPLUS_INCLUDE_PATH=/usr/include/c++/12/:/usr/include/c++/12/aarch64-openEuler-linux/:$CPLUS_INCLUDE_PATH

2.3 下载本仓库

git clone https://modelers.cn/MindIE/GLM-Image.git

2.4 安装所需依赖

pip install -r requirements.txt
git clone https://github.com/huggingface/diffusers.git
git clone https://github.com/huggingface/transformers.git
cd diffusers && pip install -e .
cd transformers && pip install -e .

三、模型权重

3.1 权重下载

GLM-Image权重下载地址

https://modelscope.cn/models/ZhipuAI/GLM-Image
或
https://huggingface.co/zai-org/GLM-Image

四、模型推理

4.1 Atlas-800I-A2-64g单卡文生图功能测试

  1. 设置权重路径:
export model_path="your local model path"
  1. 运行代码:
import torch

from diffusers.pipelines.glm_image import GlmImagePipeline

from PIL import Image

def main():
    pipe = GlmImagePipeline.from_pretrained(
        "ZhipuAI/GLM-Image",
        torch_dtype=torch.bfloat16,
        device_map='npu',
    )
    image_path = "./cond_0.jpg"
    prompt = "A cute comic-style typographic design featuring the word 'Taro' as the main element, rendered in a clean, bright pure white rounded font with a plump, soft letterform and a slight hand-drawn manga feel. The background is a gentle, delicate taro purple serving as the base color, presenting a soft misty gradient effect. Scattered around are light, playful cartoon elements such as small stars, hearts, and bubbles, creating an overall cheerful and sweet atmosphere."
    cond_image = Image.open(image_path).convert("RGB")
    image = pipe(
        prompt=prompt,
        image=[cond_image],
        height=1152,
        width=768,
        num_inference_steps=30,
        guidance_scale=1.5,
        generator=torch.Generator(device='npu').manual_seed(42),
    ).images[0]

    image.save("output_cond0.png")

if __name__ == "__main__":
    main()

声明

  • 本代码仓提到的数据集和模型仅作为示例,这些数据集和模型仅供您用于非商业目的,如您使用这些数据集和模型来完成示例,请您特别注意应遵守对应数据集和模型的License,如您因使用数据集或模型而产生侵权纠纷,华为不承担任何责任。
  • 如您在使用本代码仓的过程中,发现任何问题(包括但不限于功能问题、合规问题),请在本代码仓提交issue,我们将及时审视并解答。