Chuyển tới nội dung chính

{/* Trang này được tạo tự động từ SKILL.md của kỹ năng bởi website/scripts/generate-skill-docs.py. Chỉnh sửa nguồn SKILL.md, không phải trang này. */}

Gpu không máy chủ theo phương thức

Nền tảng đám mây GPU không có máy chủ để chạy khối lượng công việc ML. Sử dụng khi bạn cần quyền truy cập GPU theo yêu cầu mà không cần quản lý cơ sở hạ tầng, triển khai mô hình ML dưới dạng API hoặc chạy các tác vụ hàng loạt với khả năng tự động điều chỉnh quy mô.

Siêu dữ liệu kỹ năng

NguồnTùy chọn — cài đặt với
`Hermes skills install official/mlops/modal
`
Đường dẫn

optional-skills/mlops/modal ` | | Phiên bản |

1.0.0 ` | | Tác giả | Nghiên cứu dàn nhạc | | Giấy phép | MIT | | Phụ thuộc |

modal>=0.64.0 ` | | Nền tảng | Linux, macOS, Windows | | Thẻ |

Infrastructure

, `Serverless

, `GPU

, `Cloud

, `Deployment

, Modal |

Tham khảo: đầy đủ SKILL.md

thông tin

Sau đây là định nghĩa kỹ năng đầy đủ mà Hermes tải khi kỹ năng này được kích hoạt. Đây là những gì tác nhân coi là hướng dẫn khi kỹ năng được kích hoạt.

GPU không máy chủ theo phương thức

Hướng dẫn toàn diện để chạy khối lượng công việc ML trên nền tảng đám mây GPU không máy chủ của Modal.

Khi nào nên sử dụng Modal`Sử dụng Modal khi:

  • Chạy khối lượng công việc ML sử dụng nhiều GPU mà không cần quản lý cơ sở hạ tầng
  • Triển khai các mô hình ML dưới dạng API tự động mở rộng quy mô
  • Chạy các công việc xử lý hàng loạt (đào tạo, suy luận, xử lý dữ liệu)
  • Cần định giá GPU trả theo giây mà không có chi phí nhàn rỗi
  • Tạo mẫu ứng dụng ML nhanh chóng
  • Chạy các công việc theo lịch trình (khối lượng công việc giống như cron)

Các tính năng chính:

  • GPU không có máy chủ: T4, L4, A10G, L40S, A100, H100, H200, B200 theo yêu cầu
  • Python-native: Xác định cơ sở hạ tầng bằng mã Python, không có YAML
  • Tự động chia tỷ lệ: Chia tỷ lệ về 0, chia tỷ lệ lên hơn 100 GPU ngay lập tức
  • Khởi động nguội dưới giây: Cơ sở hạ tầng dựa trên rỉ sét để khởi động container nhanh
  • Bộ nhớ đệm vùng chứa: Các lớp hình ảnh được lưu vào bộ nhớ đệm để lặp lại nhanh chóng
  • Điểm cuối web: Triển khai các chức năng dưới dạng API REST với các bản cập nhật không có thời gian ngừng hoạt động`Sử dụng các lựa chọn thay thế thay thế:
  • RunPod: Dành cho các nhóm chạy lâu hơn với trạng thái liên tục
  • Lambda Labs: Dành cho phiên bản GPU dành riêng
  • SkyPilot: Để điều phối nhiều đám mây và tối ưu hóa chi phí
  • Kubernetes: Dành cho kiến trúc đa dịch vụ phức tạp

Bắt đầu nhanh

Cài đặt

pip install modal
modal setup # Opens browser for authentication

`

### Xin chào thế giới với GPU

`Python
import modal`app = modal.App("hello-gpu")`@app.function(gpu="T4")
def gpu_info():
import subprocess
return subprocess.run(["nvidia-smi"], capture_output=True, text=True).stdout`@app.local_entrypoint()
def main():
print(gpu_info.remote())

`
``Chạy:
`modal run hello_gpu.py

### Điểm cuối suy luận cơ bản

`Python
import modal`app = modal.App("text-generation")
image = modal.Image.debian_slim().pip_install("transformers", "torch", "accelerate")`@app.cls(gpu="A10G", image=image)
class TextGenerator:
@modal.enter()
def load_model(self):
from transformers import pipeline
self.pipe = pipeline("text-generation", model="GPT2", device=0)`@modal.method()
def generate(self, prompt: str) -> str:
return self.pipe(prompt, max_length=100)[0]["generated_text"]`@app.local_entrypoint()
def main():
print(TextGenerator().generate.remote("Hello, world"))

`

## Khái niệm cốt lõi`###Các thành phần chính

| Thành phần | Mục đích |
|----------||----------|
|
`App
` | Vùng chứa các chức năng và tài nguyên |
|
`Function
` | Chức năng serverless với thông số điện toán |
|
`Cls
` | Các hàm dựa trên lớp có móc vòng đời |
|
`Image
` | Định nghĩa hình ảnh vùng chứa |
|
`Volume
` | Lưu trữ liên tục cho mô hình/dữ liệu |
|
`Secret
` | Lưu trữ thông tin xác thực an toàn |

### Các chế độ thực thi

| Lệnh | Mô tả |
|----------|-------------|
|
`modal run script.py
` | Thực hiện và thoát |
|
`modal serve script.py
` | Phát triển với tải lại trực tiếp |
|
`modal deploy script.py
` | Triển khai đám mây liên tục |

## cấu hình GPU

### GPU có sẵn

| GPU | VRAM | Tốt nhất cho |
|------|------|----------|
|
`T4
` | 16GB | Suy luận ngân sách, mô hình nhỏ |
|
`L4
` | 24GB | Suy luận, vòm Ada Lovelace |
|
`A10G
` | 24GB | Đào tạo/suy luận, nhanh hơn 3,3 lần so với T4 |
|
`L40S
` | 48GB | Được đề xuất để suy luận (chi phí/hiệu suất tốt nhất) |
|
`A100-40GB
` | 40GB | Đào tạo mô hình lớn |
|
`A100-80GB
` | 80GB | Mô hình rất lớn |
|
`H100
` | 80GB | Nhanh nhất, FP8 + Động cơ biến áp |
|
`H200
` | 141GB | Tự động nâng cấp từ H100, băng thông 4,8TB/s |
|
`B200
` | Mới nhất | Kiến trúc Blackwell |

### mẫu đặc tả GPU

`Python

# Single GPU
@app.function(gpu="A100")

# Specific memory variant
@app.function(gpu="A100-80GB")

# Multiple GPUs (up to 8)
@app.function(gpu="H100:4")

# GPU with fallbacks
@app.function(gpu=["H100", "A100", "L40S"])

# Any available GPU
@app.function(gpu="any")

`

## Hình ảnh vùng chứa

``` python

# Basic image with pip
image = modal.Image.debian_slim(Python_version="3.11").pip_install(
"torch==2.1.0", "transformers==4.36.0", "accelerate"
)

# From CUDA base
image = modal.Image.from_registry(
"nvidia/cuda:12.1.0-cudnn8-devel-ubuntu22.04",
add_Python="3.11"
).pip_install("torch", "transformers")

# With system packages
image = modal.Image.debian_slim().apt_install("git", "ffmpeg").pip_install("whisper")

`

## Lưu trữ liên tục

``` python
volume = modal.Volume.from_name("model-cache", create_if_missing=True)`@app.function(gpu="A10G", volumes=\{"/models": volume})
def load_model():
import os
model_path = "/models/Llama-7b"
if not os.path.exists(model_path):
model = download_model()
model.save_pretrained(model_path)
volume.commit() # Persist changes
return load_from_path(model_path)

`

## Điểm cuối web

### Trình trang trí điểm cuối FastAPI

`Python
@app.function()
@modal.fastAPI_endpoint(method="POST")
def predict(text: str) -> dict:
return \{"result": model.predict(text)}

`

### Ứng dụng ASGI đầy đủ

`Python
from fastAPI import FastAPI
web_app = FastAPI()`@web_app.post("/predict")
async def predict(text: str):
return \{"result": await model.predict.remote.aio(text)}`@app.function()
@modal.asgi_app()
def fastAPI_app():
return web_app

`

### Các loại điểm cuối web

| Người trang trí | Trường hợp sử dụng |
|----------||----------|
|

@modal.fastAPI_endpoint()
` | Hàm đơn giản → API |
|

@modal.asgi_app()
` | Ứng dụng FastAPI/Starlette đầy đủ |
|

@modal.wsgi_app()
` | Ứng dụng Django/Flask |
|

@modal.web_server(port)
` | Máy chủ HTTP tùy ý |

## Phân khối động

`Python
@app.function()
@modal.batched(max_batch_size=32, wait_ms=100)
async def batch_predict(inputs: list[str]) -> list[dict]:

# Inputs automatically batched
return model.batch_predict(inputs)

`

## Quản lý bí mật

``` bash

# Create secret
modal secret create huggingface HF_TOKEN=hf_xxx

`

`
``` python
@app.function(secrets=[modal.Secret.from_name("huggingface")])
def download_model():
import os
token = os.environ["HF_TOKEN"]

`

## Lên lịch

`Python
@app.function(schedule=modal.Cron("0 0 * * *")) # Daily midnight
def daily_job():
pass`@app.function(schedule=modal.Period(hours=1))
def hourly_job():
pass

`

## Tối ưu hóa hiệu suất### Giảm thiểu khởi động nguội

`Python
@app.function(
container_idle_timeout=300, # Keep warm 5 min
allow_concurrent_inputs=10, # Handle concurrent requests
)
def inference():
pass

`

### Các phương pháp hay nhất về tải mô hình

`Python
@app.cls(gpu="A100")
class Model:
@modal.enter() # Run once at container start
def load(self):
self.model = load_model() # Load during warm-up`@modal.method()
def predict(self, x):
return self.model(x)

`

## Xử lý song song

`Python
@app.function()
def process_item(item):
return expensive_computation(item)`@app.function()
def run_parallel():
items = list(range(1000))

# Fan out to parallel containers
results = list(process_item.map(items))
return results

`

## Cấu hình chung

``` python
@app.function(
gpu="A100",
memory=32768, # 32GB RAM
cpu=4, # 4 CPU cores
timeout=3600, # 1 hour max
container_idle_timeout=120,# Keep warm 2 min
retries=3, # Retry on failure
concurrency_limit=10, # Max concurrent containers
)
def my_function():
pass

`

## Gỡ lỗi

`Python

# Test locally
if __name__ == "__main__":
result = my_function.local()

# View logs
# modal app logs my-app

`

## Các vấn đề thường gặp

| Vấn đề | Giải pháp |
|-------|----------|
| Độ trễ khởi động nguội | Tăng
`container_idle_timeout

, sử dụng

@modal.enter()
` |
| GPU OOM | Sử dụng GPU lớn hơn (
`A100-80GB

), bật tính năng kiểm tra độ dốc |
| Xây dựng hình ảnh không thành công | Ghim các phiên bản phụ thuộc, kiểm tra tính tương thích CUDA |
| Lỗi hết thời gian chờ | Tăng
`timeout

, thêm điểm kiểm tra |

## Tài liệu tham khảo
- **[Advanced Usage](https://GitHub.com/NousResearch/Hermes-agent/blob/main/optional-skills/mlops/modal/references/advanced-usage.md)** - Multi-GPU, đào tạo phân tán, tối ưu hóa chi phí
- **[Troubleshooting](https://GitHub.com/NousResearch/Hermes-agent/blob/main/optional-skills/mlops/modal/references/troubleshooting.md)** - Các vấn đề thường gặp và giải pháp

## Tài nguyên
- **Tài liệu**: https://modal.com/docs
- **Ví dụ**: https://GitHub.com/modal-labs/modal-examples
- **Giá**: https://modal.com/pricing
- **Discord**: https://Discord.gg/modal