Open-Sora: Democratizing Efficient Video Production for All
Python
updated llava captioning (#45)
Frank Leeaa84ad4562f8
diff --git a/tools/caption/README.md b/tools/caption/README.mdindex 56b474e..183c3a2 100644--- a/tools/caption/README.md+++ b/tools/caption/README.md@@ -52,11 +52,17 @@ torchrun --nproc_per_node 2 --standalone -m tools.caption.caption_llava DATA.csv# can also caption imagestorchrun --nproc_per_node 2 --standalone -m tools.caption.caption_llava DATA.csv --tp-size 2 --dp-size 1 --bs 16 --prompt image-3ex+# caption with llava-34B+# NOTE: remember to enable flash attention for this model+torchrun --nproc_per_node 8 --standalone -m tools.caption.caption_llava DATA.csv --dp-size 4 --tp-size 2 --model-path liuhaotian/llava-v1.6-34b --prompt image-3ex --flash-attention+# caption with mistral-7Btorchrun --nproc_per_node 8 --standalone -m tools.caption.caption_llava DATA.csv --dp-size 8 --tp-size 1 --model-path liuhaotian/llava-v1.6-mistral-7b --prompt video# bs can be 48```+Please note that you should add the `--flash-attention` flag when running with Llama-based Llava models as it provides speedup but do turn it off for mistral-based ones. Reasons can be found in [this issue](https://discuss.huggingface.co/t/flash-attention-has-no-effect-on-inference/73453).+After running the script, with `dp-size=N`, you will get `N` parts of csv files. Run the following command to merge them:```bashdiff --git a/tools/caption/caption_llava.py b/tools/caption/caption_llava.pyindex abf12e1..0134ec5 100644--- a/tools/caption/caption_llava.py+++ b/tools/caption/caption_llava.py@@ -86,7 +86,7 @@ def main(args):model_name=get_model_name_from_path(model_path),device=get_current_device(),torch_dtype=torch.float16,- attn_implementation="flash_attention_2",+ attn_implementation="flash_attention_2" if args.flash_attention else "eager",)dist.barrier()@@ -331,6 +331,11 @@ if __name__ == "__main__":parser.add_argument("--dp-size", type=int, default=4)parser.add_argument("--num-workers", type=int, default=8)parser.add_argument("--prefetch-factor", type=int, default=8, help="Prefetch factor")+ parser.add_argument(+ "--flash-attention",+ action="store_true",+ help="Whether to use flash attention. You can turn on this flag for llama model and off for mistral model.",+ )# debug relatedparser.add_argument("--profile", action="store_true")parser.add_argument("--profile-warmup", type=int, default=1)