code: def test_lsdd_online_state_online(tmp_path, seed):
      """
      Test save/load/reset state methods for LSDDDriftOnlineTorch. State is saved, reset, and loaded, with
      prediction results and stateful attributes compared to original.
      """
      n = 100
      with fixed_seed(seed):
          x_ref = np.random.normal(0, 1, (n, n_classes))
          x = np.random.normal(0.1, 1, (n, n_classes))
          dd = LSDDDriftOnlineTorch(x_ref, window_size=10, ert=20)
          # Store state for comparison
          state_dict_t0 = {}
          for key in dd.online_state_keys:
              state_dict_t0[key] = getattr(dd, key)
  
      # Run for 10 time steps
      test_stats_1 = []
      for t, x_t in enumerate(x):
          if t == 5:
              dd.save_state(tmp_path)
              # Store state for comparison
              state_dict_t5 = {}
              for key in dd.online_state_keys:
                  state_dict_t5[key] = getattr(dd, key)
          preds = dd.predict(x_t)
          test_stats_1.append(preds["data"]["test_stat"])
  
      # Reset and check state cleared
      dd.reset_state()
      for key, orig_val in state_dict_t0.items():
          np.testing.assert_array_equal(
              orig_val, getattr(dd, key)
          )  # use np.testing here as it handles torch.Tensor etc
  
      # Repeat, check that same test_stats both times
      test_stats_2 = []
      for t, x_t in enumerate(x):
          preds = dd.predict(x_t)
          test_stats_2.append(preds["data"]["test_stat"])
      np.testing.assert_array_equal(test_stats_1, test_stats_2)
  
      # Load state from t=5 timestep
      dd.load_state(tmp_path)
  
      # Compare stateful attributes to original at t=5
      for key, orig_val in state_dict_t5.items():
          np.testing.assert_array_equal(
              orig_val, getattr(dd, key)
          )  # use np.testing here as it handles torch.Tensor etc
  
      # Compare predictions to original at t=5
      new_pred = dd.predict(x[5])
      assert new_pred["data"]["test_stat"] == test_stats_1[5]
  
file_path: alibi-detect/alibi_detect/cd/pytorch/tests/test_lsdd_online_pt.py
imports: from functools import partial
  from itertools import product
  import numpy
  import pytest
  import torch
  import torch.nn
  from typing import Callable, List
  from alibi_detect.cd.pytorch.lsdd_online import LSDDDriftOnlineTorch
  from alibi_detect.cd.pytorch.preprocess import HiddenOutput, preprocess_drift
  from alibi_detect.utils._random import fixed_seed
label_desc: Use image node_id 4 for calling a global function with example usage: test_lsdd_online_state_online(tmp_path, seed) without return types