code: def test_collect_intermediate_metric(
      pipeline: Pipeline, input_data: InputData, metric: MetricIDType
  ):
      graph_gen_params = get_pipeline_generation_params()
      metrics = [metric]
  
      validation_blocks = (
          1
          if input_data.task.task_type is TaskTypesEnum.ts_forecasting
          else None
      )
      data_source = DataSourceSplitter(
          validation_blocks=validation_blocks
      ).build(input_data)
      objective_eval = PipelineObjectiveEvaluate(
          MetricsObjective(metrics),
          data_source,
          validation_blocks=validation_blocks,
      )
      dispatcher = MultiprocessingDispatcher(graph_gen_params.adapter)
      dispatcher.set_graph_evaluation_callback(
          objective_eval.evaluate_intermediate_metrics
      )
      evaluate = dispatcher.dispatch(objective_eval)
  
      population = [
          Individual(graph_gen_params.adapter.adapt(pipeline))
      ]
      evaluated_pipeline = evaluate(population)[0].graph
      restored_pipeline = graph_gen_params.adapter.restore(
          evaluated_pipeline
      )
  
      assert_intermediate_metrics(restored_pipeline)
  
imports: from itertools import chain
  from pathlib import Path
  import numpy
  import pytest
  from golem.core.dag.graph import Graph
  from golem.core.optimisers.fitness import SingleObjFitness
  from golem.core.optimisers.genetic.evaluation import MultiprocessingDispatcher
  from golem.core.optimisers.opt_history_objects.individual import Individual
  from golem.core.optimisers.opt_history_objects.opt_history import OptHistory
  from fedot import Fedot
  from fedot.core.data.data import InputData
  from fedot.core.operations.model import Model
  from fedot.core.optimisers.objective import PipelineObjectiveEvaluate
  from fedot.core.optimisers.objective.data_source_splitter import DataSourceSplitter
  from fedot.core.optimisers.objective.metrics_objective import MetricsObjective
  from fedot.core.pipelines.node import PipelineNode
  from fedot.core.pipelines.pipeline import Pipeline
  from fedot.core.pipelines.pipeline_graph_generation_params import get_pipeline_generation_params
  from fedot.core.repository.metrics_repository import ClassificationMetricsEnum, MetricIDType, RegressionMetricsEnum
  from fedot.core.repository.tasks import TaskTypesEnum
  from fedot.core.utils import fedot_project_root
  from test.unit.tasks.test_forecasting import get_ts_data
  from test.unit.validation.test_table_cv import get_classification_data
label_desc: Use image node_id 6 for calling a global function with example usage: test_collect_intermediate_metric(pipeline, input_data, metric) without return types