Fix K-FAC covariance shapes when include_bias=True#294
Open
luciaquirke wants to merge 1 commit into
Open
Conversation
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
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.
Closes #277.
bergson buildwithinclude_bias=Truestores per-layer gradients of shape[O, I+1](the bias gradient is appended as an extra "activation" column), but the K-FAC covariance path computedA = aᵀaon the raw activation, givingA: [I, I].apply_hessian's per-layerview(-1, O, I)then failed on the flatN·O·(I+1)gradients:reproduce with
bergson ekfac --include_bias true --method kfac --model EleutherAI/pythia-14m.Fix
collect_hessiansnow passesGradientProcessor(include_bias=index_cfg.include_bias)to the Hessian collectors — previously thecollect_biasflags intarget_infowere alwaysFalseduring Hessian fitting regardless of the build config._init_covariance_dictsizes the activation covariance[I+1, I+1]whencollect_bias.CovarianceCollector(kfac),TraceCovarianceCollector(tkfac), andShampooCollectoraugment the activation with a ones column, matching the build-time gradient layout.LambdaCollectoraugments the activation before rotating byeigen_a(now[I+1, I+1]), so EKFAC eigenvalue corrections come out[O, I+1].shard_bounds(rank 0 absorbs the remainder) (in this PR because with the bias column,I+1is almost never divisible by the world size.)step2_fit_hessiantiming bug (approximate_hessiansran outside its_timedblock, always reporting 0.0s).