code: def train_with_pruning_callback(
      tmpdir,
      parameters_to_prune=False,
      use_global_unstructured=False,
      pruning_fn="l1_unstructured",
      use_lottery_ticket_hypothesis=False,
      strategy="auto",
      accelerator="cpu",
      devices=1,
  ):
      seed_everything(1)
      model = TestModel()
  
      # Weights are random. None is 0
      assert torch.all(model.layer.mlp_2.weight != 0)
  
      pruning_kwargs = {
          "pruning_fn": pruning_fn,
          "amount": 0.3,
          "use_global_unstructured": use_global_unstructured,
          "use_lottery_ticket_hypothesis": use_lottery_ticket_hypothesis,
          "verbose": 1,
      }
      if parameters_to_prune:
          pruning_kwargs["parameters_to_prune"] = [
              (model.layer.mlp_1, "weight"),
              (model.layer.mlp_2, "weight"),
          ]
      else:
          if isinstance(pruning_fn, str) and pruning_fn.endswith(
              "_structured"
          ):
              pruning_kwargs["parameter_names"] = ["weight"]
          else:
              pruning_kwargs["parameter_names"] = ["weight", "bias"]
      if isinstance(pruning_fn, str) and pruning_fn.endswith(
          "_structured"
      ):
          pruning_kwargs["pruning_dim"] = 0
      if pruning_fn == "ln_structured":
          pruning_kwargs["pruning_norm"] = 1
  
      # Misconfiguration checks
      if (
          isinstance(pruning_fn, str)
          and pruning_fn.endswith("_structured")
          and use_global_unstructured
      ):
          with pytest.raises(
              MisconfigurationException,
              match="is supported with `use_global_unstructured=True`",
          ):
              ModelPruning(**pruning_kwargs)
          return
      if (
          ModelPruning._is_pruning_method(pruning_fn)
          and not use_global_unstructured
      ):
          with pytest.raises(
              MisconfigurationException,
              match="currently only supported with",
          ):
              ModelPruning(**pruning_kwargs)
          return
  
      pruning = ModelPruning(**pruning_kwargs)
  
      trainer = Trainer(
          default_root_dir=tmpdir,
          enable_progress_bar=False,
          enable_model_summary=False,
          enable_checkpointing=False,
          logger=False,
          limit_train_batches=10,
          limit_val_batches=2,
          max_epochs=10,
          strategy=strategy,
          accelerator=accelerator,
          devices=devices,
          callbacks=pruning,
      )
      trainer.fit(model)
      trainer.test(model)
  
      if not strategy:
          # Check some have been pruned
          assert torch.any(model.layer.mlp_2.weight == 0)
  
imports: import re
  from collections import OrderedDict
  from logging import INFO
  from typing import Union
  import pytest
  import torch
  import torch.nn.utils.prune
  from lightning.pytorch import Trainer, seed_everything
  from lightning.pytorch.callbacks import ModelCheckpoint, ModelPruning
  from lightning.pytorch.demos.boring_classes import BoringModel
  from lightning.pytorch.utilities.exceptions import MisconfigurationException
  from torch import nn
  from torch.nn import Sequential
  from tests_pytorch.helpers.runif import RunIf
label_desc: Use image node_id 1 for calling a global function with example usage: train_with_pruning_callback(tmpdir, parameters_to_prune, use_global_unstructured, pruning_fn, use_lottery_ticket_hypothesis, strategy, accelerator, devices) without return types