Repository navigation
fix: skip ModernBERT weight init on Windows + Python 3.14 - #129
Closed
sathariels wants to merge 1 commit into
Closed
sathariels wants to merge 1 commit into
sathariels wants to merge 1 commit into
Conversation
Agent loads checkpoint weights with load_state_dict(strict=True) right after encoder construction, so the random values from PreTrainedModel.initialize_weights are never used. On Windows with Python 3.14 that call segfaults (issue NandhaKishorM#123). Skip it only while build_model constructs the encoder on that platform. Addresses NandhaKishorM#123. Co-authored-by: Nithilan Kumaran <sathariels@users.noreply.github.com>
Contributor
Author
|
Also feel free to give me any issues you have, i have a decent amount of free time and really like this project |
Owner
|
Thank you for pinning down the Windows + Python 3.14 crash and for getting CI green on it. #195 landed today: it builds the model under |
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.
Addresses #123.
On Windows 11 with Python 3.14 and torch 2.14, building a ModernBERT encoder segfaults inside
PreTrainedModel.initialize_weights.pip install layasucceeds;Agent(...)dies during model construction. The reporter verified that replacingtransformers.modeling_utils.PreTrainedModel.initialize_weightswith a no-op before construction lets the checkpoints load. That is safe for Laya becauseAgent.__init__immediately callsload_state_dict(strict=True), so the random init values are never used.This PR applies that same no-op automatically, and only while
build_modelconstructs the encoder, whenplatform.system() == "Windows"and Python is 3.14 or newer. Other platforms leaveinitialize_weightsin place.init_weightsstill runstie_weights.DecisionModel.forwardandpredictare unchanged.Callers who construct a ModernBERT module themselves can use
laya.win_patch.guard()/install()/restore(). Holds nest, so an explicitinstall()stays in effect acrossAgentconstruction.The segfault was not remeasured on Windows here. CI for this repo runs on Linux. The change follows the stack and workaround in #123 (transformers 5.17, the crash inside
initialize_weightsduringpost_init).Python 3.14 is listed in the project classifiers. The floor stays 3.10.
Tests
Offline, no Hub download:
tests/test_win_patch.pychecks that the guard installs and restores, that it is a no-op when the platform is not Windows + Python 3.14, and thatbuild_modelholds the no-op only during local ModernBERT construction (tiny config on disk, no checkpoint download).