code: def run_docker(
      inf_port, base_model, low_mem_mode=False, do_shared=True
  ):
      datetime_str = (
          str(datetime.now()).replace(" ", "_").replace(":", "_")
      )
      msg = "Starting HF inference %s..." % datetime_str
      print(msg, flush=True)
      home_dir = os.path.expanduser("~")
      makedirs(os.path.join(home_dir, ".cache/huggingface/hub"))
      data_dir = "%s/.cache/huggingface/hub/" % home_dir
      n_gpus = get_ngpus_vis()
      cmd = (
          ["docker"]
          + [
              "run",
              "-d",
              "--runtime",
              "nvidia",
          ]
          + gpus_cmd()
          + [
              "--shm-size",
              "1g",
              "-e",
              "HUGGING_FACE_HUB_TOKEN=%s"
              % os.environ["HUGGING_FACE_HUB_TOKEN"],
              "-p",
              "%s:80" % inf_port,
              "-v",
              "%s/.cache/huggingface/hub/:/data" % home_dir,
              "-v",
              "%s:/data" % data_dir,
              "ghcr.io/huggingface/text-generation-inference:0.9.3",
              "--model-id",
              base_model,
              "--max-stop-sequences",
              "6",
              "--sharded",
              "false" if n_gpus == 1 or not do_shared else "true",
          ]
      )
      if n_gpus > 1 and do_shared:
          cmd.extend(["--num-shard", "%s" % n_gpus])
      if low_mem_mode:
          cmd.extend(
              [
                  "--max-input-length",
                  "1024",
                  "--max-total-tokens",
                  "2048",
                  # '--cuda-memory-fraction', '0.3',  # for 0.9.4, but too memory hungry
              ]
          )
      else:
          cmd.extend(
              [
                  "--max-input-length",
                  "4096",
                  "--max-total-tokens",
                  "8192",
                  # '--cuda-memory-fraction', '0.8',  # for 0.9.4, but too memory hungry
              ]
          )
  
      print(cmd, flush=True)
      docker_hash = subprocess.check_output(cmd).decode().strip()
      import time
  
      connected = False
      while not connected:
          cmd = "docker logs %s" % docker_hash
          o = subprocess.check_output(cmd, shell=True, timeout=15)
          connected = "Connected" in o.decode("utf-8")
          time.sleep(5)
      print("Done starting TGI server: %s" % docker_hash, flush=True)
      return docker_hash
  
imports: import os
  import subprocess
  import time
  from datetime import datetime
  import pytest
  from src.utils import get_ngpus_vis, makedirs
  from tests.utils import wrap_test_forked, get_inf_port, get_inf_server
  from tests.test_langchain_units import have_openai_key, have_replicate_key
  from src.client_test import run_client_many, test_client_basic_api_lean
  from src.enums import PromptType, LangChainAction
label_desc: Use image node_id 2 for calling a global function with example usage: run_docker(inf_port, base_model, low_mem_mode, do_shared) and returns: docker_hash