code: def serve(
      model_id: str,
      revision: Optional[str] = None,
      sharded: bool = False,
      quantize: Optional[Quantization] = None,
      speculate: Optional[int] = None,
      dtype: Optional[Dtype] = None,
      trust_remote_code: bool = False,
      uds_path: Path = "/tmp/text-generation-server",
      logger_level: str = "INFO",
      json_output: bool = False,
      otlp_endpoint: Optional[str] = None,
  ):
      if sharded:
          assert (
              os.getenv("RANK", None) is not None
          ), "RANK must be set when sharded is True"
          assert (
              os.getenv("WORLD_SIZE", None) is not None
          ), "WORLD_SIZE must be set when sharded is True"
          assert (
              os.getenv("MASTER_ADDR", None) is not None
          ), "MASTER_ADDR must be set when sharded is True"
          assert (
              os.getenv("MASTER_PORT", None) is not None
          ), "MASTER_PORT must be set when sharded is True"
  
      # Remove default handler
      logger.remove()
      logger.add(
          sys.stdout,
          format="{message}",
          filter="text_generation_server",
          level=logger_level,
          serialize=json_output,
          backtrace=True,
          diagnose=False,
      )
  
      # Import here after the logger is added to log potential import exceptions
      from text_generation_server import server
      from text_generation_server.tracing import setup_tracing
  
      # Setup OpenTelemetry distributed tracing
      if otlp_endpoint is not None:
          setup_tracing(
              shard=os.getenv("RANK", 0), otlp_endpoint=otlp_endpoint
          )
  
      # Downgrade enum into str for easier management later on
      quantize = None if quantize is None else quantize.value
      dtype = None if dtype is None else dtype.value
      if dtype is not None and quantize not in {
          None,
          "bitsandbytes",
          "bitsandbytes-nf4",
          "bitsandbytes-fp4",
      }:
          raise RuntimeError(
              "Only 1 can be set between `dtype` and `quantize`, as they both decide how goes the final model."
          )
      server.serve(
          model_id,
          revision,
          sharded,
          quantize,
          speculate,
          dtype,
          trust_remote_code,
          uds_path,
      )
  
file_path: text-generation-inference/server/text_generation_server/cli.py
imports: import os
  import sys
  import typer
  from pathlib import Path
  from loguru import logger
  from typing import Optional
  from enum import Enum
  from huggingface_hub import hf_hub_download
label_desc: Use image node_id 1 for calling a global function with example usage: serve(model_id, revision, sharded, quantize, speculate, dtype, trust_remote_code, uds_path, logger_level, json_output, otlp_endpoint) without return types