Compute real conv output shapes in graph operations (#536)#537
Merged
michalharakal merged 1 commit intodevelopfrom Apr 19, 2026
Merged
Compute real conv output shapes in graph operations (#536)#537michalharakal merged 1 commit intodevelopfrom
michalharakal merged 1 commit intodevelopfrom
Conversation
Conv{1,2,3}dOperation.inferOutputs previously echoed inputs[0].shape,
ignoring the weight shape and stride/padding/dilation parameters. This
left every stablehlo.convolution result as tensor<?xf32>, blocking
iree-compile on the Whisper encoder.
Extract the shape math into a public ConvShapeUtils object so the
eager (VoidTensorOps) and graph-emission paths share one source of
truth, and rewrite the three inferOutputs methods to use it. Conv2d
and Conv3d accept either Pair/Triple (as written by RecordingExecution)
or scalar Int parameters.
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
|
📖 Documentation Preview The documentation has been built successfully for this PR. Generated Files:
Artifacts:
This comment will be updated automatically when the PR is updated. |
10 tasks
michalharakal
added a commit
that referenced
this pull request
Apr 19, 2026
The DSL's flatten() previously fell back to a hardcoded lastDimension = 1568 (the value that happens to fit the MNIST CNN reference model). Any other architecture - e.g. a 64-channel CNN over 32x32 inputs - hit ArrayIndexOutOfBounds in the following dense layer. Add a per-sample shape tracker (currentShape: IntArray?) to StageImpl and NeuralNetworkDslImpl, plus a new input(intArrayOf(...)) overload that seeds it. conv1d/2d/3d, maxPool2d, avgPool2d, and upsample2d now update currentShape using the same arithmetic as VoidTensorOps via ConvShapeUtils (extended with pool2d and upsample2d helpers, building on the helper introduced in #537). flatten() reads currentShape and honors startDim / endDim instead of guessing 1568. When no input shape is declared we leave lastDimension untouched so existing flatten-only runtime tests keep working - dense() will surface the gap with a clear error if it actually matters. Update MnistCnn to declare input(intArrayOf(1, 28, 28)) so it works under the new shape inference instead of relying on the magic constant. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
5 tasks
michalharakal
added a commit
that referenced
this pull request
Apr 21, 2026
Bump VERSION_NAME to 0.19.0 in the root gradle.properties, expand the CHANGELOG [0.19.0] - 2026-04-20 section to cover the full 130 commits since 0.18.0 — not just the tokenizer work but the StableHLO → IREE lowering pipeline (softmax/layerNorm/rmsnorm real lowerings, gather/ embedding/concat/slice/cast converters, ConstantMaterializationPolicy, dense<v> splat folding, SSA type tracking), the new skainet-io-iree- params IrpaWriter, skainet-backend-api module, Antora docs migration with Diátaxis layout, Java API polish (#400), androidNativeArm32 target, and the graph/DSL shape-inference fixes (#535, #536, #537, #538) that unblock non-MNIST CNN architectures and Whisper-encoder HLO compilation. Refresh the README install snippet and "What's New" section to reflect the 0.19.0 highlights, and note the tokenizer milestone on the Q2 2026 roadmap line. Ops docs regenerated so the stamped version matches the new VERSION_NAME. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Merged
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.
Closes #536.
Summary
ConvShapeUtilsas a public, single-source-of-truth helper for conv1d/2d/3d output-shape math.VoidTensorOps.calculateConv{1,2,3}dShapethin delegates to the helper.Conv{1,2,3}dOperation.inferOutputs(tensor/ops/TensorOperations.kt) to compute the real output shape frominputs[0],inputs[1], andparameters["stride"|"padding"|"dilation"]instead of echoinginputs[0].shape. Falls back to anullshape only when input/weight shape is unknown or wrong rank. Conv2d/Conv3d accept either thePair/Tripleparameters written byRecordingExecutionor scalarInt(treated symmetrically).This unblocks the StableHLO export path: every
stablehlo.convolutionpreviously emitted astensor<?xf32>because the graph operation never published a real output shape. PRs #530 and #532 fixed adjacent pieces (TensorRef fallback, recording decorator wiring) but notinferOutputsitself.Test plan
./gradlew :skainet-lang:skainet-lang-core:jvmTest(incl. newConvOperationInferOutputsTest, 8 cases)./gradlew :skainet-compile:skainet-compile-core:jvmTest./gradlew :skainet-compile:skainet-compile-hlo:jvmTesttensor<?occurrences inencoder_skainet.mliriree-compileaccepts the module withouttools/fix_stablehlo_mlir.py🤖 Generated with Claude Code