Commit Graph

34 Commits

Author SHA1 Message Date
895316119d Revert "[BE][Easy] use pathlib.Path instead of dirname / ".." / pardir (#129374)"
This reverts commit 0314c4c101c44d5d89b4fad9d37a012dc6f31128.

Reverted https://github.com/pytorch/pytorch/pull/129374 on behalf of https://github.com/huydhn due to Sorry for reverting your change but it causes lots of internal build failures where they fail to find hipify module ([comment](https://github.com/pytorch/pytorch/pull/129374#issuecomment-2192437052))
2024-06-26 19:03:57 +00:00
0314c4c101 [BE][Easy] use pathlib.Path instead of dirname / ".." / pardir (#129374)
Changes by apply order:

1. Replace all `".."` and `os.pardir` usage with `os.path.dirname(...)`.
2. Replace nested `os.path.dirname(os.path.dirname(...))` call with `str(Path(...).parent.parent)`.
3. Reorder `.absolute()` ~/ `.resolve()`~ and `.parent`: always resolve the path first.

    `.parent{...}.absolute()` -> `.absolute().parent{...}`

4. Replace chained `.parent x N` with `.parents[${N - 1}]`: the code is easier to read (see 5.)

    `.parent.parent.parent.parent` -> `.parents[3]`

5. ~Replace `.parents[${N - 1}]` with `.parents[${N} - 1]`: the code is easier to read and does not introduce any runtime overhead.~

    ~`.parents[3]` -> `.parents[4 - 1]`~

6. ~Replace `.parents[2 - 1]` with `.parent.parent`: because the code is shorter and easier to read.~

Pull Request resolved: https://github.com/pytorch/pytorch/pull/129374
Approved by: https://github.com/justinchuby, https://github.com/malfet
2024-06-25 08:28:38 +00:00
5acd1f0f7d Add cherry-pick workflow (#119352)
After https://github.com/pytorch/test-infra/pull/4758, we can create a new workflow on PyTorch to receive `try-cherry-pick` dispatch event from the bot, and create the cherry pick PR.

* [x] Cherry pick a PR after it has been landed and create a cherry pick PR to the target release branch.
* [ ] The second part after this is to update the release tracker with the info.  This will be done in a subsequent PR.
* [ ] ghstack is not yet supported
* [ ] Cherry pick a reverted commit is not yet supported (from @kit1980 comment)

### Testing

The script can be used locally:

```
python cherry_pick.py --onto release/2.2 --classification release --github-actor huydhn 118907
The cherry pick PR is at https://github.com/pytorch/pytorch/pull/119351
```

The test cherry pick PR is created at https://github.com/pytorch/pytorch/pull/119351

Unit testing this on CI is tricky, so I test this out on canary instead.

* https://github.com/pytorch/pytorch-canary/pull/193#issuecomment-1933162707 creates the PR at https://github.com/pytorch/pytorch-canary/pull/201
  * One more test on canary with the new token https://github.com/pytorch/pytorch-canary/pull/193#issuecomment-1933229483.  The minimum required permission from what I see is `workflow`
* Cherry picking conflicts could happen and needs to be handled manually https://github.com/pytorch/pytorch-canary/pull/194#issuecomment-1933142975
* ~Require a linked issue when cherry picking regressions, critical fixes, or fixing new features https://github.com/pytorch/pytorch-canary/pull/193#issuecomment-1933174520~ Relax this requirement to a suggestion
Pull Request resolved: https://github.com/pytorch/pytorch/pull/119352
Approved by: https://github.com/atalman
2024-02-12 23:12:10 +00:00
b599f5608c Fix mergeability check for ghstack PRs (#118258)
# Changes
* introduce `--check-mergeability` trymerge flag that attempts to merge PR locally, using the same merge logic as the mergebot, but requires just a read-only `GITHUB_TOKEN` and git repo.
* change mergeability workflow to utilize the new --check-mergeability logic

# Alternatives considered

1.
> Rewrite `https://github.com/pytorch/test-infra/actions/workflows/pr-dependencies-check.yml` to correctly support partially merged ghstacks.

That would be a slightly better approach, but ROI is lower, as it requires reimplementing trymerge logic and additional effort to consolidate the codebase (trymerge lives in pytorch repo).

`pr-dependencies-check.yml` still produces human-readable results for partially merged ghstack prs (even if it falsely reports them as non-mergeable).

2.

> Instead of introducing new trymerge flag, use existing flags, including `--dry-run`.

That didn't work, as no combination of existing flags skips the rule checks and ROCKSET lookups.

# Testing

1. Manual testing  `trymerge.py --check-mergeability`  on the regular and ghstack PRs:

```
export GITHUB_TOKEN=
export GIT_REPO_DIR=`pwd`
export GITHUB_REPOSITORY=pytorch/pytorch
export GIT_REMOTE_URL=https://github.com/pytorch/pytorch

# Test 1 (2 prs, 1 is closed)
python3 ../pytorch/.github/scripts/trymerge.py --check-mergeability  117862
Skipping 1 of 2 PR (#117859) as its already been merged

echo $?
0

# Test 2 (3 prs, 1 is closed)
python3 ../pytorch/.github/scripts/trymerge.py --check-mergeability  118125
Skipping 1 of 3 PR (#117859) as its already been merged

echo $?
0

# Test 3 (3 prs, intentional conflicts introduced into `main`):

python3 ../pytorch/.github/scripts/trymerge.py --check-mergeability  118125
Skipping 1 of 3 PR (#117859) as its already been merged
stdout:
Auto-merging torch/_inductor/ir.py
Auto-merging torch/_inductor/lowering.py
CONFLICT (content): Merge conflict in torch/_inductor/lowering.py
error: could not apply 66ba5b8792f... Realize inputs to DynamicScalar before unwrapping
...
RuntimeError: Command `git -C /Users/ivanzaitsev/pytorch2 cherry-pick -x 66ba5b8792fa076c4e512d920651e5b6b7e466f4` returned non-zero exit code 1
```

2.  Workflow run:
https://github.com/pytorch/pytorch/actions/runs/7660736172/job/20878651852?pr=118258

<img width="516" alt="image" src="https://github.com/pytorch/pytorch/assets/108101595/28fbf0d2-ac2a-4518-b41d-b32b41373747">
<img width="621" alt="image" src="https://github.com/pytorch/pytorch/assets/108101595/ddbf8566-a417-43ec-9d0e-f623f4a71313">

Pull Request resolved: https://github.com/pytorch/pytorch/pull/118258
Approved by: https://github.com/PaliC, https://github.com/huydhn
2024-01-26 03:15:56 +00:00
0f0020d76f [GHF] Add support for new style stacks (#116873)
Where base stack targets default branch, rather than base. But as
default branch is likely to advance, since PR was made, search for
mergebase before determining whether `base`..`head` are in sync with `orig` branch
Also, rather than hardcode default branch name, fetch it from `GitHubPR.default_branch()`

Test Plan: https://github.com/malfet/deleteme/pull/77

Pull Request resolved: https://github.com/pytorch/pytorch/pull/116873
Approved by: https://github.com/ezyang
2024-01-05 20:32:24 +00:00
5fcc2519f5 [GHF] Refactors (#116446)
Prep change for allowing stacked reverts

This is a no-op that factors out some helper function that would be
useful later:
 - `get_pr_commit_sha` finds a committed sha for a given PR
 - `_revlist_to_prs` converts a revlist to GitHubPRs conditionally
   filtering some out
 - `do_revert_prs` reverts multiple PRs in a batch, but so far is
   invoked with only one PR
Pull Request resolved: https://github.com/pytorch/pytorch/pull/116446
Approved by: https://github.com/huydhn, https://github.com/seemethere
2023-12-27 23:01:16 +00:00
52d4b1ae31 [BE]: Enable ruff rules PIE807 and PIE810 (#106218)
* Enables PIE807 + PIE810. PIE807 is do not reimplement list builtin function using lambda and PIE810 is to always fuse startswith / endswith calls (I applied the autofixes for this before we had ruff enabled).
Pull Request resolved: https://github.com/pytorch/pytorch/pull/106218
Approved by: https://github.com/albanD
2023-07-28 22:35:56 +00:00
57f23ca58b Bot message changes for -f and rebase (#106150)
* Encourage people to use -i instead of -f for mergebot
* Add additional info for when rebase fails due to lacking permissions

<details><summary>dryrun</summary>

````
csl@csl-mbp ~/zzzzzzzz/pytorch [csl/errormsgs] $
(forpytorch) python3 .github/scripts/tryrebase.py 106089 --branch viable/strict --dry-run
+ git -C /Users/csl/zzzzzzzz/pytorch rev-parse --verify refs/remotes/origin/viable/strict
@pytorchbot started a rebase job onto [refs/remotes/origin/viable/strict](7c97c943fb). Check the current status [here](None)
+ git -C /Users/csl/zzzzzzzz/pytorch fetch origin pull/106089/head:pull/106089/head
+ git -C /Users/csl/zzzzzzzz/pytorch rebase refs/remotes/origin/viable/strict pull/106089/head
+ git -C /Users/csl/zzzzzzzz/pytorch rev-parse --verify pull/106089/head
+ git -C /Users/csl/zzzzzzzz/pytorch rev-parse --verify refs/remotes/origin/viable/strict
+ git -C /Users/csl/zzzzzzzz/pytorch push --dry-run -f https://github.com/Lightning-Sandbox/pytorch.git pull/106089/head:fix/spaces
stdout:
remote: Permission to Lightning-Sandbox/pytorch.git denied to clee2000.
fatal: unable to access 'https://github.com/Lightning-Sandbox/pytorch.git/': The requested URL returned error: 403

stderr:

Rebase failed due to Command `git -C /Users/csl/zzzzzzzz/pytorch push --dry-run -f https://github.com/Lightning-Sandbox/pytorch.git pull/106089/head:fix/spaces` returned non-zero exit code 128
```
remote: Permission to Lightning-Sandbox/pytorch.git denied to clee2000.
fatal: unable to access 'https://github.com/Lightning-Sandbox/pytorch.git/': The requested URL returned error: 403
```
This is likely because the author did not allow edits from maintainers on the PR or because the repo has additional permissions settings that mergebot does not qualify.
````
</details>
Pull Request resolved: https://github.com/pytorch/pytorch/pull/106150
Approved by: https://github.com/huydhn
2023-07-28 16:13:51 +00:00
568bac7961 [BE][GHF] Add retries_decorator (#101227)
I've noticed that 3-4 functions in trymerge are trying to implement similar tail recursion for flaky network retries.

Unify them using single wrapper in `gitutils.py`

<!--
copilot:poem
-->
### <samp>🤖 Generated by Copilot at 8d40631</samp>

> _`retries_decorator`_
> _adds resilience to GitHub scripts_
> _autumn of errors_
Pull Request resolved: https://github.com/pytorch/pytorch/pull/101227
Approved by: https://github.com/kit1980
2023-05-12 20:29:06 +00:00
02f152626c Fix typos in error message (#101231)
Pull Request resolved: https://github.com/pytorch/pytorch/pull/101231
Approved by: https://github.com/huydhn
2023-05-12 01:34:55 +00:00
4c0dce50fd [BE] Apply ufmt to run_test and GitHub Python util scripts (#97588)
This has been bugging me for a while as I'm working on these Python scripts and they are not tracked by ufmt linter.  So I add these script into that linter.

```
[[linter]]
code = 'UFMT'
include_patterns = [
    '.github/**/*.py',
    'test/run_test.py',
```

This change should just work and not break anything as ufmt (black + usort) linter is very safe to use for standalone util scripts.
Pull Request resolved: https://github.com/pytorch/pytorch/pull/97588
Approved by: https://github.com/kit1980
2023-03-26 04:52:55 +00:00
7a621c443b [GHF] Fix ghstack branches in sync logic (#93298)
Test plan:
```python
from git_utils import are_ghstack_branches_in_sync,GitRepo
repo=GitRepo("/Users/nshulga/git/pytorch/pytorch")
are_ghstack_branches_in_sync(repo, "gh/SS-JIA/206/head")
```

Pull Request resolved: https://github.com/pytorch/pytorch/pull/93298
Approved by: https://github.com/clee2000, https://github.com/ZainRizvi
2023-01-30 21:00:51 +00:00
c67a4d8a65 [GH1] replace globs with patterns that mergebot can process (#81414)
https://github.com/pytorch/pytorch/pull/81330#issuecomment-1182345751 shouldn't have happened and should have matched the linalg rule.

The reason it happened is cuz we don't treat the patterns like globs.

We may follow this up with a BE change to make the patterns be treated more like globs, which I expected originally.
Pull Request resolved: https://github.com/pytorch/pytorch/pull/81414
Approved by: https://github.com/malfet
2022-07-19 16:11:32 +00:00
2fc1725938 [GHF] Retry push unconditionally (#77426)
Pull Request resolved: https://github.com/pytorch/pytorch/pull/77426
Approved by: https://github.com/seemethere
2022-05-13 17:09:01 +00:00
e14f5336c0 Fix syncbranches (#76693)
Summary:
Skip
84d9a2e42d
and its revert
f211ec90a6
from syncbranches

Fixes #ISSUE_NUMBER

Pull Request resolved: https://github.com/pytorch/pytorch/pull/76693

Reviewed By: osalpekar

Differential Revision: D36079190

Pulled By: malfet

fbshipit-source-id: b9b8e35a27e57c7c3eb79839c2cf4df35e7443bd
(cherry picked from commit bd40bd40db65a0dbb3a43f3c323a4d68dc9406ea)
2022-05-02 22:07:42 +00:00
0bd8e237b5 rebase via comment
Fixes #ISSUE_NUMBER

start rebase bot

random testing on my fork, using `on: issue_comment` https://github.com/clee2000/pytorch/pull/6

stealing both code and an identity from mergebot

corresponding pr on test-infra https://github.com/pytorch/test-infra/pull/305

doesnt do ghstack

should accept "@pytorchbot rebase me", "@pytorchbot rebase this", "@pytorchmergebot rebase this"
Pull Request resolved: https://github.com/pytorch/pytorch/pull/76262
Approved by: https://github.com/janeyx99, https://github.com/seemethere
2022-04-27 00:55:05 +00:00
48ea440b15 ci: Unblock syncbranches, add a58c6ae and 7106d21 to block list (#76417)
Summary:
Adds a58c6aea5a0c9f8759a4154e46f544c8b03b8db1 and 7106d216c29ca16a3504aa2bedad948ebcf4abc2 to the list of excluded
commits since this was landed through phab and cherry picked to master
directly

Signed-off-by: Eli Uriegas <eliuriegas@fb.com>

Pull Request resolved: https://github.com/pytorch/pytorch/pull/76417

Reviewed By: janeyx99

Differential Revision: D35951416

Pulled By: seemethere

fbshipit-source-id: 30a226c381e0cebfccc82f7ccfa7ce79075220c9
(cherry picked from commit b75fbe3b9e8024734e749a42464620c1879265ad)
2022-04-26 23:54:22 +00:00
25d5b63acf [GHF] Skip b3aa2de (#76231)
Summary:
Difference between were b5222584e6 and 69e048b090 are reconciled in b3aa2de5be, so the commit must be manually skipped

Pull Request resolved: https://github.com/pytorch/pytorch/pull/76231

Reviewed By: bigfootjon

Differential Revision: D35845975

Pulled By: malfet

fbshipit-source-id: 4e4a2f03a26202bffe2045ac80704b356144164e
(cherry picked from commit dd32c3e33059b28c4727ffbeb40661dd14b3c7dc)
2022-04-22 14:19:24 +00:00
b447fa3912 [GHF] Manual fix syncbranches (#76200)
Summary:
By excluding 6d0f4a1d545a8f161df459e8d4ccafd4b9017dbe and edf909e58f06150f7be41da2f98a3b9de3167bca (which we re-relanded thrice)

Pull Request resolved: https://github.com/pytorch/pytorch/pull/76200

Reviewed By: george-qi

Differential Revision: D35828342

Pulled By: malfet

fbshipit-source-id: 27581a3cf00b9eadfff8ccc05b59243439aabb4d
(cherry picked from commit 5c6a502727c022816c682edda7b9cb4c10ed900b)
2022-04-21 17:27:05 -07:00
af13797c8f [GHF] Exclude 5f37e5c2a39c3acb776756a17730b865f0953432 from sync
Corresponding trunk commit generate different patch-id, as history
diverged between `master` and `fbsync`

Fixes #ISSUE_NUMBER

Pull Request resolved: https://github.com/pytorch/pytorch/pull/76048
Approved by: https://github.com/seemethere
2022-04-19 16:35:57 +00:00
b582472ac3 [GHF] Fix sync-branches
Manually skip 8e09e20c1dafcdbdb45c2d1574da68a32e54a3a5 which introduces
unstable patch-ids

Pull Request resolved: https://github.com/pytorch/pytorch/pull/75971
Approved by: https://github.com/janeyx99
2022-04-18 16:09:36 +00:00
6cdc6dd8e5 [pytorch][require export] Create smartplatform configuration for trymerge (#75542)
Summary: Pull Request resolved: https://github.com/pytorch/pytorch/pull/75542

Reviewed By: malfet

Differential Revision: D35513051

fbshipit-source-id: adf59359fcf2410fa8a61746533c896ec22d5ed3
(cherry picked from commit ab65394c6f88f17bdc317dbcfb931cc16e527eef)
2022-04-11 16:10:33 +00:00
3b1c085613 Fix duplicate commit logic in syncbranches (#75384)
Summary:
Regression introduced by caa403083b2f558d1525dddaebcd5909e69277ad

Pull Request resolved: https://github.com/pytorch/pytorch/pull/75384

Reviewed By: osalpekar

Differential Revision: D35451233

Pulled By: malfet

fbshipit-source-id: bbe81d2138a14337e1702f53a609c03c1fef3e91
(cherry picked from commit 7129435c86722d672cf749017370d2738ac3b8f8)
2022-04-06 23:28:54 +00:00
caa403083b [GHA] Small updates to syncbranches.yml
Make it accept origin environment variable
Add explicit skip for 0a6a1b27a4 as its a rare case of same commit landed/reverted twice

Pull Request resolved: https://github.com/pytorch/pytorch/pull/75209
Approved by: https://github.com/atalman, https://github.com/bigfootjon
2022-04-04 19:20:37 +00:00
70588ccddc [GHF] Rebase and retry push if fails
This fixes a pretty frequently occurring race condition when two
workflows are running concurrently

Resolve this by fetching latest branch and rebating proposed changes on
top of it

Test plan: Simulate the behavior in https://github.com/malfet/deleteme

Fixes #ISSUE_NUMBER

Pull Request resolved: https://github.com/pytorch/pytorch/pull/74382
Approved by: https://github.com/seemethere, https://github.com/bigfootjon
2022-03-17 20:45:49 +00:00
0c95209fe7 [GH1] Enable cross-repo merges
GHStack based PRs still can not be cross-repo, but for regular ones
checkout `pull/{pr_no}/head`

Pull Request resolved: https://github.com/pytorch/pytorch/pull/72750
2022-02-11 22:49:47 +00:00
3b9f2e2cca [GHF] More verbose failures messages (#71941)
Summary:
Modify _check_output to capture `CalledProcessError` and add
stdout/stderr to the failure message
Also record github actions run id in the failure message (calculated based on `${{ github.run_id}}`)

Pull Request resolved: https://github.com/pytorch/pytorch/pull/71941

Reviewed By: seemethere

Differential Revision: D33829633

Pulled By: malfet

fbshipit-source-id: 060b2856ca6c71574075effa72b982f9e1d64e6e
(cherry picked from commit a9ad7df9b540f9ab14524a644cab5e06225debe4)
2022-01-27 23:49:58 +00:00
5bd33247ec [GHF] Add revert workflow
This adds `try_revert` repository dispatch that will revert commit
that were previously landed by merge workflow if requested by org member

Pull Request resolved: https://github.com/pytorch/pytorch/pull/71868
2022-01-26 22:35:02 +00:00
9adee84a3f .github: Improve syncbranch debugability (#71596)
Summary:
Pull Request resolved: https://github.com/pytorch/pytorch/pull/71596

Adds a dry_run to test out push as well as adding in a debug flag to
allow you to see what git commands are running

Signed-off-by: Eli Uriegas <eliuriegas@fb.com>

Test Plan: Imported from OSS

Reviewed By: malfet, bigfootjon

Differential Revision: D33695224

Pulled By: seemethere

fbshipit-source-id: 03bf6a3f2d9594089e134d95c3d35a6779ba7a26
(cherry picked from commit a75a402f9d02d5e4c709e25ca385264f854945d1)
2022-01-20 23:53:02 +00:00
bc608b6e16 Add gitutils tests (#71580)
Summary:
Test PeekableIterator behavior

Add `.github/scripts/test_*.py` to list of tests run by test_tools
workflow and pin Python version to 3.7 in test_tools workflow

Change PeekableIterator inheritance from collections.abc.Iterator, to
typing.Iterator, which is a correct alias starting from Python-3.7

Pull Request resolved: https://github.com/pytorch/pytorch/pull/71580

Reviewed By: bigfootjon

Differential Revision: D33690659

Pulled By: malfet

fbshipit-source-id: 71f270b15138230772e2eed0da66cdfcb34825cc
(cherry picked from commit 42abb07396fa90272afb0b56508bd3a1f5c4ccbe)
2022-01-20 14:33:41 -08:00
42f7afc4cd [BE] Improve gitutils
Inherit `PeekableIterator` from `collections.abc.Iterator`

Pull Request resolved: https://github.com/pytorch/pytorch/pull/71515
2022-01-20 17:07:06 +00:00
61713acb07 Add trymerge workflow (#71488)
Summary:
This one, will react to `repo_dispatch` event sent by PyTorch Probot
when `pytorchbot merge this` command is issued

At the moment, workflow will only attempt to merge PRs which has not
been created from forked repo and that match rules defined in
`.github/merge_rules.json`

Pull Request resolved: https://github.com/pytorch/pytorch/pull/71488

Reviewed By: bigfootjon

Differential Revision: D33665142

Pulled By: malfet

fbshipit-source-id: e22daa1892523e62d7b7a941960636a6514cb7d7
(cherry picked from commit 92059bab073e2cd6ca6e9f946ffc2f956e22895c)
2022-01-19 23:11:48 +00:00
ff8fb717db Fix get_git_repo_dir (#71448)
Summary:
Otherwise, rev-list will only pick-up commits in `.github` repo

Before:
```
% git -C .github rev-list 1eb6146d967b2d09af37c54af411d03f0b790209..1ff7f65cc1ad499a71457368894ca14bed069749 -- .
598b55fd1894b7edb21f208b1c86fd6a377ebc69
ae089d6bdf03f1fadbc76fdf3d284081396251e8
```
After
```
% git -C . rev-list 1eb6146d967b2d09af37c54af411d03f0b790209..1ff7f65cc1ad499a71457368894ca14bed069749 -- .
1ff7f65cc1ad499a71457368894ca14bed069749
2ac58b0dc13f152bea180dd3d64b7c36fe0ba755
598b55fd1894b7edb21f208b1c86fd6a377ebc69
55899528a266363d27e0cf5e82b1b94524509756
ae089d6bdf03f1fadbc76fdf3d284081396251e8
```

Pull Request resolved: https://github.com/pytorch/pytorch/pull/71448

Reviewed By: seemethere, atalman

Differential Revision: D33644256

Pulled By: malfet

fbshipit-source-id: fa2e06f6767e7702af6ce85471aea07fa58292c0
(cherry picked from commit 594cecc0e1b95bacbd0d1d87bf7c622a3a5b04e5)
2022-01-18 22:12:41 +00:00
5243986df6 Update syncbranches workflow (#71420)
Summary:
Use `pytorchmergebot` credentials to do the merge
Infer sync branch name from the workflow rather than hardcode it
Move common functions from `syncbranches.py` to `gitutils.py`

Pull Request resolved: https://github.com/pytorch/pytorch/pull/71420

Reviewed By: bigfootjon

Differential Revision: D33638846

Pulled By: malfet

fbshipit-source-id: a568fd9ca04f4f142a7f5f64363e9516f5f4ef1c
2022-01-18 11:31:57 -08:00