Repository navigation
feat(nn): finish SKEEP-008 — export test, differentiable convert, scaffold removal (phases A2, A3, A4) - #1492
Merged
michalharakal merged 2 commits intoNov 10, 2026
Conversation
…ffold removal (#1433) Phases A2, A3 and A4 of SKEEP-008 (precision and encoding conversion). A2, export: MixedPrecisionExportTest traces an FP32 network with one BF16 dense and one FP16 stage and pins one convert pair per boundary in the graph and stablehlo.convert f32->bf16, bf16->f32, f32->f16, f16->f32 in the module. A same-dtype boundary recorded a convert although the backend returns its input, so the export carried two f32->f32 casts; PrecisionBoundary now passes a tensor of the target dtype through. A3, autograd: TensorOps.convert is @Diff. The backward rule treats the cast as the identity and casts the upstream gradient back to the source dtype, so a gradient entering an FP16/BF16 region is rounded to that format. A cast from or to an integer dtype has no gradient, and a recorded same-tensor cast returns none, or its gradient would be added to itself. MixedPrecisionBackwardTest: the rule, central finite differences through FP16 boundaries, parity with the all-FP32 network, and an SGD run that updates every weight behind a boundary. The inference-only notes are removed; the ops matrix Backward column reads 60/60. A4, cleanup: the generic dense<TLayer>() / stage<TStage>() overloads (deprecated at ERROR in 0.63.0) and MixedPrecisionModule, InternalMixedPrecisionModule, MixedPrecisionTensorOps are removed, with MixedPrecisionException, which only they could throw. The DType tests from MixedPrecisionTensorOpsTest move to DTypeCompatibilityTest. Acceptance: repackTo(Dense(4)) is checked bit-exact for Q5_0, Q5_1, Q5_K, Q6_K and BITNET_B1_58, and one network with both boundary kinds runs against the FP32 reference. SKEEP-008 moves to Status: Implemented. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
Co-Authored-By: Claude Fable 5.2 <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. |
1 similar comment
|
📖 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. |
aharakal
approved these changes
Nov 10, 2026
michalharakal
deleted the
feature/1433-skeep-008-export-autograd-cleanup
branch
November 10, 2026 22:05
This was referenced Nov 10, 2026
Closed
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.
Finishes SKEEP-008 (precision and encoding conversion). B1 (#1470) and A1 (#1469) shipped in 0.63.0; this PR carries the three remaining phases and flips the proposal to
Status: Implemented.Tracking issue: #1433 — it can be closed when this merges.
A2 — export
MixedPrecisionExportTesttraces an FP32 network with one BF16denseand one FP16stageand pins the result: oneconvertpair per boundary in the graph, inner layers typed in the narrow dtype, andstablehlo.convertf32 -> bf16,bf16 -> f32,f32 -> f16,f16 -> f32in the module.DtypeForwardPropagationPassleaves the boundaries alone.stage("body", dtype = FP32)in an FP32 network) still recordedconvert— the CPU backend returns its input, but the tracing wrapper records the call — so the export carried twostablehlo.convert f32 -> f32.PrecisionBoundarynow passes a tensor of the target dtype through without callingconvert.A3 — autograd
TensorOps.convertis@Diff.convertBackwardtreats the cast as the identity and casts the upstream gradient back to the source dtype, so a gradient entering an FP16 / BF16 region is rounded to that format, as the forward values are.MixedPrecisionBackwardTest(7 tests): the rule itself, central finite differences through FP16 boundaries, parity with the all-FP32 network for a BF16 dense + FP16 stage, and an SGD run that lowers the loss and updates every weight behind a boundary.mixed-precision.adoc, which gains "What an export looks like" and "Training through a boundary". Ops matrix Backward column: 60 / 60.A4 — cleanup
dense<TLayer>()×2 andstage<TStage>()fromNeuralNetworkDsland both implementations (deprecated atERRORin 0.63.0).MixedPrecisionModule,InternalMixedPrecisionModule,MixedPrecisionTensorOps(deprecated in 0.63.0, never implemented).MixedPrecisionException, which lived in the same file and which only the scaffold could throw. It was not marked deprecated in 0.63.0.MixedPrecisionTensorOpsTestmove totypes/DTypeCompatibilityTest.Acceptance criteria
repackTo(Dense(4))is now checked bit-exact for Q5_0, Q5_1, Q5_K, Q6_K andBITNET_B1_58as well (synthetic blocks; no quantizer produces them).denseand an FP16stageruns against the FP32 reference.Status: Implemented, an implementation-status table, and Open Questions 1 and 3 marked resolved (2 and 4 stay open).Notes for review
convertBackwardadded toDifferentiableTensorOps/DefaultGradientTape; the removals above..apifiles are regenerated.ops-status-matrix.adocwas edited by hand (theconvertrow and the total), not regenerated withgenerateDocs.Test plan
./gradlew apiCheck checkUnmarkedStubsjvmTestforskainet-lang-core,skainet-lang-models,skainet-compile-dag,skainet-compile-hlo,skainet-compile-opt,skainet-backend-cpuskainet-lang-core,skainet-compile-dagand theskainet-compile-hlotests🤖 Generated with Claude Code