THUDM / CogVideo

text and image to video generation: CogVideoX (2024) and CogVideo (ICLR 2023)
Apache License 2.0
9.17k stars 861 forks source link

KeyError: 'ops' when full fine-tuning CogVideoX1.5-5B-SAT #489

Open JWargrave opened 6 days ago

JWargrave commented 6 days ago

System Info / 系統信息

pip list结果如下(都已满足requirements.txtsat/requirements.txt):

Package                  Version
------------------------ -----------
accelerate               1.1.1
aiofiles                 23.2.1
aiohappyeyeballs         2.4.3
aiohttp                  3.10.10
aiosignal                1.3.1
annotated-types          0.7.0
antlr4-python3-runtime   4.9.3
anyio                    4.6.2.post1
attrs                    24.2.0
beartype                 0.19.0
boto3                    1.35.57
botocore                 1.35.57
braceexpand              0.1.7
certifi                  2024.8.30
charset-normalizer       3.4.0
click                    8.1.7
cpm-kernels              1.0.11
datasets                 2.14.4
decorator                4.4.2
decord                   0.6.0
deepspeed                0.15.4
diffusers                0.31.0
dill                     0.3.7
distro                   1.9.0
docker-pycreds           0.4.0
einops                   0.8.0
fastapi                  0.115.4
ffmpy                    0.4.0
filelock                 3.16.1
frozenlist               1.5.0
fsspec                   2024.10.0
gitdb                    4.0.11
GitPython                3.1.43
gradio                   5.5.0
gradio_client            1.4.2
h11                      0.14.0
hjson                    3.1.0
httpcore                 1.0.6
httpx                    0.27.2
huggingface-hub          0.26.2
idna                     3.10
imageio                  2.36.0
imageio-ffmpeg           0.5.1
importlib_metadata       8.5.0
Jinja2                   3.1.4
jiter                    0.7.0
jmespath                 1.0.1
kornia                   0.7.4
kornia_rs                0.1.7
lightning-utilities      0.11.8
markdown-it-py           3.0.0
MarkupSafe               2.1.5
mdurl                    0.1.2
moviepy                  1.0.3
mpmath                   1.3.0
msgpack                  1.1.0
multidict                6.1.0
multiprocess             0.70.15
networkx                 3.4.2
ninja                    1.11.1.1
numpy                    1.26.0
nvidia-cublas-cu12       12.4.5.8
nvidia-cuda-cupti-cu12   12.4.127
nvidia-cuda-nvrtc-cu12   12.4.127
nvidia-cuda-runtime-cu12 12.4.127
nvidia-cudnn-cu12        9.1.0.70
nvidia-cufft-cu12        11.2.1.3
nvidia-curand-cu12       10.3.5.147
nvidia-cusolver-cu12     11.6.1.9
nvidia-cusparse-cu12     12.3.1.170
nvidia-nccl-cu12         2.21.5
nvidia-nvjitlink-cu12    12.4.127
nvidia-nvtx-cu12         12.4.127
omegaconf                2.3.0
openai                   1.54.3
orjson                   3.10.11
packaging                24.2
pandas                   2.2.3
pillow                   11.0.0
pip                      24.2
platformdirs             4.3.6
proglog                  0.1.10
propcache                0.2.0
protobuf                 5.28.3
psutil                   6.1.0
py-cpuinfo               9.0.0
pyarrow                  18.0.0
pydantic                 2.9.2
pydantic_core            2.23.4
pydub                    0.25.1
Pygments                 2.18.0
python-dateutil          2.9.0.post0
python-multipart         0.0.12
pytorch-lightning        2.4.0
pytz                     2024.2
PyYAML                   6.0.2
regex                    2024.11.6
requests                 2.32.3
rich                     13.9.4
ruff                     0.7.3
s3transfer               0.10.3
safehttpx                0.1.1
safetensors              0.4.5
scikit-video             1.1.11
scipy                    1.14.1
semantic-version         2.10.0
sentencepiece            0.2.0
sentry-sdk               2.18.0
setproctitle             1.3.3
setuptools               75.1.0
shellingham              1.5.4
six                      1.16.0
smmap                    5.0.1
sniffio                  1.3.1
starlette                0.41.2
SwissArmyTransformer     0.4.12
sympy                    1.13.1
tensorboardX             2.6.2.2
tokenizers               0.20.3
tomlkit                  0.12.0
torch                    2.5.1
torchmetrics             1.5.2
torchvision              0.20.1
tqdm                     4.67.0
transformers             4.46.2
triton                   3.1.0
typer                    0.13.0
typing_extensions        4.12.2
tzdata                   2024.2
urllib3                  2.2.3
uvicorn                  0.32.0
wandb                    0.18.6
webdataset               0.2.100
websockets               12.0
wheel                    0.44.0
xxhash                   3.5.0
yarl                     1.17.1
zipp                     3.21.0

系统信息如下(由python -m torch.utils.collect_env给出):

<frozen runpy>:128: RuntimeWarning: 'torch.utils.collect_env' found in sys.modules after import of package 'torch.utils', but prior to execution of 'torch.utils.collect_env'; this may result in unpredictable behaviour
Collecting environment information...
PyTorch version: 2.5.1+cu124
Is debug build: False
CUDA used to build PyTorch: 12.4
ROCM used to build PyTorch: N/A

OS: Ubuntu 22.04.3 LTS (x86_64)
GCC version: (Ubuntu 11.4.0-1ubuntu1~22.04) 11.4.0
Clang version: Could not collect
CMake version: Could not collect
Libc version: glibc-2.35

Python version: 3.12.7 | packaged by Anaconda, Inc. | (main, Oct  4 2024, 13:27:36) [GCC 11.2.0] (64-bit runtime)
Python platform: Linux-5.15.0-78-generic-x86_64-with-glibc2.35
Is CUDA available: True
CUDA runtime version: 11.8.89
CUDA_MODULE_LOADING set to: LAZY
GPU models and configuration: 
GPU 0: NVIDIA H800
GPU 1: NVIDIA H800
GPU 2: NVIDIA H800
GPU 3: NVIDIA H800
GPU 4: NVIDIA H800
GPU 5: NVIDIA H800
GPU 6: NVIDIA H800
GPU 7: NVIDIA H800

Nvidia driver version: 535.104.12
cuDNN version: Could not collect
HIP runtime version: N/A
MIOpen runtime version: N/A
Is XNNPACK available: True

CPU:
Architecture:                    x86_64
CPU op-mode(s):                  32-bit, 64-bit
Address sizes:                   52 bits physical, 57 bits virtual
Byte Order:                      Little Endian
CPU(s):                          384
On-line CPU(s) list:             0-383
Vendor ID:                       AuthenticAMD
Model name:                      AMD EPYC 9654 96-Core Processor
CPU family:                      25
Model:                           17
Thread(s) per core:              2
Core(s) per socket:              96
Socket(s):                       2
Stepping:                        1
Frequency boost:                 enabled
CPU max MHz:                     3707.8120
CPU min MHz:                     1500.0000
BogoMIPS:                        4799.94
Flags:                           fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge mca cmov pat pse36 clflush mmx fxsr sse sse2 ht syscall nx mmxext fxsr_opt pdpe1gb rdtscp lm constant_tsc rep_good nopl nonstop_tsc cpuid extd_apicid aperfmperf rapl pni pclmulqdq monitor ssse3 fma cx16 pcid sse4_1 sse4_2 x2apic movbe popcnt aes xsave avx f16c rdrand lahf_lm cmp_legacy svm extapic cr8_legacy abm sse4a misalignsse 3dnowprefetch osvw ibs skinit wdt tce topoext perfctr_core perfctr_nb bpext perfctr_llc mwaitx cpb cat_l3 cdp_l3 invpcid_single hw_pstate ssbd mba ibrs ibpb stibp vmmcall fsgsbase bmi1 avx2 smep bmi2 erms invpcid cqm rdt_a avx512f avx512dq rdseed adx smap avx512ifma clflushopt clwb avx512cd sha_ni avx512bw avx512vl xsaveopt xsavec xgetbv1 xsaves cqm_llc cqm_occup_llc cqm_mbm_total cqm_mbm_local avx512_bf16 clzero irperf xsaveerptr rdpru wbnoinvd amd_ppin cppc arat npt lbrv svm_lock nrip_save tsc_scale vmcb_clean flushbyasid decodeassists pausefilter pfthreshold avic v_vmsave_vmload vgif v_spec_ctrl avx512vbmi umip pku ospke avx512_vbmi2 gfni vaes vpclmulqdq avx512_vnni avx512_bitalg avx512_vpopcntdq la57 rdpid overflow_recov succor smca fsrm flush_l1d
Virtualization:                  AMD-V
L1d cache:                       6 MiB (192 instances)
L1i cache:                       6 MiB (192 instances)
L2 cache:                        192 MiB (192 instances)
L3 cache:                        768 MiB (24 instances)
NUMA node(s):                    2
NUMA node0 CPU(s):               0-95,192-287
NUMA node1 CPU(s):               96-191,288-383
Vulnerability Itlb multihit:     Not affected
Vulnerability L1tf:              Not affected
Vulnerability Mds:               Not affected
Vulnerability Meltdown:          Not affected
Vulnerability Mmio stale data:   Not affected
Vulnerability Retbleed:          Not affected
Vulnerability Spec store bypass: Mitigation; Speculative Store Bypass disabled via prctl and seccomp
Vulnerability Spectre v1:        Mitigation; usercopy/swapgs barriers and __user pointer sanitization
Vulnerability Spectre v2:        Mitigation; Retpolines, IBPB conditional, IBRS_FW, STIBP always-on, RSB filling, PBRSB-eIBRS Not affected
Vulnerability Srbds:             Not affected
Vulnerability Tsx async abort:   Not affected

Versions of relevant libraries:
[pip3] numpy==1.26.0
[pip3] pytorch-lightning==2.4.0
[pip3] torch==2.5.1
[pip3] torchmetrics==1.5.2
[pip3] torchvision==0.20.1
[pip3] triton==3.1.0
[conda] numpy                     1.26.0                   pypi_0    pypi
[conda] pytorch-lightning         2.4.0                    pypi_0    pypi
[conda] torch                     2.5.1                    pypi_0    pypi
[conda] torchmetrics              1.5.2                    pypi_0    pypi
[conda] torchvision               0.20.1                   pypi_0    pypi
[conda] triton                    3.1.0                    pypi_0    pypi

Information / 问题信息

Reproduction / 复现过程

首先修改了sat/configs/sft.yaml,如下所示(主要改了load: CogVideoX1.5-5B-SAT/transformer_i2vtrain_micro_batch_size_per_gpu: 1gradient_accumulation_steps: 2video_size: [ 480, 720 ]),我想训image-to-video:

args:
  checkpoint_activations: True # using gradient checkpointing
  model_parallel_size: 1
  experiment_name: full_storyboard
  mode: finetune
  load: /suqinzs/jwargrave/CogVideo-293/sat/pretrained_weights/CogVideoX1.5-5B-SAT/transformer_i2v
  no_load_rng: True
  train_iters: 1000 # Suggest more than 1000 For Lora and SFT For 500 is enough
  eval_iters: 1
  eval_interval: 100
  eval_batch_size: 1
  save: ckpts_CogVideoX1.5-5B-SAT_i2v_full
  save_interval: 500
  log_interval: 20
  train_data: [ "/suqinzs/jwargrave/CogVideo-293/sat/storyboard_data_for_cog" ] # Train data path
  valid_data: [ "/suqinzs/jwargrave/CogVideo-293/sat/storyboard_data_for_cog" ] # Validation data path, can be the same as train_data(not recommended)
  split: 1,0,0
  num_workers: 8
  force_train: True
  only_log_video_latents: True

data:
  target: data_video.SFTDataset
  params:
    video_size: [ 480, 720 ]
    fps: 8
    max_num_frames: 49
    skip_frms_num: 3.

deepspeed:
  # Minimum for 16 videos per batch for ALL GPUs, This setting is for 8 x A100 GPUs
  train_micro_batch_size_per_gpu: 1
  gradient_accumulation_steps: 2
  steps_per_print: 50
  gradient_clipping: 0.1
  zero_optimization:
    stage: 2
    cpu_offload: false
    contiguous_gradients: false
    overlap_comm: true
    reduce_scatter: true
    reduce_bucket_size: 1000000000
    allgather_bucket_size: 1000000000
    load_from_fp32_weights: false
  zero_allow_untested_optimizer: true
  bf16:
      enabled: True  # For CogVideoX-2B Turn to False and For CogVideoX-5B Turn to True
  fp16:
      enabled: False  # For CogVideoX-2B Turn to True and For CogVideoX-5B Turn to False
  loss_scale: 0
  loss_scale_window: 400
  hysteresis: 2
  min_loss_scale: 1

  optimizer:
    type: sat.ops.FusedEmaAdam
    params:
      lr: 0.00001 # Between 1E-3 and 5E-4 For Lora and 1E-5 For SFT
      betas: [ 0.9, 0.95 ]
      eps: 1e-8
      weight_decay: 1e-4
  activation_checkpointing:
    partition_activations: false
    contiguous_memory_optimization: false
  wall_clock_breakdown: false

数据集路径storyboard_data_for_cog已经按照这里所说的整理好了,每个txt文件都只有一行,是对应视频的caption,一共大概7w多个视频,视频长短不一,有几百帧的,也有几帧的。

然后修改了sat/finetune_multi_gpus.sh,如下所示(单机8卡训练):

#! /bin/bash

export CUDA_VISIBLE_DEVICES="0,1,2,3,4,5,6,7"

echo "RUN on $(hostname), CUDA_VISIBLE_DEVICES=$CUDA_VISIBLE_DEVICES"

run_cmd="PYTORCH_CUDA_ALLOC_CONF=expandable_segments:True torchrun --standalone --nproc_per_node=8 train_video.py --base configs/cogvideox1.5_5b_i2v.yaml configs/sft.yaml --seed $RANDOM"

echo ${run_cmd}
eval ${run_cmd}

echo "DONE on `hostname`"

然后运行bash finetune_multi_gpus.sh,遇到了如下的报错:

[rank2]: Traceback (most recent call last):
[rank2]:   File "/suqinzs/jwargrave/CogVideo-293/sat/train_video.py", line 223, in <module>
[rank2]:     training_main(
[rank2]:   File "/suqinzs/anaconda3/envs/zym-cog/lib/python3.12/site-packages/sat/training/deepspeed_training.py", line 157, in training_main
[rank2]:     iteration, skipped = train(model, optimizer,
[rank2]:                          ^^^^^^^^^^^^^^^^^^^^^^^
[rank2]:   File "/suqinzs/anaconda3/envs/zym-cog/lib/python3.12/site-packages/sat/training/deepspeed_training.py", line 359, in train
[rank2]:     lm_loss, skipped_iter, metrics = train_step(train_data_iterator,
[rank2]:                                      ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
[rank2]:   File "/suqinzs/anaconda3/envs/zym-cog/lib/python3.12/site-packages/sat/training/deepspeed_training.py", line 443, in train_step
[rank2]:     forward_ret = forward_step(data_iterator, model, args, timers, **kwargs)
[rank2]:                   ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
[rank2]:   File "/suqinzs/jwargrave/CogVideo-293/sat/train_video.py", line 195, in forward_step
[rank2]:     loss, loss_dict = model.shared_step(batch)
[rank2]:                       ^^^^^^^^^^^^^^^^^^^^^^^^
[rank2]:   File "/suqinzs/jwargrave/CogVideo-293/sat/diffusion_video.py", line 170, in shared_step
[rank2]:     loss, loss_dict = self(x, batch)
[rank2]:                       ^^^^^^^^^^^^^^
[rank2]:   File "/suqinzs/anaconda3/envs/zym-cog/lib/python3.12/site-packages/torch/nn/modules/module.py", line 1736, in _wrapped_call_impl
[rank2]:     return self._call_impl(*args, **kwargs)
[rank2]:            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
[rank2]:   File "/suqinzs/anaconda3/envs/zym-cog/lib/python3.12/site-packages/torch/nn/modules/module.py", line 1747, in _call_impl
[rank2]:     return forward_call(*args, **kwargs)
[rank2]:            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
[rank2]:   File "/suqinzs/jwargrave/CogVideo-293/sat/diffusion_video.py", line 130, in forward
[rank2]:     loss = self.loss_fn(self.model, self.denoiser, self.conditioner, x, batch)
[rank2]:            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
[rank2]:   File "/suqinzs/jwargrave/CogVideo-293/sat/sgm/modules/diffusionmodules/loss.py", line 106, in __call__
[rank2]:     model_output = denoiser(network, noised_input, alphas_cumprod_sqrt, cond, **additional_model_inputs)
[rank2]:                    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
[rank2]:   File "/suqinzs/anaconda3/envs/zym-cog/lib/python3.12/site-packages/torch/nn/modules/module.py", line 1736, in _wrapped_call_impl
[rank2]:     return self._call_impl(*args, **kwargs)
[rank2]:            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
[rank2]:   File "/suqinzs/anaconda3/envs/zym-cog/lib/python3.12/site-packages/torch/nn/modules/module.py", line 1747, in _call_impl
[rank2]:     return forward_call(*args, **kwargs)
[rank2]:            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
[rank2]:   File "/suqinzs/jwargrave/CogVideo-293/sat/sgm/modules/diffusionmodules/denoiser.py", line 38, in forward
[rank2]:     return network(input * c_in, c_noise, cond, **additional_model_inputs) * c_out + input * c_skip
[rank2]:            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
[rank2]:   File "/suqinzs/anaconda3/envs/zym-cog/lib/python3.12/site-packages/torch/nn/modules/module.py", line 1736, in _wrapped_call_impl
[rank2]:     return self._call_impl(*args, **kwargs)
[rank2]:            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
[rank2]:   File "/suqinzs/anaconda3/envs/zym-cog/lib/python3.12/site-packages/torch/nn/modules/module.py", line 1747, in _call_impl
[rank2]:     return forward_call(*args, **kwargs)
[rank2]:            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
[rank2]:   File "/suqinzs/jwargrave/CogVideo-293/sat/sgm/modules/diffusionmodules/wrappers.py", line 35, in forward
[rank2]:     return self.diffusion_model(
[rank2]:            ^^^^^^^^^^^^^^^^^^^^^
[rank2]:   File "/suqinzs/anaconda3/envs/zym-cog/lib/python3.12/site-packages/torch/nn/modules/module.py", line 1736, in _wrapped_call_impl
[rank2]:     return self._call_impl(*args, **kwargs)
[rank2]:            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
[rank2]:   File "/suqinzs/anaconda3/envs/zym-cog/lib/python3.12/site-packages/torch/nn/modules/module.py", line 1747, in _call_impl
[rank2]:     return forward_call(*args, **kwargs)
[rank2]:            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
[rank2]:   File "/suqinzs/jwargrave/CogVideo-293/sat/dit_video_concat.py", line 838, in forward
[rank2]:     ofs_emb = timestep_embedding(kwargs["ofs"], self.ofs_embed_dim, repeat_only=False, dtype=self.dtype)
[rank2]:                                  ~~~~~~^^^^^^^
[rank2]: KeyError: 'ofs'

请问这个问题要如何解决?

Expected behavior / 期待表现

期望能够解决KeyError,顺利全微调CogVideoX1.5-5B-SAT

hrcheng98 commented 2 days ago

我和同学也都遇到了同样的问题,期待一下解决方案