Only do shallow clone when checkout nccl (#152826)

Note: `--depth` implies `--single-branch` since git 2.7.6

```sh
git clone https://github.com/NVIDIA/nccl.git
Cloning into 'nccl'...
remote: Enumerating objects: 4205, done.
remote: Counting objects: 100% (238/238), done.
remote: Compressing objects: 100% (122/122), done.
remote: Total 4205 (delta 144), reused 126 (delta 116), pack-reused 3967 (from 3)
Receiving objects: 100% (4205/4205), 4.22 MiB | 7.01 MiB/s, done.
Resolving deltas: 100% (2858/2858), done.
```
```sh
git clone --depth 1 --branch v2.25.1-1 https://github.com/NVIDIA/nccl.git
Cloning into 'nccl'...
remote: Enumerating objects: 249, done.
remote: Counting objects: 100% (249/249), done.
remote: Compressing objects: 100% (227/227), done.
remote: Total 249 (delta 31), reused 111 (delta 15), pack-reused 0 (from 0)
Receiving objects: 100% (249/249), 657.44 KiB | 2.14 MiB/s, done.
Resolving deltas: 100% (31/31), done.
Note: switching to '80f6bda4378b99d99e82b4d76a633791cc45fef0'.
```
Pull Request resolved: https://github.com/pytorch/pytorch/pull/152826
Approved by: https://github.com/albanD
This commit is contained in:
You Jiacheng 2025-05-06 04:56:19 +00:00 committed by PyTorch MergeBot
parent 97dfd8dd53
commit ee0cd1d8b5

View File

@ -99,10 +99,18 @@ def checkout_nccl() -> None:
nccl_basedir = os.path.join(third_party_path, "nccl")
if not os.path.exists(nccl_basedir):
subprocess.check_call(
["git", "clone", "https://github.com/NVIDIA/nccl.git", "nccl"],
[
"git",
"clone",
"--depth",
"1",
"--branch",
release_tag,
"https://github.com/NVIDIA/nccl.git",
"nccl",
],
cwd=third_party_path,
)
subprocess.check_call(["git", "checkout", release_tag], cwd=nccl_basedir)
def build_pytorch(