From 90cf412a5232c7992b5cf601f1143ba4fcaf6e74 Mon Sep 17 00:00:00 2001 From: zhouwenxue Date: Thu, 3 Apr 2025 15:59:25 +0800 Subject: [PATCH] cogvideo agbcache update --- MindIE/MultiModal/CogVideoX/README.md | 2 +- MindIE/MultiModal/CogVideoX/inference.py | 16 ++++++++++++++++ 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/MindIE/MultiModal/CogVideoX/README.md b/MindIE/MultiModal/CogVideoX/README.md index e949cdc691..669b87d155 100644 --- a/MindIE/MultiModal/CogVideoX/README.md +++ b/MindIE/MultiModal/CogVideoX/README.md @@ -217,7 +217,7 @@ TASK_QUEUE_ENABLE=2 ASCEND_RT_VISIBLE_DEVICES=0,1,2,3,4,5,6,7 torchrun --master_ ### CogVideoX-5b | 硬件形态 | cpu规格 | batch size | 迭代次数 | 数据类型 | 卡数 | 平均耗时 | | :------: | :------: | :------: |:----:| :------: | :------: | :------: | -| Atlas 800I A2(8*64G) | 64核(arm) | 1 | 50 | bfloat16 | 1 | 210s | +| Atlas 800I A2(8*64G) | 64核(arm) | 1 | 50 | bfloat16 | 1 | 224s | | Atlas 800I A2(8*64G) | 64核(arm) | 1 | 50 | bfloat16 | 8 | 58s | ### CogVideoX-2b diff --git a/MindIE/MultiModal/CogVideoX/inference.py b/MindIE/MultiModal/CogVideoX/inference.py index 76db866f4c..a5d878ac1a 100644 --- a/MindIE/MultiModal/CogVideoX/inference.py +++ b/MindIE/MultiModal/CogVideoX/inference.py @@ -129,6 +129,22 @@ def generate_video( skip_strategy = AdaStep(skip_thr=0.009, max_skip_steps=1, decay_ratio=0.99, device="npu") pipe.skip_strategy = skip_strategy + if cache_algorithm == "attention": + steps_count = num_inference_steps + blocks_count = pipe.transformer.num_layers + config = CacheConfig( + method="attention_cache", + blocks_count=blocks_count, + steps_count=steps_count, + step_start=15, + step_end=45, + step_interval=3 + ) + agent = CacheAgent(config) + pipe.transformer.use_cache = True + for block in pipe.transformer.transformer_blocks: + block.cache = agent + video_path = f'{output_path}/generated_video_{i}_{prompt[:10]}.mp4' export_to_video(video_generate, video_path, fps=fps) result[os.path.abspath(video_path)] = prompt -- Gitee