@@ -138,7 +138,6 @@ def run_merge(
138
138
merge_config ,
139
139
out_path ,
140
140
files = arch_info .tagalong_files or [],
141
- trust_remote_code = options .trust_remote_code ,
142
141
)
143
142
144
143
if getattr (arch_info , "post_fill_parameters" , False ):
@@ -204,15 +203,16 @@ def _copy_tagalong_files(
204
203
merge_config : MergeConfiguration ,
205
204
out_path : str ,
206
205
files : List [str ],
207
- trust_remote_code : bool = False ,
208
206
):
209
207
donor_model = merge_config .base_model or (merge_config .referenced_models ()[0 ])
208
+ donor_local_path = donor_model .local_path ()
210
209
211
210
for file_name in files :
212
- if os .path .exists (os .path .join (donor_model .model .path , file_name )):
211
+ fp = os .path .join (donor_local_path , file_name )
212
+ if os .path .exists (fp ):
213
213
logger .info (f"Copying { file_name } from { donor_model } " )
214
214
shutil .copy (
215
- os . path . join ( donor_model . model . path , file_name ) ,
215
+ fp ,
216
216
os .path .join (out_path , file_name ),
217
217
)
218
218
@@ -223,15 +223,14 @@ def _copy_tokenizer(
223
223
merge_config : MergeConfiguration , out_path : str , trust_remote_code : bool = False
224
224
):
225
225
donor_model = merge_config .base_model or (merge_config .referenced_models ()[0 ])
226
+ donor_local_path = donor_model .local_path ()
226
227
227
228
if (
228
229
(not merge_config .chat_template )
229
- and os .path .exists (
230
- os .path .join (donor_model .model .path , "tokenizer_config.json" )
231
- )
230
+ and os .path .exists (os .path .join (donor_local_path , "tokenizer_config.json" ))
232
231
and (
233
- os .path .exists (os .path .join (donor_model . model . path , "tokenizer.json" ))
234
- or os .path .exists (os .path .join (donor_model . model . path , "tokenizer.model" ))
232
+ os .path .exists (os .path .join (donor_local_path , "tokenizer.json" ))
233
+ or os .path .exists (os .path .join (donor_local_path , "tokenizer.model" ))
235
234
)
236
235
):
237
236
logger .info (f"Copying tokenizer from { donor_model } " )
@@ -244,9 +243,9 @@ def _copy_tokenizer(
244
243
"added_tokens.json" ,
245
244
"merges.txt" ,
246
245
]:
247
- if os .path .exists (os .path .join (donor_model . model . path , file_name )):
246
+ if os .path .exists (os .path .join (donor_local_path , file_name )):
248
247
shutil .copy (
249
- os .path .join (donor_model . model . path , file_name ),
248
+ os .path .join (donor_local_path , file_name ),
250
249
os .path .join (out_path , file_name ),
251
250
)
252
251
@@ -282,21 +281,38 @@ def _model_out_config(
282
281
for module_name in arch_info .modules :
283
282
if config .modules and module_name in config .modules :
284
283
module_def = config .modules .get (module_name )
285
- module_layers [module_name ] = sum (
286
- s .sources [0 ].layer_range [1 ] - s .sources [0 ].layer_range [0 ]
287
- for s in module_def .slices
288
- )
284
+ if module_def and module_def .slices :
285
+ module_layers [module_name ] = sum (
286
+ [
287
+ s .sources [0 ].layer_range [1 ] - s .sources [0 ].layer_range [0 ]
288
+ for s in module_def .slices
289
+ ]
290
+ )
289
291
elif config .slices :
290
292
module_layers [module_name ] = sum (
291
- s .sources [0 ].layer_range [1 ] - s .sources [0 ].layer_range [0 ]
292
- for s in config .slices
293
+ [
294
+ s .sources [0 ].layer_range [1 ] - s .sources [0 ].layer_range [0 ]
295
+ for s in config .slices
296
+ ]
293
297
)
294
298
295
299
if module_layers :
296
300
for module_name in module_layers :
301
+ if module_name not in arch_info .modules :
302
+ logger .warning (
303
+ f"Module { module_name } in config but not in architecture info"
304
+ )
305
+ continue
306
+ module_info = arch_info .modules [module_name ]
307
+ cfg_key = module_info .architecture .num_layers_config_key ()
308
+ if not cfg_key :
309
+ if module_layers [module_name ] > 0 :
310
+ logger .warning (
311
+ f"Module { module_name } has no configuration key for number of layers, "
312
+ "but the number of layers is not zero."
313
+ )
314
+ continue
297
315
try :
298
- module_info = arch_info .modules [module_name ]
299
- cfg_key = module_info .architecture .num_layers_config_key ()
300
316
set_config_value (res , cfg_key , module_layers [module_name ])
301
317
except Exception as e :
302
318
logger .warning (
0 commit comments