feat(nn): optional bias in Linear#870
Open
michalharakal wants to merge 1 commit into
Open
Conversation
|
📖 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. |
Linear's initBias is now nullable with a null default, creating a bias-less projection (y = x W^T) — the equivalent of PyTorch's nn.Linear(bias=False), needed for GPT-style qkv_bias=False projections and weight-tied output heads. A bias-less layer registers only its weight parameter, so parameter counts and checkpoints match architectures defined without bias. Adds a biasOrNull() helper next to the throwing bias() accessor. Note for Java callers: the @jvmoverloads overload set changes — the 4-arg (in, out, weights, bias) convenience overload is replaced by (in, out, weights); Kotlin callers bind the full constructor and are unaffected.
michalharakal
force-pushed
the
feature/linear-optional-bias
branch
from
July 23, 2026 21:04
c9a1fee to
3830ebe
Compare
|
📖 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 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.
What
Linear'sinitBiasbecomes nullable with anulldefault, giving a bias-less projectiony = x W^T— the equivalent of PyTorch'snn.Linear(..., bias=False):trainableParameters()counts and checkpoints match architectures defined without bias (e.g. GPT-2's scratch config withqkv_bias=Falsetotals exactly 163,009,536 parameters only when the Q/K/V projections and output head carry no bias).onForwardreturns the matmul directly when no bias is present; existing bias behavior (including the 1-D input reshape path) is unchanged.biasOrNull()helper next to the throwingbias()accessor.Compatibility
Tensorstill type-checks againstTensor?.@JvmOverloadsoverload set changes — the 4-arg(inFeatures, outFeatures, initWeights, initBias)convenience overload is replaced by(inFeatures, outFeatures, initWeights). Flagged here explicitly; API dumps updated (jvm viaapiDump, android mirrored by hand — no Android SDK on this machine). If preserving that overload matters pre-review, a secondary constructor can be added — happy to adjust.Tests
LinearOptionalBiasTest(lang-core): bias-less layer registers exactly one parameter,biasOrNull()/bias()contracts, trainable-parameter counts (15 vs 12 on a 4→3 layer).LinearNoBiasTest(backend-cpu): hand-computed pure projection, no-bias ≡ zero-bias on real ops, 1-D vector input path.jvmTestfor lang-core and backend-cpu green,apiCheckgreen.Motivation
Needed by GPT-style architectures (
qkv_bias=False, weight-tied heads); found while porting an educational GPT project to SKaiNET, which currently carries its own Linear implementation solely for this. Related prior contributions: #866 (LR schedules), #867 (Dropout).