Custom pseudo-operations for generic rewriting

未关闭
#2,162 0 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

维护者通常 4 天内回复

还没有人认领这个 Issue。

评估

难度
5/5
预计耗时
一周以上
新手友好度
28/100
Issue 类型
功能
描述清晰度
基本清楚
活跃度
停滞
技术栈
python
领域
tooling

调研方向

首先阅读附加的 cusops2ons.py.txt 和 test_generic_as_wrap.py.txt,然后检查 Opset、script、Op 和 op_schema 附近的 onnxscript rewriter 用法。确定自定义伪操作是否可以参与通用重写,并记录一个可工作的自定义节点示例,同时提供一个展示预期重写行为的测试。

由索引模型根据 Issue 内容生成。

描述

This text organized as

  1. Problem
  2. Solution
  3. This issue subject

Problem to solve

I want element-wise operations move above their commutatives (friends). See picture:

Image

I don't want to encode every possible interchange pair, so must be generic element-wise and generic friend. Can I have it with current onnxscript (0.2.2) rewriter?

  1. Solution

Use meta-abc node pairs like this:

Image

In the attachment, there is prototype implementation.
It moves elementwise operations (ReLU and Tanh) above Identity and Flatten

cusops2ons.py.txt

test_generic_as_wrap.py.txt

For now, we encode elementwise wrappers as [Split(axis=20), Sub]
and wrappers of their friend as [Split(axis=30), Sub]

What do you think about this approach to generics?

  1. The issue

Well, it works! But using Split and Sub as replacement to ABC_pre and ABC_post is obviously bad.
I actually tried to create custom pseudo-operation, but failed.

As I create op like this:

my_opset = Opset("com.mydomain", 15)

@script(my_opset)
def joy_of_relu( x:FLOAT ) -> FLOAT:
    y =    op.Relu(x)
    return op.Relu(y)


opsch = joy_of_relu.op_schema

shiny_new_op = Op(
    opset=my_opset, name="relurelu", op_schema=opsch
)

it not work with rewriter, also I tried onnxruntime_extensions.onnx_op

So, if it is possible, it would be great to have example of using rewriter with custom nodes.

主要语言
Python
星标
457
派生
149
平均合并
3 天 20 小时
30 天内合并 PR
22

环境准备

  • 没有 Dockerfile 或 Docker Compose 文件
  • 没有 Pull Request 模板
  • 阅读贡献指南

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

microsoft/onnxscript 的其他 Issue

查看 microsoft/onnxscript 的全部 Issue

相似的 Issue

更多 Python Issue

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。