Skip to content

Commit f7e3128

Browse files
committed
Update on "Some minor type stub improvements"
I was just playing around with improving the typing of symbolic_shapes. The PR is not "complete" but I in particular wanted to get feedback on whether or not people liked making ValueRanges Generic; it seems that distinguishing if you have an Expr ValueRange or a SympyBoolean ValueRange is a lot of trouble for downstream. Using TypeGuard, we can perform refinements on the generic parameter inside methods, although we still have to cast back to ValueRange[T] due to python/mypy#14425 (comment) Signed-off-by: Edward Z. Yang <ezyangmeta.com> cc voznesenskym penguinwu EikanWang jgong5 Guobing-Chen XiaobingSuper zhuhaozhe blzheng wenzhe-nrv jiayisunx peterbell10 ipiszy yf225 chenyang78 kadeng muchulee8 aakhundov ColinPeppler [ghstack-poisoned]
2 parents 5e03519 + ebdfc27 commit f7e3128

File tree

585 files changed

+19316
-9142
lines changed

Some content is hidden

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

585 files changed

+19316
-9142
lines changed
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
a34cbd4093a2eaf7267aa122cd580ea7f9b15f72
1+
export-D53340041

.ci/docker/requirements-ci.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ librosa>=0.6.2 ; python_version < "3.11"
7676
#Description: A testing library that allows you to replace parts of your
7777
#system under test with mock objects
7878
#Pinned versions:
79-
#test that import: test_module_init.py, test_modules.py, test_nn.py,
79+
#test that import: test_modules.py, test_nn.py,
8080
#test_testing.py
8181

8282
#MonkeyType # breaks pytorch-xla-linux-bionic-py3.7-clang8

.circleci/README.md

Lines changed: 1 addition & 465 deletions
Large diffs are not rendered by default.

.clang-tidy

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,6 @@ misc-*,
4242
-misc-non-private-member-variables-in-classes,
4343
-misc-confusable-identifiers,
4444
modernize-*,
45-
-modernize-concat-nested-namespaces,
4645
-modernize-macro-to-enum,
4746
-modernize-return-braced-init-list,
4847
-modernize-use-auto,

.github/auto_request_review.yml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ reviewers:
66
- albanD
77
- miladm
88
- bdhirsh
9-
- voznesenskym
109

1110
per_author:
1211
symbolic-shapes:

.github/ci_commit_pins/audio.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
b2d9c3e315405f2b5cfdfa5b93f849d5b27a4109
1+
02586da797dbfa201721d2080e2171805202f72c

.github/ci_commit_pins/vision.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
315f31527e720999eecbb986679b3177d4ed5e37
1+
806dba678d5b01f6e8a46f7c48fdf8c09369a267

.github/ci_commit_pins/xla.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
e265fd7b403d4508a1bcdaad2af9519e6c2d0b4c
1+
21653dc9859c2fa2cf5e18ce79d7ac1e392c5381

.github/scripts/filter_test_configs.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -588,7 +588,7 @@ def main() -> None:
588588
labels=labels,
589589
test_matrix=filtered_test_matrix,
590590
job_name=args.job_name,
591-
pr_body=pr_body,
591+
pr_body=pr_body if pr_body else "",
592592
)
593593

594594
# Set the filtered test matrix as the output

.github/scripts/generate_docker_release_matrix.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
55
Will output a condensed version of the matrix. Will include fllowing:
66
* CUDA version short
7-
* CUDA full verison
7+
* CUDA full version
88
* CUDNN version short
99
* Image type either runtime or devel
1010
* Platform linux/arm64,linux/amd64

.github/scripts/trymerge.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -748,7 +748,7 @@ def get_merge_base(self) -> str:
748748
# work for ghstack where the base is the custom branch, i.e. gh/USER/ID/base,
749749
# so let's just use main instead
750750
self.merge_base = gh_fetch_merge_base(
751-
self.org, self.project, last_commit_oid, "main"
751+
self.org, self.project, last_commit_oid, self.default_branch()
752752
)
753753

754754
# Fallback to baseRefOid if the API call fails, i.e. rate limit. Note that baseRefOid
@@ -2307,7 +2307,6 @@ def handle_exception(e: Exception, title: str = "Merge failed") -> None:
23072307
get_ghstack_prs(repo, pr) # raises error if out of sync
23082308
pr.merge_changes(
23092309
repo,
2310-
branch="main",
23112310
skip_mandatory_checks=True,
23122311
skip_all_rule_checks=True,
23132312
)

.github/workflows/check_mergeability_ghstack.yml

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,34 @@ jobs:
2020
git config --global user.name "PyTorch MergeBot"
2121
git fetch origin main:main
2222
23+
- name: Wait for orig branch
24+
shell: bash
25+
run: |
26+
BRANCH="${{ github.base_ref }}"
27+
echo "$BRANCH"
28+
BRANCH="${BRANCH%/base}/orig"
29+
echo "$BRANCH"
30+
31+
WAIT_SECONDS=300
32+
END_WAIT=$((SECONDS+WAIT_SECONDS))
33+
BRANCH_EXISTS=0
34+
35+
while [ $SECONDS -lt $END_WAIT ]; do
36+
git fetch --prune origin "${BRANCH}" || true
37+
if git rev-parse --verify "origin/${BRANCH}"; then
38+
BRANCH_EXISTS=1
39+
break
40+
fi
41+
echo "Waiting for branch ${BRANCH} to exist..."
42+
sleep 30 # Wait for 30 seconds before retrying
43+
done
44+
45+
if [ $BRANCH_EXISTS -eq 0 ]; then
46+
echo "Branch ${BRANCH} not found after ${WAIT_SECONDS} seconds."
47+
echo "Mergeability check failed for infrastructure reasons."
48+
exit 1
49+
fi
50+
2351
- name: Setup Python
2452
uses: actions/setup-python@v4
2553
with:

.github/workflows/create_release.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,9 @@ jobs:
1515
if: ${{ github.repository == 'pytorch/pytorch' }}
1616
name: Create Release
1717
runs-on: ubuntu-latest
18+
# https://github.com/softprops/action-gh-release?tab=readme-ov-file#permissions
19+
permissions:
20+
contents: write
1821
steps:
1922
- uses: malfet/checkout@silent-checkout
2023
with:

.github/workflows/lint.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ jobs:
5151
# Run lintrunner on all files
5252
if ! lintrunner --force-color --all-files --tee-json=lint.json 2> /dev/null; then
5353
echo ""
54-
echo -e "\e[1m\e[36mYou can reproduce these results locally by using \`lintrunner\`. (If you don't get the same results, run \'lintrunner init\' to update your local linter)\e[0m"
54+
echo -e "\e[1m\e[36mYou can reproduce these results locally by using \`lintrunner -m origin/main\`. (If you don't get the same results, run \'lintrunner init\' to update your local linter)\e[0m"
5555
echo -e "\e[1m\e[36mSee https://github.com/pytorch/pytorch/wiki/lintrunner for setup instructions.\e[0m"
5656
RC=1
5757
fi

.lintrunner.toml

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
merge_base_with = "origin/main"
2-
31
[[linter]]
42
code = 'FLAKE8'
53
include_patterns = ['**/*.py']
@@ -1549,7 +1547,6 @@ exclude_patterns = [
15491547
'test/test_mkldnn_verbose.py',
15501548
'test/test_mobile_optimizer.py',
15511549
'test/test_model_dump.py',
1552-
'test/test_module_init.py',
15531550
'test/test_modules.py',
15541551
'test/test_monitor.py',
15551552
'test/test_mps.py',

CMakeLists.txt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,10 @@ if(CMAKE_COMPILER_IS_GNUCXX AND CMAKE_CXX_COMPILER_VERSION VERSION_LESS 9.4)
4848
message(FATAL "GCC-9.4 or newer is required to compile PyTorch, but found ${CMAKE_CXX_COMPILER_VERSION}")
4949
endif()
5050

51+
# This define is needed to preserve behavior given anticpated changes to cccl/thrust
52+
# https://nvidia.github.io/libcudacxx/standard_api/numerics_library/complex.html
53+
string(APPEND CMAKE_CUDA_FLAGS "-DLIBCUDACXX_ENABLE_SIMPLIFIED_COMPLEX_OPERATIONS")
54+
5155
if(LINUX)
5256
include(cmake/CheckAbi.cmake)
5357
string(APPEND CMAKE_CXX_FLAGS " -D_GLIBCXX_USE_CXX11_ABI=${GLIBCXX_USE_CXX11_ABI}")

CODEOWNERS

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -97,9 +97,9 @@ test/functorch/test_ops.py @zou3519 @chillee @kshitij12345
9797
test/functorch/test_vmap.py @zou3519 @chillee @kshitij12345
9898

9999
# torch MPS
100-
test/test_mps.py @kulinseth
101-
aten/src/ATen/mps/ @kulinseth
102-
aten/src/ATen/native/mps/ @kulinseth
100+
test/test_mps.py @kulinseth @malfet
101+
aten/src/ATen/mps/ @kulinseth @malfet
102+
aten/src/ATen/native/mps/ @kulinseth @malfet
103103

104104
# Profiler
105105
torch/csrc/autograd/profiler* @aaronenyeshi
@@ -130,3 +130,12 @@ caffe2/utils/hip @jeffdaily @jithunnair-amd
130130
# torch.export
131131
/torch/export/ @avikchaudhuri @gmagogsfm @tugsbayasgalan @zhxchen17
132132
/torch/_export/ @avikchaudhuri @gmagogsfm @tugsbayasgalan @zhxchen17
133+
134+
# serialization-related files
135+
/aten/src/ATen/MapAllocator* @mikaylagawarecki
136+
/caffe2/serialize/ @mikaylagawarecki
137+
/torch/serialization.py @mikaylagawarecki
138+
/torch/storage.py @mikaylagawarecki
139+
/torch/csrc/Storage* @mikaylagawarecki
140+
# subscribing for PyTorchFileWriter/PyTorchFileReader changes
141+
/torch/csrc/jit/python/init.cpp @mikaylagawarecki

android/pytorch_android/generate_test_torchscripts.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,15 @@ def conv2d(self, x: Tensor, w: Tensor, toChannelsLast: bool) -> Tensor:
125125
r = r.contiguous()
126126
return r
127127

128+
@torch.jit.script_method
129+
def conv3d(self, x: Tensor, w: Tensor, toChannelsLast: bool) -> Tensor:
130+
r = torch.nn.functional.conv3d(x, w)
131+
if toChannelsLast:
132+
r = r.contiguous(memory_format=torch.channels_last_3d)
133+
else:
134+
r = r.contiguous()
135+
return r
136+
128137
@torch.jit.script_method
129138
def contiguous(self, x: Tensor) -> Tensor:
130139
return x.contiguous()
Binary file not shown.

android/pytorch_android/src/androidTest/java/org/pytorch/PytorchTestBase.java

Lines changed: 114 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -348,15 +348,32 @@ public void testChannelsLast3d() throws IOException {
348348
@Test
349349
public void testChannelsLastConv2d() throws IOException {
350350
long[] inputShape = new long[] {1, 3, 2, 2};
351-
long[] dataNCHW = new long[] {1, 2, 3, 4, 11, 12, 13, 14, 101, 102, 103, 104};
351+
long[] dataNCHW = new long[] {
352+
111, 112,
353+
121, 122,
354+
355+
211, 212,
356+
221, 222,
357+
358+
311, 312,
359+
321, 322};
352360
Tensor inputNCHW = Tensor.fromBlob(dataNCHW, inputShape, MemoryFormat.CONTIGUOUS);
353-
long[] dataNHWC = new long[] {1, 11, 101, 2, 12, 102, 3, 13, 103, 4, 14, 104};
354-
Tensor inputNHWC = Tensor.fromBlob(dataNHWC, inputShape, MemoryFormat.CHANNELS_LAST);
361+
long[] dataNHWC = new long[] {
362+
111, 211, 311, 112, 212, 312,
355363

364+
121, 221, 321, 122, 222, 322};
365+
Tensor inputNHWC = Tensor.fromBlob(dataNHWC, inputShape, MemoryFormat.CHANNELS_LAST);
356366
long[] weightShape = new long[] {3, 3, 1, 1};
357-
long[] dataWeightOIHW = new long[] {2, 0, 0, 0, 1, 0, 0, 0, -1};
367+
long[] dataWeightOIHW = new long[] {
368+
2, 0, 0,
369+
0, 1, 0,
370+
0, 0, -1};
358371
Tensor wNCHW = Tensor.fromBlob(dataWeightOIHW, weightShape, MemoryFormat.CONTIGUOUS);
359-
long[] dataWeightOHWI = new long[] {2, 0, 0, 0, 1, 0, 0, 0, -1};
372+
long[] dataWeightOHWI = new long[] {
373+
2, 0, 0,
374+
0, 1, 0,
375+
0, 0, -1};
376+
360377
Tensor wNHWC = Tensor.fromBlob(dataWeightOHWI, weightShape, MemoryFormat.CHANNELS_LAST);
361378

362379
final Module module = loadModel(TEST_MODULE_ASSET_NAME);
@@ -367,15 +384,105 @@ public void testChannelsLastConv2d() throws IOException {
367384
outputNCHW,
368385
MemoryFormat.CONTIGUOUS,
369386
new long[] {1, 3, 2, 2},
370-
new long[] {2, 4, 6, 8, 11, 12, 13, 14, -101, -102, -103, -104});
387+
new long[] {
388+
2*111, 2*112,
389+
2*121, 2*122,
390+
391+
211, 212,
392+
221, 222,
393+
394+
-311, -312,
395+
-321, -322});
371396

372397
final IValue outputNHWC =
373398
module.runMethod("conv2d", IValue.from(inputNHWC), IValue.from(wNHWC), IValue.from(true));
374399
assertIValueTensor(
375400
outputNHWC,
376401
MemoryFormat.CHANNELS_LAST,
377402
new long[] {1, 3, 2, 2},
378-
new long[] {2, 11, -101, 4, 12, -102, 6, 13, -103, 8, 14, -104});
403+
new long[] {
404+
2*111, 211, -311, 2*112, 212, -312,
405+
2*121, 221, -321, 2*122, 222, -322});
406+
}
407+
408+
@Test
409+
public void testChannelsLastConv3d() throws IOException {
410+
long[] inputShape = new long[] {1, 3, 2, 2, 2};
411+
long[] dataNCDHW = new long[] {
412+
1111, 1112,
413+
1121, 1122,
414+
1211, 1212,
415+
1221, 1222,
416+
417+
2111, 2112,
418+
2121, 2122,
419+
2211, 2212,
420+
2221, 2222,
421+
422+
3111, 3112,
423+
3121, 3122,
424+
3211, 3212,
425+
3221, 3222};
426+
Tensor inputNCDHW = Tensor.fromBlob(dataNCDHW, inputShape, MemoryFormat.CONTIGUOUS);
427+
long[] dataNDHWC = new long[] {
428+
1111, 2111, 3111,
429+
1112, 2112, 3112,
430+
431+
1121, 2121, 3121,
432+
1122, 2122, 3122,
433+
434+
1211, 2211, 3211,
435+
1212, 2212, 3212,
436+
437+
1221, 2221, 3221,
438+
1222, 2222, 3222};
439+
440+
Tensor inputNDHWC = Tensor.fromBlob(dataNDHWC, inputShape, MemoryFormat.CHANNELS_LAST_3D);
441+
442+
long[] weightShape = new long[] {3, 3, 1, 1, 1};
443+
long[] dataWeightOIDHW = new long[] {
444+
2, 0, 0,
445+
0, 1, 0,
446+
0, 0, -1,
447+
};
448+
Tensor wNCDHW = Tensor.fromBlob(dataWeightOIDHW, weightShape, MemoryFormat.CONTIGUOUS);
449+
long[] dataWeightODHWI = new long[] {
450+
2, 0, 0,
451+
0, 1, 0,
452+
0, 0, -1,
453+
};
454+
Tensor wNDHWC = Tensor.fromBlob(dataWeightODHWI, weightShape, MemoryFormat.CHANNELS_LAST_3D);
455+
456+
final Module module = loadModel(TEST_MODULE_ASSET_NAME);
457+
458+
final IValue outputNCDHW =
459+
module.runMethod("conv3d", IValue.from(inputNCDHW), IValue.from(wNCDHW), IValue.from(false));
460+
assertIValueTensor(
461+
outputNCDHW,
462+
MemoryFormat.CONTIGUOUS,
463+
new long[] {1, 3, 2, 2, 2},
464+
new long[] {
465+
2*1111, 2*1112, 2*1121, 2*1122,
466+
2*1211, 2*1212, 2*1221, 2*1222,
467+
468+
2111, 2112, 2121, 2122,
469+
2211, 2212, 2221, 2222,
470+
471+
-3111, -3112, -3121, -3122,
472+
-3211, -3212, -3221, -3222});
473+
474+
final IValue outputNDHWC =
475+
module.runMethod("conv3d", IValue.from(inputNDHWC), IValue.from(wNDHWC), IValue.from(true));
476+
assertIValueTensor(
477+
outputNDHWC,
478+
MemoryFormat.CHANNELS_LAST_3D,
479+
new long[] {1, 3, 2, 2, 2},
480+
new long[] {
481+
2*1111, 2111, -3111, 2*1112, 2112, -3112,
482+
2*1121, 2121, -3121, 2*1122, 2122, -3122,
483+
484+
2*1211, 2211, -3211, 2*1212, 2212, -3212,
485+
2*1221, 2221, -3221, 2*1222, 2222, -3222});
379486
}
380487

381488
@Test

android/pytorch_android/test_asset.jit

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,15 @@ def conv2d(self, x: Tensor, w: Tensor, toChannelsLast: bool) -> Tensor:
8484
r = r.contiguous()
8585
return r
8686

87+
def conv3d(self, x: Tensor, w: Tensor, toChannelsLast: bool) -> Tensor:
88+
r = torch.conv3d(x, w)
89+
if (toChannelsLast):
90+
# memory_format=torch.channels_last_3d
91+
r = r.contiguous(memory_format=2)
92+
else:
93+
r = r.contiguous()
94+
return r
95+
8796
def contiguous(self, x: Tensor) -> Tensor:
8897
return x.contiguous()
8998

aten/src/ATen/MapAllocator.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -325,6 +325,11 @@ MapAllocator::MapAllocator(WithFd, c10::string_view filename, int fd, int flags,
325325
TORCH_CHECK(false, "unable to mmap ", size_, " bytes from file <", filename_, ">: ", strerror(errno), " (", errno, ")");
326326
}
327327

328+
#if !defined(__APPLE__) && !defined(__ANDROID__)
329+
/* attempt to use larger block size on Linux, which is important for getting better CUDA upload speed */
330+
posix_fadvise(fd, 0, size, POSIX_FADV_SEQUENTIAL);
331+
#endif
332+
328333
if (flags_ & ALLOCATOR_MAPPED_KEEPFD) {
329334
fd_ = fd;
330335
} else {

aten/src/ATen/core/DeprecatedTypeProperties.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,10 @@ class TORCH_API DeprecatedTypeProperties {
9494
return toBackend(Backend::HIP);
9595
}
9696

97+
DeprecatedTypeProperties & privateUser1() const {
98+
return toBackend(Backend::PrivateUse1);
99+
}
100+
97101
/// Constructs the `TensorOptions` from a type and a `device_index`.
98102
TensorOptions options(int16_t device_index = -1) const {
99103
return TensorOptions().dtype(typeMeta())

aten/src/ATen/cpu/vec/vec256/vsx/vec256_float_vsx.h

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -234,11 +234,6 @@ class Vectorized<float> {
234234
return ret._nor();
235235
}
236236

237-
Vectorized<float> _isinf() const {
238-
auto x = *this;
239-
return (x == v_inf) | (x == v_minus_inf);
240-
}
241-
242237
bool has_inf_nan() const {
243238
for (const auto i : c10::irange(size()/2)) {
244239
if(_isnan(_vec0[i]) || _isinf(_vec0[i])) {

0 commit comments

Comments
 (0)