TorchOps Zero#6
Merged
Merged
Conversation
Implement a large set of new Torch->ONNX export helpers and corresponding unit tests. Added numerous Export* methods (unary ops like Abs/Neg/Exp/Log/Sin/Cos/Tan/Floor/Ceil/Round/Trunc/Reciprocal/Sign and many trig/special functions, comparisons/logical ops, reductions, index/search ops, clamp/mod/remainder handling, and a number of composite helpers) plus TorchOp annotations including aliases (e.g. _operator::*, prims::*). Tests were added to verify emitted ONNX nodes and attributes. Updated the TorchSharp operator coverage report (coverage increased from 25.70% (128/498) to 37.35% (186/498)) and reworked README to highlight TorchSharp Operator Porting and move the TODO list. This change increases operator coverage and adds tests to validate ONNX graph emission.
Add broad support for additional Torch operators and corresponding tests. Updates include new unit tests verifying Identity/alias/type operators, extra math ops (deg2rad, rad2deg, exp2, frac, log10, etc.), and all/any truth-reduction behaviors. In TorchTensorOperatorExtensions, many TorchOp attributes were added (prims::*, aten::*, _operator::*, aten::broadcast_to/ tile/ view_as/ type_as) and new helpers implemented: ExportNotEqual, ExportIdentity, ExportViewAs, ExportDeg2Rad/Rad2Deg/Exp2/Frac/Log10, ExportTypeAs, ExportAll/ExportAny and a shared ExportTruthReduction routine. Also added mappings for reshape/transpose/squeeze/where/sum/repeat/pow/sqrt and expanded coveredOperators assertions in tests to reflect the increased operator coverage.
Regenerate the Onnxify TorchSharp converter reference docs via the agent generator. The index was updated (signatures: 101 -> 179, torch-op-backed converters: 99 -> 177, distinct Torch ops: 129 -> 268) and many new torch-ops reference pages were added for math/comparison/prims/_operator variants and other ops. Several files were renamed to include _operator variants (e.g. add, mul, sub) and existing entries were expanded to list additional Torch/prim mappings; some reference pages were also modified. Added update-agent-skills.ps1. These files are autogenerated; do not hand-edit.
Add runtime smoke tests and ONNX runtime helpers: introduce multiple Smoke_RuntimeExecutes* tests, CreateModel/CreateRuntimeModel, Add*Output helpers, RunModel, and AssertTensorValues using Microsoft.ML.OnnxRuntime. Update several test expectations to reflect decomposed operator sequences. Improve TorchTensorOperatorExtensions: handle floating-point remainder and frac by decomposing into Div/Floor/Mul/Sub/Abs/Sign, replace CastLike usage with explicit Cast exports and a GetOnnxTensorDataType mapper, and add IsFloatingPointTensorType and ExportCastTo helpers. Use opset 23 for runtime models and clean up graph/model creation. These changes enable runtime execution tests and correct casting/float operator exports.
Regenerate TorchSharp converter references and update internal porting guidance. Adds many new torch-op reference pages (e.g. floordiv, amin, atan2, full/full_like, isneginf/isposinf, ones/ones_like, pow.Scalar, round.decimals, sinc, special_erfcx, zeros/zeros_like, prims::tanh) and expands op signatures/aliases (including prims variants). Updates the index counts and per-op metadata, and adjusts generated source/tests: TorchTensorOperatorExtensions.cs, observer report, and related unit tests. Also improves .agents/skills/onnxify-internal/SKILL.md with a required candidate-selection workflow for batching TorchSharp operator ports.
Add TorchSharp-to-ONNX converters and tests for range, linspace, and extrema operations. Introduces ExportArange overloads for aten::arange, aten::arange.start and aten::arange.start_step, ExportLinspace for aten::linspace, and ExportMax/ExportMin (including .dim variants) with helper routines (ExportRange, ExportExtremumByDim, AddScalarTensor). Also add TorchOp annotations for aten::_conj and aten::conj, update generated reference docs for the new converters, and update the TorchSharp operator coverage report. Tests (TorchTensorOperatorExtensionsTests) were added to verify emitted nodes and runtime execution, and existing coverage assertions were extended to include the new operators.
Implement TorchSharp->ONNX converters for several ops: aten::equal, aten::allclose, aten::isclose, aten::isfinite, aten::isinf, aten::isnan, aten::logaddexp, aten::logaddexp2, aten::logit and aten::logsumexp. Add a new helper ExportReduceNode for Reduce-style ops and wire up conversions in TorchTensorOperatorExtensions.cs. Add unit tests to verify node emission and runtime execution (ExportCloseAndLogOperators_EmitExpectedNodes and Smoke_RuntimeExecutesCloseAndLogOperators). Generate reference markdown entries and update the operator index and coverage report to reflect the newly supported ops.
Implement several TorchSharp->ONNX converters and their tests. Adds ExportAddBmm, ExportAddCDiv, ExportAddCMul, ExportAddMM, ExportAddMV, ExportAddr, ExportBAddBmm, ExportLerp (Tensor/Scalar) and ExportMV in TorchTensorOperatorExtensions, plus helper methods (ScaleLikeIfNeeded, CastLikeIfNeeded, ExportLerpCore). Adds autogenerated reference markdown for the new converters and updates the converters index. Adds unit tests that verify node emission and runtime execution for the new linear-algebra/blend ops, and updates the torchsharp operator coverage report (coverage increased to 65.06%).
Add a new reference guide (.agents/skills/onnxify-internal/references/validating-existing-torchsharp-converters-against-onnxscript.md) that provides a step-by-step workflow to validate existing Onnxify.TorchSharp exporters against the Python ONNXScript implementations. The guide covers using the observer report, locating generated converter signatures, tracing the real C# exporter and its helpers, finding the ONNXScript exporter, semantic comparison criteria, common pitfalls, and recording outcomes. Also update .agents/skills/onnxify-internal/SKILL.md to link to the new document and surface a short validation procedure in the TorchSharp section.
Make the TorchSharp porting/validation guidance explicit and opt-in. Changes: require explicit user request before running ONNXScript-vs-TorchSharp validation; emphasize using ONNXScript Python tests to learn operator contracts; recommend deriving idiomatic C# tests in Onnxify.Tests (test-first/test-guided flow) rather than line-by-line translating Python tests; instruct reviewers to inspect existing C# tests as part of validation; and add practical search examples and ordering for implementation. Updates applied to SKILL.md, porting-onnxscript-converters.md, and validating-existing-torchsharp-converters-against-onnxscript.md.
Special-case scalar inputs/indices and improve ordering/export behavior. TorchTensorOperatorExtensions now: - Treat scalar input for Gather by returning Identity (scalar index) or expanding the scalar to the index shape; cast indices to long and Unsqueeze/Squeeze when index is scalar. - Return Identity + scalar index for Sort when input is scalar. - Throw NotSupportedException for TopK on scalar inputs. Tests updated/added to cover these scenarios (remainder scalar tensor, scalar extrema branches for max/min values and indices, sort/topk ordering, shape-sensitive indexing ops, logsumexp scalar, logit no-eps, addr beta case, etc.). Also enhanced AssertTensorValues to correctly assert NaN and +/-Infinity values. These changes improve ONNX export correctness and increase test coverage for scalar and shape-sensitive operators.
There was a problem hiding this comment.
Pull request overview
Bumps the Onnxify.TorchSharp Torch-op coverage from 25.70% to 65.06% by adding many new [TorchOp]-decorated exporters (reflected entirely through regenerated skill docs and the observer coverage report), refreshes README structure, and extends the internal skill workflow with explicit guidance for choosing porting candidates and for validating existing exporters against ONNXScript.
Changes:
- Regenerated TorchSharp operator coverage report and ~110 generated converter skill pages reflecting newly-decorated exporters and added op aliases (e.g.,
prims::*,aten::tile,aten::broadcast_to, etc.). - Reworked
README.md: replaced the "Status" section with a TorchSharp porting summary and moved/refreshed the TODO list. - Updated
.agents/skills/onnxify-internal/SKILL.mdand added a newvalidating-existing-torchsharp-converters-against-onnxscript.mdreference, plus expandedporting-onnxscript-converters.mdwith Python-test-driven guidance. - Added a 2-line
update-agent-skills.ps1helper to regenerate the observer report and agent skills.
Reviewed changes
Copilot reviewed 144 out of 145 changed files in this pull request and generated 1 comment.
Show a summary per file
| File | Description |
|---|---|
| update-agent-skills.ps1 | New helper invoking observer and skill generator projects. |
| src/Onnxify.TorchSharp.Observer/torchsharp-operator-report.md | Coverage stats updated to 65.06%; many rows gain a coverage checkmark. |
| README.md | TorchSharp porting blurb replaces Status section; TODO moved below skills install instructions. |
| .agents/skills/onnxify/references/torchsharp-converters/index.md | Regenerated index listing all newly-covered exporters, with merged Torch-op alias lists. |
| .agents/skills/onnxify/references/torchsharp-converters/torch-ops/*.md | Many new/updated generated converter pages (signatures, Torch ops, parameters) for the added exporters. |
| .agents/skills/onnxify-internal/SKILL.md | Adds workflows for choosing porting candidates and for validating existing converters against ONNXScript. |
| .agents/skills/onnxify-internal/references/validating-existing-torchsharp-converters-against-onnxscript.md | New reference describing the opt-in validation workflow. |
| .agents/skills/onnxify-internal/references/porting-onnxscript-converters.md | Adds steps for using ONNXScript tests to inform C# tests and exporter behavior. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| Search by method name first, not just by Torch op string. For example: | ||
|
|
||
| ```powershell | ||
| rg -n "ExportAddMM|\[TorchOp\(\" src\Onnxify.TorchSharp |
Refactor TorchSharp converters and tests: introduce ExportReshape and ExportView backed by a shared ExportReshapeCore (allowZero flag) so reshape emits Reshape without allowzero while view sets allowzero=1. Add a prims::transpose ExportTranspose path and normalize/handle permute/transpose edge cases (empty permutation reverses axes, negative-axis normalization, rank-0 returns Identity). ExportT now returns Identity for non-rank-2 inputs. Update autogenerated converter references (counts and per-op entries) and add converter docs for aten::view and prims::transpose. Add a persistent torchsharp operator verification log and remove the old wave1 report. Update and expand unit tests to cover the new behaviors and parity fixes.
Fix operator exporter semantics and add coverage to match ONNXScript behavior. Key changes: - Remap aten::split.Tensor to split_with_sizes and expose aten::split overloads consistently; update autogenerated converter docs. - Add explicit prims::squeeze exporter (with axes tensor) and separate it from aten::squeeze; update docs. - Make aten::squeeze.dim return Identity for scalar inputs to match ONNXScript. - Ensure aten::masked_fill.Tensor casts the replacement like `self` before lowering to Where (CastLike behavior). - Treat empty dims for aten::all.dims and aten::any.dims as reduce-all (pass null axes) instead of emitting an empty axes tensor. - Make aten::clamp return Identity when both bounds are omitted (no-ops) instead of throwing. - Add broad unit and runtime tests covering split-with-sizes, split/chunk/select, prims/aten squeeze variants, masked_fill tensor/scalar paths, empty-dims truth reductions, clamp no-bounds, and combined runtime smoke tests. - Update autogenerated reference files (renames and new prims::squeeze doc) and expand the operator verification log (wave3) entries. - Bump project package versions from 0.0.0.14 to 0.0.0.15 across affected csproj files. These changes improve parity with ONNXScript and increase branch- and runtime-sensitive test coverage for the TorchSharp export surface.
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
No description provided.