File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -74,15 +74,18 @@ def _run_validation(
7474 device : torch .device ,
7575) -> dict [str , float ]:
7676 model .eval ()
77- accumulated : dict [str , list [float ]] = defaultdict (list )
77+ weighted_sums : dict [str , float ] = defaultdict (float )
78+ total_samples = 0
7879 for x , y in val_loader :
7980 x , y = x .to (device ), y .to (device )
81+ batch_size = x .shape [0 ]
8082 head_out = model (x )
8183 loss = loss_function (head_out , y )
8284 for key , value in compute_metrics (head_out , y , loss ).items ():
83- accumulated [key ].append (value )
85+ weighted_sums [key ] += value * batch_size
86+ total_samples += batch_size
8487 model .train ()
85- return {key : sum ( values ) / len ( values ) for key , values in accumulated .items ()}
88+ return {key : total / total_samples for key , total in weighted_sums .items ()}
8689
8790
8891def run_training_loop (
You can’t perform that action at this time.
0 commit comments