Skip to content

Commit 59d0a6a

Browse files
committed
Bump PyTorch pin to 2.13
1 parent e500fee commit 59d0a6a

19 files changed

Lines changed: 190 additions & 49 deletions

File tree

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
release/2.12
1+
release/2.13

.ci/docker/common/install_pytorch.sh

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,21 @@ install_domains() {
1616
pip_install --no-build-isolation --user "git+https://github.com/pytorch/vision.git@${TORCHVISION_VERSION}"
1717
}
1818

19+
configure_pytorch_compiler() {
20+
local cxx_version
21+
cxx_version=$(/usr/bin/c++ --version | head -n1)
22+
if [[ "${cxx_version}" == *clang* ]]; then
23+
local clang_major
24+
clang_major=$(/usr/bin/c++ -dumpversion | cut -d. -f1)
25+
if [[ "${clang_major}" =~ ^[0-9]+$ && "${clang_major}" -lt 16 ]] &&
26+
command -v gcc >/dev/null &&
27+
command -v g++ >/dev/null; then
28+
export CC=gcc
29+
export CXX=g++
30+
fi
31+
fi
32+
}
33+
1934
install_pytorch_and_domains() {
2035
git clone https://github.com/pytorch/pytorch.git
2136

@@ -33,14 +48,15 @@ install_pytorch_and_domains() {
3348
if [[ -n "${PYTORCH_BUILD_MAX_JOBS:-}" ]]; then
3449
export MAX_JOBS="${PYTORCH_BUILD_MAX_JOBS}"
3550
fi
51+
configure_pytorch_compiler
3652
# Then build and install PyTorch
3753
conda_run python setup.py bdist_wheel
3854
pip_install "$(echo dist/*.whl)"
3955

4056
# Grab the pinned audio and vision commits from PyTorch
4157
TORCHAUDIO_VERSION=release/2.11
4258
export TORCHAUDIO_VERSION
43-
TORCHVISION_VERSION=release/0.27
59+
TORCHVISION_VERSION=release/0.28
4460
export TORCHVISION_VERSION
4561

4662
install_domains

.ci/scripts/utils.sh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ install_pytorch_and_domains() {
107107
local torch_release=$(cat version.txt)
108108
# Download key must match the upload key below (basename of dist/*.whl,
109109
# which always carries setup.py's resolved +gitHASH). Branch-ref pins
110-
# like `release/2.12` would otherwise produce `+gitrelease` here and
110+
# like `release/2.13` would otherwise produce `+gitrelease` here and
111111
# never hit the cache.
112112
local torch_short_hash=$(git rev-parse --short=7 HEAD)
113113
local torch_wheel_path="cached_artifacts/pytorch/executorch/pytorch_wheels/${system_name}/${python_version}"
@@ -178,7 +178,7 @@ install_pytorch_and_domains() {
178178
# Grab the pinned audio and vision commits from PyTorch
179179
TORCHAUDIO_VERSION=release/2.11
180180
export TORCHAUDIO_VERSION
181-
TORCHVISION_VERSION=release/0.27
181+
TORCHVISION_VERSION=release/0.28
182182
export TORCHVISION_VERSION
183183

184184
install_domains

backends/aoti/common_shims.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -154,6 +154,11 @@ AOTITorchError aoti_torch_get_dim(Tensor* tensor, int64_t* ret_dim) {
154154
return Error::Ok;
155155
}
156156

157+
AOTITorchError aoti_torch_get_numel(Tensor* tensor, int64_t* ret_numel) {
158+
*ret_numel = static_cast<int64_t>(tensor->numel());
159+
return Error::Ok;
160+
}
161+
157162
// Device and layout utility functions
158163
int32_t aoti_torch_device_type_cpu() {
159164
// Let's say cpu is 0 for ET as well

backends/aoti/common_shims.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,9 @@ aoti_torch_get_device_index(Tensor* tensor, int32_t* ret_device_index);
5959
AOTI_SHIM_EXPORT AOTITorchError
6060
aoti_torch_get_dim(Tensor* tensor, int64_t* ret_dim);
6161

62+
AOTI_SHIM_EXPORT AOTITorchError
63+
aoti_torch_get_numel(Tensor* tensor, int64_t* ret_numel);
64+
6265
// Utility functions for device and layout information
6366
AOTI_SHIM_EXPORT int32_t aoti_torch_device_type_cpu();
6467
AOTI_SHIM_EXPORT int32_t aoti_torch_layout_strided();

backends/aoti/common_shims_slim.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,14 @@ AOTITorchError aoti_torch_get_dim(Tensor* tensor, int64_t* ret_dim) {
6060
return Error::Ok;
6161
}
6262

63+
AOTITorchError aoti_torch_get_numel(Tensor* tensor, int64_t* ret_numel) {
64+
if (tensor == nullptr || ret_numel == nullptr) {
65+
return Error::InvalidArgument;
66+
}
67+
*ret_numel = static_cast<int64_t>(tensor->numel());
68+
return Error::Ok;
69+
}
70+
6371
int32_t aoti_torch_layout_strided() {
6472
// Slimtensor only support strided layout, the return value will always be 0,
6573
// a.k.a at::Layout::Strided;

backends/aoti/common_shims_slim.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,9 @@ aoti_torch_get_dtype(Tensor* tensor, int32_t* ret_dtype);
4848
AOTI_SHIM_EXPORT AOTITorchError
4949
aoti_torch_get_dim(Tensor* tensor, int64_t* ret_dim);
5050

51+
AOTI_SHIM_EXPORT AOTITorchError
52+
aoti_torch_get_numel(Tensor* tensor, int64_t* ret_numel);
53+
5154
AOTI_SHIM_EXPORT int32_t aoti_torch_layout_strided();
5255

5356
// ============================================================

backends/aoti/tests/test_common_shims.cpp

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -241,6 +241,21 @@ TEST_F(CommonShimsTest, ScalarTensor) {
241241
error = aoti_torch_get_sizes(tensor_0d, &sizes_ptr2);
242242
EXPECT_EQ(error, Error::Ok);
243243
EXPECT_EQ(sizes_ptr, sizes_ptr2);
244+
245+
int64_t numel = -1;
246+
error = aoti_torch_get_numel(tensor_0d, &numel);
247+
EXPECT_EQ(error, Error::Ok);
248+
EXPECT_EQ(numel, 1);
249+
}
250+
251+
TEST_F(CommonShimsTest, GetNumel) {
252+
auto tensor = create_tracked_tensor({2, 3, 4});
253+
254+
int64_t numel = -1;
255+
AOTITorchError error = aoti_torch_get_numel(tensor, &numel);
256+
257+
EXPECT_EQ(error, Error::Ok);
258+
EXPECT_EQ(numel, 24);
244259
}
245260

246261
// Test large tensor dimensions
@@ -266,6 +281,11 @@ TEST_F(CommonShimsTest, LargeTensorDimensions) {
266281
EXPECT_EQ(strides_ptr[1], 120000);
267282
EXPECT_EQ(strides_ptr[2], 400);
268283
EXPECT_EQ(strides_ptr[3], 1);
284+
285+
int64_t numel = -1;
286+
error = aoti_torch_get_numel(tensor, &numel);
287+
EXPECT_EQ(error, Error::Ok);
288+
EXPECT_EQ(numel, 2400000000);
269289
}
270290

271291
// Test that cleanup_tensor_metadata clears the cache

backends/aoti/tests/test_common_shims_slim.cpp

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -289,6 +289,50 @@ void runGetDimTest(slim_c10::DeviceType device_type) {
289289
}
290290
}
291291

292+
void runGetNumelTest(slim_c10::DeviceType device_type) {
293+
slim_c10::Device device(device_type, 0);
294+
295+
// Test 0D tensor (scalar)
296+
{
297+
std::vector<int64_t> sizes = {};
298+
std::vector<int64_t> strides = {};
299+
300+
Tensor* tensor = new Tensor(slim::empty_strided(
301+
slim::makeArrayRef(sizes),
302+
slim::makeArrayRef(strides),
303+
slim_c10::ScalarType::Float,
304+
device));
305+
306+
int64_t ret_numel = -1;
307+
AOTITorchError error = aoti_torch_get_numel(tensor, &ret_numel);
308+
309+
EXPECT_EQ(error, Error::Ok);
310+
EXPECT_EQ(ret_numel, 1);
311+
312+
delete tensor;
313+
}
314+
315+
// Test 3D tensor
316+
{
317+
std::vector<int64_t> sizes = {2, 3, 4};
318+
std::vector<int64_t> strides = calculateContiguousStrides(sizes);
319+
320+
Tensor* tensor = new Tensor(slim::empty_strided(
321+
slim::makeArrayRef(sizes),
322+
slim::makeArrayRef(strides),
323+
slim_c10::ScalarType::Float,
324+
device));
325+
326+
int64_t ret_numel = -1;
327+
AOTITorchError error = aoti_torch_get_numel(tensor, &ret_numel);
328+
329+
EXPECT_EQ(error, Error::Ok);
330+
EXPECT_EQ(ret_numel, 24);
331+
332+
delete tensor;
333+
}
334+
}
335+
292336
// ============================================================================
293337
// Storage & Device Property Tests
294338
// ============================================================================
@@ -400,6 +444,10 @@ TEST_F(CommonShimsSlimTest, GetDim_CPU) {
400444
runGetDimTest(slim_c10::DeviceType::CPU);
401445
}
402446

447+
TEST_F(CommonShimsSlimTest, GetNumel_CPU) {
448+
runGetNumelTest(slim_c10::DeviceType::CPU);
449+
}
450+
403451
TEST_F(CommonShimsSlimTest, GetStorageOffset_CPU) {
404452
runGetStorageOffsetTest(slim_c10::DeviceType::CPU);
405453
}
@@ -456,6 +504,13 @@ TEST_F(CommonShimsSlimTest, GetDim_CUDA) {
456504
runGetDimTest(slim_c10::DeviceType::CUDA);
457505
}
458506

507+
TEST_F(CommonShimsSlimTest, GetNumel_CUDA) {
508+
if (!isCudaAvailable()) {
509+
GTEST_SKIP() << "CUDA not available";
510+
}
511+
runGetNumelTest(slim_c10::DeviceType::CUDA);
512+
}
513+
459514
TEST_F(CommonShimsSlimTest, GetStorageOffset_CUDA) {
460515
if (!isCudaAvailable()) {
461516
GTEST_SKIP() << "CUDA not available";
@@ -495,13 +550,15 @@ TEST_F(CommonShimsSlimTest, NullTensorArgument) {
495550
int64_t* strides = nullptr;
496551
int32_t dtype = -1;
497552
int64_t dim = -1;
553+
int64_t numel = -1;
498554

499555
EXPECT_EQ(
500556
aoti_torch_get_data_ptr(nullptr, &data_ptr), Error::InvalidArgument);
501557
EXPECT_EQ(aoti_torch_get_sizes(nullptr, &sizes), Error::InvalidArgument);
502558
EXPECT_EQ(aoti_torch_get_strides(nullptr, &strides), Error::InvalidArgument);
503559
EXPECT_EQ(aoti_torch_get_dtype(nullptr, &dtype), Error::InvalidArgument);
504560
EXPECT_EQ(aoti_torch_get_dim(nullptr, &dim), Error::InvalidArgument);
561+
EXPECT_EQ(aoti_torch_get_numel(nullptr, &numel), Error::InvalidArgument);
505562
}
506563

507564
TEST_F(CommonShimsSlimTest, NullReturnPointer) {
@@ -512,6 +569,7 @@ TEST_F(CommonShimsSlimTest, NullReturnPointer) {
512569
EXPECT_EQ(aoti_torch_get_strides(tensor, nullptr), Error::InvalidArgument);
513570
EXPECT_EQ(aoti_torch_get_dtype(tensor, nullptr), Error::InvalidArgument);
514571
EXPECT_EQ(aoti_torch_get_dim(tensor, nullptr), Error::InvalidArgument);
572+
EXPECT_EQ(aoti_torch_get_numel(tensor, nullptr), Error::InvalidArgument);
515573
}
516574

517575
// ============================================================================
@@ -534,6 +592,7 @@ TEST_F(CommonShimsSlimTest, ScalarTensor) {
534592
int64_t* ret_sizes = nullptr;
535593
int64_t* ret_strides = nullptr;
536594
int64_t ret_dim = -1;
595+
int64_t ret_numel = -1;
537596

538597
EXPECT_EQ(aoti_torch_get_sizes(tensor, &ret_sizes), Error::Ok);
539598
EXPECT_NE(ret_sizes, nullptr);
@@ -543,6 +602,9 @@ TEST_F(CommonShimsSlimTest, ScalarTensor) {
543602

544603
EXPECT_EQ(aoti_torch_get_dim(tensor, &ret_dim), Error::Ok);
545604
EXPECT_EQ(ret_dim, 0);
605+
606+
EXPECT_EQ(aoti_torch_get_numel(tensor, &ret_numel), Error::Ok);
607+
EXPECT_EQ(ret_numel, 1);
546608
}
547609

548610
TEST_F(CommonShimsSlimTest, LargeTensor) {
@@ -559,6 +621,7 @@ TEST_F(CommonShimsSlimTest, LargeTensor) {
559621

560622
int64_t* ret_sizes = nullptr;
561623
int64_t* ret_strides = nullptr;
624+
int64_t ret_numel = -1;
562625

563626
EXPECT_EQ(aoti_torch_get_sizes(tensor, &ret_sizes), Error::Ok);
564627
EXPECT_EQ(ret_sizes[0], 100);
@@ -569,6 +632,9 @@ TEST_F(CommonShimsSlimTest, LargeTensor) {
569632
EXPECT_EQ(ret_strides[0], 60000); // 200 * 300
570633
EXPECT_EQ(ret_strides[1], 300); // 300
571634
EXPECT_EQ(ret_strides[2], 1);
635+
636+
EXPECT_EQ(aoti_torch_get_numel(tensor, &ret_numel), Error::Ok);
637+
EXPECT_EQ(ret_numel, 6000000);
572638
}
573639

574640
TEST_F(CommonShimsSlimTest, ConsistentPointerReturn) {
234 Bytes
Binary file not shown.

0 commit comments

Comments
 (0)