Open
[Requirement|需求建议]: support custom op export #2869
hid22900163Add on Aug 4
Aug 4 Modify description of issue
Hhid22900163
Aug 4 Change title to "[Requirement|需求建议]: support custom op export", originally titled "[Requirement|需求建议]: ".
Aug 4 Change title to "[Requirement|需求建议]: support custom op export", originally titled "[Requirement|需求建议]: ".
Aug 4 Modify description of issue
Aug 4 Modify description of issue
Aug 6 Assign Nikita17 as responsible person
Aug 6 Associated pull request
Aug 6 Associated pull request
Aug 6 Associated pull request
Aug 6 Associated pull request
Aug 6 Associated pull request
Aug 6 Associated pull request
hid22900163
Sep 15 Comments:
Sep 15 Comments:
Implementation PRs
Custom op export is delivered as a stack of PRs against master. Each PR builds on the one listed before it, so they merge in this order.
Prerequisite (merged)
Core: pypto.extensions.torch_custom_op
Examples library: export, codegen and build
Demos
Docs
Chain overview
Pypto Custom-Op Surface shows the dependency graph between these PRs and, for each PR, every class, function and method it adds. It reflects the chain tip 3546f7f60.
High-level component diagram: https://claude.ai/artifact/MgM1bKEGubuZ6JYFqDsWg2


Sep 15 changed custom category from 任务 to 需求
Background(背景信息)
We write compute kernels in PyPTO, but today we can only run them standalone from a Python script. There is no supported way to put one inside a real model and ship it.
To get a PyPTO kernel into a production inference model, someone on our side has to hand-write the framework plumbing for every single operator - registering it, making it survive model export, and describing it to the graph compiler. That is several hundred lines per operator, none of it about the computation we care about. It is slow, only two or three people can do it, and whenever a framework interface changes, every operator we already wrote has to be fixed one by one.
We need a PyPTO kernel to become a deployable operator without any of that. The author should describe the kernel and how its output shape and dtype are derived; everything the frameworks need should be produced from that description, so the operator can be exported into a model, compiled with the rest of the graph, and executed on device.
Origin(信息来源)
Requested by the team deploying PyPTO-authored operators into customer inference models on Kirin, where the model is compiled ahead of time and executed on device.
Benefit / Necessity(价值/作用)
Why we need it
Value
Where we would use it
Delivered means
Design(设计方案)
Overall idea: the operator is described once, in Python, by the person who wrote the kernel. Everything the frameworks need is derived from that description - nothing framework-specific is written by hand.
1. The author describes the operator in one place
my_op = CustomOp( kernel = my_kernel, # the PyPTO kernel, kept as an ordinary editable file infer_shape = my_infer_shape, # output shape, from the input shapes infer_dtype = my_infer_dtype, # output dtype, from the input dtypes reference = my_cpu_version, # used on CPU, and as the correctness baseline parameters = [ scale: float, channels: int ], )The shape and dtype rules are given once and used both while the model is traced and by the deployed operator, so they cannot drift apart.
2. Export and build then just work
The author exports the model as usual, and the operator is built and compiled together with the rest of the graph:
3. The same description runs everywhere
Which one runs is chosen by how the model is run, rather than by editing the description: on CPU it uses the reference version, on the simulator and on device it uses the real kernel. That is what lets us compare device output against CPU output.
4. The shipped kernel file stays the real kernel
Editing it and redeploying is a single step.