@@ -252,17 +252,20 @@ def trainer_config_finalize(self, args, model, num_training_steps):
252252 hidden_size_auto_keys = [x for x in hidden_size_based_keys if self .is_auto (x )]
253253
254254 if len (hidden_size_auto_keys ) > 0 :
255- if hasattr (model .config , "hidden_size" ):
256- hidden_size = model .config .hidden_size
257- elif hasattr (model .config , "hidden_sizes" ):
258- # if there are many hidden sizes pick the largest one
259- hidden_size = max (model .config .hidden_sizes )
260- elif hasattr (model .config , "text_config" ) and hasattr (model .config .text_config , "hidden_size" ):
261- hidden_size = model .config .text_config .hidden_size
262- elif hasattr (model .config , "text_config" ) and hasattr (model .config .text_config , "hidden_sizes" ):
263- # if there are many hidden sizes pick the largest one
264- hidden_size = max (model .config .text_config .hidden_sizes )
265- else :
255+ hidden_size = None
256+ if hasattr (model , "config" ):
257+ if hasattr (model .config , "hidden_size" ):
258+ hidden_size = model .config .hidden_size
259+ elif hasattr (model .config , "hidden_sizes" ):
260+ # if there are many hidden sizes pick the largest one
261+ hidden_size = max (model .config .hidden_sizes )
262+ elif hasattr (model .config , "text_config" ) and hasattr (model .config .text_config , "hidden_size" ):
263+ hidden_size = model .config .text_config .hidden_size
264+ elif hasattr (model .config , "text_config" ) and hasattr (model .config .text_config , "hidden_sizes" ):
265+ # if there are many hidden sizes pick the largest one
266+ hidden_size = max (model .config .text_config .hidden_sizes )
267+
268+ if hidden_size is None :
266269 raise ValueError (
267270 "The model's config file has neither `hidden_size` nor `hidden_sizes` entry, "
268271 "therefore it's not possible to automatically fill out the following `auto` entries "
0 commit comments