code: def check_for_nonfinite(
      tensor: torch.Tensor, names: Union[str, List[str]]
  ) -> torch.Tensor:
      """
      Check if 2D tensor contains NAs or inifinite values.
  
      Args:
          names (Union[str, List[str]]): name(s) of column(s) (used for error messages)
          tensor (torch.Tensor): tensor to check
  
      Returns:
          torch.Tensor: returns tensor if checks yield no issues
      """
      if isinstance(names, str):
          names = [names]
          assert tensor.ndim == 1
          nans = (~torch.isfinite(tensor).unsqueeze(-1)).sum(0)
      else:
          assert tensor.ndim == 2
          nans = (~torch.isfinite(tensor)).sum(0)
      for name, na in zip(names, nans):
          if na > 0:
              raise ValueError(
                  f"{na} ({na/tensor.size(0):.2%}) of {name} "
                  "values were found to be NA or infinite (even after encoding). NA values are not allowed "
                  "`allow_missing_timesteps` refers to missing rows, not to missing values. Possible strategies to "
                  f"fix the issue are (a) dropping the variable {name}, "
                  "(b) using `NaNLabelEncoder(add_nan=True)` for categorical variables, "
                  "(c) filling missing values and/or (d) optionally adding a variable indicating filled values"
              )
      return tensor
  
imports: from copy import copy, deepcopy
  from functools import lru_cache
  import inspect
  from typing import Any, Callable, Dict, List, Tuple, Union
  import warnings
  import matplotlib.pyplot
  import numpy
  import pandas
  from sklearn.exceptions import NotFittedError
  from sklearn.preprocessing import RobustScaler, StandardScaler
  from sklearn.utils.validation import check_is_fitted
  import torch
  from torch.distributions import Beta
  from torch.nn.utils import rnn
  from torch.utils.data import DataLoader, Dataset
  from torch.utils.data.sampler import Sampler, SequentialSampler
  from pytorch_forecasting.data.encoders import EncoderNormalizer, GroupNormalizer, MultiNormalizer, NaNLabelEncoder, TorchNormalizer
  from pytorch_forecasting.data.samplers import TimeSynchronizedBatchSampler
  from pytorch_forecasting.utils import repr_class
label_desc: Use image node_id 2 for calling a global function with example usage: check_for_nonfinite(tensor, names) and returns: tensor