vkML 0.1.0

Linear

y = x @ Wᵀ + b, matching torch.nn.Linear.

class Linear : Modulepython/vkml/nn.py:253

The weight is stored as (out_features, in_features) and transposed in forward, exactly as PyTorch does. That layout is not arbitrary — it means a PyTorch state_dict loads without any transposition, which keeps the validation comparison honest.

Initialisation draws U(−1/√fan_in, +1/√fan_in) for both weight and bias. That closed form is exactly torch's default kaiming_uniform_(w, a=√5): with a=√5 the gain is √(2/6), so the bound reduces to 1/√fan_in. Verified against torch.nn.Linear — both give ±0.0357142857 at fan_in=784.

Weights are drawn from a module-level generator seeded by nn.manual_seed, not from default_rng() per layer. An unseeded generator would give every run different weights, making a training result impossible to reproduce and a divergence impossible to investigate.

ⓘ Note

manual_seed mirrors torch.manual_seed in spirit, not in stream — the two libraries draw from different generators by design, so equal seeds do not give equal weights. To compare against torch, copy a state_dict rather than seeding both.

Construction

__init__

def __init__self, in_features: int, out_features: int, bias: bool=Truepython/vkml/nn.py:267

Forward

forward

def forwardself, x: V.Tensor -> V.Tensorpython/vkml/nn.py:291

Internals

__setattr__

def __setattr__self, name, valuepython/vkml/nn.py:283

__repr__

def __repr__self -> strpython/vkml/nn.py:297

See also matmul, Module

vkML — Vulkan-first machine learning in C++20. Apache-2.0. Signatures on this page are generated from the installed module.