code: def test_callback_events_torch():
      from torch.optim import SGD
      from torch.utils.data import DataLoader
      from fastNLP.core.controllers.trainer import Trainer
      from tests.helpers.models.torch_model import (
          TorchNormalModel_Classification_1,
      )
      from tests.helpers.datasets.torch_data import (
          TorchNormalDataset_Classification,
      )
  
      model = TorchNormalModel_Classification_1(
          num_labels=3, feature_dimension=10
      )
      optimizer = SGD(model.parameters(), lr=0.0001)
      dataset = TorchNormalDataset_Classification(
          num_labels=3, feature_dimension=10
      )
      dataloader = DataLoader(dataset=dataset, batch_size=4)
  
      trainer = Trainer(
          model=model,
          driver="torch",
          device="cpu",
          train_dataloader=dataloader,
          optimizers=optimizer,
      )
  
      def filter_fn(filter, trainer):
          if trainer.__heihei_test__ == 10:
              return True
          return False
  
      event_state = Event.on_train_begin(filter_fn=filter_fn)
  
      @Filter(filter_fn=event_state.filter_fn)
      def _fn(trainer, data):
          return data
  
      _res = []
      for i in range(100):
          trainer.__heihei_test__ = i
          cu_res = _fn(trainer, i)
          if cu_res is not None:
              _res.append(cu_res)
      assert _res == [10]
  
file_path: fastNLP/tests/core/callbacks/test_callback_event.py
imports: import pytest
  from functools import reduce
  from fastNLP.core.callbacks.callback_event import Event, Filter
label_desc: Use image node_id 2 for calling a global function with example usage: test_callback_events_torch() and returns: False, data, True