code: def test_mqf2_modules(
      num_feat_dynamic_real: int,
      num_feat_static_real: int,
      num_feat_static_cat: int,
      cardinality: Optional[List[int]],
  ):
      batch_size = 4
      prediction_length = 6
      context_length = 12
  
      distr_output = MQF2DistributionOutput(prediction_length)
  
      lightning_module = MQF2MultiHorizonLightningModule(
          {
              "freq": "1H",
              "context_length": context_length,
              "prediction_length": prediction_length,
              "num_feat_dynamic_real": num_feat_dynamic_real,
              "num_feat_static_real": num_feat_static_real,
              "num_feat_static_cat": num_feat_static_cat,
              "cardinality": cardinality,
              "distr_output": distr_output,
          }
      )
      model = lightning_module.model
  
      feat_static_cat = torch.zeros(
          batch_size, num_feat_static_cat, dtype=torch.long
      )
      feat_static_real = torch.ones(batch_size, num_feat_static_real)
      past_time_feat = torch.ones(
          batch_size, model._past_length, num_feat_dynamic_real
      )
      future_time_feat = torch.ones(
          batch_size, prediction_length, num_feat_dynamic_real
      )
      past_target = torch.ones(batch_size, model._past_length)
      past_observed_values = torch.ones(batch_size, model._past_length)
      future_target = torch.ones(batch_size, prediction_length)
      future_observed_values = torch.ones(batch_size, prediction_length)
  
      _, scale, hidden_state, _, _ = model.unroll_lagged_rnn(
          feat_static_cat,
          feat_static_real,
          past_time_feat,
          past_target,
          past_observed_values,
          future_time_feat,
          future_target,
      )
  
      hidden_state = hidden_state[:, :context_length]
  
      assert scale.shape == (batch_size, 1)
  
      hidden_size = model.rnn.hidden_size
  
      assert hidden_state.shape == (
          batch_size,
          context_length,
          hidden_size,
      )
  
      distr = model.output_distribution(
          model.picnn, hidden_state, inference=False
      )
  
      assert distr.batch_shape == (
          batch_size,
          context_length,
      )
  
      assert distr.event_shape == ()
  
      distr_infer = model.output_distribution(
          model.picnn, hidden_state, inference=True
      )
  
      assert distr_infer.batch_shape == (batch_size,)
      assert distr_infer.event_shape == ()
  
      samples = model(
          feat_static_cat,
          feat_static_real,
          past_time_feat,
          past_target,
          past_observed_values,
          future_time_feat,
      )
  
      assert samples.shape == (batch_size, 100, prediction_length)
  
      batch = dict(
          feat_static_cat=feat_static_cat,
          feat_static_real=feat_static_real,
          past_time_feat=past_time_feat,
          future_time_feat=future_time_feat,
          past_target=past_target,
          past_observed_values=past_observed_values,
          future_target=future_target,
          future_observed_values=future_observed_values,
      )
  
      assert (
          lightning_module.training_step(batch, batch_idx=0).shape == ()
      )
      assert (
          lightning_module.validation_step(batch, batch_idx=0).shape
          == ()
      )
  
imports: from typing import List, Optional
  import pytest
  import torch
  from gluonts.torch.model.mqf2 import MQF2MultiHorizonLightningModule
  from gluonts.torch.model.mqf2.distribution import MQF2DistributionOutput
label_desc: Use image node_id 1 for calling a global function with example usage: test_mqf2_modules(num_feat_dynamic_real, num_feat_static_real, num_feat_static_cat, cardinality) without return types