Ultralytics YOLO27:

Ultralytics YOLO26 と Triton Inference Server#

Triton Inference Server(旧称 TensorRT Inference Server)は、NVIDIA が開発したオープンソースのソフトウェアソリューションです。NVIDIA GPU 向けに最適化されたクラウド推論ソリューションを提供します。Triton は、本番環境で AI モデルを大規模にデプロイするプロセスを簡素化します。Ultralytics YOLO26 と Triton Inference Server を統合することで、スケーラブルで高性能なディープラーニング推論ワークロードをデプロイできます。このガイドでは、統合のセットアップとテストの手順を説明します。



Watch: Getting Started with NVIDIA Triton Inference Server.

Triton Inference Server とは何ですか?#

Triton Inference Server は、さまざまな AI モデルを本番環境にデプロイできるように設計されています。PyTorchTensorFlowONNXOpenVINOTensorRT など、幅広いディープラーニングおよび機械学習フレームワークをサポートしています。主なユースケースは次のとおりです。

  • 単一のサーバーインスタンスから複数のモデルをサービングする
  • サーバーを再起動せずにモデルを動的にロードおよびアンロードする
  • 複数のモデルを組み合わせて結果を得るアンサンブル推論
  • A/B テストとローリングアップデートのためのモデルバージョン管理

Triton Inference Server の主なメリット#

Ultralytics YOLO26 で Triton Inference Server を使用すると、次のようなメリットがあります。

  • 自動バッチ処理: 複数の AI リクエストを処理前にまとめることで、レイテンシを短縮し、推論速度を向上させます
  • Kubernetes 統合: クラウドネイティブ設計により Kubernetes とシームレスに連携し、AI アプリケーションを管理およびスケーリングできます
  • ハードウェア固有の最適化: NVIDIA GPU の性能を最大限に活用します
  • フレームワークの柔軟性: PyTorchTensorFlowONNXOpenVINOTensorRT など、複数の AI フレームワークをサポートします
  • オープンソースでカスタマイズ可能: 特定のニーズに合わせて変更でき、さまざまな AI アプリケーションに柔軟に対応できます

前提条件#

続行する前に、次の前提条件を満たしていることを確認してください。

  • Docker(>= 28.2.0、CDI GPU アクセス用の NVIDIA Container Toolkit >= 1.18)または Podman がマシンにインストールされていること
  • ultralytics をインストールします。
    pip install ultralytics
  • tritonclient をインストールします。
    pip install tritonclient[all]

Triton Inference Server のセットアップ#

次の完全なセットアップブロックを実行して、Ultralytics YOLO26ONNX にエクスポートし、Triton モデルリポジトリを構築して、Triton Inference Server を起動します。

注記

スクリプトの runtime スイッチを使用して、コンテナエンジンを選択します。

  • Docker の場合は runtime = "docker" を設定します
  • Podman の場合は runtime = "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)

# CDI GPU request works identically on Docker and Podman
gpu_flags = "--device nvidia.com/gpu=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)

推論の実行#

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")

コンテナをクリーンアップします。

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)

TensorRT の最適化(オプション)#

さらに高い性能を得るには、Triton Inference Server で TensorRT を使用できます。TensorRT は NVIDIA GPU 専用に構築された高性能ディープラーニングオプティマイザーで、推論速度を大幅に向上させることができます。

Triton で TensorRT を使用する主なメリットは次のとおりです。

  • 最適化されていないモデルと比較して、推論が最大 36 倍高速
  • GPU 使用率を最大化するハードウェア固有の最適化
  • 精度を維持しながら、低精度形式(INT8、FP16)をサポート
  • 計算オーバーヘッドを削減するレイヤーフュージョン

TensorRT を直接使用するには、Ultralytics YOLO26 モデルを 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'

TensorRT の最適化について詳しくは、TensorRT 統合ガイドを参照してください。

これで、Triton Inference Server に Ultralytics YOLO26 モデルをデプロイし、スケーラブルで高性能な推論を実行できます。詳細については、Triton の公式ドキュメントを参照するか、Ultralytics コミュニティに質問してください。

FAQ#

  • Ultralytics YOLO26NVIDIA Triton Inference Server とセットアップするには、いくつかの重要な手順が必要です。

    1. YOLO26 を 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. Triton モデルリポジトリをセットアップ:

      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. 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)
      
      # CDI GPU request works identically on Docker and Podman
      gpu_flags = "--device nvidia.com/gpu=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)

    このセットアップにより、Triton Inference Server 上で Ultralytics YOLO26 モデルを大規模に効率よくデプロイし、高性能な AI モデル推論を実現できます。

  • Ultralytics YOLO26NVIDIA Triton Inference Server を統合すると、次のようなメリットがあります。

    • スケーラブルな AI 推論: Triton は単一のサーバーインスタンスから複数のモデルをサービングし、モデルの動的なロードとアンロードをサポートするため、多様な AI ワークロードに対して高いスケーラビリティを実現します。
    • 高性能: NVIDIA GPU 向けに最適化された Triton Inference Server は、高速な推論処理を実現し、物体検出などのリアルタイムアプリケーションに最適です。
    • アンサンブルとモデルバージョン管理: Triton のアンサンブルモードでは複数のモデルを組み合わせて結果を向上させることができ、モデルバージョン管理では A/B テストとローリングアップデートをサポートします。
    • 自動バッチ処理: Triton は複数の推論リクエストを自動的にまとめることで、スループットを大幅に向上させ、レイテンシを削減します。
    • デプロイの簡素化: システム全体を大幅に変更することなく AI ワークフローを段階的に最適化でき、効率的なスケーリングが容易になります。

    Ultralytics YOLO26 を Triton でセットアップして実行する詳しい手順については、Triton Inference Server のセットアップ推論の実行を参照してください。

  • NVIDIA Triton Inference Server にデプロイする前に、Ultralytics YOLO26 モデルで ONNX(オープン・ニューラル・ネットワーク交換)形式を使用すると、次のような重要なメリットがあります。

    • 相互運用性: ONNX 形式は異なるディープラーニングフレームワーク(PyTorch、TensorFlow など)間での転送をサポートし、幅広い互換性を確保します。
    • 最適化: Triton を含む多くのデプロイ環境は ONNX 向けに最適化されており、より高速な推論と高い性能を実現できます。
    • デプロイの容易さ: ONNX はフレームワークやプラットフォーム間で広くサポートされているため、さまざまなオペレーティングシステムやハードウェア構成でのデプロイプロセスを簡素化します。
    • フレームワークからの独立性: ONNX に変換すると、モデルは元のフレームワークに依存しなくなり、より高い移植性を実現できます。
    • 標準化: ONNX は標準化された表現を提供し、異なる AI フレームワーク間の互換性問題の解決に役立ちます。

    モデルをエクスポートするには、次を使用します。

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

    ONNX 統合ガイドの手順に従って、プロセスを完了できます。

  • はい、NVIDIA Triton Inference ServerUltralytics YOLO26 モデルを使用して推論を実行できます。モデルを Triton モデルリポジトリにセットアップし、サーバーを起動したら、次のようにモデルをロードして推論を実行できます。

    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")

    この方法により、使い慣れた Ultralytics YOLO インターフェースを使用しながら、Triton の最適化を活用できます。

  • デプロイにおいて、Ultralytics YOLO26 には TensorFlow および PyTorch モデルと比較して、次のような独自のメリットがあります。

    • リアルタイム性能: リアルタイム物体検出タスク向けに最適化された Ultralytics YOLO26 は、最先端の精度と速度を提供し、ライブ動画分析が必要なアプリケーションに最適です。
    • 使いやすさ: Ultralytics YOLO26 は Triton Inference Server とシームレスに統合でき、さまざまなエクスポート形式(ONNXTensorRT)をサポートするため、多様なデプロイシナリオに柔軟に対応できます。
    • 高度な機能: Tritonによるサービングには、動的なモデル読み込み、モデルのバージョニング、アンサンブル推論が追加され、これらはスケーラブルで信頼性の高いAIデプロイメントに不可欠です。
    • シンプルな API: Ultralytics API は異なるデプロイ先で一貫したインターフェースを提供し、学習曲線と開発時間を短縮します。
    • エッジ最適化: Ultralytics YOLO26 モデルはエッジデプロイを想定して設計されており、リソースに制約のあるデバイスでも優れた性能を発揮します。

    詳細については、モデルエクスポートガイドでデプロイオプションを比較してください。

コメント