code: def decode_block_str(block_str):
      """Decode block definition string
      Gets a list of block arg (dicts) through a string notation of arguments.
      E.g. ir_r2_k3_s2_e1_i32_o16_se0.25_noskip
      All args can exist in any order with the exception of the leading string which
      is assumed to indicate the block type.
      leading string - block type (
        ir = InvertedResidual, ds = DepthwiseSep, dsa = DeptwhiseSep with pw act, cn = ConvBnAct)
      r - number of repeat blocks,
      k - kernel size,
      s - strides (1-9),
      e - expansion ratio,
      c - output channels,
      se - squeeze/excitation ratio
      n - activation fn ('re', 'r6', 'hs', or 'sw')
      Args:
          block_str: a string representation of block arguments.
      Returns:
          A list of block args (dicts)
      Raises:
          ValueError: if the string def not properly specified (TODO)
      """
      assert isinstance(block_str, str)
      ops = block_str.split("_")
      block_type = ops[0]  # take the block type off the front
      ops = ops[1:]
      options = {}
      noskip = False
      for op in ops:
          # string options being checked on individual basis, combine if they
          # grow
          if op == "noskip":
              noskip = True
          elif op.startswith("n"):
              # activation fn
              key = op[0]
              v = op[1:]
              if v == "re":
                  value = nn.ReLU
              elif v == "r6":
                  value = nn.ReLU6
              elif v == "sw":
                  value = Swish
              else:
                  continue
              options[key] = value
          else:
              # all numeric options
              splits = re.split(r"(\d.*)", op)
              if len(splits) >= 2:
                  key, value = splits[:2]
                  options[key] = value
  
      # if act_layer is None, the model default (passed to model init) will be
      # used
      act_layer = options["n"] if "n" in options else None
      exp_kernel_size = (
          parse_ksize(options["a"]) if "a" in options else 1
      )
      pw_kernel_size = (
          parse_ksize(options["p"]) if "p" in options else 1
      )
      # FIXME hack to deal with in_chs issue in TPU def
      fake_in_chs = int(options["fc"]) if "fc" in options else 0
  
      num_repeat = int(options["r"])
      # each type of block has different valid arguments, fill accordingly
      if block_type == "ir":
          block_args = dict(
              block_type=block_type,
              dw_kernel_size=parse_ksize(options["k"]),
              exp_kernel_size=exp_kernel_size,
              pw_kernel_size=pw_kernel_size,
              out_chs=int(options["c"]),
              exp_ratio=float(options["e"]),
              se_ratio=float(options["se"])
              if "se" in options
              else None,
              stride=int(options["s"]),
              act_layer=act_layer,
              noskip=noskip,
          )
          if "cc" in options:
              block_args["num_experts"] = int(options["cc"])
      elif block_type == "ds" or block_type == "dsa":
          block_args = dict(
              block_type=block_type,
              dw_kernel_size=parse_ksize(options["k"]),
              pw_kernel_size=pw_kernel_size,
              out_chs=int(options["c"]),
              se_ratio=float(options["se"])
              if "se" in options
              else None,
              stride=int(options["s"]),
              act_layer=act_layer,
              pw_act=block_type == "dsa",
              noskip=block_type == "dsa" or noskip,
          )
      elif block_type == "cn":
          block_args = dict(
              block_type=block_type,
              kernel_size=int(options["k"]),
              out_chs=int(options["c"]),
              stride=int(options["s"]),
              act_layer=act_layer,
          )
      else:
          assert False, "Unknown block type (%s)" % block_type
  
      return block_args, num_repeat
  
file_path: nni/examples/nas/legacy/cream/lib/utils/builder_util.py
imports: import re
  import math
  import torch.nn
  from copy import deepcopy
  from timm.utils import *
  from timm.models.layers.activations import Swish
  from timm.models.layers import CondConv2d, get_condconv_initializer
label_desc: Use image node_id 4 for calling a global function with example usage: decode_block_str(block_str) and returns: block_args,  num_repeat