code: def check_functional_vs_PIL_vs_scripted(
      fn,
      fn_pil,
      fn_t,
      config,
      device,
      dtype,
      channels=3,
      tol=2.0 + 1e-10,
      agg_method="max",
  ):
      script_fn = torch.jit.script(fn)
      torch.manual_seed(15)
      tensor, pil_img = _create_data(
          26, 34, channels=channels, device=device
      )
      batch_tensors = _create_data_batch(
          16, 18, num_samples=4, channels=channels, device=device
      )
  
      if dtype is not None:
          tensor = F.convert_image_dtype(tensor, dtype)
          batch_tensors = F.convert_image_dtype(batch_tensors, dtype)
  
      out_fn_t = fn_t(tensor, **config)
      out_pil = fn_pil(pil_img, **config)
      out_scripted = script_fn(tensor, **config)
      assert out_fn_t.dtype == out_scripted.dtype
      assert out_fn_t.size()[1:] == out_pil.size[::-1]
  
      rbg_tensor = out_fn_t
  
      if out_fn_t.dtype != torch.uint8:
          rbg_tensor = F.convert_image_dtype(out_fn_t, torch.uint8)
  
      # Check that max difference does not exceed 2 in [0, 255] range
      # Exact matching is not possible due to incompatibility convert_image_dtype and PIL results
      _assert_approx_equal_tensor_to_pil(
          rbg_tensor.float(), out_pil, tol=tol, agg_method=agg_method
      )
  
      atol = 1e-6
      if (
          out_fn_t.dtype == torch.uint8
          and "cuda" in torch.device(device).type
      ):
          atol = 1.0
      assert out_fn_t.allclose(out_scripted, atol=atol)
  
      # FIXME: fn will be scripted again in _test_fn_on_batch. We could avoid that.
      _test_fn_on_batch(
          batch_tensors, fn, scripted_fn_atol=atol, **config
      )
  
imports: import colorsys
  import itertools
  import math
  import os
  from functools import partial
  from typing import Sequence
  import numpy
  import PIL.Image
  import pytest
  import torch
  import torchvision.transforms
  import torchvision.transforms._functional_pil
  import torchvision.transforms._functional_tensor
  import torchvision.transforms.functional
  from common_utils import _assert_approx_equal_tensor_to_pil, _assert_equal_tensor_to_pil, _create_data, _create_data_batch, _test_fn_on_batch, assert_equal, cpu_and_cuda, needs_cuda
  from torchvision.transforms import InterpolationMode
label_desc: Use image node_id 10 for calling a global function with example usage: check_functional_vs_PIL_vs_scripted(fn, fn_pil, fn_t, config, device, dtype, channels, tol, agg_method) without return types