Skip to content

feat(ops): implement convTranspose2d — CPU kernel, backward and StableHLO lowering - #1464

Merged
michalharakal merged 3 commits into
developfrom
feature/1371-conv-transpose2d
Oct 31, 2026
Merged

michalharakal merged 3 commits into
developfrom
feature/1371-conv-transpose2d

Conversation

@michalharakal

Copy link
Copy Markdown
Contributor

Summary

Implements 2D transposed convolution end to end, closing the ❌ rows for TensorOps.convTranspose2d and TransposedConv2d in the operator coverage matrix.

  • API (TensorOps): convTranspose2d promoted from a @NotImplemented default-throwing stub to an abstract @Diff op. PyTorch conv_transpose2d semantics: weight [C_in, C_out/groups, kH, kW], output size (in-1)*stride - 2*padding + dilation*(k-1) + outputPadding + 1.
  • CPU kernel (DefaultCpuOps): scatter-add over out[b, oc, ih*sH-pH+kh*dH, iw*sW-pW+kw*dW] += in * w, mirroring convTranspose1d, with full validation (shapes, groups divisibility, outputPadding < max(stride, dilation) per axis, bias shape, dtype guard so non-float dtypes fail loudly instead of corrupting).
  • Backward (DefaultExecutionTape): convTranspose2dBackward adjoint for input, weight and bias, wired into the dispatch table (the autodiff-coverage guard enforces this once the op is @Diff).
  • StableHLO lowering (NeuralNetOperationsConverter): the standard conv-transpose rewrite — stablehlo.convolution with lhs_dilate = stride, window stride 1, kernel spatially flipped via stablehlo.reverse dims = [2, 3] and read with [i, o, 0, 1] dim numbers, padding rewritten to low = dilation*(k-1) - padding, high = low + outputPadding. Grouped lowering is explicitly rejected (needs a kernel reshape; tracked in [Lane 2 · kotlin-core] TransposedConv2d — StableHLO lowering for convTranspose2d #1375 follow-up if needed).
  • Plumbing: VoidTensorOps shape-only impl (groups-aware C_out), RecordingExecution delegation, KSP tracing-wrapper bias-nullability list, test fake in ComputeGraphExecutorTest.
  • Docs: regenerated coverage matrix — convTranspose2d now ✅ for cpu, Backward and StableHLO; TransposedConv2d layer ✅.

Tests

  • ConvTranspose2dOpsTest (backend-cpu, commonTest): hand-computed basics (k2/s1 full scatter, k2/s2 non-overlapping stamp) plus a double-precision reference across the parameter grid — multi-channel stride-2 pad-1 outputPadding-1, asymmetric stride/padding, dilation 2, groups 2, bias, and TransposedConv2d.forward layer integration incl. outputSize() agreement; validation failure cases.
  • OpsAutodiffBackwardTest: finite-difference parity for the new backward, basic and strided/padded variants.
  • ConvTranspose2dConverterTest (compile-hlo): asserts the lowering structure (reverse, lhs_dilate, pad rewrite, dim numbers) and that grouped lowering is not silently wrong.
  • apiDump regenerated and apiCheck green; all affected module suites pass locally.

Closes #1373, closes #1374, closes #1375, closes #1376. Part of #1371 (lanes 1/2a/2b/2c/4 + docs partial; review lane #1378 is this PR's review).

…eHLO lowering (#1371)

- Promote TensorOps.convTranspose2d from a @NotImplemented default-throwing
  stub to an abstract @Diff op (PyTorch conv_transpose2d semantics, weight
  layout [C_in, C_out/groups, kH, kW]).
- DefaultCpuOps: scatter-add kernel with full parameter validation (stride,
  padding, outputPadding < max(stride, dilation), dilation, groups, bias
  shape, dtype guard) — mirrors convTranspose1d, extended to NCHW.
- DefaultExecutionTape: convTranspose2dBackward adjoint (input, weight and
  bias grads) wired into the backward dispatch table.
- VoidTensorOps: shape-only implementation incl. groups-aware C_out.
- StableHLO: lower convTranspose2d to stablehlo.convolution with
  lhs_dilate = stride, spatially flipped kernel (stablehlo.reverse) read
  with [i, o, 0, 1] dim numbers, and padding rewritten to
  low = dilation*(k-1) - padding, high = low + outputPadding.
  Grouped lowering is rejected explicitly (needs a kernel reshape).
- TransposedConv2d: remove the @NotImplemented marker — forward now runs.
- Tests: CPU kernel vs double-precision reference across the parameter grid
  (stride/padding/outputPadding/dilation/groups/bias + hand-computed cases),
  finite-difference backward parity, StableHLO lowering assertions.
- Regenerate api dumps (convTranspose2d abstract, convTranspose2dBackward).

Closes #1373, closes #1374, closes #1375, closes #1376. Part of #1371.
@github-actions

Copy link
Copy Markdown

📖 Documentation Preview

The documentation has been built successfully for this PR.

Generated Files:

  • Operator documentation: docs/modules/operators/_generated_/
  • JSON schema output: operators.json

Artifacts:

  • Download the documentation-preview-1464 artifact to view the complete documentation locally.

This comment will be updated automatically when the PR is updated.

…transpose2d

# Conflicts:
#	docs/modules/ROOT/pages/reference/operators/generated/index.adoc
#	docs/modules/ROOT/pages/reference/ops-status-matrix.adoc
@github-actions

Copy link
Copy Markdown

📖 Documentation Preview

The documentation has been built successfully for this PR.

Generated Files:

  • Operator documentation: docs/modules/operators/_generated_/
  • JSON schema output: operators.json

Artifacts:

  • Download the documentation-preview-1464 artifact to view the complete documentation locally.

This comment will be updated automatically when the PR is updated.

@michalharakal
michalharakal merged commit 6cc2523 into develop Oct 31, 2026
21 checks passed
@michalharakal
michalharakal deleted the feature/1371-conv-transpose2d branch October 31, 2026 21:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

2 participants