code: def export_model(model, target: str, *inputs):
      assert (
          Device.DEFAULT in EXPORT_SUPPORTED_DEVICE
      ), "only WEBGPU, WEBGL, CLANG, CUDA, GPU, METAL are supported"
      run, special_names = jit_model(model, *inputs)
      functions, statements, bufs, bufs_to_save = compile_net(
          run, special_names
      )
      state = get_state_dict(model)
      weight_names = {
          id(x.lazydata.base.realized): name
          for name, x in state.items()
      }
      input_names = [
          name for _, name in special_names.items() if "input" in name
      ]
      output_names = [
          name for _, name in special_names.items() if "output" in name
      ]
      prg = ""
      if target == "clang":
          prg = export_model_clang(
              functions,
              statements,
              bufs,
              bufs_to_save,
              input_names,
              output_names,
          )
      elif target == "webgpu":
          prg = export_model_webgpu(
              functions,
              statements,
              bufs,
              bufs_to_save,
              weight_names,
              input_names,
              output_names,
          )
      elif target == "webgl":
          prg = export_model_webgl(
              functions,
              statements,
              bufs,
              bufs_to_save,
              weight_names,
              input_names,
              output_names,
          )
      else:
          prg = json.dumps(
              {
                  "backend": Device.DEFAULT,
                  "inputs": [
                      {
                          "size": bufs[name][0],
                          "dtype": bufs[name][1].name,
                      }
                      for name in input_names
                  ],
                  "outputs": [
                      {
                          "size": bufs[name][0],
                          "dtype": bufs[name][1].name,
                      }
                      for name in output_names
                  ],
                  "functions": functions,
                  "statements": [
                      {
                          "kernel": kernel,
                          "args": args,
                          "global_size": global_size,
                          "local_size": local_size,
                      }
                      for (
                          kernel,
                          args,
                          global_size,
                          local_size,
                      ) in statements
                  ],
                  "buffers": {
                      name: {
                          "size": size,
                          "dtype": dtype.name,
                          "id": weight_names[_key]
                          if _key in weight_names
                          else "",
                      }
                      for name, (size, dtype, _key) in bufs.items()
                      if name not in ["input", "outputs"]
                  },
              }
          )
  
      return (
          prg,
          {input: bufs[input][0] for input in input_names},
          {output: bufs[output][0] for output in output_names},
          state,
      )
  
file_path: tinygrad/extra/export_model.py
imports: from typing import Tuple, Dict, List
  from tinygrad.dtype import DType
  from tinygrad.tensor import Device, Tensor
  from tinygrad.jit import TinyJit
  from tinygrad.nn.state import get_state_dict
  from tinygrad.dtype import dtypes
  import json
label_desc: Use image node_id 6 for calling a global function with example usage: export_model(model, target) and returns: prg,  unknown,  unknown,  state