8000 Update base for Update on "Add cuSOLVER path for torch.linalg.qr" · pytorch/pytorch@97e9b5b · GitHub
[go: up one dir, main page]

Skip to content

Commit 97e9b5b

Browse files
committed
Update base for Update on "Add cuSOLVER path for torch.linalg.qr"
Using cuSOLVER path with `pytest test/test_ops.py -k 'linalg_qr' --durations=5` cuts the runtime for these tests by 1 minute locally. See #56256 (comment). Performance comparison: #56256 (comment). Differential Revision: [D27960154](https://our.internmc.facebook.com/intern/diff/D27960154) [ghstack-poisoned]
2 parents 6d272f3 + c2fbd96 commit 97e9b5b

File tree

126 files changed

+2462
-1959
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

126 files changed

+2462
-1959
lines changed

.circleci/cimodel/data/binary_build_definitions.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,12 @@ def gen_build_env_parms(self):
2727

2828
def gen_docker_image(self):
2929
if self.gcc_config_variant == 'gcc5.4_cxx11-abi':
30-
return miniutils.quote("pytorch/pytorch-binary-docker-image-ubuntu16.04:latest")
30+
if self.gpu_version is None:
31+
return miniutils.quote("pytorch/libtorch-cxx11-builder:cpu")
32+
else:
33+
return miniutils.quote(
34+
f"pytorch/libtorch-cxx11-builder:{self.gpu_version}"
35+
)
3136
if self.pydistro == "conda":
3237
if self.gpu_version is None:
3338
return miniutils.quote("pytorch/conda-builder:cpu")

.circleci/config.yml

Lines changed: 36 additions & 36 deletions
Large diffs are not rendered by default.

.circleci/scripts/binary_checkout.sh

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,5 +64,7 @@ popd
6464
retry git clone -q https://github.com/pytorch/builder.git "$BUILDER_ROOT"
6565
pushd "$BUILDER_ROOT"
6666
echo "Using builder from "
67+
# TODO: Remove before landing, this is just for testing
68+
git checkout driazati/torch_debug_flag
6769
git --no-pager log --max-count 1
6870
popd

.github/scripts/run_torchbench.py

Lines changed: 97 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,97 @@
1+
"""
2+
Generate a torchbench test report from a file containing the PR body.
3+
Currently, only supports running tests on specified model names
4+
5+
Testing environment:
6+
- Intel Xeon 8259CL @ 2.50 GHz, 24 Cores with disabled Turbo and HT
7+
- Nvidia Tesla T4
8+
- Nvidia Driver 450.51.06
9+
- Python 3.7
10+
- CUDA 10.2
11+
"""
12+
# Known issues:
13+
# 1. Does not reuse the build artifact in other CI workflows
14+
# 2. CI jobs are serialized because there is only one worker
15+
import os
16+
import pathlib
17+
import argparse
18+
import subprocess
19+
20+
from typing import List
21+
22+
CUDA_VERSION = "cu102"
23+
PYTHON_VERSION = "3.7"
24+
TORCHBENCH_CONFIG_NAME = "config.yaml"
25+
MAGIC_PREFIX = "RUN_TORCHBENCH:"
26+
ABTEST_CONFIG_TEMPLATE = """# This config is automatically generated by run_torchbench.py
27+
start: {control}
28+
end: {treatment}
29+
threshold: 100
30+
direction: decrease
31+
timeout: 60
32+
tests:"""
33+
34+
def gen_abtest_config(control: str, treatment: str, models: List[str]):
35+
d = {}
36+
d["control"] = control
37+
d["treatment"] = treatment
38+
config = ABTEST_CONFIG_TEMPLATE.format(**d)
39+
for model in models:
40+
config = f"{config}\n - {model}"
41+
config = config + "\n"
42+
return config
43+
44+
def deploy_torchbench_config(output_dir: str, config: str):
45+
# Create test dir if needed
46+
pathlib.Path(output_dir).mkdir(exist_ok=True)
47+
# TorchBench config file name
48+
config_path = os.path.join(output_dir, TORCHBENCH_CONFIG_NAME)
49+
with open(config_path, "w") as fp:
50+
fp.write(config)
51+
52+
def extract_models_from_pr(torchbench_path: str, prbody_file: str) -> List[str]:
53+
model_list = []
54+
with open(prbody_file, "r") as pf:
55+
lines = map(lambda x: x.strip(), pf.read().splitlines())
56+
magic_lines = list(filter(lambda x: x.startswith(MAGIC_PREFIX), lines))
57+
if magic_lines:
58+
# Only the first magic line will be respected.
59+
model_list = list(map(lambda x: x.strip(), magic_lines[0][len(MAGIC_PREFIX):].split(",")))
60+
# Sanity check: make sure all the user specified models exist in torchbench repository
61+
full_model_list = os.listdir(os.path.join(torchbench_path, "torchbenchmark", "models"))
62+
for m in model_list:
63+
if m not in full_model_list:
64+
print(f"The model {m} you specified does not exist in TorchBench suite. Please double check.")
65+
return []
66+
return model_list
67+
68+
def run_torchbench(pytorch_path: str, torchbench_path: str, output_dir: str):
69+
# Copy system environment so that we will not override
70+
env = dict(os.environ)
71+
command = ["python", "bisection.py", "--work-dir", output_dir,
72+
"--pytorch-src", pytorch_path, "--torchbench-src", torchbench_path,
73+
"--config", os.path.join(output_dir, "config.yaml"),
74+
"--output", os.path.join(output_dir, "result.txt")]
75+
subprocess.check_call(command, cwd=torchbench_path, env=env)
76+
77+
if __name__ == "__main__":
78+
parser = argparse.ArgumentParser(description='Run TorchBench tests based on PR')
79+
parser.add_argument('--pr-num', required=True, type=str, help="The Pull Request number")
80+
parser.add_argument('--pr-base-sha', required=True, type=str, help="The Pull Request base hash")
81+ F421
parser.add_argument('--pr-head-sha', required=True, type=str, help="The Pull Request head hash")
82+
parser.add_argument('--pr-body', required=True, help="The file that contains body of a Pull Request")
83+
parser.add_argument('--pytorch-path', required=True, type=str, help="Path to pytorch repository")
84+
parser.add_argument('--torchbench-path', required=True, type=str, help="Path to TorchBench repository")
85+
args = parser.parse_args()
86+
87+
output_dir: str = os.path.join(os.environ["HOME"], ".torchbench", "bisection", f"pr{args.pr_num}")
88+
# Identify the specified models and verify the input
89+
models = extract_models_from_pr(args.torchbench_path, args.pr_body)
90+
if not models:
91+
print("Can't parse the model filter from the pr body. Currently we only support allow-list.")
92+
exit(1)
93+
print(f"Ready to run TorchBench with benchmark. Result will be saved in the directory: {output_dir}.")
94+
# Run TorchBench with the generated config
95+
torchbench_config = gen_abtest_config(args.pr_base_sha, args.pr_head_sha, models)
96+
deploy_torchbench_config(output_dir, torchbench_config)
97+
run_torchbench(pytorch_path=args.pytorch_path, torchbench_path=args.torchbench_path, output_dir=output_dir)

.github/workflows/cancel_redundant_workflows.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ on:
88
- Lint
99
- Linux CI (pytorch-linux-xenial-py3.6-gcc5.4)
1010
- Test tools
11+
- TorchBench CI (pytorch-linux-py3.7-cu102)
1112
- clang-format
1213
jobs:
1314
cancel:

.github/workflows/lint.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -215,6 +215,7 @@ jobs:
215215
[ ! -s "${GITHUB_WORKSPACE}"/flake8-output.txt ]
216216
217217
clang-tidy:
218+
if: github.event_name == 'pull_request'
218219
runs-on: ubuntu-18.04
219220
steps:
220221
- name: Setup Python

.github/workflows/run_torchbench.yml

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
name: TorchBench CI (pytorch-linux-py3.7-cu102)
2+
on:
3+
pull_request:
4+
5+
env:
6+
PR_NUM: ${{ github.event.number }}
7+
PR_BODY: ${{ github.event.pull_request.body }}
8+
PR_BASE_SHA: ${{ github.event.pull_request.base.sha }}
9+
PR_HEAD_SHA: ${{ github.event.pull_request.head.sha }}
10+
11+
jobs:
12+
run-torchbench:
13+
# We don't accept running on non-pytorch repos because of security concerns
14+
# Only run the job when the body contains magic word "RUN_TORCHBENCH:"
15+
if: ${{ github.repository_owner == 'pytorch' && contains(github.event.pull_request.body, 'RUN_TORCHBENCH:') }}
16+
runs-on: [self-hosted, bm-runner]
17+
steps:
18+
- name: Checkout PyTorch
19+
uses: actions/checkout@v2
20+
with:
21+
path: pytorch
22+
- name: Checkout TorchBench
23+
uses: actions/checkout@v2
24+
with:
25+
repository: pytorch/benchmark
26+
path: benchmark
27+
- name: Create conda environment
28+
run: |
29+
conda create -y -n pr-ci python=3.7
30+
# shellcheck disable=SC1091
31+
. "${HOME}"/anaconda3/etc/profile.d/conda.sh
32+
conda activate pr-ci
33+
conda install -y numpy=1.17 requests=2.22 ninja pyyaml mkl mkl-include setuptools cmake cffi typing_extensions future six dataclasses pillow pytest tabulate
34+
- name: Update self-hosted PyTorch
35+
run: |
36+
pushd "${HOME}"/pytorch
37+
git fetch
38+
popd
39+
- name: Run TorchBench
40+
run: |
41+
pushd "${HOME}"/pytorch
42+
PR_MERGE_BASE=$(git merge-base "$PR_BASE_SHA" "$PR_HEAD_SHA")
43+
popd
44+
PR_BODY_FILE=/tmp/pr-body.txt
45+
echo "$PR_BODY" > ${PR_BODY_FILE}
46+
# shellcheck disable=SC1091
47+
. "${HOME}"/anaconda3/etc/profile.d/conda.sh
48+
conda activate pr-ci
49+
python3 pytorch/.github/scripts/run_torchbench.py \
50+
--pytorch-path "${HOME}"/pytorch \
51+
--torchbench-path "${PWD}"/benchmark \
52+
--pr-num "$PR_NUM" \
53+
--pr-base-sha "$PR_MERGE_BASE" \
54+
--pr-head-sha "$PR_HEAD_SHA" \
55+
--pr-body "$PR_BODY_FILE"
56+
- name: Remove conda environment and cleanup
57+
run: |
58+
conda env remove --name pr-ci
59+
rm /tmp/pr-body.txt
60+
- name: Upload artifact
61+
uses: actions/upload-artifact@v2
62+
with:
63+
name: TorchBench result
64+
path: ~/.torchbench/bisection/pr${{ github.event.number }}

BUILD.bazel

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -341,7 +341,6 @@ filegroup(
341341
"aten/src/ATen/cuda/CUDABlas.cpp",
342342
"aten/src/ATen/cuda/CUDASolver.cpp",
343343
"aten/src/ATen/cuda/CUDAContext.cpp",
344-
"aten/src/ATen/cuda/CUDAFuture.cpp",
345344
"aten/src/ATen/cuda/CUDAGeneratorImpl.cpp",
346345
"aten/src/ATen/cuda/CUDAGraph.cpp",
347346
"aten/src/ATen/cuda/CuSparseHandlePool.cpp",

CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -282,6 +282,7 @@ cmake_dependent_option(
282282
option(USE_TBB "Use TBB" OFF)
283283
option(ONNX_ML "Enable traditional ONNX ML API." ON)
284284
option(HAVE_SOVERSION "Whether to add SOVERSION to the shared objects" OFF)
285+
option(BUILD_LIBTORCH_CPU_WITH_DEBUG "Enable RelWithDebInfo for libtorch_cpu target only" OFF)
285286
cmake_dependent_option(
286287
USE_DEPLOY "Build embedded torch::deploy interpreter. See torch/csrc/deploy/README.md for more info." OFF
287288
"BUILD_PYTHON" OFF)

aten/src/ATen/ExpandUtils.cpp

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -43,22 +43,21 @@ DimVector infer_size_dimvector(IntArrayRef a, IntArrayRef b) {
4343
return infer_size_impl<DimVector>(a, b);
4444
}
4545

46-
template <typename Container>
47-
std::tuple<Container, Container> inferExpandGeometryImpl(
46+
template<typename Container>
47+
C10_ALWAYS_INLINE InferExpandGeometryResult<Container> inferExpandGeometryImpl(
4848
IntArrayRef tensor_sizes,
4949
IntArrayRef tensor_strides,
5050
IntArrayRef sizes) {
5151
int64_t ndim = sizes.size();
5252
int64_t tensor_dim = tensor_sizes.size();
5353

5454
if (tensor_dim == 0) {
55-
return std::make_tuple(
56-
Container(sizes.begin(), sizes.end()), Container(ndim, 0));
55+
return InferExpandGeometryResult<Container>(sizes, ndim);
5756
}
5857

59-
std::tuple<Container, Container> result{Container(ndim), Container(ndim)};
60-
auto& expandedSizes = std::get<0>(result);
61-
auto& expandedStrides = std::get<1>(result);
58+
InferExpandGeometryResult<Container> result(ndim);
59+
auto& expandedSizes = result.sizes;
60+
auto& expandedStrides = result.strides;
6261

6362
// create a new geometry for the tensors
6463
for (int64_t i = ndim - 1; i >= 0; --i) {
@@ -103,11 +102,12 @@ std::tuple<std::vector<int64_t>, std::vector<int64_t>> inferExpandGeometry(
103102
IntArrayRef tensor_sizes,
104103
IntArrayRef tensor_strides,
105104
IntArrayRef sizes) {
106-
return inferExpandGeometryImpl<std::vector<int64_t>>(
105+
auto result = inferExpandGeometryImpl<std::vector<int64_t>>(
107106
tensor_sizes, tensor_strides, sizes);
107+
return std::make_tuple(std::move(result.sizes), std::move(result.strides));
108108
}
109109

110-
std::tuple<DimVector, DimVector> inferExpandGeometry_dimvector(
110+
InferExpandGeometryResult<DimVector> inferExpandGeometry_dimvector(
111111
IntArrayRef tensor_sizes,
112112
IntArrayRef tensor_strides,
113113
IntArrayRef sizes) {

0 commit comments

Comments
 (0)
0