Views
No views yet

[2025-12-15]:🔥 The project page, code, technical report and a basic model checkpoint are released. Further acceleration part (Adaptive Latent Prediction) will be released very soon. Stay tuned!pip install torch==2.6.0 torchvision==0.21.0 torchaudio==2.1.1 --index-url https://download.pytorch.org/whl/cu124
pip install -r requirements.txt
# Optional to install flash_attn to accelerate attention computation
pip install flash_attnexport HF_ENDPOINT=https://hf-mirror.com.
Please download weights manually as follows:pip install "huggingface_hub[cli]"
cd FlashPortrait
mkdir checkpoints
huggingface-cli download FrancisRing/FlashPortrait --local-dir ./checkpoints/FlashPortrait
huggingface-cli download Wan-AI/Wan2.1-I2V-14B-720P --local-dir ./checkpoints/Wan2.1-I2V-14B-720PFlashPortrait/
├── config
├── examples
├── wan
├── checkpoints
│ ├── FlashPortrait
│ └── Wan2.1-I2V-14B-720P
├── infer.py
├── fast_infer.py
├── train_portrait.py
├── bin_convert_pt.py
├── train_single_machine.sh
├── train_multiple_machine.sh
├── requirement.txt infer.py and fast_infer.py. You can also easily modify the various configurations according to your needs.bash inference.shinfer.py to set the resolution of the animation. "--validation_image_start", "--validation_driven_video_path", and "--prompt" in infer.py refer to the path of the given reference image, the path of the driven audio, and the text prompts respectively.
Prompts are also very important. It is recommended to [Description of first frame]-[Description of human behavior]-[Description of background (optional)].
"--wan_model_name", "--transformer_path", and "--portrait_encoder_path" in infer.py are the paths of pretrained Wan2.1-14B weights, pretrained FlashPortrait DiT weights, and pretrained FlashPortrait Portrait Encoder weights, respectively.
"--num_inference_steps", "--sub_num_frames", "--latents_num_frames", "--context_overlap" and "--context_size" refer to the total number of inference steps, the synthesized rgb frame number in a batch, the synthesized latent frame number in a batch, the overlapping context length between two context windows, the synthesized latent frame number in a context window, respectively.
Notably, the recommended --num_inference_steps range is [30-50], more steps bring higher quality. The recommended --context_overlap range is [10-40], as longer overlapping length results in higher quality and slower inference speed.
"--text_cfg_scale" and "--emo_cfg_scale" are Classify-Free-Guidance scale of text prompt and portrait emotion. The recommended range for prompt and audio cfg is [2-5]. You can increase the emotion cfg to facilitate the emotion synchronization with the driven video.path/FlashPortrait/examples for validation. ❤️❤️Please feel free to try it out and enjoy the endless entertainment of infinite-length portrait video generation❤️❤️!fast_infer.py has faster inference speed, which has the same configuration settings as infer.py.infer.py. The options of "--GPU_memory_mode" are model_full_load, sequential_cpu_offload, model_cpu_offload_and_qfloat8, and model_cpu_offload. In particular, when you set --GPU_memory_mode to sequential_cpu_offload, the total GPU memory consumption is approximately 10G with slower inference speed.
Setting --GPU_memory_mode to model_cpu_offload can significantly cut GPU memory usage, reducing it by roughly half compared to model_full_load mode.poirtrait_data/
├── rec
│ │ ├──speech
│ │ │ ├──00001
│ │ │ │ ├──images
│ │ │ │ │ ├──frame_0.png
│ │ │ │ │ ├──frame_1.png
│ │ │ │ │ ├──frame_2.png
│ │ │ │ │ ├──...
│ │ │ │ ├──face_masks
│ │ │ │ │ ├──frame_0.png
│ │ │ │ │ ├──frame_1.png
│ │ │ │ │ ├──frame_2.png
│ │ │ │ │ ├──...
│ │ │ │ ├──lip_masks
│ │ │ │ │ ├──frame_0.png
│ │ │ │ │ ├──frame_1.png
│ │ │ │ │ ├──frame_2.png
│ │ │ │ │ ├──...
│ │ │ ├──00002
│ │ │ │ ├──images
│ │ │ │ ├──face_masks
│ │ │ │ ├──lip_masks
│ │ │ └──...
│ │ ├──singing
│ │ │ ├──00001
│ │ │ │ ├──images
│ │ │ │ ├──face_masks
│ │ │ │ ├──lip_masks
│ │ │ └──...
│ │ ├──dancing
│ │ │ ├──00001
│ │ │ │ ├──images
│ │ │ │ ├──face_masks
│ │ │ │ ├──lip_masks
│ │ │ └──...
├── vec
│ │ ├──speech
│ │ │ ├──00001
│ │ │ │ ├──images
│ │ │ │ ├──face_masks
│ │ │ │ ├──lip_masks
│ │ │ └──...
│ │ ├──singing
│ │ │ ├──00001
│ │ │ │ ├──images
│ │ │ │ ├──face_masks
│ │ │ │ ├──lip_masks
│ │ │ └──...
│ │ ├──dancing
│ │ │ ├──00001
│ │ │ │ ├──images
│ │ │ │ ├──face_masks
│ │ │ │ ├──lip_masks
│ │ │ └──...
├── square
│ │ ├──speech
│ │ │ ├──00001
│ │ │ │ ├──images
│ │ │ │ ├──face_masks
│ │ │ │ ├──lip_masks
│ │ │ └──...
│ │ ├──singing
│ │ │ ├──00001
│ │ │ │ ├──images
│ │ │ │ ├──face_masks
│ │ │ │ ├──lip_masks
│ │ │ └──...
│ │ ├──dancing
│ │ │ ├──00001
│ │ │ │ ├──images
│ │ │ │ ├──face_masks
│ │ │ │ ├──lip_masks
│ │ │ └──...
├── video_rec_path.txt
├── video_square_path.txt
└── video_vec_path.txtpoirtrait_data/square, 480x832 videos stored in poirtrait_data/vec, and 832x480 videos stored in poirtrait_data/rec. Each folder in poirtrait_data/square or poirtrait_data/rec or poirtrait_data/vec contains three subfolders which contains different types of videos (speech, singing, and dancing).
All .png image files are named in the format frame_i.png, such as frame_0.png, frame_1.png, and so on.
00001, 00002, 00003 indicate individual video information.
In terms of three subfolders, images, face_masks, and lip_masks store RGB frames, corresponding human face masks, and corresponding human lip masks, respectively.
video_square_path.txt, video_rec_path.txt, and video_vec_path.txt record folder paths of talking_face_data/square, talking_face_data/rec, and talking_face_data/vec, respectively.
For example, the content of video_rec_path.txt is shown as follows:path/FlashPortrait/poirtrait_data/rec/speech/00001
path/FlashPortrait/poirtrait_data/rec/speech/00002
...
path/FlashPortrait/poirtrait_data/rec/singing/00003
path/FlashPortrait/poirtrait_data/rec/singing/00004
...
path/FlashPortrait/poirtrait_data/rec/dancing/00005
path/FlashPortrait/poirtrait_data/rec/dancing/00006
...ffmpeg to extract frames from raw videos (speech) and store them in the subfolder images.ffmpeg -i raw_video_1.mp4 -q:v 1 -start_number 0 path/FlashPortrait/poirtrait_data/rec/speech/00001/images/frame_%d.pngpath/FlashPortrait/poirtrait_data/rec/speech/00001/images.# Training FlashPortrait on a mixed resolution setting (480x832, 832x480, and 720X720) in a single node
bash train_single_machine.sh
# Training FlashPortrait on a mixed resolution setting (480x832, 832x480, and 720X720) in multiple nodes
bash train_multiple_machine.shtrain_single_machine.sh and train_multiple_machine.sh, CUDA_VISIBLE_DEVICES refers to gpu devices. In my setting, I use 4 NVIDIA A100 80G to train FlashPortrait (CUDA_VISIBLE_DEVICES=3,2,1,0) in a single node.
--pretrained_model_name_or_path and --output_dir refer to the pretrained Wan2.1-14B path and the checkpoint saved path of the trained FlashPortrait.
--train_data_square_dir, --train_data_rec_dir, and --train_data_vec_dir are the paths of video_square_path.txt, video_rec_path.txt, and video_vec_path.txt, respectively.
--video_sample_n_frames is the number of frames that FlashPortrait processes in a single batch.
--num_train_epochs is the training epoch number.cd output_14B_dir/checkpoint-x
python zero_to_fp32.py /path/FlashPortrait/output_14B_dir/checkpoint-x /path/FlashPortrait/output_14B_dir/checkpoint-x-fp32-infer --max_shard_size 80GB
cd ../..
python bin_convert_pt.py --pretrained_model_path="/path/FlashPortrait/output_14B_dir/checkpoint-x-fp32-infer"--transformer_path="path/FlashPortrait/checkpoints/FlashPortrait/transformer.pt and --portrait_encoder_path="path/FlashPortrait/checkpoints/FlashPortrait/portrait_encoder.pt to the train_single_machine.sh or train_multiple_machine.sh:# Finetuning FlashPortrait on a mixed resolution setting (480x832, 832x480, and 720X720) in a single node
bash train_single_machine.sh
# Finetuning FlashPortrait on a mixed resolution setting (480x832, 832x480, and 720X720) in multiple nodes
bash train_multiple_machine.sh1@article{tu2025flashportrait,
2 title={FlashPortrait: 6$\times$ Faster Infinite Portrait Animation with Adaptive Latent Prediction},
3 author={Tu, Shuyuan and Pan, Yueming and Huang, Yinming and Han, Xintong and Xing, Zhen and Dai, Qi and Qiu, Kai and Luo, Chong and Wu, Zuxuan},
4 journal={arXiv preprint arXiv:2512.16900},
5 year={2025}
6}