class_docstr: An abstract evaluator for KGE models.
  
  The evaluator encapsulates the computation of evaluation metrics based on head and tail scores. To this end, it
  offers two methods to process a batch of triples together with the scores produced by some model. It maintains
  intermediate results in its state, and offers a method to obtain the final results once finished.
class_docstr_tok: ["An","abstract","evaluator","for","KGE","models",".","The","evaluator","encapsulates","the","computation","of","evaluation","metrics","based","on","head","and","tail","scores",".","To","this","end",",","it","offers","two","methods","to","process","a","batch","of","triples","together","with","the","scores","produced","by","some","model",".","It","maintains","intermediate","results","in","its","state",",","and","offers","a","method","to","obtain","the","final","results","once","finished","."]
docstr: Evaluate the model on the given device.
docstr_tok: ["Evaluate","the","model","on","the","given","device","."]
code: def _evaluate_on_device(
      self,
      model: Model,
      mapped_triples: MappedTriples,
      batch_size: int | None,
      slice_size: int | None,
      device: torch.device,
      all_pos_triples: MappedTriples | None,
      targets: Collection[Target],
      tqdm_kwargs: Mapping[str, Any],
      **kwargs,
  ) -> MetricResults:
      """Evaluate the model on the given device."""
      # Ensure evaluation mode
      model.eval()
      # Send model & tensors to device
      model = model.to(device)
      if all_pos_triples is not None:
          all_pos_triples = all_pos_triples.to(device=device)
      mapped_triples = mapped_triples.to(device=device)
      num_triples = mapped_triples.shape[0]
      # no batch size -> automatic memory optimization
      if batch_size is None:
          batch_size = 32 if device.type == "cpu" else num_triples
          logger.debug(
              f"Automatically set maximum batch size to {batch_size=}"
          )
      # no slice size -> automatic memory optimization
      if slice_size is None:
          nums: set[int] = set()
          if {LABEL_HEAD, LABEL_TAIL}.intersection(targets):
              nums.add(model.num_entities)
          if LABEL_RELATION in targets:
              nums.add(model.num_relations)
          slice_size = max(nums)
          logger.debug(
              f"Automatically set maximum slice size to {slice_size=}"
          )
      # Show progressbar
      with tqdm(
          **ChainMap(
              dict(tqdm_kwargs),
              dict(
                  desc=f"Evaluating on {model.device}",
                  total=num_triples,
                  unit="triple",
                  unit_scale=True,
              ),
          )
      ) as progress_bar:
          return evaluate(
              evaluator=self,
              mapped_triples=mapped_triples,
              # note: we provide the *maximum* batch and slice size here; it is reduced if necessary
              batch_size=num_triples,
              slice_size=slice_size,
              progress_bar=progress_bar,
              targets=targets,
              # kwargs
              all_pos_triples=all_pos_triples,
              model=model,
              mode=self.mode,
              **kwargs,
          )
  
imports: from __future__ import annotations
  import logging
  import timeit
  import warnings
  from abc import ABC, abstractmethod
  from collections import ChainMap
  from typing import Any, ClassVar, Collection, Generic, List, Mapping, NamedTuple, Optional, Tuple, Type, TypeVar, Union, cast
  import pandas
  import torch
  from torch_max_mem import maximize_memory_utilization
  from tqdm.autonotebook import tqdm
  from ..constants import COLUMN_LABELS, TARGET_TO_INDEX, TARGET_TO_KEY_LABELS
  from ..metrics.utils import Metric
  from ..models import Model
  from ..triples.triples_factory import restrict_triples
  from ..triples.utils import get_entities, get_relations
  from ..typing import LABEL_HEAD, LABEL_RELATION, LABEL_TAIL, InductiveMode, MappedTriples, Target
  from ..utils import flatten_dictionary, format_relative_comparison, normalize_string, prepare_filter_triples
label_desc: Use image node_id 7 for calling the Evaluator obj's underlying member method code with example usage: obj._evaluate_on_device(model, mapped_triples, batch_size, slice_size, device, all_pos_triples, targets, tqdm_kwargs) and returns: evaluate