code: def test_conv2d(padds, backend, io_type):
      n_in = 2
      n_out = 2
      kernel_size = 3
      size_in_width = 4
      size_in_height = 4
  
      model = torch.nn.Sequential(
          nn.Conv2d(n_in, n_out, kernel_size, padding=padds), nn.ReLU()
      ).to()
      model.eval()
  
      X_input = np.random.rand(100, n_in, size_in_height, size_in_width)
      pytorch_prediction = model(torch.Tensor(X_input)).detach().numpy()
  
      if io_type == "io_stream":
          X_input = np.ascontiguousarray(X_input.transpose(0, 2, 3, 1))
          config = config_from_pytorch_model(
              model, inputs_channel_last=True, transpose_outputs=False
          )
      else:
          config = config_from_pytorch_model(
              model, inputs_channel_last=False, transpose_outputs=True
          )
  
      output_dir = str(
          test_root_path
          / f"hls4mlprj_pytorch_api_conv2d_{padds}_{backend}_{io_type}"
      )
      hls_model = convert_from_pytorch_model(
          model,
          (None, n_in, size_in_height, size_in_width),
          hls_config=config,
          output_dir=output_dir,
          backend=backend,
          io_type=io_type,
      )
      hls_model.compile()
  
      from torch.fx import symbolic_trace
  
      traced_model = symbolic_trace(model)
      nNodes = 0
      convNode = None
      reluNode = None
      for _node in traced_model.graph.nodes:
          nNodes += 1
          if nNodes == 2:
              convNode = _node
          if nNodes == 3:
              reluNode = _node
      # if io_type == 'io_stream':
      #    assert nNodes -1 == len(hls_model.get_layers())
      # else:
      #    assert nNodes == len(hls_model.get_layers())
  
      children = {c[0]: c[1] for c in model.named_children()}
      class_object_conv = children[convNode.target]
      class_object_relu = children[reluNode.target]
  
      from hls4ml.converters.utils import compute_padding_2d
  
      padding = "valid" if padds == 0 else "same"
      out_dims_hls = compute_padding_2d(
          padding,
          size_in_height,
          size_in_width,
          1,
          1,
          kernel_size,
          kernel_size,
      )
  
      out_width = int(
          (
              size_in_width
              + 2 * class_object_conv.padding[1]
              - class_object_conv.dilation[1]
              * (class_object_conv.kernel_size[1] - 1)
              - 1
          )
          / class_object_conv.stride[1]
          + 1
      )  # following https://pytorch.org/docs/stable/generated/torch.nn.Conv2d.html
      assert out_dims_hls[0] == out_width
      out_height = int(
          (
              size_in_height
              + 2 * class_object_conv.padding[0]
              - class_object_conv.dilation[0]
              * (class_object_conv.kernel_size[0] - 1)
              - 1
          )
          / class_object_conv.stride[0]
          + 1
      )  # following https://pytorch.org/docs/stable/generated/torch.nn.Conv2d.html
      assert out_dims_hls[1] == out_height
  
      if io_type == "io_stream":
          hls_prediction = np.transpose(
              np.reshape(
                  hls_model.predict(X_input),
                  (100, out_height, out_width, n_out),
              ),
              (0, 3, 1, 2),
          )
      else:
          hls_prediction = np.reshape(
              hls_model.predict(X_input),
              (100, n_out, out_height, out_width),
          )
      # results are not very good at the moment
      np.testing.assert_allclose(
          hls_prediction, pytorch_prediction, rtol=0, atol=5e-2
      )
  
      if not (
          backend == "Vivado" and io_type == "io_stream" and padds == 1
      ):
          # Vivado inserts and additional layer for 'same' padding in io_stream
          conv_index = 2
          act_index = 3
          if io_type == "io_stream":
              conv_index = 1
              act_index = 2
          assert (
              list(hls_model.get_layers())[conv_index].attributes[
                  "name"
              ]
              == convNode.name
          )
          assert (
              list(hls_model.get_layers())[conv_index].attributes[
                  "class_name"
              ]
              == "Conv2D"
          )
          assert (
              list(hls_model.get_layers())[act_index].attributes[
                  "activation"
              ]
              == class_object_relu.__class__.__name__
          )
          assert (
              list(hls_model.get_layers())[conv_index].attributes[
                  "in_width"
              ]
              == size_in_width
          )
          assert (
              list(hls_model.get_layers())[conv_index].attributes[
                  "in_height"
              ]
              == size_in_height
          )
          assert (
              list(hls_model.get_layers())[conv_index].attributes[
                  "filt_width"
              ]
              == class_object_conv.kernel_size[1]
          )
          assert (
              list(hls_model.get_layers())[conv_index].attributes[
                  "filt_height"
              ]
              == class_object_conv.kernel_size[0]
          )
          assert (
              list(hls_model.get_layers())[conv_index].attributes[
                  "n_chan"
              ]
              == class_object_conv.in_channels
          )
          assert (
              list(hls_model.get_layers())[conv_index].attributes[
                  "n_filt"
              ]
              == class_object_conv.out_channels
          )
          assert (
              list(hls_model.get_layers())[conv_index].attributes[
                  "stride_width"
              ]
              == class_object_conv.stride[1]
          )
          assert (
              list(hls_model.get_layers())[conv_index].attributes[
                  "stride_height"
              ]
              == class_object_conv.stride[0]
          )
          if (
              list(hls_model.get_layers())[conv_index].attributes[
                  "padding"
              ]
              == "valid"
          ):
              padding = 0
          else:
              padding = 1
          assert padding == class_object_conv.padding[0]
          assert (
              list(hls_model.get_layers())[conv_index].attributes[
                  "data_format"
              ]
              == "channels_last"
          )
  
          pad_along_width = max(
              (out_width - 1) * class_object_conv.stride[1]
              + class_object_conv.kernel_size[1]
              - size_in_width,
              0,
          )
          pad_along_height = max(
              (out_height - 1) * class_object_conv.stride[0]
              + class_object_conv.kernel_size[0]
              - size_in_height,
              0,
          )
  
          pad_top = pad_along_height // 2
          pad_bottom = pad_along_height - pad_top
          pad_left = pad_along_width // 2
          pad_right = pad_along_width - pad_left
  
          if padds == 1:
              assert (
                  list(hls_model.get_layers())[conv_index].attributes[
                      "pad_left"
                  ]
                  == pad_left
              )
              assert (
                  list(hls_model.get_layers())[conv_index].attributes[
                      "pad_right"
                  ]
                  == pad_right
              )
              assert (
                  list(hls_model.get_layers())[conv_index].attributes[
                      "pad_top"
                  ]
                  == pad_top
              )
              assert (
                  list(hls_model.get_layers())[conv_index].attributes[
                      "pad_bottom"
                  ]
                  == pad_bottom
              )
          elif padds == 0:
              assert (
                  list(hls_model.get_layers())[conv_index].attributes[
                      "pad_left"
                  ]
                  == 0
              )
              assert (
                  list(hls_model.get_layers())[conv_index].attributes[
                      "pad_right"
                  ]
                  == 0
              )
              assert (
                  list(hls_model.get_layers())[conv_index].attributes[
                      "pad_top"
                  ]
                  == 0
              )
              assert (
                  list(hls_model.get_layers())[conv_index].attributes[
                      "pad_bottom"
                  ]
                  == 0
              )
  
imports: import math
  from pathlib import Path
  import numpy
  import pytest
  import torch
  import torch.nn
  from torch.nn import AvgPool1d, AvgPool2d, MaxPool1d, MaxPool2d
  from hls4ml.converters import convert_from_pytorch_model
  from hls4ml.utils.config import config_from_pytorch_model
label_desc: Use image node_id 5 for calling a global function with example usage: test_conv2d(padds, backend, io_type) without return types