code: def test_knn_kernel_ts(ensembler):
      """
      Test the knn torch backend can be correctly initialized with a kernel,
      and torchscripted, as well as saved and loaded to and from disk.
      """
  
      kernel = GaussianRBF(sigma=torch.tensor((0.25)))
      knn_torch = KNNTorch(k=[4, 5], kernel=kernel, ensembler=ensembler)
      x_ref = torch.randn((1024, 10))
      knn_torch.fit(x_ref)
      x = torch.randn((3, 10)) * torch.tensor([[1], [1], [100]])
      knn_torch.infer_threshold(x_ref, 0.1)
      pred_1 = knn_torch(x)
      knn_torch = torch.jit.script(knn_torch)
      pred_2 = knn_torch(x)
      assert torch.all(pred_1 == pred_2)
  
file_path: alibi-detect/alibi_detect/od/tests/test__knn/test__knn_backend.py
imports: import pytest
  import torch
  from alibi_detect.od.pytorch.knn import KNNTorch
  from alibi_detect.utils.pytorch.kernels import GaussianRBF
  from alibi_detect.od.pytorch.ensemble import Ensembler, PValNormalizer, AverageAggregator
  from alibi_detect.exceptions import NotFittedError, ThresholdNotInferredError
label_desc: Use image node_id 7 for calling a global function with example usage: test_knn_kernel_ts(ensembler) without return types