Skip to content
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

add pnp domain with one op: LinalgSVD #5821

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open

Conversation

liqunfu
Copy link
Contributor

@liqunfu liqunfu commented Dec 24, 2023

Description

It is needed to add data pre/post-processing (pnp) ops to ONNX. These ops mostly come from pre-processing SIG. They usually do not exist in a neural network but are still required in order for a runtime to execute in an end-to-end scenario in production.
This PR is to add infrastructure support for the pnp domain. Followings are still needed to be solved:

  • do we need granular sub domains: pnp.linalg so example?

Motivation and Context

Signed-off-by: Liqun Fu <liqfu@microsoft.com>
@liqunfu liqunfu requested review from a team as code owners December 24, 2023 03:46
[0.618057, -0.412802, -0.841065, -2.316042]
]
])
U, S, Vh = np.linalg.svd(A, full_matrices=True)

Check warning

Code scanning / lintrunner

EDITORCONFIG-CHECKER/editorconfig Warning

Trailing whitespace
[0.618057, -0.412802, -0.841065, -2.316042]
]
])
U, S, Vh = np.linalg.svd(A, full_matrices=True)

Check warning

Code scanning / lintrunner

RUFF/W291 Warning

@@ -0,0 +1,37 @@
# Copyright (c) ONNX Project Contributors

Check warning

Code scanning / lintrunner

RUFF/format Warning

Run lintrunner -a to apply this patch.
@@ -0,0 +1,37 @@
# Copyright (c) ONNX Project Contributors

Check warning

Code scanning / lintrunner

BLACK-ISORT/format Warning

Run lintrunner -a to apply this patch.
@@ -0,0 +1,75 @@
/*

Check warning

Code scanning / lintrunner

CLANGFORMAT/format Warning

See https://clang.llvm.org/docs/ClangFormat.html.
Run lintrunner -a to apply this patch.
@@ -0,0 +1,75 @@
/*

Check warning

Code scanning / lintrunner

EDITORCONFIG-CHECKER/editorconfig Warning

Final newline expected
@@ -74,6 +74,7 @@
("1.14.0", 9, 19, 3, 1),
("1.14.1", 9, 19, 3, 1),
("1.15.0", 9, 20, 4, 1),
("1.16.0", 9, 20, 4, 1, 1),

Check failure

Code scanning / lintrunner

MYPY/list-item Error

List item 22 has incompatible type "tuple[str, int, int, int, int, int]"; expected "tuple[str, int, int, int] | tuple[str, int, int, int, int]" To disable, use # type: ignore[list-item]
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Need to update VersionRowType in line 47


ONNX_PNP_OPERATOR_SET_SCHEMA(LinalgSVD, 1,
OpSchema()
.SetDoc(R"DOC(For internal use.)DOC")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That would be great to have a longer description. onnx runtimes do not need to declare an operator in onnx to implement a kernel. Is it needed for onnx?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

+1. I don't understand what "internal use" means here.

@@ -25,6 +26,7 @@
ONNX_DOMAIN = ""
ONNX_ML_DOMAIN = "ai.onnx.ml"
AI_ONNX_PREVIEW_TRAINING_DOMAIN = "ai.onnx.preview.training"
AI_ONNX_PNP_DOMAIN = "ai.onnx.pnp"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just thinking aloud: I wonder if "ai.onnx.linalg" would be better?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would think ai.onnx.linalg is a clearer domain name


namespace ONNX_NAMESPACE {

ONNX_PNP_OPERATOR_SET_SCHEMA(LinalgSVD, 1,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We could just call it "SVD". Especially if we change the domain to "ai.onnx.linalg" as discussed elsewhere.

ONNX_NAMESPACE::propagateElemTypeFromInputToOutput(ctx, 0, 2);
int64_t full_matrices = ctx.getAttribute("full_matrices")->i();

const TensorShapeProto& A_shape = ctx.getInputType(0)->tensor_type().shape();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These lines should be protected by the usual hasNInputShape or hasInputShape.

auto* u_shape = ctx.getOutputType(0)->mutable_tensor_type()->mutable_shape();
auto* s_shape = ctx.getOutputType(1)->mutable_tensor_type()->mutable_shape();
auto* v_shape = ctx.getOutputType(2)->mutable_tensor_type()->mutable_shape();
if (A_shape.dim_size() == 3) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These shape aspects should be explained in the operator documentation: I guess the input is required to be either 2-dim or 3-dim?

"LinalgSVD",
inputs=["A"],
outputs=["U", "S", "Vh"],
threshold=threshold,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What is threshold?

@gramalingam
Copy link
Contributor

What about the reference implementation? I guess since numpy has one, it should be easy to add?

@gramalingam
Copy link
Contributor

Please also take a look at this PR #4416 for various aspects mentioned there, in case it is useful

@XXXDoraemonslayer
Copy link

Hi can anyone please check in this branch to the Onnx main branch so it can be used with the main build

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: In progress
Development

Successfully merging this pull request may close these issues.

None yet

5 participants