Pipeline Parallelism
パイプライン並列処理がどのようにディープラーニングモデルを複数のGPUに分割するかを学びましょう。メモリ不足エラーを回避し、分散学習を最適化する方法について解説します。
Pipeline Parallelism is an advanced distributed training technique designed to partition a large neural network (NN) across multiple computing devices, such as GPUs, by separating the model depth-wise. When a modern architecture's model weights and optimizer states exceed the memory limits of a single accelerator, engineers split the network's sequential layers into "stages." For example, the first 10 layers might reside on GPU 0, while the subsequent 10 layers reside on GPU 1. During the forward pass, data flows from one device to the next. By chaining these devices together, researchers can train massive deep learning (DL) algorithms without encountering hardware-limiting out-of-memory errors.
Link to this sectionパイプライン並列化の仕組み#
デバイス間でレイヤーを単純に分割する実装では、「パイプラインバブル」と呼ばれる深刻な非効率性が生じます。レイヤーは順次処理されるため、GPU 0が最初のレイヤーを処理している間、GPU 1は完全にアイドル状態になります。ハードウェアの稼働率を最大化するために、最新のパイプラインスケジューラーでは、グローバルなバッチサイズを小さな「マイクロバッチ」に分割します。
バッチ全体が完了するのを待つのではなく、GPU 0は最初のマイクロバッチをGPU 1に渡すとすぐに、2つ目のマイクロバッチの処理を開始します。Microsoft DeepSpeedやPyTorch Distributed Pipelining APIなどのツールでは、1F1B (One Forward, One Backward) スケジューリング戦略が一般的に使用されます。この手法は、異なるマイクロバッチのフォワードパスとバックワードパスの計算を交互に同時並行で行うことで、パイプラインバブルとメモリ消費を大幅に最小化します。2024年から2025年にかけての最近の進歩では、計算クラスター全体のアイドル時間をほぼ解消するオプティマイザーを意識した重み予測戦略であるZero Bubble Pipeline Parallelismも導入されています。
Link to this section関連する並列化手法との違い#
パイプライン並列化は、分散コンピューティング戦略というより広範なエコシステムの中で機能します。AIモデルを効率的にスケーリングするには、その違いを理解することが不可欠です。
- モデル並列化: これは、モデルを複数のデバイスに分割するための包括的な用語です。パイプライン並列化は、アーキテクチャを深さ方向に順次パーティション分割する、モデル並列化の非常に特殊な形態です。
- テンソル並列化: パイプライン並列化の深さ方向の分割とは異なり、テンソル並列化では個々の行列演算をGPU間で水平方向にシャーディングします。これら2つの手法は、スループットを最大化するために頻繁に組み合わされます。
- Data Parallelism: Data parallelism replicates the entire model on every GPU and distributes the training data among them. For compact, highly optimized object detection and image segmentation architectures like the Ultralytics YOLO26 model, which natively fits into a single device's VRAM, data parallelism via PyTorch's DistributedDataParallel (DDP) is the preferred method to accelerate training.
Link to this sectionAIおよびMLにおける実用的な応用#
複雑なインフラストラクチャのスケールアップは、最新の最先端AIシステムを構築するために不可欠です。
- Training Foundation Models: Developing gigantic Large Language Models (LLMs) and foundation models like Meta's Llama 3 requires combining tensor, data, and pipeline parallelism. Frameworks like NVIDIA Megatron-LM leverage these strategies to train massive Mixture-of-Experts (MoE) architectures across thousands of GPUs on cloud platforms like AWS SageMaker.
- 高解像度の医療診断: ヘルスケアにおけるAIや科学モデリングにおいて、3Dボリュームスキャンは、1つのアクセラレータでは処理しきれないほど巨大なアクティベーションを生成することがあります。ネットワークレイヤーをノード間でパイプライン化することで、研究病院は画像解像度を損なうことなく、巨大なMRIデータセットでディープネットワークを学習させることが可能になります。
Link to this sectionコード例: レイヤー分割の概念#
歴史的に、デバイス間でレイヤーを分散させるには複雑でカスタムのコードが必要でした。現在、基本的なロジックは特定のレイヤーを異なるデバイスIDにマッピングすることです。以下は、パイプライン並列運用の基礎となる、PyTorchにおけるネットワークステージをデバイス間で分割する方法の概念的な表現です。
import torch.nn as nn
class SimplePipelineModel(nn.Module):
def __init__(self):
super().__init__()
# Stage 1 is assigned to the first GPU
self.stage1 = nn.Sequential(nn.Linear(1024, 1024), nn.ReLU()).to("cuda:0")
# Stage 2 is assigned to the second GPU
self.stage2 = nn.Sequential(nn.Linear(1024, 1024), nn.ReLU()).to("cuda:1")
def forward(self, x):
# The forward pass seamlessly crosses device boundaries
x_out = self.stage1(x.to("cuda:0"))
return self.stage2(x_out.to("cuda:1"))基盤モデルの作成には複雑なオーケストレーションが必要ですが、迅速でスケーラブルなコンピュータビジョン (CV)プロジェクトのデプロイは通常よりシンプルです。合理化されたモデルデプロイと自動化されたマルチGPU利用のために、開発者はUltralytics Platformを信頼してワークロードを自動的にスケーリングしています。堅牢なモデル学習のヒントを活用することで、プラットフォームはインフラストラクチャ管理を抽象化し、エンジニアがリアルタイム推論が可能な精度の高いAIソリューションの構築に完全に集中できるようにします。






