code: def handle_metadata(cfg, hp):
      import convert
  
      assert (
          cfg.model_metadata_dir.is_dir()
      ), "Metadata dir is not a directory"
      hf_config_path = cfg.model_metadata_dir / "config.json"
      orig_config_path = cfg.model_metadata_dir / "params.json"
      # We pass a fake model here. "original" mode will check the shapes of some
      # tensors if information is missing in the .json file: other than that, the
      # model data isn't used so this should be safe (at least for now).
      fakemodel = {
          "tok_embeddings.weight": convert.LazyTensor.__new__(
              convert.LazyTensor
          ),
          "layers.0.feed_forward.w1.weight": convert.LazyTensor.__new__(
              convert.LazyTensor
          ),
      }
      fakemodel["tok_embeddings.weight"].shape = [hp.n_vocab]
      fakemodel["layers.0.feed_forward.w1.weight"].shape = [hp.n_ff]
      if hf_config_path.exists():
          params = convert.Params.loadHFTransformerJson(
              fakemodel, hf_config_path
          )
      elif orig_config_path.exists():
          params = convert.Params.loadOriginalParamsJson(
              fakemodel, orig_config_path
          )
      else:
          raise ValueError("Unable to load metadata")
      vocab = convert.load_vocab(
          cfg.vocab_dir
          if cfg.vocab_dir is not None
          else cfg.model_metadata_dir,
          cfg.vocabtype,
      )
      # FIXME: Respect cfg.vocab_dir?
      svocab = gguf.SpecialVocab(
          cfg.model_metadata_dir,
          load_merges=cfg.vocabtype == "bpe",
          n_vocab=vocab.vocab_size,
      )
      convert.check_vocab_size(params, vocab)
      return (params, vocab, svocab)
  
imports: from __future__ import annotations
  import argparse
  import struct
  import sys
  from enum import IntEnum
  from pathlib import Path
  import numpy
  import os
  import gguf
label_desc: Use image node_id 1 for calling a global function with example usage: handle_metadata(cfg, hp) and returns: params,  vocab,  svocab