code: def modify_coremltools_torch_frontend_badbmm():
      """
      Modifies coremltools torch frontend for baddbmm to be robust to the `beta` argument being of non-float dtype:
      e.g. https://github.com/huggingface/diffusers/blob/v0.8.1/src/diffusers/models/attention.py#L315
      """
      from coremltools.converters.mil import register_torch_op
      from coremltools.converters.mil.mil import Builder as mb
      from coremltools.converters.mil.frontend.torch.ops import (
          _get_inputs,
      )
      from coremltools.converters.mil.frontend.torch.torch_op_registry import (
          _TORCH_OPS_REGISTRY,
      )
  
      if "baddbmm" in _TORCH_OPS_REGISTRY:
          del _TORCH_OPS_REGISTRY["baddbmm"]
  
      @register_torch_op
      def baddbmm(context, node):
          """
          baddbmm(Tensor input, Tensor batch1, Tensor batch2, Scalar beta=1, Scalar alpha=1)
          output = beta * input + alpha * batch1 * batch2
          Notice that batch1 and batch2 must be 3-D tensors each containing the same number of matrices.
          If batch1 is a (b×n×m) tensor, batch2 is a (b×m×p) tensor, then input must be broadcastable with a (b×n×p) tensor
          and out will be a (b×n×p) tensor.
          """
          assert len(node.outputs) == 1
          inputs = _get_inputs(context, node, expected=5)
          bias, batch1, batch2, beta, alpha = inputs
  
          if beta.val != 1.0:
              # Apply scaling factor beta to the bias.
              if beta.val.dtype == np.int32:
                  beta = mb.cast(x=beta, dtype="fp32")
                  logger.warning(
                      f"Casted the `beta`(value={beta.val}) argument of `baddbmm` op "
                      "from int32 to float32 dtype for conversion!"
                  )
              bias = mb.mul(x=beta, y=bias, name=bias.name + "_scaled")
  
              context.add(bias)
  
          if alpha.val != 1.0:
              # Apply scaling factor alpha to the input.
              batch1 = mb.mul(
                  x=alpha, y=batch1, name=batch1.name + "_scaled"
              )
              context.add(batch1)
  
          bmm_node = mb.matmul(
              x=batch1, y=batch2, name=node.name + "_bmm"
          )
          context.add(bmm_node)
  
          baddbmm_node = mb.add(x=bias, y=bmm_node, name=node.name)
          context.add(baddbmm_node)
  
imports: from python_coreml_stable_diffusion import unet, controlnet, chunk_mlprogram
  import argparse
  from collections import OrderedDict, defaultdict
  from copy import deepcopy
  import coremltools
  from diffusers import StableDiffusionPipeline, DiffusionPipeline, ControlNetModel
  import gc
  import logging
  import numpy
  import os
  import requests
  import shutil
  import time
  import re
  import pathlib
  import torch
  import torch.nn
  import torch.nn.functional
  from types import MethodType
  from transformers.models.clip import modeling_clip
label_desc: Use image node_id 12 for calling a global function with example usage: modify_coremltools_torch_frontend_badbmm() without return types