Add upsample2d Bilinear (eager+autodiff) and traceable StableHLO lowering (Nearest + Bilinear)#771
Merged
Merged
Conversation
…ering for both modes #770 upsample2d existed eager-only for Nearest with no StableHLO converter, so any traced upsample node hit the "Operation not supported" path and could not export (blocking YOLO/FPN). Add Bilinear end-to-end and a converter for both modes. Because scale/sizes/alignCorners are static at trace time, both lower to fixed shape/linear ops (no runtime index math, no custom_call): - DefaultCpuOps.upsample2d: Bilinear forward (PyTorch coord map + clamp + blend). - DefaultExecutionTape.upsample2dGrad: mode dispatch; Bilinear = scatter transpose. - NeuralNetOperationsConverter.convertUpsample2d: Nearest -> reshape/broadcast_in_dim/reshape pixel replication. Bilinear -> constant resize matrices A_h/A_w applied via two dot_general. Tests: Upsample2dConverterTest (both modes), Bilinear forward golden values, Bilinear backward vs finite-difference. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
kotlinStoreYarnLock fails on develop-based PRs because the committed JS kotlin-js-store/yarn.lock (last touched Jun 7) drifted from the resolved build/js/yarn.lock (lockFileMismatchReport:FAIL). A transitive now pulls ws 8.20.1. Mirrors the earlier Kotlin/Wasm lock bump (c67f515). Unrelated to the upsample2d change in this branch. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This was referenced Jun 29, 2026
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 #770.
What
upsample2dpreviously existed eager-only for Nearest and had no StableHLO converter, so a tracedupsample2dnode fell through to the converter's "Operation not supported" path and could not export → compile → run on IREE (blocking YOLO/FPN-style models). This PR makesupsample2dfirst-class and exportable for both modes.Because
scale, sizes andalignCornersare all static at trace time, both modes lower to fixed shape/linear ops — no runtime index math, nocustom_call, so they compile on stock IREE.Changes
DefaultCpuOps.upsample2d— add Bilinear forward (PyTorch coordinate map with/withoutalign_corners, border clamp, 4-neighbor blend). Nearest unchanged.DefaultExecutionTape.upsample2dGrad— dispatch by mode; Bilinear backward is the scatter transpose of the forward (distribute each output gradient to its 4 source neighbors with the same weights). Now threadsalignCornersfrom the recorded attributes.NeuralNetOperationsConverter.convertUpsample2d(new; registered insupportedOperations+when):reshape [N,C,H,W] → [N,C,H,1,W,1]→broadcast_in_dim → [N,C,H,sH,W,sW]→reshape → [N,C,H*sH,W*sW], exactly matchingout[oh,ow]=in[oh/sH,ow/sW].A_h [outH×inH],A_w [outW×inW](each row = the two bilinear neighbor weights) and apply via twostablehlo.dot_generalcontractions (no transposes). The weights are the same static floats the eager blend uses, so results match to fp tolerance.Tests
Upsample2dConverterTest(new) — Nearest reshape/broadcast lowering; Bilinear constant-matrix +dot_generallowering; both assert nocustom_call/ unsupported path.DefaultCpuOpsUpsampleTest— Bilinear forward golden values (corners clamp; interior blends).ConvPoolBackwardTest— Bilinear backward vs finite-difference.All three module test suites pass locally (
skainet-backend-cpu,skainet-compile-dag,skainet-compile-hlo).Follow-up
A conformance op-suite probe (separate repo) that compiles+runs+validates these on IREE, gated on a release/source build containing this change.
🤖 Generated with Claude Code