code: def test_r2_score(
      preds: torch.Tensor,
      target: torch.Tensor,
      num_outputs: int,
      output: torch.Tensor,
  ):
      metric = metric_modules.R2Score(num_outputs=num_outputs)
      with metric.sync_context():
          metric.update(preds, target)
          assert metric.compute() == output
  
imports: import pytest
  import torch
  from ludwig.distributed import init_dist_strategy
  from ludwig.modules import metric_modules
  from ludwig.schema.features.loss.loss import BWCEWLossConfig, SigmoidCrossEntropyLossConfig, SoftmaxCrossEntropyLossConfig
label_desc: Use image node_id 5 for calling a global function with example usage: test_r2_score(preds, target, num_outputs, output) without return types