[python] Set up binding for preprocessing transform ops#22227
Conversation
3419a6f to
9f3f729
Compare
kuhar
left a comment
There was a problem hiding this comment.
Looks good overall. Maybe reference the mlir PR you used as a reference in the PR description, so that we can track the overall design/mechanics to that original PR?
|
When updating the test, I noticed that the printed operation from python looks like: determined by assembly format It turns out the parser accepts both of the following formats: // Format 1: Custom format (what the printer outputs)
transform.iree.match.contraction %op, lhs_type = f32, rhs_type = f32, output_type = f32
indexing_maps [#map1, #map2, #map3]
: !transform.any_op -> !transform.param<i64>
// Format 2: Attribute dictionary format (also accepted!)
transform.iree.match.contraction %op, lhs_type = f32, rhs_type = f32, output_type = f32
{indexing_maps = [#map1, #map2, #map3]}
: !transform.any_op -> !transform.param<i64>To make the printed and test formats consistent, I updated the assembly format of transform.iree.match.contraction to : This change doesn’t alter semantics or parsing behavior. It only ensures that the Python-printed module matches the format used in tests. |
|
Can we print it as: with a leading comma and equals? It's weird to have some attributes printed inline and some in the attribute dictionary |
Updated! The assembly format now prints all attributes inline: Should I update the tests in preprocessing_match_ops.mlir for consistency, if so I prefer to do it in another separate PR. |
| `,` `lhs_type` `=` $lhs_type | ||
| `,` `rhs_type` `=` $rhs_type | ||
| `,` `output_type` `=` $output_type | ||
| (`,` `indexing_maps` `=` $indexing_maps^)? |
There was a problem hiding this comment.
Can we also use this syntax in all tests and add an op example in let description = above?
There was a problem hiding this comment.
Here is my comment: #22227 (comment)
Should we do it in this PR?
be0e02c to
942931b
Compare
|
cc @kuhar for another look, since other PRs are also on top of this. |
Don't stack PRs when not necessary -- AFAICT, the other PRs don't need these python bindings, and we don't need syntax changes in this PR. |
For python testing, we updated the assembly format for match contraction op in this PR. |
|
You can either update the assembly format first and then come back and update this PR, or land this first and update the assembly format later. We should avoid stacking PRs when not necessary. |
Ok, could I send a new PR that focuses only on updating the assembly format? The existing PR (#22247) should be closed since it depends on the current one. |
|
You can force-push to an existing PR branch to avoid closing/opening PRs |
Ok the PR is closed automatically when reset --hard and push it to no change. I sent a PR which is independent and pure about updating assembly format: #22270. |
…cher ops (#22270) According to this comment: #22227 (comment), this PR updates the assembly format for contraction and convolution matcher ops. The attention matcher op's indexing map is not optional and also consistent with what is suggested in the comment, so no need to update. Signed-off-by: Bangtian Liu <liubangtian@gmail.com>
942931b to
a3d441c
Compare
Signed-off-by: Bangtian Liu <liubangtian@gmail.com> address the comment and also update the assembly format Signed-off-by: Bangtian Liu <liubangtian@gmail.com> update assembly format Signed-off-by: Bangtian Liu <liubangtian@gmail.com>
a3d441c to
0e595e3
Compare
…op (#22311) This PR extends the preprocessing transform dialect Python bindings by adding `MatchConvolutionOp `and `MatchAttentionOp`, completing the matcher operation API suite started in #22227. **Motivation** Completes the Python binding API for all preprocessing transform matcher operations, enabling SHARK Tuner to programmatically generate Transform Dialect specs for convolutions and attention operations in addition to contractions. This removes the need for string-based spec generation and improves type safety and maintainability. Signed-off-by: Bangtian Liu <liubangtian@gmail.com>
This PR uses python binding to build td specs for contraction op. The python binding is exposed from IREE PR iree-org/iree#22227 (MatchContractionOp binding). Right now, the code still contains two paths for building TD specs: - Contraction ops: Use new Python bindings via `build_contraction_td_spec()` - Convolution/Attention ops: Still use old string template approach via `build_td_spec()` After this PR, I will also send PRs for convolution and attention ops to migrate them to Python bindings. Once all operations are supported, some code relevant to temporary solutions and string-based method will be fully cleaned up. --------- Signed-off-by: Bangtian Liu <liubangtian@gmail.com>
…cher ops (iree-org#22270) According to this comment: iree-org#22227 (comment), this PR updates the assembly format for contraction and convolution matcher ops. The attention matcher op's indexing map is not optional and also consistent with what is suggested in the comment, so no need to update. Signed-off-by: Bangtian Liu <liubangtian@gmail.com> Signed-off-by: Philipp <philipp.weidel@intel.com>
This PR adds Python bindings for the Preprocessing Transform Extension ops. It exposes the transform ops defined in that extension, such as `transform.iree.match.contraction`, as well as other commonly used ops like `transform.iree.match.cast_compatible_dag_from_root `and `transform.iree.match.dim_is_multiple_of`, etc. The bindings are exposed using `declare_mlir_dialect_extension_python_bindings`. The logic mainly follows this llvm upstream PR: llvm/llvm-project#159450. Signed-off-by: Bangtian Liu <liubangtian@gmail.com> Signed-off-by: Philipp <philipp.weidel@intel.com>
…op (iree-org#22311) This PR extends the preprocessing transform dialect Python bindings by adding `MatchConvolutionOp `and `MatchAttentionOp`, completing the matcher operation API suite started in iree-org#22227. **Motivation** Completes the Python binding API for all preprocessing transform matcher operations, enabling SHARK Tuner to programmatically generate Transform Dialect specs for convolutions and attention operations in addition to contractions. This removes the need for string-based spec generation and improves type safety and maintainability. Signed-off-by: Bangtian Liu <liubangtian@gmail.com> Signed-off-by: Philipp <philipp.weidel@intel.com>
…cher ops (#22270) According to this comment: iree-org/iree#22227 (comment), this PR updates the assembly format for contraction and convolution matcher ops. The attention matcher op's indexing map is not optional and also consistent with what is suggested in the comment, so no need to update. Signed-off-by: Bangtian Liu <liubangtian@gmail.com>
This PR adds Python bindings for the Preprocessing Transform Extension ops. It exposes the transform ops defined in that extension, such as `transform.iree.match.contraction`, as well as other commonly used ops like `transform.iree.match.cast_compatible_dag_from_root `and `transform.iree.match.dim_is_multiple_of`, etc. The bindings are exposed using `declare_mlir_dialect_extension_python_bindings`. The logic mainly follows this llvm upstream PR: llvm/llvm-project#159450. Signed-off-by: Bangtian Liu <liubangtian@gmail.com>
…op (iree-org#22311) This PR extends the preprocessing transform dialect Python bindings by adding `MatchConvolutionOp `and `MatchAttentionOp`, completing the matcher operation API suite started in iree-org#22227. **Motivation** Completes the Python binding API for all preprocessing transform matcher operations, enabling SHARK Tuner to programmatically generate Transform Dialect specs for convolutions and attention operations in addition to contractions. This removes the need for string-based spec generation and improves type safety and maintainability. Signed-off-by: Bangtian Liu <liubangtian@gmail.com>
This PR uses python binding to build td specs for contraction op. The python binding is exposed from IREE PR iree-org/iree#22227 (MatchContractionOp binding). Right now, the code still contains two paths for building TD specs: - Contraction ops: Use new Python bindings via `build_contraction_td_spec()` - Convolution/Attention ops: Still use old string template approach via `build_td_spec()` After this PR, I will also send PRs for convolution and attention ops to migrate them to Python bindings. Once all operations are supported, some code relevant to temporary solutions and string-based method will be fully cleaned up. --------- Signed-off-by: Bangtian Liu <liubangtian@gmail.com>
This PR adds Python bindings for the Preprocessing Transform Extension ops.
It exposes the transform ops defined in that extension, such as
transform.iree.match.contraction, as well as other commonly used ops liketransform.iree.match.cast_compatible_dag_from_rootandtransform.iree.match.dim_is_multiple_of, etc.The bindings are exposed using
declare_mlir_dialect_extension_python_bindings. The logic mainly follows this llvm upstream PR: llvm/llvm-project#159450.