在云中使用GPU
这是一个示例工作流程,说明如何使用云中的 GPU,通过 EC2 实例渲染你的视频。
🌐 Here is an example workflow for how to use the GPU in the cloud to render your videos using EC2 instances.
更新 Remotion
🌐 Update Remotion
确保你使用的是 Remotion v4.0.248 或更高版本,以使本指南有效。
🌐 Ensure you are using Remotion v4.0.248 or later for this guide to work.
启动一个 EC2 实例
🌐 Launch an EC2 instance
你可能需要向AWS申请提高GPU数量的使用限制。 你可以在AWS控制台里实现这一点。 访问“服务配额” -> “AWS 服务” -> “亚马逊弹性计算云(Amazon EC2)” -> “按需运行 G 和 VT 实例” -> “账户层请求增加”。 你也可以点击[这里](https://us-east-1.console.aws.amazon.com/servicequotas/home/services/ec2/quotas/L-DB2E81BA)直接进入“us-east-1”区域的页面。
🌐 You might need to ask AWS for a limit increase for the number of GPUs you can use.
You can do this in the AWS console.
Go to "Service Quotas" -> "AWS Services" -> "Amazon Elastic Compute Cloud (Amazon EC2)" -> "Running On-Demand G and VT instances" -> "Request increase at account-level".
You may also click here to go to the page directly for the us-east-1 region.
选择“浏览更多 AMI”,搜索 ami-06a1f46caddb5669e,选择“社区 AMI”选项卡并选择具有正确 AMI (ubuntu/images/hvm-ssd/ubuntu-jammy-22.04-amd64-server-20230608) 的镜像。
🌐 Select "Browse more AMIs", search for ami-06a1f46caddb5669e, select the "Community AMIs" tab and select the image with the right AMI (ubuntu/images/hvm-ssd/ubuntu-jammy-22.04-amd64-server-20230608).
搜索可能需要长达30秒才能找到AMI,并且它不是第一个结果。
我们推荐 g4dn.xlarge 尺寸 - 请注意,此实例的默认配置每月费用为 $375。 如果你收到“订阅 AMI 正在花费比预期更长的时间”的信息,这是正常的。你可能需要等待几分钟。
🌐 We recommend the g4dn.xlarge size - note that this instance costs $375 per month with the default configuration.
If you get a message "Subscribing to AMI is taking longer than expected", it is normal. You may need to wait a few minutes.
一旦你连接到实例,运行以下命令:
🌐 Once you connected to the instance, run the following commands:
Upgrade the Linux Kernel to v6sudo bash -c "apt update && export DEBIAN_FRONTEND=noninteractive && export NEEDRESTART_MODE=a && apt upgrade -y && reboot"
该实例将重启,因此会断开连接。请稍等片刻,然后重新连接。
🌐 The instance will restart and therefore disconnect. Wait a few moments and then reconnect.
为 Remotion 安装 Linux 依赖:
🌐 Install the Linux Dependencies for Remotion:
Install Linux Dependenciessudo apt install -y \ libnss3 \ libdbus-1-3 \ libatk1.0-0 \ libasound2 \ libxrandr2 \ libxkbcommon-dev \ libxfixes3 \ libxcomposite1 \ libxdamage1 \ libcups2 \ libgbm-dev \ libpangocairo-1.0-0 \ libatk-bridge2.0-0
安装 GPU 驱动程序:
🌐 Set up GPU drivers:
Install libvulkansudo apt install -y build-essential libvulkan1
Install GPU driversDRIVER_URL="https://us.download.nvidia.com/tesla/535.104.12/NVIDIA-Linux-x86_64-535.104.12.run" DRIVER_NAME="NVIDIA-Linux-driver.run" wget -O "$DRIVER_NAME" "$DRIVER_URL" sudo sh "$DRIVER_NAME" --disable-nouveau --silent rm "$DRIVER_NAME"
Configure startup serviceecho '[Unit] Description=Run nvidia-smi at system startup [Service] ExecStart=/usr/bin/nvidia-smi Type=oneshot RemainAfterExit=yes [Install] WantedBy=multi-user.target' | sudo tee /etc/systemd/system/nvidia-smi.service sudo systemctl enable nvidia-smi.service sudo systemctl start nvidia-smi.service
Install Node.jssudo mkdir -p /etc/apt/keyrings curl -fsSL https://deb.nodesource.com/gpgkey/nodesource-repo.gpg.key | sudo gpg --dearmor -o /etc/apt/keyrings/nodesource.gpg NODE_MAJOR=20 echo "deb [signed-by=/etc/apt/keyrings/nodesource.gpg] https://deb.nodesource.com/node_$NODE_MAJOR.x nodistro main" | sudo tee /etc/apt/sources.list.d/nodesource.list sudo apt-get update sudo apt-get install nodejs -y
Clone a Remotion GPU demogit clone https://github.com/remotion-dev/gpu-scene cd gpu-scene npm i npx remotion gpu --chrome-mode="chrome-for-testing" --gl=vulkan # Verify content is hardware accelerated npx remotion render --chrome-mode="chrome-for-testing" --gl=vulkan # Render a test video
使用 --chrome-mode="chrome-for-testing" 时,Chrome 的一个版本会模拟显示器,从而可以使用 GPU。
使用 --gl=vulkan 时,Chrome 则使用正确的 OpenGL 渲染器。
🌐 With --chrome-mode="chrome-for-testing", a flavor of Chrome is used that emulates a display, which can make use of the GPU.
With --gl=vulkan, Chrome uses the right OpenGL renderer.
可能会出现诸如 vkCreateInstance() failed: -7 和 Failed to create and initialize Vulkan implementation. 的警告,然而,渲染速度应该会显著更快。
另请参阅
🌐 See also

