Skip to content

Commit ba04623

Browse files
committed
init
1 parent dbd0e9f commit ba04623

File tree

3 files changed

+164
-0
lines changed

3 files changed

+164
-0
lines changed

.ci/scripts/check_pytorch_pin.py

Lines changed: 116 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,116 @@
1+
#!/usr/bin/env python3
2+
# Copyright (c) Meta Platforms, Inc. and affiliates.
3+
# All rights reserved.
4+
#
5+
# This source code is licensed under the BSD-style license found in the
6+
# LICENSE file in the root directory of this source tree.
7+
8+
"""
9+
This script checks if the PyTorch commit hash in pytorch.txt matches
10+
the commit hash for the NIGHTLY_VERSION specified in torch_pin.py.
11+
12+
It uses functions from update_pytorch_pin.py to fetch the expected commit
13+
hash and compares it with the current pin.
14+
"""
15+
16+
import os
17+
import sys
18+
from pathlib import Path
19+
20+
# Add the parent directory to path to import update_pytorch_pin module
21+
repo_root = Path(__file__).resolve().parent.parent.parent
22+
sys.path.insert(0, str(repo_root / ".github" / "scripts"))
23+
24+
from update_pytorch_pin import (
25+
get_commit_hash_for_nightly,
26+
get_torch_nightly_version,
27+
parse_nightly_version,
28+
)
29+
30+
31+
def get_current_pytorch_commit():
32+
"""
33+
Read the current commit hash from .ci/docker/ci_commit_pins/pytorch.txt.
34+
35+
Returns:
36+
Current commit hash string
37+
"""
38+
pin_file = repo_root / ".ci" / "docker" / "ci_commit_pins" / "pytorch.txt"
39+
if not pin_file.exists():
40+
raise FileNotFoundError(f"Could not find {pin_file}")
41+
42+
with open(pin_file, "r") as f:
43+
commit_hash = f.read().strip()
44+
45+
if not commit_hash:
46+
raise ValueError(f"{pin_file} is empty")
47+
48+
return commit_hash
49+
50+
51+
def main():
52+
print("=" * 80)
53+
print("Checking PyTorch commit pin consistency")
54+
print("=" * 80)
55+
print()
56+
57+
try:
58+
# Get NIGHTLY_VERSION from torch_pin.py
59+
os.chdir(repo_root)
60+
nightly_version = get_torch_nightly_version()
61+
print(f"Nightly version: {nightly_version}")
62+
63+
# Parse to date string
64+
date_str = parse_nightly_version(nightly_version)
65+
print(f"Expected date: {date_str}")
66+
67+
# Get expected commit hash from PyTorch nightly branch
68+
print(f"Fetching commit hash for {date_str} from PyTorch nightly branch...")
69+
expected_commit = get_commit_hash_for_nightly(date_str)
70+
print(f"Expected commit hash: {expected_commit}")
71+
print()
72+
73+
# Get current commit hash from pytorch.txt
74+
current_commit = get_current_pytorch_commit()
75+
print(f"Current commit hash: {current_commit}")
76+
print()
77+
78+
# Compare commits
79+
print("=" * 80)
80+
print("Verification Result")
81+
print("=" * 80)
82+
print()
83+
84+
if expected_commit == current_commit:
85+
print("✓ SUCCESS: PyTorch commit pin matches the nightly version!")
86+
print()
87+
print(f"Commit {current_commit} corresponds to {nightly_version}")
88+
print()
89+
print(
90+
f"Reference: https://hud.pytorch.org/pytorch/pytorch/commit/{current_commit}"
91+
)
92+
return 0
93+
else:
94+
print("✗ ERROR: PyTorch commit pin does NOT match the nightly version!")
95+
print()
96+
print(f" Expected commit: {expected_commit}")
97+
print(f" Current commit: {current_commit}")
98+
print()
99+
print(f"The commit in .ci/docker/ci_commit_pins/pytorch.txt")
100+
print(f"does not correspond to NIGHTLY_VERSION={nightly_version}")
101+
print()
102+
print("To fix this, you can run:")
103+
print(f" python .github/scripts/update_pytorch_pin.py")
104+
print(
105+
"or manually update the commit hash in .ci/docker/ci_commit_pins/pytorch.txt"
106+
)
107+
print(f"with the expected commit hash {expected_commit}")
108+
return 1
109+
110+
except Exception as e:
111+
print(f"✗ ERROR: {e}", file=sys.stderr)
112+
return 1
113+
114+
115+
if __name__ == "__main__":
116+
sys.exit(main())

.ci/scripts/check_pytorch_pin.sh

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
#!/bin/bash
2+
# Copyright (c) Meta Platforms, Inc. and affiliates.
3+
# All rights reserved.
4+
#
5+
# This source code is licensed under the BSD-style license found in the
6+
# LICENSE file in the root directory of this source tree.
7+
8+
# This script checks if the PyTorch commit hash in pytorch.txt matches
9+
# the commit hash for the NIGHTLY_VERSION specified in torch_pin.py.
10+
#
11+
# It calls the Python script check_pytorch_pin.py which uses functions
12+
# from update_pytorch_pin.py to fetch the expected commit hash and
13+
# compare it with the current pin.
14+
15+
set -eu
16+
17+
# Get the directory of this script
18+
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
19+
20+
# Run the Python check script
21+
python3 "$SCRIPT_DIR/check_pytorch_pin.py"
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
name: check-pytorch-pin
2+
3+
on:
4+
pull_request:
5+
paths:
6+
- torch_pin.py
7+
- .ci/docker/ci_commit_pins/pytorch.txt
8+
- .ci/scripts/check_pytorch_pin.sh
9+
10+
concurrency:
11+
group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.sha }}-${{ github.event_name == 'workflow_dispatch' }}-${{ github.event_name == 'schedule' }}
12+
cancel-in-progress: true
13+
14+
jobs:
15+
check-pytorch-pin:
16+
permissions:
17+
id-token: write
18+
contents: read
19+
name: check-pytorch-pin
20+
runs-on: ubuntu-latest
21+
steps:
22+
- uses: actions/checkout@v3
23+
with:
24+
fetch-depth: 0
25+
- name: Check PyTorch Pin Consistency
26+
run: |
27+
.ci/scripts/check_pytorch_pin.sh

0 commit comments

Comments
 (0)