Skip to content

Commit c3e6386

Browse files
authored
Merge branch 'main' into Add-support-for-elu
2 parents 242dbfc + deaf37f commit c3e6386

File tree

74 files changed

+3875
-873
lines changed

Some content is hidden

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

74 files changed

+3875
-873
lines changed

.ci/scripts/setup-vulkan-linux-deps.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ install_vulkan_sdk() {
4343
export PATH="${PATH}:${_vulkan_sdk_dir}/${VULKAN_SDK_VERSION}/x86_64/bin/"
4444
}
4545

46-
VULKAN_SDK_VERSION="1.3.296.0"
46+
VULKAN_SDK_VERSION="1.4.321.1"
4747

4848
install_swiftshader
4949
install_vulkan_sdk "${VULKAN_SDK_VERSION}"

.github/workflows/apple-perf.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -416,7 +416,7 @@ jobs:
416416
- set-parameters
417417
secrets: inherit
418418
with:
419-
runner: macos-latest-xlarge
419+
runner: macos-14-xlarge
420420
python-version: '3.11'
421421
submodules: 'recursive'
422422
ref: ${{ github.event_name == 'pull_request' && github.event.pull_request.head.sha || github.sha }}

.github/workflows/apple.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ jobs:
4949
uses: pytorch/test-infra/.github/workflows/macos_job.yml@main
5050
secrets: inherit
5151
with:
52-
runner: macos-latest-xlarge
52+
runner: macos-14-xlarge
5353
python-version: '3.11'
5454
submodules: 'recursive'
5555
ref: ${{ github.event_name == 'pull_request' && github.event.pull_request.head.sha || github.sha }}
@@ -136,7 +136,7 @@ jobs:
136136
needs: set-version
137137
uses: pytorch/test-infra/.github/workflows/macos_job.yml@main
138138
with:
139-
runner: macos-latest-xlarge
139+
runner: macos-14-xlarge
140140
python-version: '3.11'
141141
submodules: 'recursive'
142142
ref: ${{ github.event_name == 'pull_request' && github.event.pull_request.head.sha || github.sha }}
@@ -276,7 +276,7 @@ jobs:
276276
uses: pytorch/test-infra/.github/workflows/macos_job.yml@main
277277
secrets: inherit
278278
with:
279-
runner: macos-latest-xlarge
279+
runner: macos-14-xlarge
280280
python-version: '3.11'
281281
submodules: 'recursive'
282282
ref: ${{ github.event_name == 'pull_request' && github.event.pull_request.head.sha || github.sha }}

.github/workflows/build-presets.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ jobs:
2222
with:
2323
job-name: build
2424
ref: ${{ github.event_name == 'pull_request' && github.event.pull_request.head.sha || github.sha }}
25-
runner: macos-latest-xlarge
25+
runner: macos-14-xlarge
2626
python-version: 3.12
2727
submodules: recursive
2828
timeout: 90

.github/workflows/build-wheels-macos.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ jobs:
6363
post-script: ${{ matrix.post-script }}
6464
package-name: ${{ matrix.package-name }}
6565
# Meta's macOS runners do not have Xcode, so use GitHub's runners.
66-
runner-type: macos-latest-xlarge
66+
runner-type: macos-14-xlarge
6767
setup-miniconda: true
6868
smoke-test-script: ${{ matrix.smoke-test-script }}
6969
trigger-event: ${{ github.event_name }}

.github/workflows/pull.yml

Lines changed: 31 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -855,13 +855,14 @@ jobs:
855855
.ci/scripts/setup-linux.sh --build-tool "cmake"
856856
857857
# Install test requirements
858-
pip install -r backends/nxp/requirements-tests.txt
858+
pip install -r backends/nxp/requirements-tests-pypi.txt
859+
pip install -r backends/nxp/requirements-tests-eiq.txt
859860
860861
# Run pytest
861862
PYTHON_EXECUTABLE=python bash backends/nxp/run_unittests.sh
862863
863864
# Run aot examples:
864-
PYTHON_EXECUTABLE=python bash examples/nxp/run_aot_example.sh cifar10
865+
PYTHON_EXECUTABLE=python bash examples/nxp/run_aot_example.sh cifar10
865866
PYTHON_EXECUTABLE=python bash examples/nxp/run_aot_example.sh mobilenetv2
866867
867868
@@ -901,6 +902,34 @@ jobs:
901902
done
902903
903904
905+
test-vulkan-operators-linux:
906+
name: test-vulkan-operators-linux
907+
uses: pytorch/test-infra/.github/workflows/linux_job_v2.yml@main
908+
permissions:
909+
id-token: write
910+
contents: read
911+
with:
912+
runner: linux.2xlarge
913+
docker-image: ci-image:executorch-ubuntu-22.04-clang12
914+
submodules: 'recursive'
915+
ref: ${{ github.event_name == 'pull_request' && github.event.pull_request.head.sha || github.sha }}
916+
timeout: 90
917+
script: |
918+
set -eux
919+
920+
# The generic Linux job chooses to use base env, not the one setup by the image
921+
CONDA_ENV=$(conda env list --json | jq -r ".envs | .[-1]")
922+
conda activate "${CONDA_ENV}"
923+
924+
# Setup swiftshader and Vulkan SDK which are required to build the Vulkan delegate
925+
source .ci/scripts/setup-vulkan-linux-deps.sh
926+
927+
# Setup python
928+
PYTHON_EXECUTABLE=python \
929+
CMAKE_ARGS="-DEXECUTORCH_BUILD_VULKAN=ON" \
930+
.ci/scripts/setup-linux.sh --build-tool "cmake"
931+
932+
PYTHON_EXECUTABLE=python bash backends/vulkan/test/custom_ops/build_and_run.sh add
904933
905934
nxp-build-test:
906935
name: nxp-build-test

.github/workflows/trunk.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -435,7 +435,7 @@ jobs:
435435
name: test-coreml-delegate
436436
uses: pytorch/test-infra/.github/workflows/macos_job.yml@main
437437
with:
438-
runner: macos-latest-xlarge
438+
runner: macos-14-xlarge
439439
python-version: '3.11'
440440
submodules: 'recursive'
441441
ref: ${{ github.event_name == 'pull_request' && github.event.pull_request.head.sha || github.sha }}

backends/cadence/aot/TARGETS

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -604,3 +604,17 @@ python_unittest(
604604
"//later:lib",
605605
],
606606
)
607+
608+
python_unittest(
609+
name = "test_ref_implementations",
610+
srcs = [
611+
"tests/test_ref_implementations.py",
612+
],
613+
supports_static_listing = False,
614+
typing = True,
615+
deps = [
616+
":typing_stubs",
617+
"//executorch/backends/cadence/aot:ref_implementations",
618+
"//caffe2:torch",
619+
]
620+
)

backends/cadence/aot/ops_registrations.py

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
get_im2row_output_size,
1717
)
1818
from executorch.exir.scalar_type import ScalarType
19+
from torch._meta_registrations import _linalg_svd_meta
1920
from torch.library import Library, register_fake
2021

2122
lib = Library("cadence", "DEF")
@@ -250,6 +251,12 @@
250251
"int in_zero_point, bool channel_last=False) -> (Tensor out)"
251252
)
252253
lib.define("linalg_vector_norm(Tensor X) -> (Tensor Y)")
254+
lib.define(
255+
"linalg_svd(Tensor A, bool full_matrices=False, bool compute_uv=True, str? driver=None) -> (Tensor U, Tensor S, Tensor Vh)"
256+
)
257+
lib.define(
258+
"linalg_svd.out(Tensor A, bool full_matrices=False, bool compute_uv=True, str? driver=None, *, Tensor(a!) U, Tensor(b!) S, Tensor(c!) Vh) -> (Tensor(a!) U, Tensor(b!) S, Tensor(c!) Vh)"
259+
)
253260
lib.define(
254261
"transposed_im2row(Tensor input, int[2] kernel_size, int[2] dilation, int[2] padding, int[2] stride, "
255262
"int[2] output_padding, Tensor in_zero_point, bool channel_last=False) -> (Tensor out)"
@@ -1576,6 +1583,26 @@ def linalg_vector_norm_meta(
15761583
return X.new_empty([], dtype=X.dtype)
15771584

15781585

1586+
@register_fake("cadence::linalg_svd")
1587+
def linalg_svd_meta(
1588+
A: torch.Tensor,
1589+
full_matrices: bool = False,
1590+
compute_uv: bool = True,
1591+
driver: Optional[str] = None,
1592+
) -> Tuple[torch.Tensor, torch.Tensor, torch.Tensor]:
1593+
# Based on the _linalg_svd meta implementation, but ensuring contiguous strides
1594+
1595+
# Get the shapes from the original meta function
1596+
U, S, Vh = _linalg_svd_meta(A, full_matrices, compute_uv, driver)
1597+
1598+
# Create new tensors with contiguous strides to fix the non-contiguous issue
1599+
U_contiguous = A.new_empty(U.shape, dtype=A.dtype).contiguous()
1600+
S_contiguous = A.new_empty(S.shape, dtype=A.dtype).contiguous()
1601+
Vh_contiguous = A.new_empty(Vh.shape, dtype=A.dtype).contiguous()
1602+
1603+
return U_contiguous, S_contiguous, Vh_contiguous
1604+
1605+
15791606
@register_fake("cadence::requantize")
15801607
def requantize_meta(
15811608
input: torch.Tensor,

backends/cadence/aot/ref_implementations.py

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,42 @@
2020
}
2121

2222

23+
@impl(m, "quantize_per_tensor")
24+
def quantize_per_tensor(
25+
input: torch.Tensor,
26+
scale: float,
27+
zero_point: int,
28+
quant_min: int,
29+
quant_max: int,
30+
dtype: torch.dtype,
31+
) -> torch.Tensor:
32+
"""
33+
Quantizes a floating-point tensor to an integral tensor.
34+
35+
Args:
36+
- input (Tensor): input tensor
37+
- scale (float): Quantization scale. Derived from the ratio
38+
between the min/max of the floating-point tensor and the
39+
min/max of the quantized range.
40+
- zero_point (int): The point which represents 0 in the quantized
41+
range. For example, consider the floating point range [-1., 2.] and
42+
quantized integer range [-7, 7]. In this case, 0 is 1/3 of way from
43+
-1. to 2. So, the point that represents 0 in the quantized range should
44+
be 1/3 of the way from [-7, 7]. This ends up being -2 in the integer space.
45+
- quant_min (int): The smallest value in the quantized domain. Unused since scale
46+
is already provided.
47+
- quant_max (int): The largest value in the quantized domain. Unused since scale
48+
is already provided.
49+
- dtype (torch.dtype): The type of the output tensor
50+
"""
51+
supported_quant_types = [torch.int8, torch.int16, torch.int32]
52+
if dtype not in supported_quant_types:
53+
raise ValueError(
54+
f"Unsupported dtype to quantize to. Supported dtypes must be one of {supported_quant_types}"
55+
)
56+
return torch.round(input / scale + zero_point).to(dtype)
57+
58+
2359
@impl(m, "requantize")
2460
def requantize(
2561
input: torch.Tensor,

0 commit comments

Comments
 (0)