"docs/source/en/model_doc/data2vec.md" did not exist on "cf028d0c3d2e7e21cd56cc4958aee09798ee743e"
Unverified Commit bdd690a7 authored by yujun's avatar yujun Committed by GitHub
Browse files

add torch.no_grad when in eval mode (#17020)

* add torch.no_grad when in eval mode

* make style quality
parent 9586e222
......@@ -469,6 +469,7 @@ def main():
model.eval()
samples_seen = 0
for step, batch in enumerate(eval_dataloader):
with torch.no_grad():
outputs = model(**batch)
predictions = outputs.logits.argmax(dim=-1)
predictions, references = accelerator.gather((predictions, batch["labels"]))
......
......@@ -579,6 +579,7 @@ def main():
model.eval()
samples_seen = 0
for step, batch in enumerate(tqdm(eval_dataloader, disable=not accelerator.is_local_main_process)):
with torch.no_grad():
outputs = model(**batch)
upsampled_logits = torch.nn.functional.interpolate(
......
......@@ -22,6 +22,7 @@ import random
from pathlib import Path
import datasets
import torch
from datasets import load_dataset, load_metric
from torch.utils.data import DataLoader
from tqdm.auto import tqdm
......@@ -514,6 +515,7 @@ def main():
model.eval()
samples_seen = 0
for step, batch in enumerate(eval_dataloader):
with torch.no_grad():
outputs = model(**batch)
predictions = outputs.logits.argmax(dim=-1) if not is_regression else outputs.logits.squeeze()
predictions, references = accelerator.gather((predictions, batch["labels"]))
......
......@@ -28,6 +28,7 @@ from dataclasses import dataclass, field
from typing import Optional, List
import datasets
import torch
from datasets import load_dataset
import transformers
......@@ -871,6 +872,7 @@ def main():
model.eval()
for step, batch in enumerate(eval_dataloader):
with torch.no_grad():
outputs = model(**batch)
predictions = outputs.logits.argmax(dim=-1)
metric.add_batch(
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment