Repository navigation
perf: profile and speed up diff, patch, checkpoints and describe - #11
Merged
Merged
Conversation
…ntiles; content-keyed describe cache Co-Authored-By: Leonardo Marciano <leonardo.marciano@toolzz.me>
Contributor
Author
|
I'll fix CI failures and address comments from users with write access. I'll skip comments containing "(aside)".
|
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 and why
Profiled the hot paths on a 546M-parameter bf16 synthetic model (cProfile, py-spy, tracemalloc) and fixed what showed up. The new
benchmarks/profile_hotpaths.pyreproduces the numbers._chunks.py: block-wise passes on a small shared thread pool (NumPy drops the GIL), used bydiff,patch, snapshots, restores and stats. Nothing makes a full float64 copy of a tensor anymore.diff/patch/ checkpoints compare weights bitwise, and the original norm forrel_deltais computed once per tensor instead of on every write.describe: exact quantiles from one histogram pass plus a partition of the few bins holding the wanted ranks (same values asnp.quantile), one-pass moments, blocked row/col norms, Gram spectrum in the input precision. Its output is keyed by content, so a touched but unchanged tensor is not recomputed.apply_patchdid nothing on non-contiguous arrays; untouched NaN weights were counted as edits.describeembedding 151936 x 1024describeMLP 3584 x 1024write_tensor(+ diff over 237M touched weights)ws.diff()ws.patch()ws.checkpoint()ws.restore()+ diffPublic API and
describeoutput are unchanged (diffed the text against main on six tensor shapes: identical).How it was tested
ruff check . && ruff format --check .pytest(55 passed; newtests/test_perf_paths.pyforces the threaded/histogram paths on small arrays and checks them against NumPy)CHANGELOG.mdentry (if user-facing)mypy src/weightspace,python -m build,twine check --strict dist/*