Repository navigation
[Feature]: TransposedConv2d β convTranspose2d op, CPU kernel, backward and StableHLO loweringΒ #1371
Description
π§ 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 overout = in*stride - padding + k*dilation),DefaultCpuOps.conv2d(2D validation, bias, groups), and the input-gradient loop ofconv2dGradsinDefaultExecutionTape.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 β
convTranspose1dcasts toFloateverywhere (FP32 only); the 2D kernel should at least not silently corrupt other dtypes. Promoting the op to an abstract@Diffinterface method touches everyTensorOpsimplementer 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.convolutionwithlhs_dilation = stride, flipped kernel, swapped feature dims (Lane 2c)
π οΈ C: CODE β Implementation Plan
- CPU kernel (Lane 2a) β makes
TransposedConv2d.forwardwork on CPU - Promote to
@Diffop + backward (Lane 2b) - StableHLO converter (Lane 2c)
- Ground-truth CI (Lane 4)
- Docs partial (Lane 5)
- Review (Lane 6)
Acceptance Criteria
-
TransposedConv2d.forwardmatches PyTorch on the Lane-1 cases -
@NotImplementedremoved fromTensorOps.convTranspose2dandTransposedConv2d; the regenerated matrix shows β for cpu, StableHLO and Backward
Lane breakdown
- [Lane 1 Β· numerics] TransposedConv2d β PyTorch reference cases for conv_transpose2dΒ #1372 β [Lane 1 Β· numerics] PyTorch reference cases for conv_transpose2d (
size:s, good first issue) - [Lane 2 Β· kotlin-core] TransposedConv2d β CPU kernel for convTranspose2dΒ #1373 β [Lane 2 Β· kotlin-core] CPU kernel for convTranspose2d (
size:m) - [Lane 2 Β· kotlin-core] TransposedConv2d β promote convTranspose2d to a @Diff op with backward ruleΒ #1374 β [Lane 2 Β· kotlin-core] promote convTranspose2d to a @Diff op with backward rule (
size:s) - [Lane 2 Β· kotlin-core] TransposedConv2d β StableHLO lowering for convTranspose2dΒ #1375 β [Lane 2 Β· kotlin-core] StableHLO lowering for convTranspose2d (
size:s) - [Lane 4 Β· kotlin-core] TransposedConv2d β ground-truth test for convTranspose2dΒ #1376 β [Lane 4 Β· kotlin-core] ground-truth test for convTranspose2d (
size:s) - [Lane 5 Β· docs] TransposedConv2d β operator doc partial for convTranspose2dΒ #1377 β [Lane 5 Β· docs] operator doc partial for convTranspose2d (
size:s, good first issue) - [Lane 6 Β· review] TransposedConv2d β DARC review of convTranspose2dΒ #1378 β [Lane 6 Β· review] DARC review of convTranspose2d (
size:s)
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.
Activity
Link coverage gaps to their DARC tracking issues