GH-3630: persist trust_remote_code across save/load round-trips#3697
Open
haoyu-haoyu wants to merge 1 commit intoflairNLP:masterfrom
Open
GH-3630: persist trust_remote_code across save/load round-trips#3697haoyu-haoyu wants to merge 1 commit intoflairNLP:masterfrom
haoyu-haoyu wants to merge 1 commit intoflairNLP:masterfrom
Conversation
Models that require trust_remote_code=True (EuroBERT, OLMo, etc.) train fine but crash on reload because the custom config class is not in CONFIG_MAPPING. This happens because the flag was consumed by __init__ but never saved. - Store trust_remote_code as an instance attribute - Include it in to_params() when True - In from_params(), when the model type is not in CONFIG_MAPPING and trust_remote_code was saved, re-download the config from the hub so the custom class gets registered. Strip _name_or_path from the overrides to avoid clobbering the freshly-resolved repo id. - Pass trust_remote_code through to create_from_state() so tokenizer and model loading also get it
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.
Models that need
trust_remote_code=True(EuroBERT, OLMo, etc.) train fine but crash when the trainer tries to reload the best checkpoint, because the custom config class is not inCONFIG_MAPPINGat that point.Root cause:
trust_remote_codeflows into__init__via**kwargsand gets consumed by the HF calls, but is never stored. On save,to_params()does not include it. On reload,from_params()hitsCONFIG_MAPPING[model_type]which raisesKeyErrorfor custom types.The fix:
trust_remote_codeas an instance attributeto_params()when Truefrom_params(), when the model type is unknown andtrust_remote_codewas saved, useAutoConfig.from_pretrained()to re-download the config (which registers the custom class)._name_or_pathis stripped from the overrides to avoid clobbering the freshly-resolved repo id.trust_remote_codethrough tocreate_from_state()so the tokenizer and model loading calls also get itCloses #3630