Skip to content

[Feature]: TransposedConv2d β€” convTranspose2d op, CPU kernel, backward and StableHLO loweringΒ #1371

Open
0 of 7 issues completed

Description

@michalharakal

🧠 D: DOCUMENT β€” Problem & Opportunity

TransposedConv2d (skainet-lang/skainet-lang-core/src/commonMain/kotlin/sk/ainet/lang/nn/TransposedConv2d.kt) has a full constructor, parameter validation, outputSize() and factory helpers, but forward cannot run: there is no 2D transposed-convolution op. TensorOps.convTranspose2d now exists as a placeholder whose default throws, marked @NotImplemented, so the gap is visible as ❌ in the operator coverage matrix (both in the TensorOps table and the NN-layers table).

Transposed convolution is the learned-upsampling block of GAN generators, U-Net / segmentation decoders and super-resolution nets, so this gap blocks a whole family of models. The 1D variant is implemented end to end (TransposedConv1d, DefaultCpuOps.convTranspose1d, convTranspose1dBackward), so this is mostly a careful extension to a second spatial axis.

Summary: implement convTranspose2d on the CPU backend with PyTorch-identical semantics, wire autodiff and StableHLO, and turn the ❌ rows green.


πŸ” A: ASSESS β€” Feasibility & Impact

  • Feasibility: high. Templates exist for every piece: DefaultCpuOps.convTranspose1d (scatter-add over out = in*stride - padding + k*dilation), DefaultCpuOps.conv2d (2D validation, bias, groups), and the input-gradient loop of conv2dGrads in DefaultExecutionTape.kt, which is mathematically a transposed conv2d already.
  • Semantics to match: PyTorch torch.nn.functional.conv_transpose2d: weight [C_in, C_out/groups, kH, kW], output size (in-1)*stride - 2*padding + dilation*(k-1) + outputPadding + 1, outputPadding < stride.
  • Risks: dtype β€” convTranspose1d casts to Float everywhere (FP32 only); the 2D kernel should at least not silently corrupt other dtypes. Promoting the op to an abstract @Diff interface method touches every TensorOps implementer and test fake, so it is its own lane.

πŸ“š R: RESEARCH β€” What Must Be Understood First?

  • PyTorch reference cases for the parameter grid (Lane 1)
  • StableHLO lowering: stablehlo.convolution with lhs_dilation = stride, flipped kernel, swapped feature dims (Lane 2c)

πŸ› οΈ C: CODE β€” Implementation Plan

  • CPU kernel (Lane 2a) β€” makes TransposedConv2d.forward work on CPU
  • Promote to @Diff op + backward (Lane 2b)
  • StableHLO converter (Lane 2c)
  • Ground-truth CI (Lane 4)
  • Docs partial (Lane 5)
  • Review (Lane 6)

Acceptance Criteria

  • TransposedConv2d.forward matches PyTorch on the Lane-1 cases
  • @NotImplemented removed from TensorOps.convTranspose2d and TransposedConv2d; the regenerated matrix shows βœ… for cpu, StableHLO and Backward

Lane breakdown

Lanes 0 (no SKEEP trigger β€” additive op behind an existing interface) and 3 (no platform-specific code) are skipped.

New here? Read Getting started as a contributor and the Issue taxonomy. Lanes marked good first issue assume no prior SKaiNET codebase knowledge. The gap markers and the coverage matrix were introduced in #1370.

Metadata

Metadata

Assignees

No one assigned

    Labels

    darcFeature driven through the DARC workflow (Document / Assess / Research / Code)enhancementNew feature or requestlayersNeural network layerstensorsTensor operations and data structurestrackingParent/tracking issue with sub-issues

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions