-
Notifications
You must be signed in to change notification settings - Fork 964
Qualcomm AI Engine Direct - oss model enablement (EfficientSAM) #9266
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
cccclai
merged 1 commit into
pytorch:main
from
CodeLinaro:dev1/danny/EfficientSAM_enablement
Apr 10, 2025
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,27 @@ | ||
| # Copyright (c) Qualcomm Innovation Center, Inc. | ||
| # All rights reserved | ||
| # | ||
| # This source code is licensed under the BSD-style license found in the | ||
| # LICENSE file in the root directory of this source tree. | ||
| from executorch.exir.dialects._ops import ops as exir_ops | ||
| from executorch.exir.pass_base import ExportPass | ||
|
|
||
|
|
||
| class ConvertUpsampleBicubicWithBilinear(ExportPass): | ||
| """ | ||
| Qnn does not support bicubic interpolation, so we need to convert it to bilinear. | ||
| This pass will convert bicubic interpolation to bilinear interpolation. | ||
| """ | ||
|
|
||
| bicubic_op_targets = { | ||
| exir_ops.edge.aten.upsample_bicubic2d.vec, | ||
| } | ||
| upsample_bilinear_op = exir_ops.edge.aten.upsample_bilinear2d.default | ||
|
|
||
| def __init__(self): | ||
| super(ConvertUpsampleBicubicWithBilinear, self).__init__() | ||
|
|
||
| def call_operator(self, op, args, kwargs, meta): | ||
| if op not in self.bicubic_op_targets: | ||
| return super().call_operator(op, args, kwargs, meta) | ||
| return super().call_operator(self.upsample_bilinear_op, args[:-1], kwargs, meta) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,84 @@ | ||
| # Copyright (c) Qualcomm Innovation Center, Inc. | ||
| # All rights reserved | ||
| # | ||
| # This source code is licensed under the BSD-style license found in the | ||
| # LICENSE file in the root directory of this source tree. | ||
| from typing import cast, Dict | ||
|
|
||
| import executorch.backends.qualcomm.python.PyQnnWrapperAdaptor as PyQnnWrapper | ||
|
|
||
| import numpy as np | ||
| import torch | ||
| from executorch.backends.qualcomm.utils.constants import QCOM_AXIS_ORDER, QCOM_DATA | ||
|
|
||
| from .node_visitor import NodeVisitor, register_node_visitor | ||
| from .qnn_constants import OpCumulativeSum, QNN_OP_PACKAGE_NAME_QTI_AISW | ||
|
|
||
|
|
||
| @register_node_visitor | ||
| class CumulativeSum(NodeVisitor): | ||
| target = ["aten.cumsum.default"] | ||
|
|
||
| def __init__(self, *args) -> None: | ||
| super().__init__(*args) | ||
|
|
||
| def get_param(self, node, input_tensor): | ||
| dim = node.args[1] | ||
|
|
||
| if dim < 0: | ||
| dim = dim % len(input_tensor.shape) | ||
| if QCOM_AXIS_ORDER in node.meta: | ||
| dim = node.meta[QCOM_AXIS_ORDER].index(dim) | ||
|
|
||
| return cast(np.uint32, dim) | ||
|
|
||
| def define_node( | ||
| self, | ||
| node: torch.fx.Node, | ||
| nodes_to_wrappers: Dict[torch.fx.Node, PyQnnWrapper.TensorWrapper], | ||
| ) -> PyQnnWrapper.PyQnnOpWrapper: | ||
| input_node = node.args[0] | ||
| input_tensor = self.get_tensor(input_node, node) | ||
| input_tensor_wrapper = self.define_tensor( | ||
| input_node, | ||
| node, | ||
| input_tensor, | ||
| PyQnnWrapper.Qnn_TensorType_t.QNN_TENSOR_TYPE_NATIVE, | ||
| nodes_to_wrappers, | ||
| ) | ||
|
|
||
| dim = self.get_param(node, input_tensor) | ||
|
|
||
| output_tensor = self.get_tensor(node, node) | ||
| output_tensor_wrapper = self.define_tensor( | ||
| node, | ||
| node, | ||
| output_tensor, | ||
| PyQnnWrapper.Qnn_TensorType_t.QNN_TENSOR_TYPE_NATIVE, | ||
| nodes_to_wrappers, | ||
| ) | ||
|
|
||
| cumsum_op = PyQnnWrapper.PyQnnOpWrapper( | ||
| node.name, | ||
| QNN_OP_PACKAGE_NAME_QTI_AISW, | ||
| OpCumulativeSum.op_name, | ||
| ) | ||
| cumsum_op.AddInputTensors([input_tensor_wrapper]) | ||
| cumsum_op.AddOutputTensors([output_tensor_wrapper]) | ||
| cumsum_op.AddScalarParam( | ||
| OpCumulativeSum.param_axis, | ||
| PyQnnWrapper.Qnn_DataType_t.QNN_DATATYPE_UINT_32, | ||
| {QCOM_DATA: dim}, | ||
| ) | ||
| cumsum_op.AddScalarParam( | ||
| OpCumulativeSum.param_exclusive, | ||
| PyQnnWrapper.Qnn_DataType_t.QNN_DATATYPE_BOOL_8, | ||
| {QCOM_DATA: False}, | ||
| ) | ||
| cumsum_op.AddScalarParam( | ||
| OpCumulativeSum.param_reverse, | ||
| PyQnnWrapper.Qnn_DataType_t.QNN_DATATYPE_BOOL_8, | ||
| {QCOM_DATA: False}, | ||
| ) | ||
|
|
||
| return cumsum_op |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It seems like the fp test is failing, can you double check? The quantized one is passing.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could you please share the log~?
Both the fp and quantized tests are passing from my side.