## About Env
### Q1.1: Why is PyTorch 2.4 recommended?
Because the minimum version required to resolve [pytorch/pytorch#123510](https://github.com/pytorch/pytorch/issues/123510) is 2.4. If you do not care about it, lower versions may also work.
## About Inference/Testing
### Q2.1: Minimum GPU Memory Requirements for Inference?
Please refer to the following table:
| Resolution |
Frames |
Condition Encode+Diffusion (max with cpu offload) |
Decode (max) |
| no sp |
sp=2 |
sp=4 |
sp=8 |
| 224x400x6 |
17 frame |
17.91 |
17.91 |
17.91 |
17.91 |
3.87 |
| full |
21.93 |
18.51 |
18.51 |
18.51 |
4.82 |
| 424x800x6 |
17 frame |
17.97 |
17.97 |
17.97 |
17.97 |
12.43 |
| full |
40.69 |
25.70 |
19.80 |
19.80 |
16.24 |
| 848x1600x6 |
17 frame |
18.08 |
18.08 |
18.08 |
18.08 |
51.33 |
| 33 frame |
24.89 |
18.33 |
18.33 |
18.33 |
52.08 |
| 65 frame |
43.62 |
26.67 |
18.83 |
18.83 |
53.59 |
| 129 frame |
81.14 |
48.24 |
29.66 |
23.83 |
56.84 |
| full |
96G OOM |
83.40 |
50.19 |
39.76 |
58.20 |
Note:
1. GPU memory are logged with `torch.cuda.max_memory_allocated`. The actual memory usage might be slightly higher than the values shown above (please refer to [this page](https://discuss.pytorch.org/t/pytorchs-torch-cuda-max-memory-allocated-showing-different-results-from-nvidia-smi/165706)). If there are more reliable methods, please open an issue to let us know. We will redo the test.
2. We tested on NVIDIA H20 with 96G memory.
3. The GPU memory consumption for VAE decoding is (relatively) steady for any frame lengths. However, higher resolutions significantly cost more memory. Sequence Parallel can reduce the GPU memory consumption for diffusion process but not VAE decoding.
4. If you want to reduce the decoding consumption, please use `vae_tiling=384` (~14.2G). However, be prepared to observe some blending seams between tiles.
For Ascend NPU, we tested on 910B1:
| Resolution |
Frames |
Condision Encode+Diffusion (max with cpu offload) |
Decode (max) |
| no sp |
sp=2 |
sp=4 |
sp=8 |
| 424x800x6 |
17 frame |
17.95 |
17.95 |
17.95 |
17.95 |
14.85 |
| full |
46.47 |
27.72 |
19.77 |
19.77 |
39.83 |
| 848x1600x6 |
17 frame |
18.05 |
18.05 |
18.05 |
18.05 |
*12.72 |
| full |
64G OOM |
64G OOM |
64G OOM |
39.73 |
*36.97 |
*: we use `vae_tiling=384`.
Here are some hints to run on NPUs:
1. To run 848x1600 generation, you have to use `vae_tiling`. The default decoding process cannot fit in 64G memory.
2. Please make sure you set `PYTORCH_NPU_ALLOC_CONF=expandable_segments:True` as an environment variable.
### Q2.2: I observe "grid effect" on model inference.
Your generation may look like:
This is also related to the following warning:
> Your input shape ... was rounded into ... Please pay attention to potential mismatch between w/ and w/o sp.
In most cases, it is caused by "padding" for sequence parallel. Our stage3 model is trained with `sp_size=4` and fine-tuned with `sp_size=4` and `sp_size=8`. Therefore, it should support both 4 and 8 processes for inference. If you observe this (with less than 4 GPUs), please use `model.force_pad_h_for_sp_size=4` or `model.force_pad_h_for_sp_size=8` (add to the command line) for inference.
### Q2.3: Why does the long video quality deteriorate towards the end?
When we output the results as an MP4 video, the bitrate is limited to 4M on [this line](https://github.com/flymin/MagicDriveDiT/blob/c7df9b68e811cf2d689494745593410dc99e5ddf/magicdrivedit/datasets/utils.py#L101), which causes the video quality to decrease. This is done not only to control the video size but also to meet the storage bitrate requirements of the W-CODA2024 Benchmark.
If you want higher quality video, you can increase the bitrate limit or set it to `None` (let ffmpeg decide). Additionally, we support saving each frame as a PNG image by setting `force_image=true` through the command line, which provides a lossless output. In this case, `tools/imgFoler2vid.py` is provided to convert an folder of video frames to an mp4 file.
## About Training
### Q3.1: Got nan with 64 GPUs training.
We noticed [hpcaitech/ColossalAI#6091](https://github.com/hpcaitech/ColossalAI/issues/6091) but failed to really resolve the issue. Currently my workaround is to replace `colossalai/zero/low_level/low_level_optim.py` in your python env with `patch/low_level_optim.py`. We were able to launch 64-GPU training with this and the loss was stable.
### Q3.2: Process got SIGKILL signal which do not have traceback
Our high-resolution video requires a lot of CPU memory for the dataloader. If you set `num_workers` or `prefetch_factor` too high, it may lead to insufficient memory and cause the program to crash. Please try reducing these parameters. Additionally, during the inference phase, we have set `ignore_ori_imgs` to prevent the dataloader from loading images from the dataset, thereby reducing memory pressure.