code: def _test_PackNetPlugin(
      self, expectations, optimizer_constructor, lr
  ):
      torch.manual_seed(0)
      if "USE_GPU" in os.environ:
          use_gpu = os.environ["USE_GPU"].lower() in ["true"]
      else:
          use_gpu = False
      scenario = get_fast_benchmark(True, seed=0)
      construct_model = partial(
          packnet_simple_mlp,
          num_classes=10,
          drop_rate=0,
          input_size=6,
          hidden_size=20,
      )
      model = construct_model()
      optimizer = optimizer_constructor(model.parameters(), lr=lr)
      strategy = PackNet(
          model,
          prune_proportion=0.5,
          post_prune_epochs=1,
          optimizer=optimizer,
          train_epochs=2,
          train_mb_size=10,
          eval_mb_size=10,
          device="cuda" if use_gpu else "cpu",
      )
      x_test = torch.rand(10, 6)
      t_test = torch.ones(10, dtype=torch.long)
      task_ouputs = []
  
      # Train
      for i, experience in enumerate(scenario.train_stream):
          strategy.train(experience)
          # Assert that the model achieves the expected accuracy for each task
          # the model has trained on so far. PackNet should not degrade
          # performance on previous tasks.
          self.assert_eval(
              expectations, strategy.eval(scenario.test_stream), i
          )
          # Store the model output for each task
          task_ouputs.append(model.forward(x_test, t_test * i))
  
      # Check that the model achieves the expected accuracy
      self.assert_eval(
          expectations, strategy.eval(scenario.test_stream), 5
      )
  
      # Verify the model can be saved and loaded from a state dict
      new_model = construct_model()
      missing_keys, unexpected_keys = new_model.load_state_dict(
          strategy.model.state_dict()
      )
      self.assertEqual(len(missing_keys), 0)
      self.assertEqual(len(unexpected_keys), 0)
      strategy.model = new_model
  
      # Check that the loaded model achieves the expected accuracy
      self.assert_eval(
          expectations, strategy.eval(scenario.test_stream), 5
      )
  
      # Ensure that given the same inputs, the model produces the same outputs
      for i, task_out in enumerate(task_ouputs):
          out = model.forward(x_test, t_test * i)
          self.assertTrue(torch.allclose(out, task_out))
  
file_path: avalanche/tests/models/test_packnet.py
imports: import unittest
  from avalanche.models.packnet import PackNetModel, packnet_simple_mlp
  from avalanche.training.supervised.strategy_wrappers import PackNet
  from torch.optim import SGD, Adam
  import torch
  import os
  from tests.unit_tests_utils import get_fast_benchmark
  from functools import partial
label_desc: Use image node_id 1 for calling the TestPackNet obj's underlying member method code with example usage: obj._test_PackNetPlugin(expectations, optimizer_constructor, lr) without return types