Compare commits

...

10 Commits

Author SHA1 Message Date
cc00e13198 adapt for bi100 2025-09-11 13:50:28 +08:00
2888ee8043 add dockerfile for mrv100 2025-09-09 14:57:59 +08:00
54ac219d77 support MODEL_TYPE from ENV 2025-09-09 14:22:25 +08:00
4525010edc update run_in docker script 2025-09-09 13:41:56 +08:00
0965e974ce fix ms model 2025-09-09 13:38:14 +08:00
yuxiaojie@4paradigm.com
c526bbcdd0 renaming log 2025-09-09 12:56:07 +08:00
2855e94b0b update clear.sh 2025-09-09 12:10:32 +08:00
a07ba004ef fix clear 2025-09-09 11:46:34 +08:00
796520a5f7 renaming 2025-09-09 11:45:35 +08:00
12a1443b38 update permission 2025-09-09 11:43:56 +08:00
21 changed files with 18 additions and 119 deletions

View File

@@ -1,8 +0,0 @@
FROM pytorch/pytorch:2.6.0-cuda12.4-cudnn9-devel
WORKDIR /workspace
RUN pip install pytorch-lightning opencv-python-headless imageio[ffmpeg] einops datasets==3.2.0 simplejson diffusers==0.34.0 open_clip_torch==2.24.0 sortedcontainers modelscope av==11.0.0 addict -i https://nexus.4pd.io/repository/pypi-all/simple
RUN pip install transformers accelerate -i https://nexus.4pd.io/repository/pypi-all/simple
COPY . /workspace/

View File

@@ -1,9 +0,0 @@
FROM git.modelhub.org.cn:9443/enginex-ascend/vllm-ascend:v0.10.0rc1
WORKDIR /workspace
RUN pip install diffusers==0.34.0
RUN pip install imageio[ffmpeg] einops datasets==3.2.0 simplejson addict open_clip_torch==2.24.0 sortedcontainers modelscope==1.28.2 av==11.0.0 pytorch-lightning
COPY . /workspace/
RUN patch /usr/local/python3.11.13/lib/python3.11/site-packages/modelscope/models/multi_modal/video_synthesis/text_to_video_synthesis_model.py patch.ascend/text_to_video_synthesis_model.py.patch
RUN patch /usr/local/python3.11.13/lib/python3.11/site-packages/modelscope/utils/device.py patch.ascend/device.py.patch

View File

@@ -1,12 +0,0 @@
FROM git.modelhub.org.cn:9443/enginex-cambricon/mlu370-pytorch:v25.01-torch2.5.0-torchmlu1.24.1-ubuntu22.04-py310
WORKDIR /workspace
ENV PATH=/torch/venv3/pytorch_infer/bin:/workspace/ffmpeg-mlu-v4.2.0/install/bin:/usr/local/neuware/bin:/usr/local/openmpi/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
RUN rm -rf /workspace/*
RUN pip install diffusers==0.34.0
RUN pip install open_clip_torch==2.24.0 sortedcontainers modelscope av==11.0.0
RUN sed -i 's|source /torch/venv3/pytorch/bin/activate|source /torch/venv3/pytorch_infer/bin/activate|' /root/.bashrc
COPY . /workspace/
RUN pip install whls.mlu/cambricon_pytorch_lightning-2.5.0+mlu0.7.0-py3-none-any.whl

View File

@@ -1,11 +0,0 @@
FROM git.modelhub.org.cn:9443/enginex-kunlunxin/text2image/r200_8f-diffuser:v0.21.4
WORKDIR /workspace
RUN source /root/miniconda/etc/profile.d/conda.sh && conda activate python38_torch201_cuda && pip install imageio[ffmpeg] einops datasets==3.1.0 simplejson addict sortedcontainers modelscope==1.28.2 av==11.0.0 -i https://pypi.tuna.tsinghua.edu.cn/simple
RUN source /root/miniconda/etc/profile.d/conda.sh && conda activate python38_torch201_cuda && pip install megatron megatron-core urllib3==1.26.20 -i https://pypi.tuna.tsinghua.edu.cn/simple
RUN source /root/miniconda/etc/profile.d/conda.sh && conda activate python38_torch201_cuda && pip install open_clip_torch==2.24.0 pytorch-lightning==2.0.1 -i https://pypi.tuna.tsinghua.edu.cn/simple
RUN source /root/miniconda/etc/profile.d/conda.sh && conda activate python38_torch201_cuda && pip install huggingface_hub==0.25.0 -i https://pypi.tuna.tsinghua.edu.cn/simple
ENV PATH=/root/miniconda/envs/python38_torch201_cuda/bin:/root/miniconda/condabin:/opt/linux-bcecmd-0.3.3:/usr/local/go/bin:/bin:/opt/cmake-3.22.2/bin:/opt/just:/root/.cargo/bin:/usr/local/cuda-11.7/bin:/root/miniconda/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/bin:/binnexport
COPY . /workspace/

View File

@@ -6,8 +6,8 @@ docker build -t text2video:v0.1 .
```
### 模型下载
模型地址https://modelscope.cn/models/iic/text-to-video-synthesis
并放到目录:`/mnt/contest_ceph/zhanghao/models/iic/text-to-video-synthesis`(如更改目录,请修改后面的执行脚本中的模型路径)
模型地址https://modelscope.cn/models/AI-ModelScope/text-to-video-ms-1.7b
并放到目录:`/mnt/contest_ceph/zhanghao/models/AI-ModelScope/text-to-video-ms-1.7b`(如更改目录,请修改后面的执行脚本中的模型路径)
### 测试程序
1. 准备输入数据集,可以参考示例`dataset.json`
@@ -17,7 +17,7 @@ docker build -t text2video:v0.1 .
```
## 测试结果
| | A100 平均生成时间(秒) | MLU-x4 平均生成时间(秒) | MLU-x8 平均生成时间(秒)|
|------|-------------------------|----------------------------|---------------------------|
| 时间 | 12 | 37 | 45
| | A100 平均生成时间(秒) | 天垓100 平均生成时间(秒) |
|------|-------------------------|----------------------------|
| 时间 | 21 | 60 |

4
clear.sh Normal file → Executable file
View File

@@ -7,10 +7,12 @@ do
continue
fi
git rm Dockerfile.$device
git rm patch.$device
git rm -r patch.$device
git rm -r whls.$device
done
git rm diffusers_video.py
git rm iic.py
git rm test_ms.sh
git mv Dockerfile.$own Dockerfile
git rm clear.sh

View File

@@ -1,13 +0,0 @@
import torch
from diffusers import DiffusionPipeline
from diffusers.utils import export_to_video
model_path = "/mnt/models/AI-ModelScope/text-to-video-ms-1.7b"
pipe = DiffusionPipeline.from_pretrained(
model_path, torch_dtype=torch.float16, variant="fp16"
)
pipe.enable_model_cpu_offload() # 省显存
pipe.enable_vae_slicing()
frames = pipe("Spiderman is surfing", num_frames=16).frames[0]
export_to_video(frames, "output.mp4") # 默认约2秒/8fps

16
iic.py
View File

@@ -1,16 +0,0 @@
import os
import torch
device = "cuda" if torch.cuda.is_available() else "npu"
import patch
from modelscope.pipelines import pipeline
from modelscope.outputs import OutputKeys
model_path = "/mnt/contest_ceph/zhanghao/models/iic/text-to-video-synthesis"
p = pipeline('text-to-video-synthesis', model_path, device=device)
test_text = {
'text': 'A panda eating a burger and french fries on a rock.',
}
output_video_path = p(test_text, device=device, output_video='./output.mp4')[OutputKeys.OUTPUT_VIDEO]
print('output_video_path:', output_video_path)

10
main.py
View File

@@ -54,8 +54,9 @@ def build_pipeline(model_path: str, device: str = "cuda", dtype=torch.float16, m
pipe = pipeline('text-to-video-synthesis', model_path, device=device)
elif model_type == "text-to-video-ms":
pipe = DiffusionPipeline.from_pretrained(model_path, torch_dtype=dtype)
pipe.enable_model_cpu_offload() # 省显存
pipe.enable_vae_slicing()
pipe.to(device)
# pipe.enable_model_cpu_offload() # 省显存
# pipe.enable_vae_slicing()
else:
raise ValueError(f"不支持的模型类型: {model_type}")
return pipe
@@ -102,8 +103,9 @@ def main():
parser.add_argument("--outdir", required=True, help="图片输出目录")
parser.add_argument("--device", default="cuda", help="推理设备")
parser.add_argument("--dtype", default="fp16", choices=["fp16", "fp32"], help="推理精度")
parser.add_argument("--model_type", default="text-to-video-synthesis", choices=["text-to-video-synthesis", "text-to-video-ms"], help="模型类型")
parser.add_argument("--model_type", default=os.getenv("MODEL_TYPE", "text-to-video-synthesis"), choices=["text-to-video-synthesis", "text-to-video-ms"], help="模型类型")
args, _ = parser.parse_known_args()
print("参数:", args)
model_path = args.model
json_path = Path(args.json)
@@ -147,7 +149,7 @@ def main():
print(f"\nAll done. vidoes: {len(records)}, total_elapsed: {total_elapsed:.3f}s, avg_latency: {avg_latency:.3f}")
print(f"Results JSON: {results_path}")
print(f"Images dir : {out_dir.resolve()}")
print(f"Output dir : {out_dir.resolve()}")
if __name__ == "__main__":

View File

@@ -1,2 +0,0 @@
27d26
< assert eles[0] in ['cpu', 'cuda', 'gpu'], err_msg

View File

@@ -1,10 +0,0 @@
60a61
> print(f"kwargs: {kwargs}")
62a64
> print(f"device: {self.device}")
129c131
< layer='penultimate')
---
> layer='penultimate', device=self.device)
224a227
> print(f"self.device: {self.device}")

View File

@@ -2,4 +2,4 @@
# cnmon
image=text2video:v0.1
device_id=0
docker run -v `pwd`:/workspace -v /mnt:/mnt --device=/dev/cambricon_dev$device_id:/dev/cambricon_dev0 --device=/dev/cambricon_ctl:/dev/cambricon_ctl $image ./test.sh
docker run -v `pwd`:/workspace -v /mnt:/mnt --device=dev/iluvatar$device_id:/dev/iluvatar0 $image ./test.sh

View File

@@ -1,3 +0,0 @@
#! /usr/bin/env bash
image=harbor-contest.4pd.io/zhanghao/t2v:a100-0.2
docker run -it -v /home/zhanghao/workspace:/workspace -v /mnt:/mnt $image bash

View File

@@ -1,4 +0,0 @@
#! /usr/bin/env bash
image=harbor-contest.4pd.io/zhanghao/t2v:ascend-0.1
device=0
docker run -it -v `pwd`:/host -e ASCEND_VISIBLE_DEVICES=$device --device /dev/davinci$device:/dev/davinci0 --device /dev/davinci_manager --device /dev/devmm_svm --device /dev/hisi_hdc -v /mnt:/mnt -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 --privileged --entrypoint bash $image

View File

@@ -1,3 +0,0 @@
#! /usr/bin/env bash
image=harbor-contest.4pd.io/zhanghao/t2v:bi100-0.1
docker run -it -v /data2:/data2 -v /home/zhanghao/workspace:/host -v /mnt:/mnt --device=dev/iluvatar1:/dev/iluvatar0 --device=/dev/iluvatar2:/dev/iluvatar1 $image bash

View File

@@ -1,6 +0,0 @@
#! /usr/bin/env bash
# cnmon
image=harbor-contest.4pd.io/zhanghao/iic:mlu370
image=harbor-contest.4pd.io/zhanghao/t2v:mlu370-0.1
device_id=2
docker run -it -v /root/zhanghao:/workspace -v /mnt:/mnt --device=/dev/cambricon_dev$device_id:/dev/cambricon_dev0 --device=/dev/cambricon_ctl:/dev/cambricon_ctl $image bash

View File

@@ -1,6 +0,0 @@
#! /usr/bin/env bash
# cnmon
image=harbor-contest.4pd.io/zhanghao/t2v:r200-0.1
device_id=2
# docker run -it -v /root/zhanghao:/workspace -v /mnt:/mnt --security-opt=seccomp=unconfined --cap-add=SYS_PTRACE --cap-add=SYS_ADMIN --device /dev/fuse --shm-size=32g --ulimit=memlock=-1 --ulimit=nofile=120000 --ulimit=stack=67108864 --device=/dev/xpu$device_id:/dev/xpu0 --device=/dev/xpuctrl:/dev/xpuctrl $image bash
docker run -it -v /root/zhanghao:/workspace -v /mnt:/mnt --device=/dev/xpu$device_id:/dev/xpu0 --device=/dev/xpuctrl:/dev/xpuctrl $image bash

View File

@@ -1 +1,3 @@
python3 main.py --model "/mnt/contest_ceph/zhanghao/models/iic/text-to-video-synthesis" --json "dataset.json" --results "results.json" --outdir "output" --device cuda --dtype fp16
#! /usr/bin/env bash
python3 main.py --model "/mnt/contest_ceph/zhanghao/models/AI-ModelScope/text-to-video-ms-1.7b" --json "dataset.json" --results "results.json" --outdir "output" --device cuda --dtype fp32 --model_type text-to-video-ms

View File

@@ -1 +0,0 @@
python3 main.py --model "/mnt/models/AI-ModelScope/text-to-video-ms-1.7b" --json "dataset.json" --results "results.json" --outdir "output" --device cuda --dtype fp16 --model_type "text-to-video-ms"

Binary file not shown.