Meet YOLO26: next-gen vision AI.

Link to this sectionTriton Inference Server với Ultralytics YOLO26#

Triton Inference Server (trước đây được gọi là TensorRT Inference Server) là một giải pháp phần mềm nguồn mở do NVIDIA phát triển. Nó cung cấp giải pháp inference trên đám mây được tối ưu hóa cho GPU NVIDIA. Triton đơn giản hóa việc triển khai các model AI ở quy mô lớn trong môi trường production. Việc tích hợp Ultralytics YOLO26 với Triton Inference Server cho phép bạn triển khai các khối lượng công việc inference deep learning hiệu năng cao và có khả năng mở rộng. Hướng dẫn này cung cấp các bước để thiết lập và kiểm thử tích hợp.



Watch: Getting Started with NVIDIA Triton Inference Server.

Link to this sectionTriton Inference Server là gì?#

Triton Inference Server được thiết kế để triển khai đa dạng các model AI trong môi trường production. Nó hỗ trợ nhiều framework deep learning và machine learning, bao gồm PyTorch, TensorFlow, ONNX, OpenVINO, TensorRT và nhiều framework khác. Các trường hợp sử dụng chính bao gồm:

  • Phục vụ nhiều model từ một instance server duy nhất
  • Tải và gỡ model linh hoạt (dynamic) mà không cần khởi động lại server
  • Ensemble inference, cho phép sử dụng nhiều model cùng nhau để đạt kết quả tốt hơn
  • Quản lý phiên bản model cho A/B testing và cập nhật cuốn chiếu (rolling updates)

Link to this sectionLợi ích chính của Triton Inference Server#

Sử dụng Triton Inference Server với Ultralytics YOLO26 mang lại một số ưu điểm:

  • Automatic batching: Nhóm nhiều yêu cầu AI lại với nhau trước khi xử lý, giúp giảm độ trễ và cải thiện tốc độ inference
  • Tích hợp Kubernetes: Thiết kế cloud-native hoạt động trơn tru với Kubernetes để quản lý và mở rộng quy mô các ứng dụng AI
  • Tối ưu hóa theo phần cứng: Tận dụng tối đa khả năng của GPU NVIDIA để đạt hiệu năng cao nhất
  • Tính linh hoạt của framework: Hỗ trợ nhiều framework AI bao gồm PyTorch, TensorFlow, ONNX, OpenVINOTensorRT
  • Nguồn mở và có thể tùy chỉnh: Có thể sửa đổi để phù hợp với các nhu cầu cụ thể, đảm bảo tính linh hoạt cho nhiều ứng dụng AI khác nhau

Link to this sectionĐiều kiện tiên quyết#

Đảm bảo bạn đã có các điều kiện tiên quyết sau trước khi tiếp tục:

  • Đã cài đặt Docker hoặc Podman trên máy của bạn
  • Cài đặt ultralytics:
    pip install ultralytics
  • Cài đặt tritonclient:
    pip install tritonclient[all]

Link to this sectionThiết lập Triton Inference Server#

Chạy khối lệnh thiết lập đầy đủ này để xuất Ultralytics YOLO26 sang ONNX, xây dựng repository model Triton và khởi động Triton Inference Server:

Lưu ý

Sử dụng switch runtime trong script để chọn container engine của bạn:

  • Đặt runtime = "docker" cho Docker
  • Đặt runtime = "podman" cho Podman
import contextlib
import subprocess
import time
from pathlib import Path

from tritonclient.http import InferenceServerClient

from ultralytics import YOLO

runtime = "docker"  # set to "podman" to use Podman

# 1) Exporting YOLO26 to ONNX Format

# Load a model
model = YOLO("yolo26n.pt")  # load an official model

# Retrieve metadata during export. Metadata needs to be added to config.pbtxt. See next section.
metadata = []

def export_cb(exporter):
    metadata.append(exporter.metadata)

model.add_callback("on_export_end", export_cb)

# Export the model
onnx_file = model.export(format="onnx", dynamic=True)

# 2) Setting Up Triton Model Repository

# Define paths
model_name = "yolo"
triton_repo_path = Path("tmp") / "triton_repo"
triton_model_path = triton_repo_path / model_name

# Create directories
(triton_model_path / "1").mkdir(parents=True, exist_ok=True)

# Move ONNX model to Triton Model path
Path(onnx_file).rename(triton_model_path / "1" / "model.onnx")

# Create config file
(triton_model_path / "config.pbtxt").touch()

data = """
# Add metadata
parameters {
  key: "metadata"
  value {
    string_value: "%s"
  }
}

# Enable TensorRT acceleration (requires a GPU and TensorRT-enabled Triton; remove this block for CPU-only serving)
# The first run will be slow due to TensorRT engine conversion
optimization {
  execution_accelerators {
    gpu_execution_accelerator {
      name: "tensorrt"
      parameters {
        key: "precision_mode"
        value: "FP16"
      }
      parameters {
        key: "max_workspace_size_bytes"
        value: "3221225472"
      }
      parameters {
        key: "trt_engine_cache_enable"
        value: "1"
      }
      parameters {
        key: "trt_engine_cache_path"
        value: "/models/yolo/1"
      }
    }
  }
}
""" % metadata[0]  # noqa

with open(triton_model_path / "config.pbtxt", "w") as f:
    f.write(data)

# 3) Running Triton Inference Server

# Define image https://catalog.ngc.nvidia.com/orgs/nvidia/containers/tritonserver
tag = "nvcr.io/nvidia/tritonserver:26.02-py3"  # 16.17 GB (Compressed Size)

subprocess.call(f"{runtime} pull {tag}", shell=True)

# GPU flags differ between Docker and Podman
gpu_flags = "--device nvidia.com/gpu=all" if runtime == "podman" else "--runtime=nvidia --gpus all"

container_name = "triton_server"

# Note: The :z flag on the volume mount is necessary for systems with SELinux (like Fedora/RHEL)
subprocess.call(
    f"{runtime} run -d --rm --name {container_name} {gpu_flags} -v {triton_repo_path.absolute()}:/models:z -p 8000:8000 {tag} tritonserver --model-repository=/models",
    shell=True,
)

# Wait for the Triton server to start
triton_client = InferenceServerClient(url="127.0.0.1:8000", verbose=False, ssl=False)

# Wait until model is ready
for _ in range(10):
    with contextlib.suppress(Exception):
        assert triton_client.is_model_ready(model_name)
        break
    time.sleep(1)

Link to this sectionChạy Inference#

Chạy inference bằng model Triton Server:

from ultralytics import YOLO

# Load the Triton Server model
model = YOLO("http://127.0.0.1:8000/yolo", task="detect")

# Run inference on the server
results = model("path/to/image.jpg")

Dọn dẹp container:

import subprocess

runtime = "docker"  # set to "podman" to use Podman
container_name = "triton_server"  # Kill the named container
subprocess.call(f"{runtime} kill {container_name}", shell=True)

Link to this sectionTối ưu hóa TensorRT (Tùy chọn)#

Để có hiệu năng cao hơn nữa, bạn có thể sử dụng TensorRT với Triton Inference Server. TensorRT là bộ tối ưu hóa deep learning hiệu năng cao được xây dựng dành riêng cho GPU NVIDIA, có thể tăng đáng kể tốc độ inference.

Các lợi ích chính khi sử dụng TensorRT với Triton bao gồm:

  • Tốc độ inference nhanh hơn tới 36 lần so với các model chưa được tối ưu hóa
  • Tối ưu hóa theo phần cứng để đạt hiệu suất sử dụng GPU tối đa
  • Hỗ trợ các định dạng độ chính xác giảm (INT8, FP16) trong khi vẫn duy trì độ chính xác
  • Hợp nhất các lớp (Layer fusion) để giảm chi phí tính toán

Để sử dụng trực tiếp TensorRT, bạn có thể xuất model Ultralytics YOLO26 sang định dạng TensorRT:

from ultralytics import YOLO

# Load the YOLO26 model
model = YOLO("yolo26n.pt")

# Export the model to TensorRT format
model.export(format="engine")  # creates 'yolo26n.engine'

Để biết thêm thông tin về tối ưu hóa TensorRT, hãy xem hướng dẫn tích hợp TensorRT.

Giờ đây bạn có thể triển khai và chạy các model Ultralytics YOLO26 trên Triton Inference Server để thực hiện inference hiệu năng cao và có khả năng mở rộng. Để biết thêm chi tiết, hãy xem tài liệu chính thức của Triton hoặc yêu cầu sự trợ giúp từ cộng đồng Ultralytics.

Link to this sectionCâu hỏi thường gặp#

Link to this sectionLàm thế nào để thiết lập Ultralytics YOLO26 với NVIDIA Triton Inference Server?#

Việc thiết lập Ultralytics YOLO26 với NVIDIA Triton Inference Server bao gồm một vài bước chính:

  1. Xuất YOLO26 sang định dạng ONNX:

    from ultralytics import YOLO
    
    # Load a model
    model = YOLO("yolo26n.pt")  # load an official model
    
    # Export the model to ONNX format
    onnx_file = model.export(format="onnx", dynamic=True)
  2. Thiết lập Triton Model Repository:

    from pathlib import Path
    
    # Define paths
    model_name = "yolo"
    triton_repo_path = Path("tmp") / "triton_repo"
    triton_model_path = triton_repo_path / model_name
    
    # Create directories
    (triton_model_path / "1").mkdir(parents=True, exist_ok=True)
    Path(onnx_file).rename(triton_model_path / "1" / "model.onnx")
    (triton_model_path / "config.pbtxt").touch()
  3. Chạy Triton Server:

    import contextlib
    import subprocess
    import time
    
    from tritonclient.http import InferenceServerClient
    
    # Define image https://catalog.ngc.nvidia.com/orgs/nvidia/containers/tritonserver
    tag = "nvcr.io/nvidia/tritonserver:26.02-py3"
    
    runtime = "docker"  # set to "podman" to use Podman
    subprocess.call(f"{runtime} pull {tag}", shell=True)
    
    # GPU flags differ between Docker and Podman
    gpu_flags = "--device nvidia.com/gpu=all" if runtime == "podman" else "--runtime=nvidia --gpus all"
    
    container_name = "triton_server"
    subprocess.call(
        f"{runtime} run -d --rm --name {container_name} {gpu_flags} -v {triton_repo_path.absolute()}:/models:z -p 8000:8000 {tag} tritonserver --model-repository=/models",
        shell=True,
    )
    
    triton_client = InferenceServerClient(url="127.0.0.1:8000", verbose=False, ssl=False)
    
    for _ in range(10):
        with contextlib.suppress(Exception):
            assert triton_client.is_model_ready(model_name)
            break
        time.sleep(1)

Thiết lập này có thể giúp bạn triển khai model Ultralytics YOLO26 hiệu quả ở quy mô lớn trên Triton Inference Server để đạt hiệu năng inference AI tối ưu.

Link to this sectionViệc sử dụng Ultralytics YOLO26 với NVIDIA Triton Inference Server mang lại những lợi ích gì?#

Tích hợp Ultralytics YOLO26 với NVIDIA Triton Inference Server mang lại một số lợi thế:

  • Scalable AI Inference: Triton cho phép phục vụ nhiều model từ một instance server duy nhất, hỗ trợ tải và gỡ model linh hoạt, giúp mở rộng quy mô tốt cho các khối lượng công việc AI đa dạng.
  • Hiệu năng cao: Được tối ưu hóa cho GPU NVIDIA, Triton Inference Server đảm bảo các hoạt động inference tốc độ cao, hoàn hảo cho các ứng dụng thời gian thực như phát hiện đối tượng.
  • Ensemble và quản lý phiên bản model: Chế độ ensemble của Triton cho phép kết hợp nhiều model để cải thiện kết quả, và tính năng quản lý phiên bản model hỗ trợ A/B testing và cập nhật cuốn chiếu.
  • Automatic Batching: Triton tự động nhóm nhiều yêu cầu inference lại với nhau, cải thiện đáng kể thông lượng và giảm độ trễ.
  • Đơn giản hóa việc triển khai: Tối ưu hóa dần dần các luồng công việc AI mà không cần phải thay đổi toàn bộ hệ thống, giúp việc mở rộng quy mô hiệu quả hơn.

Để biết hướng dẫn chi tiết về cách thiết lập và chạy Ultralytics YOLO26 với Triton, hãy xem Thiết lập Triton Inference ServerChạy Inference.

Link to this sectionTại sao tôi nên xuất model YOLO26 sang định dạng ONNX trước khi sử dụng Triton Inference Server?#

Sử dụng định dạng ONNX (Open Neural Network Exchange) cho model Ultralytics YOLO26 trước khi triển khai trên NVIDIA Triton Inference Server mang lại một số lợi ích chính:

  • Khả năng tương tác: Định dạng ONNX hỗ trợ chuyển đổi giữa các framework deep learning khác nhau (như PyTorch, TensorFlow), đảm bảo tính tương thích rộng hơn.
  • Tối ưu hóa: Nhiều môi trường triển khai, bao gồm cả Triton, tối ưu hóa cho ONNX, cho phép inference nhanh hơn và hiệu năng tốt hơn.
  • Dễ dàng triển khai: ONNX được hỗ trợ rộng rãi trên nhiều framework và nền tảng, giúp đơn giản hóa quy trình triển khai trên các hệ điều hành và cấu hình phần cứng khác nhau.
  • Không phụ thuộc vào framework: Sau khi chuyển đổi sang ONNX, model của bạn không còn bị ràng buộc vào framework gốc, giúp nó trở nên linh hoạt hơn.
  • Chuẩn hóa: ONNX cung cấp một biểu diễn chuẩn hóa giúp giải quyết các vấn đề tương thích giữa các framework AI khác nhau.

Để xuất model của bạn, hãy sử dụng:

from ultralytics import YOLO

model = YOLO("yolo26n.pt")
onnx_file = model.export(format="onnx", dynamic=True)

Bạn có thể làm theo các bước trong hướng dẫn tích hợp ONNX để hoàn tất quy trình.

Link to this sectionTôi có thể chạy inference bằng model Ultralytics YOLO26 trên Triton Inference Server không?#

Có, bạn có thể chạy inference bằng model Ultralytics YOLO26 trên NVIDIA Triton Inference Server. Khi model của bạn đã được thiết lập trong Triton Model Repository và server đang chạy, bạn có thể tải và chạy inference trên model của mình như sau:

from ultralytics import YOLO

# Load the Triton Server model
model = YOLO("http://127.0.0.1:8000/yolo", task="detect")

# Run inference on the server
results = model("path/to/image.jpg")

Cách tiếp cận này cho phép bạn tận dụng các tối ưu hóa của Triton trong khi vẫn sử dụng giao diện Ultralytics YOLO quen thuộc.

Link to this sectionUltralytics YOLO26 so với các model TensorFlow và PyTorch trong việc triển khai như thế nào?#

Ultralytics YOLO26 mang lại một số ưu điểm độc đáo so với các model TensorFlow và PyTorch khi triển khai:

  • Hiệu năng thời gian thực: Được tối ưu hóa cho các tác vụ phát hiện đối tượng thời gian thực, Ultralytics YOLO26 cung cấp độ chính xác và tốc độ hàng đầu, rất lý tưởng cho các ứng dụng yêu cầu phân tích video trực tiếp.
  • Dễ sử dụng: Ultralytics YOLO26 tích hợp trơn tru với Triton Inference Server và hỗ trợ nhiều định dạng xuất khác nhau (ONNX, TensorRT), giúp linh hoạt cho nhiều kịch bản triển khai khác nhau.
  • Tính năng nâng cao: Ultralytics YOLO26 bao gồm các tính năng như tải model linh hoạt, quản lý phiên bản model và ensemble inference, vốn rất quan trọng cho các triển khai AI đáng tin cậy và có khả năng mở rộng.
  • API đơn giản hóa: Ultralytics API cung cấp một giao diện nhất quán trên các mục tiêu triển khai khác nhau, giảm bớt quá trình học tập và thời gian phát triển.
  • Tối ưu hóa cho Edge: Các model Ultralytics YOLO26 được thiết kế với mục tiêu triển khai trên thiết bị biên, mang lại hiệu năng tuyệt vời ngay cả trên các thiết bị hạn chế về tài nguyên.

Để biết thêm chi tiết, hãy so sánh các tùy chọn triển khai trong hướng dẫn xuất model.

Bình luận