Skip to content

Commit

Permalink
Update
Browse files Browse the repository at this point in the history
[ghstack-poisoned]
  • Loading branch information
XuehaiPan committed Jun 18, 2024
2 parents 58e00f2 + 7b62971 commit 9f26069
Show file tree
Hide file tree
Showing 384 changed files with 7,932 additions and 5,959 deletions.
2 changes: 1 addition & 1 deletion .ci/pytorch/common_utils.sh
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,7 @@ function clone_pytorch_xla() {
function checkout_install_torchbench() {
local commit
commit=$(get_pinned_commit torchbench)
git clone https://github.com/eellison/benchmark torchbench
git clone https://github.com/pytorch/benchmark torchbench
pushd torchbench
git checkout "$commit"

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ test_cpu_speed_mini_sequence_labeler () {
export OMP_NUM_THREADS=4
export MKL_NUM_THREADS=4

git clone https://github.com/eellison/benchmark.git
git clone https://github.com/pytorch/benchmark.git

cd benchmark/

Expand Down
2 changes: 1 addition & 1 deletion .ci/pytorch/perf_test/test_gpu_speed_cudnn_lstm.sh
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ test_gpu_speed_cudnn_lstm () {
export OMP_NUM_THREADS=4
export MKL_NUM_THREADS=4

git clone https://github.com/eellison/benchmark.git
git clone https://github.com/pytorch/benchmark.git

cd benchmark/

Expand Down
2 changes: 1 addition & 1 deletion .ci/pytorch/perf_test/test_gpu_speed_lstm.sh
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ test_gpu_speed_lstm () {
export OMP_NUM_THREADS=4
export MKL_NUM_THREADS=4

git clone https://github.com/eellison/benchmark.git
git clone https://github.com/pytorch/benchmark.git

cd benchmark/

Expand Down
2 changes: 1 addition & 1 deletion .ci/pytorch/perf_test/test_gpu_speed_mlstm.sh
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ test_gpu_speed_mlstm () {
export OMP_NUM_THREADS=4
export MKL_NUM_THREADS=4

git clone https://github.com/eellison/benchmark.git
git clone https://github.com/pytorch/benchmark.git

cd benchmark/

Expand Down
2 changes: 1 addition & 1 deletion .github/ci_commit_pins/torchbench.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
pin_yolo_dep
0dab1dd97709096e8129f8a08115ee83f64f2194
114 changes: 102 additions & 12 deletions .github/scripts/cherry_pick.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@
import json
import os
import re
from typing import Any, Optional
from typing import Any, cast, Dict, List, Optional

from urllib.error import HTTPError

from github_utils import gh_fetch_url, gh_post_pr_comment
from github_utils import gh_fetch_url, gh_post_pr_comment, gh_query_issues_by_labels

from gitutils import get_git_remote_name, get_git_repo_dir, GitRepo
from trymerge import get_pr_commit_sha, GitHubPR
Expand All @@ -19,6 +19,7 @@
"critical",
"fixnewfeature",
}
RELEASE_BRANCH_REGEX = re.compile(r"release/(?P<version>.+)")


def parse_args() -> Any:
Expand Down Expand Up @@ -58,6 +59,33 @@ def get_merge_commit_sha(repo: GitRepo, pr: GitHubPR) -> Optional[str]:
return commit_sha if pr.is_closed() else None


def get_release_version(onto_branch: str) -> Optional[str]:
"""
Return the release version if the target branch is a release branch
"""
m = re.match(RELEASE_BRANCH_REGEX, onto_branch)
return m.group("version") if m else ""


def get_tracker_issues(
org: str, project: str, onto_branch: str
) -> List[Dict[str, Any]]:
"""
Find the tracker issue from the repo. The tracker issue needs to have the title
like [VERSION] Release Tracker following the convention on PyTorch
"""
version = get_release_version(onto_branch)
if not version:
return []

tracker_issues = gh_query_issues_by_labels(org, project, labels=["release tracker"])
if not tracker_issues:
return []

# Figure out the tracker issue from the list by looking at the title
return [issue for issue in tracker_issues if version in issue.get("title", "")]


def cherry_pick(
github_actor: str,
repo: GitRepo,
Expand All @@ -77,17 +105,49 @@ def cherry_pick(
)

try:
org, project = repo.gh_owner_and_name()

cherry_pick_pr = ""
if not dry_run:
org, project = repo.gh_owner_and_name()
cherry_pick_pr = submit_pr(repo, pr, cherry_pick_branch, onto_branch)

msg = f"The cherry pick PR is at {cherry_pick_pr}"
if fixes:
msg += f" and it is linked with issue {fixes}"
elif classification in REQUIRES_ISSUE:
msg += f" and it is recommended to link a {classification} cherry pick PR with an issue"
tracker_issues_comments = []
tracker_issues = get_tracker_issues(org, project, onto_branch)
for issue in tracker_issues:
issue_number = int(str(issue.get("number", "0")))
if not issue_number:
continue

res = cast(
Dict[str, Any],
post_tracker_issue_comment(
org,
project,
issue_number,
pr.pr_num,
cherry_pick_pr,
classification,
fixes,
dry_run,
),
)

comment_url = res.get("html_url", "")
if comment_url:
tracker_issues_comments.append(comment_url)

post_comment(org, project, pr.pr_num, msg)
msg = f"The cherry pick PR is at {cherry_pick_pr}"
if fixes:
msg += f" and it is linked with issue {fixes}."
elif classification in REQUIRES_ISSUE:
msg += f" and it is recommended to link a {classification} cherry pick PR with an issue."

if tracker_issues_comments:
msg += " The following tracker issues are updated:\n"
for tracker_issues_comment in tracker_issues_comments:
msg += f"* {tracker_issues_comment}\n"

post_pr_comment(org, project, pr.pr_num, msg, dry_run)

finally:
if current_branch:
Expand Down Expand Up @@ -159,7 +219,9 @@ def submit_pr(
raise RuntimeError(msg) from error


def post_comment(org: str, project: str, pr_num: int, msg: str) -> None:
def post_pr_comment(
org: str, project: str, pr_num: int, msg: str, dry_run: bool = False
) -> List[Dict[str, Any]]:
"""
Post a comment on the PR itself to point to the cherry picking PR when success
or print the error when failure
Expand All @@ -182,7 +244,35 @@ def post_comment(org: str, project: str, pr_num: int, msg: str) -> None:
comment = "\n".join(
(f"### Cherry picking #{pr_num}", f"{msg}", "", f"{internal_debugging}")
)
gh_post_pr_comment(org, project, pr_num, comment)
return gh_post_pr_comment(org, project, pr_num, comment, dry_run)


def post_tracker_issue_comment(
org: str,
project: str,
issue_num: int,
pr_num: int,
cherry_pick_pr: str,
classification: str,
fixes: str,
dry_run: bool = False,
) -> List[Dict[str, Any]]:
"""
Post a comment on the tracker issue (if any) to record the cherry pick
"""
comment = "\n".join(
(
"Link to landed trunk PR (if applicable):",
f"* https://github.com/{org}/{project}/pull/{pr_num}",
"",
"Link to release branch PR:",
f"* {cherry_pick_pr}",
"",
"Criteria Category:",
" - ".join((classification.capitalize(), fixes.capitalize())),
)
)
return gh_post_pr_comment(org, project, issue_num, comment, dry_run)


def main() -> None:
Expand Down Expand Up @@ -214,7 +304,7 @@ def main() -> None:

except RuntimeError as error:
if not args.dry_run:
post_comment(org, project, pr_num, str(error))
post_pr_comment(org, project, pr_num, str(error))
else:
raise error

Expand Down
9 changes: 9 additions & 0 deletions .github/scripts/github_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -202,3 +202,12 @@ def gh_update_pr_state(org: str, repo: str, pr_num: int, state: str = "open") ->
)
else:
raise


def gh_query_issues_by_labels(
org: str, repo: str, labels: List[str], state: str = "open"
) -> List[Dict[str, Any]]:
url = f"{GITHUB_API_URL}/repos/{org}/{repo}/issues"
return gh_fetch_json(
url, method="GET", params={"labels": ",".join(labels), "state": state}
)

0 comments on commit 9f26069

Please sign in to comment.