code: def test_with_debug():
      pytest.importorskip("ml_datasets")
      import ml_datasets
  
      (train_X, train_Y), (dev_X, dev_Y) = ml_datasets.mnist()
  
      counts = Counter()
  
      def on_init(*_):
          counts["init"] += 1
  
      def on_forward(*_):
          counts["forward"] += 1
  
      def on_backprop(*_):
          counts["backprop"] += 1
  
      relu = Relu()
      relu2 = with_debug(
          Relu(),
          on_init=on_init,
          on_forward=on_forward,
          on_backprop=on_backprop,
      )
      chained = chain(relu, relu2, relu2)
      chained.initialize(X=train_X[:5], Y=train_Y[:5])
      _, backprop = chained(X=train_X[:5], is_train=False)
  
      # Not real loss gradients, but we don't care for testing.
      backprop(train_Y[:5])
  
      # Four times forward, because initialization also applies forward for
      # validation.
      assert counts == {"init": 2, "forward": 4, "backprop": 2}
  
imports: import threading
  import time
  from collections import Counter
  import numpy
  import pytest
  from thinc.api import Adam, CupyOps, Dropout, Linear, Model, Relu, Shim, Softmax, chain, change_attr_values, concatenate, set_dropout_rate, use_ops, with_debug, wrap_model_recursive
  from thinc.compat import has_cupy_gpu
  from ..util import make_tempdir
label_desc: Use image node_id 28 for calling a global function with example usage: test_with_debug() without return types