使用 RunPod GPU

RunPod 是提供 GPU 资源的一个平台,可以在平台上租 GPU 按小时计费。支持所有主流的 GPU,价格也还好。本文将介绍如何在 RunPod 启动 Notebook 运行模型,模型使用 Flux UpScaler,显存需求大于 24 G。登陆网站,注册并充值,https://www.runpod.io/

在这里插入图片描述

创建 POD

选择 GPU 和 Docker 镜像,镜像选择 runpod/pytorch:2.4.0-py3.11-cuda12.4.1-devel-ubuntu22.04。
在这里插入图片描述
默认硬盘只有 20 G,如果模型很大,需要进行修改存储尺寸,点击 Edit Template,存储是要收费的,公用就可以。
在这里插入图片描述

启动Pod

安装需要的依赖

!pip install transformers diffusers accelerate protobuf sentencepiece matplotlib

UpScale

代码来自huggging face 的例子,https://huggingface.co/jasperai/Flux.1-dev-Controlnet-Upscaler

import torch
from diffusers.utils import load_image
from diffusers import FluxControlNetModel
from diffusers.pipelines import FluxControlNetPipeline
from huggingface_hub import login

login(token = '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')
from huggingface_hub import snapshot_download
flux = snapshot_download("black-forest-labs/FLUX.1-dev",local_dir="./flux")
upscaler = snapshot_download("jasperai/Flux.1-dev-Controlnet-Upscaler",local_dir="./flux")
# Load pipeline
controlnet = FluxControlNetModel.from_pretrained(
  upscaler,
  torch_dtype=torch.bfloat16
)
pipe = FluxControlNetPipeline.from_pretrained(
 flux,
  controlnet=controlnet,
  torch_dtype=torch.bfloat16
)
pipe.to("cuda")

# Load a control image
control_image = load_image(
  "https://huggingface.co/jasperai/Flux.1-dev-Controlnet-Upscaler/resolve/main/examples/input.jpg"
)

w, h = control_image.size

# Upscale x4
control_image = control_image.resize((w * 4, h * 4))

image = pipe(
    prompt="", 
    control_image=control_image,
    controlnet_conditioning_scale=0.6,
    num_inference_steps=28, 
    guidance_scale=3.5,
    height=control_image.size[1],
    width=control_image.size[0]
).images[0]
image

在这里插入图片描述
原始图片

import requests
from PIL import Image
from io import BytesIO
import matplotlib.pyplot as plt

# URL of the image
url = "https://huggingface.co/jasperai/Flux.1-dev-Controlnet-Upscaler/resolve/main/examples/input.jpg"

# Send a GET request to the URL
response = requests.get(url)

# Check if the request was successful
if response.status_code == 200:
    # Open the image from the response content
    image = Image.open(BytesIO(response.content))
    
    # Display the image
    plt.imshow(image)
    plt.axis('off')  # Hide axes
    plt.show()
else:
    print(f"Failed to retrieve image. Status code: {response.status_code}")

在这里插入图片描述

总结

RunPod 可以支持大显存需求的模型,将 Runpod 镜像下载到本地先调试好,例如需要的类库等等,这样可以省时间,有很多平台的都 提供 GPU 租赁,原理都是相似的,就看哪家更便宜些,国内的算力平台更便宜,就是英伟达的卡不好租。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值