1717from aiu_fms_testing_utils .testing .validation import get_default_validation_prefix
1818
1919from aiu_fms_testing_utils .utils import prepare_inputs
20- from aiu_fms_testing_utils .utils .metrics_utils import tensor_abs_diff , tensor_cos_sim
20+ from aiu_fms_testing_utils .utils .metrics_utils import tensor_abs_diff , tensor_cos_sim , save_layers_output
2121
2222
2323logger = logging .getLogger (__name__ )
@@ -390,8 +390,7 @@ def generate_layers_metrics(model_path, batch_size, seq_length, max_new_tokens):
390390 seq_length = seq_length , max_new_tokens = max_new_tokens ,
391391 tokenizer = tokenizer )
392392
393- with open (os .path .join (output_path ,f"{ model_path } -layer-output-stack-cpu.json" ), 'w' ) as f :
394- json .dump (layer_stack_cpu , f )
393+ save_layers_output (os .path .join (output_path ,f"{ model_path } -layer-output-stack-cpu.json" ),layer_stack_cpu )
395394
396395 global generate_iters
397396 generate_iters = 0
@@ -403,8 +402,7 @@ def generate_layers_metrics(model_path, batch_size, seq_length, max_new_tokens):
403402 seq_length = seq_length , max_new_tokens = max_new_tokens ,
404403 tokenizer = tokenizer )
405404
406- with open (os .path .join (output_path ,f"{ model_path } -layer-output-stack-gpu.json" ), 'w' ) as f :
407- json .dump (layer_stack_cuda , f )
405+ save_layers_output (os .path .join (output_path ,f"{ model_path } -layer-output-stack-gpu.json" ), layer_stack_cuda )
408406
409407 assert len (layer_stack_cuda .keys ()) == len (layer_stack_cpu .keys ())
410408
0 commit comments