开源AI视频生成项目Open-Sora

# 开源AI视频生成项目Open-Sora

# 什么是Open-Sora

首先, 此 Open-Sora 并非 Open AI 发布的 Sora 开源版。

Open-Sora项目是一项致力于高效制作高质量视频,并使所有人都能使用其模型、工具和内容的计划。 通过采用开源原则,Open-Sora 不仅实现了先进视频生成技术的低成本普及,还提供了一个精简且用户友好的方案,简化了视频制作的复杂性。 通过 Open-Sora,我们希望更多开发者一起探索内容创作领域的创新、创造和包容。

开源地址: https://github.com/hpcaitech/Open-Sora

更多:https://hpcaitech.github.io/Open-Sora/

# windows系统下部署

虽然Open-Sora目前的效果和Sora还有一些差距,生成视频的效果和长度都还有很大改善空间,但是优点在于完全开源,灵活性更高,而且是目前唯一能用上的模型。所以这篇文章就来介绍如何在单机上部署Open-Sora并进行文生视频推理。之后的文章会介绍如何将Open-Sora部署为可支持多人在线调用的API服务。

(Open-Sora一共需要下载20多个G的模型)、数据盘可以单独保存使得我们不用每次部署都重新下载模型。 虽然Open-Sora目前的效果和Sora还有一些差距,生成视频的效果和长度都还有很大改善空间,但是优点在于完全开源,灵活性更高,而且是目前唯一能用上的模型。所以这篇文章就来介绍如何在单机上部署Open-Sora并进行文生视频推理。之后的文章会介绍如何将Open-Sora部署为可支持多人在线调用的API服务。

(Open-Sora一共需要下载20多个G的模型)、数据盘可以单独保存使得我们不用每次部署都重新下载模型。

# 系统介绍

https://mirrors.tuna.tsinghua.edu.cn/anaconda/miniconda/ 选择: https://mirrors.tuna.tsinghua.edu.cn/anaconda/miniconda/Miniconda3-py310_24.1.2-0-Windows-x86_64.exe

# 安装 conda

image-20240325182500554

image-20240325182542331

安装完成

image-20240325182739624

在github中下载open-sora,并且解压到D盘

cd D:\Open-Sora
# create a virtual env
conda create -n opensora python=3.10
# activate virtual environment
conda activate opensora

# install torch
# the command below is for CUDA 12.1, choose install commands from 
# https://pytorch.org/get-started/locally/ based on your own CUDA version
pip install torch torchvision

# install flash attention (optional)
pip install packaging ninja
pip install flash-attn --no-build-isolation

# install apex (optional)
pip install -v --disable-pip-version-check --no-cache-dir --no-build-isolation --config-settings "--build-option=--cpp_ext" --config-settings "--build-option=--cuda_ext" git+https://github.com/NVIDIA/apex.git

# install xformers
pip install -U xformers --index-url https://download.pytorch.org/whl/cu121

# install this project
git clone https://github.com/hpcaitech/Open-Sora
cd Open-Sora
pip install -v .
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25

image-20240325183424398

pip3 install torch torchvision
1

image-20240325183957110

image-20240325234546751

pip install packaging ninja
1

image-20240325234718324

# 报错

(base) PS D:\Open-Sora> pip install flash-attn --no-build-isolation
Defaulting to user installation because normal site-packages is not writeable
Collecting flash-attn
  Using cached flash_attn-2.5.6.tar.gz (2.5 MB)
  Preparing metadata (setup.py) ... error
  error: subprocess-exited-with-error

  × python setup.py egg_info did not run successfully.
  │ exit code: 1
  ╰─> [12 lines of output]
      Traceback (most recent call last):
        File "<string>", line 2, in <module>
        File "<pip-setuptools-caller>", line 34, in <module>
        File "C:\Users\CQ-0458\AppData\Local\Temp\pip-install-i8w0sfb9\flash-attn_d29c3c58d07e46e78480f660ddbd0204\setup.py", line 94, in <module>
          subprocess.run(["git", "submodule", "update", "--init", "csrc/cutlass"])
        File "d:\miniconda3\lib\subprocess.py", line 503, in run
          with Popen(*popenargs, **kwargs) as process:
        File "d:\miniconda3\lib\subprocess.py", line 971, in __init__
          self._execute_child(args, executable, preexec_fn, close_fds,
        File "d:\miniconda3\lib\subprocess.py", line 1456, in _execute_child
          hp, ht, pid, tid = _winapi.CreateProcess(executable, args,
      FileNotFoundError: [WinError 2] 系统找不到指定的文件。
      [end of output]

  note: This error originates from a subprocess, and is likely not a problem with pip.
error: metadata-generation-failed

× Encountered error while generating package metadata.
╰─> See above for output.

note: This is an issue with the package mentioned above, not pip.
hint: See above for details.
(base) PS D:\Open-Sora>
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33

使用管理员身份运行报错:

(base) PS D:\Open-Sora> pip install flash-attn --no-build-isolation
Collecting flash-attn
  Using cached flash_attn-2.5.6.tar.gz (2.5 MB)
  Preparing metadata (setup.py) ... error
  error: subprocess-exited-with-error

  × python setup.py egg_info did not run successfully.
  │ exit code: 1
  ╰─> [12 lines of output]
      Traceback (most recent call last):
        File "<string>", line 2, in <module>
        File "<pip-setuptools-caller>", line 34, in <module>
        File "C:\Users\CQ-0458\AppData\Local\Temp\pip-install-rfvh6i9s\flash-attn_a898fba1b1cc4d2f848548537f6cf939\setup.py", line 94, in <module>
          subprocess.run(["git", "submodule", "update", "--init", "csrc/cutlass"])
        File "d:\miniconda3\lib\subprocess.py", line 503, in run
          with Popen(*popenargs, **kwargs) as process:
        File "d:\miniconda3\lib\subprocess.py", line 971, in __init__
          self._execute_child(args, executable, preexec_fn, close_fds,
        File "d:\miniconda3\lib\subprocess.py", line 1456, in _execute_child
          hp, ht, pid, tid = _winapi.CreateProcess(executable, args,
      FileNotFoundError: [WinError 2] 系统找不到指定的文件。
      [end of output]

  note: This error originates from a subprocess, and is likely not a problem with pip.
error: metadata-generation-faile
× Encountered error while generating package metadata.
╰─> See above for output.

note: This is an issue with the package mentioned above, not pip.
hint: See above for details.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30

解决:

python.exe -m pip install --upgrade pip
1

image-20240329105754893

继续报错:

(base) PS D:\Open-Sora> pip install flash-attn --no-build-isolation
Collecting flash-attn
  Downloading flash_attn-2.5.6.tar.gz (2.5 MB)
     ---------------------------------------- 2.5/2.5 MB 21.9 kB/s eta 0:00:00
  Preparing metadata (setup.py) ... error
  error: subprocess-exited-with-error

  × python setup.py egg_info did not run successfully.
  │ exit code: 1
  ╰─> [12 lines of output]
      Traceback (most recent call last):
        File "<string>", line 2, in <module>
        File "<pip-setuptools-caller>", line 34, in <module>
        File "C:\Users\CQ-0458\AppData\Local\Temp\pip-install-451jzjm3\flash-attn_ee57d2253106408dbfafd10a79667fe4\setup.py", line 94, in <module>
          subprocess.run(["git", "submodule", "update", "--init", "csrc/cutlass"])
        File "d:\miniconda3\lib\subprocess.py", line 503, in run
          with Popen(*popenargs, **kwargs) as process:
        File "d:\miniconda3\lib\subprocess.py", line 971, in __init__
          self._execute_child(args, executable, preexec_fn, close_fds,
        File "d:\miniconda3\lib\subprocess.py", line 1456, in _execute_child
          hp, ht, pid, tid = _winapi.CreateProcess(executable, args,
      FileNotFoundError: [WinError 2] 系统找不到指定的文件。
      [end of output]

  note: This error originates from a subprocess, and is likely not a problem with pip.
error: metadata-generation-failed

× Encountered error while generating package metadata.
╰─> See above for output.

note: This is an issue with the package mentioned above, not pip.
hint: See above for details.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32