Repository navigation
feat(nn): mixed-precision dense/stage via PrecisionBoundary (SKEEP-008 phase A1) - #1469
Merged
Merged
Conversation
…8 A1, #1433) Implement rollout phase A1 of SKEEP-008: the DSL takes the layer dtype as a value (dense(64, dtype = BF16) { }, stage(id, dtype = FP16) { }) and wraps the layer or block in PrecisionBoundary, which casts in and out with the existing TensorOps.convert — free when dtypes match, visible in traces and StableHLO exports, inference-only until convert becomes @Diff (phase A3). The old generic overloads (dense<TLayer>(), stage<TStage>()) could never be implemented — an interface method's type parameter cannot be reified, so there was no KClass to build tensors with. They are deprecated at level ERROR and their six TODO() stubs replaced by error() bodies; the NetworkBuilder.kt entry leaves config/stub-allowlist.txt. The never-implemented scaffold (MixedPrecisionModule, InternalMixedPrecisionModule, MixedPrecisionTensorOps) is deprecated for removal. Docs: new Antora explanation article on the value and limits of mixed precision, linked from the nav and from SKEEP-008.
|
📖 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. |
…nsorDataFactory The non-JVM CI lanes failed on MixedPrecisionDslTest because BF16 was missing from the float-backed dtype branches: DenseTensorDataFactory.init/uniform/ randomInit/wrapFloatArray/adoptFloatArray rejected it, and every DefaultCpuOps float dispatch (matmul and 33 siblings) plus the sqrt/pow/powScalar/ convTranspose2d/upsample2d guards listed only FP32/FP16. BF16 is float-backed exactly like FP16, so it joins those branches.
|
📖 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. |
|
📖 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 5, 2026
Conflict in config/stub-allowlist.txt: both deleted lines stand — this branch implemented the six NetworkBuilder.kt mixed-precision stubs, and develop independently removed the TensorDSL.kt entry (#1417). The merged code has zero unmarked stubs in both files; checkUnmarkedStubs, lang-core apiCheck and the lang-core/backend-cpu JVM tests pass on the merge.
|
📖 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. |
This was referenced Nov 6, 2026
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.
Part of #1433, implementing rollout phase A1 of xref SKEEP-008 (
docs/modules/skeep/pages/008-precision-and-encoding-conversion.adoc). Part B (repackTo/requantizeTo) is a separate follow-up, so the SKEEP status stays Draft.What
PrecisionBoundary(new,sk.ainet.lang.nn): wraps a module built in another dtype; casts in/out with the existingTensorOps.convert. Free when dtypes match, recorded by the tracing wrappers, lowers tostablehlo.convert. Inference-only until phase A3 makesconvert@Diff— stated in the KDoc.dense(64, dtype = BF16) { }andstage("head", dtype = FP16) { }— implemented in bothNeuralNetworkDslImplandStageImpl. The dtype object gives the implementation both the instance (forconvert) and theKClasswitness (for tensor creation); the outer dtype is recovered withDType.fromWitness.dense<TLayer>()/stage<TStage>()overloads could never be implemented (an interface method's type parameter cannot bereified, so noKClassexists at runtime) — now@Deprecated(level = ERROR)with fail-louderror()bodies, removing all sixTODO()stubs and theNetworkBuilder.ktline fromconfig/stub-allowlist.txt. The never-implemented scaffold (MixedPrecisionModule,InternalMixedPrecisionModule,MixedPrecisionTensorOps) is deprecated for removal (phase A4).explanation/mixed-precision.adoc— why per-layer precision matters (FP16 vs BF16 trade-offs, SKaiNET's wasm/mobile targets), what the boundary design guarantees, and what it deliberately does not do yet (training, AMP, integer layers; float-backed storage per SKEEP-003).Tests
MixedPrecisionDslTest(backend-cpu commonTest): a BF16 dense and an FP16 stage inside an FP32 network run on the CPU backend, stay close to the all-FP32 reference and differ from it (proving the rounding actually happens), an FP32-in-FP32 boundary is bit-exact (cast elision), and the wrapped layer appears as aPrecisionBoundarymodule../gradlew apiDump apiCheck checkUnmarkedStubs+ jvmTest on lang-core, backend-cpu, compile-core/json/dag, plus a wasmJs compile — all green. API change is additive + deprecations (skainet-lang-core.apiregenerated).