Tensor Parallelism
テンソル並列処理がどのようにGPU間で重み行列を分割し、大規模モデルを学習させるかを学びましょう。Ultralyticsを活用して、データ並列処理との違いを探求します。
Tensor Parallelism is an advanced distributed training technique used in machine learning to divide large individual mathematical structures, or tensors, across multiple hardware accelerators such as GPUs or TPUs. When training massive deep learning models, the parameter count can easily exceed the memory capacity of a single device. Instead of placing an entire neural network layer on one GPU, tensor parallelism shards the weight matrices and splits the mathematical operations (like matrix multiplications) across multiple devices in a cluster. This allows the model to leverage the combined memory and compute power of the entire hardware setup, executing parallel computations in a Single-Program Multiple-Data (SPMD) paradigm while synchronizing the results via high-speed interconnects like NVIDIA NVLink.
Link to this sectionテンソル並列化の仕組み#
ニューラルネットワークの核心は行列乗算です。テンソル並列化では、行列を行方向または列方向に分割することでこれらの演算を分散させます。例えば、全結合層やTransformerのアテンションメカニズムでは、1つのGPUが行列の左半分を計算し、別のGPUが右半分を計算するといった処理を行います。並列計算が終了すると、デバイス間で通信が行われ(多くの場合、高速なAll-Reduce集合演算が使用されます)、部分的な結果を集約してから完全なテンソルを次のレイヤーに渡します。2025年の最近の学術的進歩では、大規模な計算クラスタでボトルネックとなりがちな通信オーバーヘッドを削減するため、部分的に同期されたアクティベーションを導入することでこのプロセスをさらに最適化しています。
Link to this section関連する並列化手法との違い#
テンソル並列化が分散コンピューティングの広範な状況においてどのような位置付けにあるかを理解するには、他の一般的な戦略との違いを知る必要があります。
- テンソル並列化 vs. モデル並列化: テンソル並列化は、モデル並列化の非常に特殊なサブカテゴリです。一般的なモデル並列化がモデルをデバイス間で任意の方法で分割することを指すのに対し、テンソル並列化は、単一レイヤー内部の個々のテンソルをシャーディングすることを厳密に指します。
- テンソル並列化 vs. パイプライン並列化: パイプライン並列化は、ネットワークを深さ方向に分割する別のモデル並列化形態であり、最初の数レイヤーをGPU 0に、次のレイヤーをGPU 1に配置するといった方法をとります。これにより、パイプラインバブルとして知られる逐次的な依存関係が生じます。一方、テンソル並列化はレイヤー自体を分割し、逐次的な遅延なしに同時に実行しますが、より高いネットワーク帯域幅を必要とします。
- テンソル並列化 vs. データ並列化: データ並列化では、モデル全体がすべてのGPUに完全に複製され、学習データセットのみがデバイス間で分割されます。Ultralytics YOLO26のように現代のGPUに容易に収まる高度に最適化されたアーキテクチャでは、PyTorchの
DistributedDataParallelを介したデータ並列化がデフォルトの方法です。テンソル並列化は通常、単一レイヤーのパラメータがハードウェアのVRAMを超過し、Out-of-Memory (OOM) エラーが発生する場合にのみ必要となります。
Link to this section現実世界のアプリケーション#
テンソル並列化は現代のAIインフラストラクチャにおいて不可欠であり、特に大規模な計算規模を必要とする最先端のアーキテクチャで重要です。
- 大規模言語モデル (LLM) の学習: MetaのLlama 3やDeepSeek V3のような巨大な基盤モデルは、テンソル並列化を実装するためにNVIDIA Megatron-LMのようなフレームワークを利用しています。これらのモデルの隠れ次元やアテンションヘッドは非常に巨大であるため、効率的に学習を行い、リアルタイム推論中に低レイテンシを維持するには、8-GPUノード間でそれらを分割することが必須となります。
- 大規模ビジョンモデル (LVM) および3D生成: コンピュータビジョンが大規模なマルチモーダル推論システムへとスケールするにつれ、研究者はAWS SageMakerのようなサービス上でテンソル並列化とパイプライン並列化を組み合わせ、巨大なビジョンTransformer (ViT) を学習させています。この手法により、膨大な連続メモリブロックを必要とする高解像度画像処理や動画生成が可能になります。
Link to this sectionPyTorchにおけるテンソル並列化の実装#
かつてエンジニアは、テンソルをシャーディングするために複雑なカスタム分散ロジックを作成する必要がありました。最近では、PyTorchがDTensor (Distributed Tensor) を導入したことで、このワークフローがネイティブに簡素化されました。以下は、公式PyTorch Distributed Tensor APIを使用して行方向にシャーディングされたテンソルを作成する例です。
import torch
from torch.distributed.device_mesh import init_device_mesh
from torch.distributed.tensor import Shard, distribute_tensor
# Initialize a 1D device mesh across 2 GPUs
mesh = init_device_mesh("cuda", (2,))
# Create a standard PyTorch tensor (e.g., representing a layer's weights)
local_tensor = torch.randn(1024, 1024)
# Distribute the tensor across the GPUs by sharding along the first dimension (row-wise)
# Each GPU now holds a (512, 1024) chunk of the original tensor
distributed_tensor = distribute_tensor(local_tensor, mesh, [Shard(0)])
print(f"Global shape: {distributed_tensor.shape}, Local shape: {distributed_tensor.to_local().shape}")For edge-optimized vision tasks and rapid model deployment, developers typically rely on the Ultralytics Platform to automatically handle optimal hardware utilization. While multi-billion parameter foundation models require manual tensor parallelism configurations, you can efficiently scale training for models like YOLO26 using simple CLI commands out-of-the-box. This ensures maximum throughput by seamlessly utilizing native data parallelism techniques alongside robust model training tips.






