@@ -280,11 +280,12 @@ def thinker_uses_mrope(config: PretrainedConfig) -> bool:
280
280
281
281
def is_encoder_decoder (config : PretrainedConfig ) -> bool :
282
282
"""Detect if the model with this config is used as an encoder/decoder."""
283
- text_config = getattr (config , "text_config" , None )
284
- if text_config is not None :
285
- return is_encoder_decoder (text_config )
286
283
287
- return getattr (config , "is_encoder_decoder" , False )
284
+ def _is_encoder_decoder (config : PretrainedConfig ) -> bool :
285
+ return getattr (config , "is_encoder_decoder" , False )
286
+
287
+ return (_is_encoder_decoder (config )
288
+ or _is_encoder_decoder (config .get_text_config ()))
288
289
289
290
290
291
def is_interleaved (config : PretrainedConfig ) -> bool :
@@ -298,13 +299,21 @@ def is_interleaved(config: PretrainedConfig) -> bool:
298
299
return False
299
300
300
301
302
+ def _maybe_update_auto_config_kwargs (kwargs : dict [str , Any ], model_type : str ):
303
+ """
304
+ Update kwargs for AutoConfig initialization based on model_type
305
+ """
306
+ if model_type in _AUTO_CONFIG_KWARGS_OVERRIDES :
307
+ kwargs .update (_AUTO_CONFIG_KWARGS_OVERRIDES [model_type ])
308
+ return kwargs
309
+
310
+
301
311
def _maybe_remap_hf_config_attrs (config : PretrainedConfig ) -> PretrainedConfig :
302
312
"""Remap config attributes to match the expected names."""
303
313
for old_attr , new_attr in _CONFIG_ATTRS_MAPPING .items ():
304
314
if hasattr (config , old_attr ):
305
315
if not hasattr (config , new_attr ):
306
316
config .update ({new_attr : getattr (config , old_attr )})
307
- delattr (config , old_attr )
308
317
logger .debug ("Remapped config attribute '%s' to '%s'" , old_attr ,
309
318
new_attr )
310
319
return config
@@ -415,15 +424,14 @@ def get_config(
415
424
)
416
425
else :
417
426
try :
427
+ kwargs = _maybe_update_auto_config_kwargs (
428
+ kwargs , model_type = model_type )
418
429
config = AutoConfig .from_pretrained (
419
430
model ,
420
431
trust_remote_code = trust_remote_code ,
421
432
revision = revision ,
422
433
code_revision = code_revision ,
423
434
token = _get_hf_token (),
424
- # some old custom model's config needs
425
- # `has_no_defaults_at_init=True` to work.
426
- has_no_defaults_at_init = trust_remote_code ,
427
435
** kwargs ,
428
436
)
429
437
except ValueError as e :
0 commit comments