콘텐츠로 이동

Legato Collective Communication Library

Legato Collective Communication Library(lccl)는 HyperAccel LPU 디바이스 간의 집합 통신과 점대점 통신을 제공합니다. API가 NCCL을 따르므로 NCCL 기반 분산 코드를 최소한의 변경으로 옮길 수 있습니다.


스택 내 위치

lccl은 프레임워크 통합 계층(torch_ha) 아래, 런타임(hart) 위에 있습니다. 랭크 랑데부, 토폴로지, 전송 자체를 담당하며, 디바이스 메모리와 커널 실행은 hart의 몫입니다.

다이어그램

LPU에서 lccl을 쓰는 일반적인 경로는 torch.distributed의 lccl 백엔드입니다. torch_ha가 이 라이브러리를 대신 호출하므로 lccl의 API를 직접 부를 일이 없습니다. 이 문서는 그 아래의 라이브러리 자체, 즉 백엔드를 만들거나 프레임워크에 통합하는 사람을 위한 것입니다.


한눈에 보기

패키지 lccl (+hw 빌드)
버전 0.0.6
언어 C++ 코어, Python 바인딩
공개 헤더 lccl.h (lccl 패키지에 포함)
API 모델 NCCL 호환 명명과 시맨틱
전송 계층 P2P(같은 프로세스 안), 공유 메모리, TCP 소켓, ibverbs(InfiniBand, RoCE)
Python 3.10
플랫폼 Linux x86_64
상태 Beta

문서


시작하기

LPU에서 torch.distributed로. 한 서버에서 랭크당 프로세스 하나가 자기 카드를 고른 뒤 lccl 백엔드로 프로세스 그룹을 만듭니다.

1
2
3
4
5
6
7
8
import torch
import torch.distributed as dist

torch.accelerator.set_device_index(local_rank)   # 프로세스 그룹을 만들기 전에 카드를 고릅니다
dist.init_process_group(backend="lccl")

x = torch.randn(32, 1024, dtype=torch.bfloat16).to("lpu")
dist.all_reduce(x, op=dist.ReduceOp.SUM)

실행 방법과 병렬화 패턴은 분산에 있습니다.

lccl을 직접. 고유 ID를 만들어 나누고, 랭크마다 디바이스를 고른 뒤 커뮤니케이터를 만드는 전체 순서는 프로그래밍 가이드의 첫 프로그램에 있습니다.


설계 전에 반드시 확인할 것

lccl은 beta이며 지원 범위가 고르지 않습니다. 다음은 설계 판단을 바꿉니다.

연산 × 리덕션 × 데이터 타입 조합이 전부 구현되어 있지는 않습니다

등록된 커널이 없는 조합은 대개 호출한 지점에서 kLcclNotSupported로 거부됩니다. 조용히 성공을 반환하지도, 조용히 잘못된 데이터를 만들지도 않습니다. 다만 NCCL에서 동작하던 코드가 여기서는 실패할 수 있다는 뜻입니다. 설계를 확정하기 전에 워크로드가 실제로 사용하는 조합을 지원 매트릭스와 대조하십시오.

LPU에는 제약이 있습니다

LPU에서는 모든 집합 연산과 LcclSend/LcclRecv가 장치 커널로 실행됩니다. 다만 리덕션은 Float16과 Bfloat16만 되고, LcclBroadcast, LcclReduce, LcclGather, LcclScatter, LcclSend/LcclRecv는 바이트 수를 512의 배수로 맞춰야 합니다. 커뮤니케이터는 랭크 16개까지입니다. 이를 벗어난 호출은 kLcclNotSupported로 거부됩니다. LcclAllToAll의 count와 LcclReduceScatter의 recv_count도 바이트 수가 512의 배수여야 하며, 맞지 않으면 kLcclInvalidArgument로 거부됩니다. 연산별 크기 규칙은 지원 매트릭스에 있습니다.

집합 연산은 스트림과 순서를 맺지 않습니다

그룹 밖에서 호출한 집합 연산은 반환될 때 이미 끝나 있습니다. 대신 호출 전에 스트림에 큐잉해 둔 작업을 기다린다는 보장이 없으므로, 송신 버퍼를 만든 작업을 직접 동기화한 뒤 호출해야 합니다. 집합 연산을 보십시오.


설치

드라이버 설치와 SDK 컨테이너 이미지는 SDK 설치 가이드를 참고하십시오. 다만 SDK 컨테이너 이미지에는 lccl 패키지가 들어 있지 않으므로, 그 이미지에서 lccl API를 직접 부르려면(import lccl, lccl.h) 아래 표와 같이 설치하십시오.

lccl은 같은 버전의 hart와 함께 같은 Python 환경에 설치하고, 두 패키지 모두 ===로 버전을 정확히 지정하십시오. PyPI에는 이름만 같은 무관한 hart 패키지가 있어서, hart의 버전을 지정하지 않으면 그 패키지가 설치될 수 있습니다.

실행 환경 설치할 패키지
LPU lccl===<버전>+hw, hart===<버전>+hw

Python 코드에서 로그 레벨과 로그 파일을 정하는 halogger는 별도 패키지이므로, lccl과 hart만 설치했다면 halogger===<버전>도 설치하십시오. halogger에는 +hw 빌드가 없으니 +hw를 붙이지 마십시오.


호환성

이 문서는 lccl 0.0.6 기준입니다.

검증된 버전
Python 3.10
Runtime (hart) 0.0.6
PyTorch 2.10.0

자세한 내용은 지원 매트릭스에 있습니다.


서드파티 라이선스

lccl은 NVIDIA NCCL의 코드를 바탕으로 만들었고, ibverbs 전송 계층에 rdma-core(libibverbs)에서 온 코드가 들어 있으며, Python 바인딩에 pybind11을 씁니다. 세 구성요소의 라이선스 고지는 아래와 같습니다. NCCL과 rdma-core 고지는 torch_ha에 들어 있는 LCCL에도 적용됩니다. lccl 패키지의 dist-info/licenses/에도 같은 파일이 들어 있습니다.

NCCL (BSD-3-Clause)
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
 Copyright (c) 2015-2020, NVIDIA CORPORATION. All rights reserved.

 Redistribution and use in source and binary forms, with or without
 modification, are permitted provided that the following conditions
 are met:
  * Redistributions of source code must retain the above copyright
    notice, this list of conditions and the following disclaimer.
  * Redistributions in binary form must reproduce the above copyright
    notice, this list of conditions and the following disclaimer in the
    documentation and/or other materials provided with the distribution.
  * Neither the name of NVIDIA CORPORATION, Lawrence Berkeley National
    Laboratory, the U.S. Department of Energy, nor the names of their
    contributors may be used to endorse or promote products derived
    from this software without specific prior written permission.

 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ``AS IS'' AND ANY
 EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
 IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
 PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE COPYRIGHT OWNER OR
 CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
 EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
 PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
 PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
 OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
 (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
 OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

 The U.S. Department of Energy funded the development of this software
 under subcontract 7078610 with Lawrence Berkeley National Laboratory.


This code also includes files from the NVIDIA Tools Extension SDK project.

See:

   https://github.com/NVIDIA/NVTX

for more information and license details.
rdma-core (OpenIB.org BSD)
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
Copyright (c) 2004, 2005 Topspin Communications.  All rights reserved.
Copyright (c) 2004, 2011-2012 Intel Corporation.  All rights reserved.
Copyright (c) 2005, 2006, 2007 Cisco Systems, Inc.  All rights reserved.
Copyright (c) 2005 PathScale, Inc.  All rights reserved.

This software is available to you under the OpenIB.org BSD license below:

    Redistribution and use in source and binary forms, with or
    without modification, are permitted provided that the following
    conditions are met:

     - Redistributions of source code must retain the above
       copyright notice, this list of conditions and the following
       disclaimer.

     - Redistributions in binary form must reproduce the above
       copyright notice, this list of conditions and the following
       disclaimer in the documentation and/or other materials
       provided with the distribution.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
pybind11 (BSD-3-Clause)
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
Copyright (c) 2016 Wenzel Jakob <wenzel.jakob@epfl.ch>, All rights reserved.

Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:

1. Redistributions of source code must retain the above copyright notice, this
   list of conditions and the following disclaimer.

2. Redistributions in binary form must reproduce the above copyright notice,
   this list of conditions and the following disclaimer in the documentation
   and/or other materials provided with the distribution.

3. Neither the name of the copyright holder nor the names of its contributors
   may be used to endorse or promote products derived from this software
   without specific prior written permission.

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

Please also refer to the file .github/CONTRIBUTING.md, which clarifies licensing of
external contributions to this project including patches, pull requests, etc.