[Bugfix] Fix _CONFIG_REGISTRY types getting wrong config class when on-disk model_type differs (#39554)

Signed-off-by: Misa <misaAle@users.noreply.github.com>
Signed-off-by: Misael Casarez <misacasa@amazon.com>
Co-authored-by: Misael Casarez <misacasa@amazon.com>
This commit is contained in:
Misa
2026-04-20 19:04:48 -07:00
committed by GitHub
co-authored by Misael Casarez
parent fe5c115ee4
commit 0e884fe638
2 changed files with 91 additions and 0 deletions
+10
View File
@@ -210,6 +210,16 @@ class HFConfigParser(ConfigParserBase):
config_class = _CONFIG_REGISTRY[model_type]
config_class.model_type = model_type
AutoConfig.register(model_type, config_class, exist_ok=True)
# If the on-disk model_type differs from the overridden
# one, register under both so AutoConfig.from_pretrained
# returns the correct class regardless of what the
# checkpoint says
if (
config_model_type := config_dict.get("model_type")
) and config_model_type != model_type:
config_class.model_type = config_model_type
AutoConfig.register(config_model_type, config_class, exist_ok=True)
config_class.model_type = model_type
# Now that it is registered, it is not considered remote code anymore
trust_remote_code = False
try: