utils/trainer.py
def evaluate_one_epoch(self, model, dataloader, prefix, debugging=False, save_csv_path=None, show_progress=False):
        """Evaluate the model for one epoch."""
        model.eval()
        tot_inp, tot_outp = [], []

        with torch.no_grad():
            total = 10 if debugging else len(dataloader)
            with tqdm(dataloader, total=total) as t:
                t.set_description(prefix)

                for i, data in enumerate(t):
                    # Input
                    data = to_device(data, self.device)
                    tot_inp.append(data)

                    # Forward
                    output = model(**data)
                    tot_outp.append(output)

                    # Break when reaching 10 iterations when debugging
                    if debugging and i == 9:
                        break

        metrics = compute_metrics_from_inputs_and_outputs(
            inputs=tot_inp, outputs=tot_outp, tokenizer=self.tokenizer, save_csv_path=save_csv_path,
            show_progress=show_progress)

        if metrics is not None:
            self._record_metrics(metrics)

            to_log = json.dumps(metrics, indent=2)
            logger.info(f"{prefix}:\n{to_log}")

        model.train()
        return
Evaluate the model for one epoch.
Evaluate the model for one epoch.
Evaluate the model for one epoch .
def evaluate_one_epoch(self, model, dataloader, prefix, debugging=False, save_csv_path=None, show_progress=False):
        model.eval()
        tot_inp, tot_outp = [], []
        with torch.no_grad():
            total = 10 if debugging else len(dataloader)
            with tqdm(dataloader, total=total) as t:
                t.set_description(prefix)
                for i, data in enumerate(t):
                    data = to_device(data, self.device)
                    tot_inp.append(data)
                    output = model(**data)
                    tot_outp.append(output)
                    if debugging and i == 9:
                        break
        metrics = compute_metrics_from_inputs_and_outputs(
            inputs=tot_inp, outputs=tot_outp, tokenizer=self.tokenizer, save_csv_path=save_csv_path,
            show_progress=show_progress)
        if metrics is not None:
            self._record_metrics(metrics)
            to_log = json.dumps(metrics, indent=2)
            logger.info(f"{prefix}:\n{to_log}")
        model.train()
        return
def evaluate_one_epoch ( self , model , dataloader , prefix , debugging = False , save_csv_path = None , show_progress = False ) : model . eval ( ) tot_inp , tot_outp = [ ] , [ ] with torch . no_grad ( ) : total = 10 if debugging else len ( dataloader ) with tqdm ( dataloader , total = total ) as t : t . set_description ( prefix ) for i , data in enumerate ( t ) : data = to_device ( data , self . device ) tot_inp . append ( data ) output = model ( ** data ) tot_outp . append ( output ) if debugging and i == 9 : break metrics = compute_metrics_from_inputs_and_outputs ( inputs = tot_inp , outputs = tot_outp , tokenizer = self . tokenizer , save_csv_path = save_csv_path , show_progress = show_progress ) if metrics is not None : self . _record_metrics ( metrics ) to_log = json . dumps ( metrics , indent = 2 ) logger . info ( f"{prefix}:\n{to_log}" ) model . train ( ) return
Evaluate the model for one epoch.
Evaluate the model for one epoch .
"""Evaluate the model for one epoch.""" # Input # Forward # Break when reaching 10 iterations when debugging
self
model
dataloader
prefix
debugging
save_csv_path
show_progress