Expand description
Seeded, host-side weight-initialization helpers that make policy
construction bit-exact under PsroConfig::seed / NfspConfig::seed
(issue #135). Burn 0.21’s Initializer has no seed parameter, so we
pre-compute the trunk + head weights from an StdRng instead.
Seeded, host-side weight-initialization helpers for bit-exact
policy construction.
§Why this module exists
Burn 0.21’s burn::nn::Initializer::init_with /
init_tensor (see
burn-core-0.21.0/src/module/initializer.rs) take no seed
parameter — they route through a backend-internal
Tensor::random that draws from an unseeded, thread-local
generator. That makes
Initializer::Orthogonal and
Initializer::KaimingUniform the
last non-reproducible site in the PSRO/NFSP determinism contract advertised
by crate::multi_agent::psro::PsroConfig::seed /
crate::multi_agent::nfsp::NfspConfig::seed (every rollout/
training RNG site was plumbed through StdRng::seed_from_u64 in
PRs #113/#116/#122/#123/#125; this closes the policy-init gap —
issue #135).
§What it does
Provides pure-Rust, StdRng-driven ports of the two
init recipes the MLP policies use:
seeded_orthogonal— orthogonal init via Householder QR of a Gaussian matrix, scaled bygain(PPO recipe:sqrt(2)trunk,0.01heads).seeded_kaiming_uniform— Kaiming-uniform init matching Burn’sKaimingUniform { gain, fan_out_only: false }formula (bound = gain * sqrt(3 / fan_in)), the pathcrate::policy::mlp::MlpBurnPolicy::newexercises.
§Bit-parity caveat
These are not byte-identical to Burn’s unseeded output — we are
replacing the distribution with a reproducible one, not mirroring
Burn’s internal sampler. The only contract is: same seed (and
same shape/gain) ⇒ same Vec<f32>, every run, every machine.
Functions§
- seeded_
kaiming_ uniform - Generate a seeded Kaiming-uniform weight matrix of shape
[d_in, d_out]flattened in row-major order. - seeded_
orthogonal - Generate a seeded orthogonal weight matrix of shape
[d_in, d_out]flattened in row-major order (row index overd_in, column index overd_out) — matching Burn’sLinearweight layout (weight: Param<Tensor<B, 2>>with dims[d_input, d_output]).