code: def run_rest_test(model, register_model=True, unregister_model=True):
      model_name = model["name"]
      model_inputs = model["inputs"]
      model_handler = model["handler"]
  
      if register_model:
          response = ts.register_model(model_name)
          if response and response.status_code == 200:
              print(
                  f"## Successfully registered {model_name} model with torchserve"
              )
          else:
              print(
                  f"## Failed to register {model_name} model with torchserve"
              )
              sys.exit(1)
  
      # For each input execute inference n=4 times
      for input in model_inputs:
          for i in range(4):
              response = ts.run_inference(model_name, input)
              if response and response.status_code == 200:
                  print(
                      f"## Successfully ran inference on {model_name} model."
                  )
              else:
                  print(
                      f"## Failed to run inference on {model_name} model"
                  )
                  sys.exit(1)
  
      if torch.cuda.is_available():
          if validate_model_on_gpu():
              print(f"## Model {model_name} successfully loaded on GPU")
          else:
              sys.exit(
                  f"## Something went wrong, model {model_name} did not load on GPU!!"
              )
  
      # skip unregistering resnet-18 model to test snapshot feature with restart
      if unregister_model:
          response = ts.unregister_model(model_name)
          if response and response.status_code == 200:
              print(f"## Successfully unregistered {model_name}")
          else:
              print(f"## Failed to unregister {model_name}")
              sys.exit(1)
  
      print(f"## {model_handler} handler is stable.")
  
file_path: serve/ts_scripts/sanity_utils.py
imports: import glob
  import json
  import os
  import subprocess
  import sys
  from pathlib import Path
  import torch
  from ts_scripts import marsgen
  from ts_scripts import tsutils
  from ts_scripts import utils
  from ts_scripts.tsutils import generate_grpc_client_stubs
label_desc: Use image node_id 6 for calling a global function with example usage: run_rest_test(model, register_model, unregister_model) without return types