Repository navigation
Skip redundant initialization when loading checkpoints - #195
Merged
NandhaKishorM merged 1 commit intoSep 23, 2026
Merged
NandhaKishorM merged 1 commit into
NandhaKishorM merged 1 commit into
Conversation
Owner
|
Thank you, this is a great find, and a very small diff for what it buys. I checked it against the real English checkpoint before merging: 396 labelled decisions (emotion, tweet topic, prompt injection), and every answer and every probability is bit-identical to |
This was referenced Sep 23, 2026
Closed
Closed
3 tasks done
baninaveen
pushed a commit
to baninaveen/laya
that referenced
this pull request
Sep 24, 2026
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.
Loading a Laya checkpoint currently initializes random encoder and decision-head weights immediately before overwriting them with checkpoint weights. If the checkpoint has no bundled encoder config, it also loads base-model weights that are subsequently discarded.
Wrap inference model construction in Transformers'
no_init_weights()and construct the encoder from its config when loading a full Laya checkpoint. Keepbuild_model()'s existing pretrained default for other callers and retain strict checkpoint validation and loading. Support both Transformers 4.x and the newer initialization-module import path.Before / after profiling
Compared the parent commit (
c752770) with this fix (5170536) using the same cachedconvaiinnovations/layacheckpoint. Measurements are medians of three fresh Python processes per version, alternating before/after runs. CPU, four Torch threads, Python 3.14.7, PyTorch 2.14.0, Transformers 5.17.0; network access disabled. Timed withtime.perf_counter().build_model)load_state_dict)laya.load()callThat is approximately 30 seconds saved per load, or 15.5× faster loading in this benchmark. Total loading times ranged from 30.51–33.45 s before and 1.73–2.45 s after. The total includes lazy imports performed inside
laya.load(), but excludes initial imports of Torch and Laya and excludes inference. Phase medians need not sum to the total; weight-copy timings also varied between runs. The change targets checkpoint loading, not inference speed.Validation
All 5 offline checkpoint/download tests pass (
python tests/test_download.py). The new regression covers bundled and external encoder configs, checks that loading does not consume Torch RNG state or load base-model weights, verifies exact checkpoint tensor equality, and runs inference.