code: def canonicalize_padding(
      padding: PaddingLike, rank: int
  ) -> LaxPadding:
      """ "Canonicalizes conv padding to a jax.lax supported format."""
      if isinstance(padding, str):
          return padding
      if isinstance(padding, int):
          return [(padding, padding)] * rank
      if isinstance(padding, tp.Sequence) and len(padding) == rank:
          new_pad = []
          for p in padding:
              if isinstance(p, int):
                  new_pad.append((p, p))
              elif isinstance(p, tuple) and len(p) == 2:
                  new_pad.append(p)
              else:
                  break
          if len(new_pad) == rank:
              return new_pad
      raise ValueError(
          f"Invalid padding format: {padding}, should be str, int,"
          f" or a sequence of len {rank} where each element is an"
          " int or pair of ints."
      )
  
imports: from __future__ import annotations
  import typing
  from types import MappingProxyType
  import jax
  import jax.numpy
  import numpy
  from jax import lax
  from flax.experimental import nnx
  from flax.experimental.nnx.nnx import rnglib, variables
  from flax.experimental.nnx.nnx.module import Module
  from flax.experimental.nnx.nnx.nn import dtypes, initializers
label_desc: Use image node_id 1 for calling a global function with example usage: canonicalize_padding(padding, rank) and returns: padding, unknown, new_pad