envs.py 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422
  1. import os
  2. import tempfile
  3. from typing import TYPE_CHECKING, Any, Callable, Dict, List, Optional
  4. if TYPE_CHECKING:
  5. APHRODITE_HOST_IP: str = ""
  6. APHRODITE_PORT: Optional[int] = None
  7. APHRODITE_RPC_BASE_PATH: str = tempfile.gettempdir()
  8. APHRODITE_USE_MODELSCOPE: bool = False
  9. APHRODITE_RINGBUFFER_WARNING_INTERVAL: int = 60
  10. APHRODITE_INSTANCE_ID: Optional[str] = None
  11. APHRODITE_NCCL_SO_PATH: Optional[str] = None
  12. LD_LIBRARY_PATH: Optional[str] = None
  13. APHRODITE_USE_TRITON_FLASH_ATTN: bool = False
  14. LOCAL_RANK: int = 0
  15. CUDA_VISIBLE_DEVICES: Optional[str] = None
  16. APHRODITE_ENGINE_ITERATION_TIMEOUT_S: int = 60
  17. APHRODITE_API_KEY: Optional[str] = None
  18. APHRODITE_ADMIN_KEY: Optional[str] = None
  19. S3_ACCESS_KEY_ID: Optional[str] = None
  20. S3_SECRET_ACCESS_KEY: Optional[str] = None
  21. S3_ENDPOINT_URL: Optional[str] = None
  22. APHRODITE_CACHE_ROOT: str = os.path.expanduser("~/.cache/aphrodite")
  23. APHRODITE_CONFIG_ROOT: str = os.path.expanduser("~/.config/aphrodite")
  24. APHRODITE_CONFIGURE_LOGGING: int = 1
  25. APHRODITE_LOGGING_LEVEL: str = "INFO"
  26. APHRODITE_LOGGING_CONFIG_PATH: Optional[str] = None
  27. APHRODITE_TRACE_FUNCTION: int = 0
  28. APHRODITE_ATTENTION_BACKEND: Optional[str] = None
  29. APHRODITE_USE_SAMPLING_KERNELS: bool = False
  30. APHRODITE_PP_LAYER_PARTITION: Optional[str] = None
  31. APHRODITE_CPU_KVCACHE_SPACE: int = 0
  32. APHRODITE_CPU_OMP_THREADS_BIND: str = ""
  33. APHRODITE_OPENVINO_KVCACHE_SPACE: int = 0
  34. APHRODITE_OPENVINO_CPU_KV_CACHE_PRECISION: Optional[str] = None
  35. APHRODITE_OPENVINO_ENABLE_QUANTIZED_WEIGHTS: bool = False
  36. APHRODITE_XLA_CACHE_PATH: str = os.path.join(APHRODITE_CACHE_ROOT, "xla_cache") # noqa: E501
  37. APHRODITE_FUSED_MOE_CHUNK_SIZE: int = 64 * 1024
  38. APHRODITE_USE_RAY_SPMD_WORKER: bool = False
  39. APHRODITE_USE_RAY_COMPILED_DAG: bool = False
  40. APHRODITE_USE_RAY_COMPILED_DAG_NCCL_CHANNEL: bool = True
  41. APHRODITE_WORKER_MULTIPROC_METHOD: str = "fork"
  42. APHRODITE_ASSETS_CACHE: str = os.path.join(APHRODITE_CACHE_ROOT, "assets")
  43. APHRODITE_IMAGE_FETCH_TIMEOUT: int = 5
  44. APHRODITE_AUDIO_FETCH_TIMEOUT: int = 5
  45. APHRODITE_TARGET_DEVICE: str = "cuda"
  46. MAX_JOBS: Optional[str] = None
  47. NVCC_THREADS: Optional[str] = None
  48. APHRODITE_USE_PRECOMPILED: bool = False
  49. APHRODITE_NO_DEPRECATION_WARNING: bool = False
  50. APHRODITE_KEEP_ALIVE_ON_ENGINE_DEATH: bool = False
  51. CMAKE_BUILD_TYPE: Optional[str] = None
  52. VERBOSE: bool = False
  53. APHRODITE_DYNAMIC_ROPE_SCALING: bool = False
  54. APHRODITE_TEST_FORCE_FP8_MARLIN: bool = False
  55. APHRODITE_PLUGINS: Optional[List[str]] = None
  56. APHRODITE_RPC_TIMEOUT: int = 5000
  57. APHRODITE_FORCE_SINGLE_USER_PREFIX_CACHE: bool = False
  58. APHRODITE_TEST_DYNAMO_GRAPH_CAPTURE: int = 0
  59. APHRODITE_TEST_DYNAMO_FULLGRAPH_CAPTURE: int = 0
  60. APHRODITE_USE_TRITON_AWQ: bool = False
  61. APHRODITE_DYNAMO_USE_CUSTOM_DISPATCHER: bool = False
  62. APHRODITE_USE_TRITON_BACKEND: bool = False
  63. def get_default_cache_root():
  64. return os.getenv(
  65. "XDG_CACHE_HOME",
  66. os.path.join(os.path.expanduser("~"), ".cache"),
  67. )
  68. def get_default_config_root():
  69. return os.getenv(
  70. "XDG_CONFIG_HOME",
  71. os.path.join(os.path.expanduser("~"), ".config"),
  72. )
  73. # The begin-* and end* here are used by the documentation generator
  74. # to extract the used env vars.
  75. # begin-env-vars-definition
  76. environment_variables: Dict[str, Callable[[], Any]] = {
  77. # ================== Installation Time Env Vars ==================
  78. # Target device of Aphrodite, supporting [cuda (by default),
  79. # rocm, neuron, cpu, openvino]
  80. "APHRODITE_TARGET_DEVICE":
  81. lambda: os.getenv("APHRODITE_TARGET_DEVICE", "cuda"),
  82. # Maximum number of compilation jobs to run in parallel.
  83. # By default this is the number of CPUs
  84. "MAX_JOBS":
  85. lambda: os.getenv("MAX_JOBS", None),
  86. # Number of threads to use for nvcc
  87. # By default this is 1.
  88. # If set, `MAX_JOBS` will be reduced to avoid oversubscribing the CPU.
  89. "NVCC_THREADS":
  90. lambda: os.getenv("NVCC_THREADS", None),
  91. # If set, Aphrodite will use precompiled binaries (*.so)
  92. "APHRODITE_USE_PRECOMPILED":
  93. lambda: bool(os.environ.get("APHRODITE_USE_PRECOMPILED")),
  94. # CMake build type
  95. # If not set, defaults to "Debug" or "RelWithDebInfo"
  96. # Available options: "Debug", "Release", "RelWithDebInfo"
  97. "CMAKE_BUILD_TYPE":
  98. lambda: os.getenv("CMAKE_BUILD_TYPE"),
  99. # If set, Aphrodite will print verbose logs during installation
  100. "VERBOSE":
  101. lambda: bool(int(os.getenv('VERBOSE', '0'))),
  102. # Root directory for APHRODITE configuration files
  103. # Defaults to `~/.config/aphrodite` unless `XDG_CONFIG_HOME` is set
  104. # Note that this not only affects how aphrodite finds its configuration
  105. # files during runtime, but also affects how aphrodite installs its
  106. # configuration files during **installation**.
  107. "APHRODITE_CONFIG_ROOT":
  108. lambda: os.path.expanduser(
  109. os.getenv(
  110. "APHRODITE_CONFIG_ROOT",
  111. os.path.join(get_default_config_root(), "aphrodite"),
  112. )),
  113. # ================== Runtime Env Vars ==================
  114. # Root directory for APHRODITE cache files
  115. # Defaults to `~/.cache/aphrodite` unless `XDG_CACHE_HOME` is set
  116. "APHRODITE_CACHE_ROOT":
  117. lambda: os.path.expanduser(
  118. os.getenv(
  119. "APHRODITE_CACHE_ROOT",
  120. os.path.join(get_default_cache_root(), "aphrodite"),
  121. )),
  122. # used in distributed environment to determine the ip address
  123. # of the current node, when the node has multiple network interfaces.
  124. # If you are using multi-node inference, you should set this differently
  125. # on each node.
  126. 'APHRODITE_HOST_IP':
  127. lambda: os.getenv('APHRODITE_HOST_IP', "") or os.getenv("HOST_IP", ""),
  128. # used in distributed environment to manually set the communication port
  129. # Note: if APHRODITE_PORT is set, and some code asks for multiple ports, the
  130. # APHRODITE_PORT will be used as the first port, and the rest will be
  131. # generated by incrementing the APHRODITE_PORT value.
  132. # '0' is used to make mypy happy
  133. 'APHRODITE_PORT':
  134. lambda: int(os.getenv('APHRODITE_PORT', '0'))
  135. if 'APHRODITE_PORT' in os.environ else None,
  136. # path used for ipc when the frontend api server is running in
  137. # multi-processing mode to communicate with the backend engine process.
  138. 'APHRODITE_RPC_BASE_PATH':
  139. lambda: os.getenv('APHRODITE_RPC_BASE_PATH', tempfile.gettempdir()),
  140. # If true, will load models from ModelScope instead of Hugging Face Hub.
  141. # note that the value is true or false, not numbers
  142. "APHRODITE_USE_MODELSCOPE":
  143. lambda: os.environ.get(
  144. "APHRODITE_USE_MODELSCOPE", "False").lower() == "true",
  145. # Instance id represents an instance of the APHRODITE. All processes in the
  146. # same instance should have the same instance id.
  147. "APHRODITE_INSTANCE_ID":
  148. lambda: os.environ.get("APHRODITE_INSTANCE_ID", None),
  149. # Interval in seconds to log a warning message when the ring buffer is full
  150. "APHRODITE_RINGBUFFER_WARNING_INTERVAL":
  151. lambda: int(os.environ.get("APHRODITE_RINGBUFFER_WARNING_INTERVAL", "60")),
  152. # path to cudatoolkit home directory, under which should be bin, include,
  153. # and lib directories.
  154. "CUDA_HOME":
  155. lambda: os.environ.get("CUDA_HOME", None),
  156. # Path to the NCCL library file. It is needed because nccl>=2.19 brought
  157. # by PyTorch contains a bug: https://github.com/NVIDIA/nccl/issues/1234
  158. "APHRODITE_NCCL_SO_PATH":
  159. lambda: os.environ.get("APHRODITE_NCCL_SO_PATH", None),
  160. # when `APHRODITE_NCCL_SO_PATH` is not set, aphrodite will try to find the
  161. # nccl library file in the locations specified by `LD_LIBRARY_PATH`
  162. "LD_LIBRARY_PATH":
  163. lambda: os.environ.get("LD_LIBRARY_PATH", None),
  164. # flag to control if aphrodite should use triton flash attention
  165. "APHRODITE_USE_TRITON_FLASH_ATTN":
  166. lambda: (os.environ.get(
  167. "APHRODITE_USE_TRITON_FLASH_ATTN", "True").lower() in ("true", "1")),
  168. # Internal flag to enable Dynamo graph capture
  169. "APHRODITE_TEST_DYNAMO_GRAPH_CAPTURE":
  170. lambda: int(os.environ.get("APHRODITE_TEST_DYNAMO_GRAPH_CAPTURE", "0")),
  171. "APHRODITE_DYNAMO_USE_CUSTOM_DISPATCHER":
  172. lambda:
  173. (os.environ.get("APHRODITE_DYNAMO_USE_CUSTOM_DISPATCHER", "True").lower() in
  174. ("true", "1")),
  175. # Internal flag to enable Dynamo fullgraph capture
  176. "APHRODITE_TEST_DYNAMO_FULLGRAPH_CAPTURE":
  177. lambda: bool(
  178. os.environ.get("APHRODITE_TEST_DYNAMO_FULLGRAPH_CAPTURE", "1") != "0"),
  179. # local rank of the process in the distributed setting, used to determine
  180. # the GPU device id
  181. "LOCAL_RANK":
  182. lambda: int(os.environ.get("LOCAL_RANK", "0")),
  183. # used to control the visible devices in the distributed setting
  184. "CUDA_VISIBLE_DEVICES":
  185. lambda: os.environ.get("CUDA_VISIBLE_DEVICES", None),
  186. # timeout for each iteration in the engine
  187. "APHRODITE_ENGINE_ITERATION_TIMEOUT_S":
  188. lambda: int(os.environ.get("APHRODITE_ENGINE_ITERATION_TIMEOUT_S", "60")),
  189. # API key for APHRODITE API server
  190. "APHRODITE_API_KEY":
  191. lambda: os.environ.get("APHRODITE_API_KEY", None),
  192. # Admin API key for APHRODITE API server
  193. "APHRODITE_ADMIN_KEY":
  194. lambda: os.environ.get("APHRODITE_ADMIN_KEY", None),
  195. # S3 access information, used for tensorizer to load model from S3
  196. "S3_ACCESS_KEY_ID":
  197. lambda: os.environ.get("S3_ACCESS_KEY_ID", None),
  198. "S3_SECRET_ACCESS_KEY":
  199. lambda: os.environ.get("S3_SECRET_ACCESS_KEY", None),
  200. "S3_ENDPOINT_URL":
  201. lambda: os.environ.get("S3_ENDPOINT_URL", None),
  202. # Logging configuration
  203. # If set to 0, aphrodite will not configure logging
  204. # If set to 1, aphrodite will configure logging using the default
  205. # configuration or the configuration file specified by
  206. # APHRODITE_LOGGING_CONFIG_PATH
  207. "APHRODITE_CONFIGURE_LOGGING":
  208. lambda: int(os.getenv("APHRODITE_CONFIGURE_LOGGING", "1")),
  209. "APHRODITE_LOGGING_CONFIG_PATH":
  210. lambda: os.getenv("APHRODITE_LOGGING_CONFIG_PATH"),
  211. # this is used for configuring the default logging level
  212. "APHRODITE_LOGGING_LEVEL":
  213. lambda: os.getenv("APHRODITE_LOGGING_LEVEL", "INFO"),
  214. # Trace function calls
  215. # If set to 1, aphrodite will trace function calls
  216. # Useful for debugging
  217. "APHRODITE_TRACE_FUNCTION":
  218. lambda: int(os.getenv("APHRODITE_TRACE_FUNCTION", "0")),
  219. # Backend for attention computation
  220. # Available options:
  221. # - "TORCH_SDPA": use torch.nn.MultiheadAttention
  222. # - "FLASH_ATTN": use FlashAttention
  223. # - "XFORMERS": use XFormers
  224. # - "ROCM_FLASH": use ROCmFlashAttention
  225. # - "FLASHINFER": use flashinfer
  226. "APHRODITE_ATTENTION_BACKEND":
  227. lambda: os.getenv("APHRODITE_ATTENTION_BACKEND", None),
  228. # If set, aphrodite will use custom sampling kernels
  229. "APHRODITE_USE_SAMPLING_KERNELS":
  230. lambda: bool(int(os.getenv("APHRODITE_USE_SAMPLING_KERNELS", "0"))),
  231. # Pipeline stage partition strategy
  232. "APHRODITE_PP_LAYER_PARTITION":
  233. lambda: os.getenv("APHRODITE_PP_LAYER_PARTITION", None),
  234. # (CPU backend only) CPU key-value cache space.
  235. # default is 4GB
  236. "APHRODITE_CPU_KVCACHE_SPACE":
  237. lambda: int(os.getenv("APHRODITE_CPU_KVCACHE_SPACE", "0")),
  238. # (CPU backend only) CPU core ids bound by OpenMP threads, e.g., "0-31",
  239. # "0,1,2", "0-31,33". CPU cores of different ranks are separated by '|'.
  240. "APHRODITE_CPU_OMP_THREADS_BIND":
  241. lambda: os.getenv("APHRODITE_CPU_OMP_THREADS_BIND", "all"),
  242. # OpenVINO key-value cache space
  243. # default is 4GB
  244. "APHRODITE_OPENVINO_KVCACHE_SPACE":
  245. lambda: int(os.getenv("APHRODITE_OPENVINO_KVCACHE_SPACE", "0")),
  246. # OpenVINO KV cache precision
  247. # default is bf16 if natively supported by platform, otherwise f16
  248. # To enable KV cache compression, please, explicitly specify u8
  249. "APHRODITE_OPENVINO_CPU_KV_CACHE_PRECISION":
  250. lambda: os.getenv("APHRODITE_OPENVINO_CPU_KV_CACHE_PRECISION", None),
  251. # Enables weights compression during model export via HF Optimum
  252. # default is False
  253. "APHRODITE_OPENVINO_ENABLE_QUANTIZED_WEIGHTS":
  254. lambda: bool(os.getenv(
  255. "APHRODITE_OPENVINO_ENABLE_QUANTIZED_WEIGHTS", False)),
  256. # If the env var is set, then all workers will execute as separate
  257. # processes from the engine, and we use the same mechanism to trigger
  258. # execution on all workers.
  259. # Run aphrodite with APHRODITE_USE_RAY_SPMD_WORKER=1 to enable it.
  260. "APHRODITE_USE_RAY_SPMD_WORKER":
  261. lambda: bool(int(os.getenv("APHRODITE_USE_RAY_SPMD_WORKER", "0"))),
  262. # If the env var is set, it uses the Ray's compiled DAG API
  263. # which optimizes the control plane overhead.
  264. # Run aphrodite with APHRODITE_USE_RAY_COMPILED_DAG=1 to enable it.
  265. "APHRODITE_USE_RAY_COMPILED_DAG":
  266. lambda: bool(int(os.getenv("APHRODITE_USE_RAY_COMPILED_DAG", "0"))),
  267. # If the env var is set, it uses NCCL for communication in
  268. # Ray's compiled DAG. This flag is ignored if
  269. # APHRODITE_USE_RAY_COMPILED_DAG is not set.
  270. "APHRODITE_USE_RAY_COMPILED_DAG_NCCL_CHANNEL":
  271. lambda: bool(int(
  272. os.getenv("APHRODITE_USE_RAY_COMPILED_DAG_NCCL_CHANNEL", "1"))),
  273. # Use dedicated multiprocess context for workers.
  274. # Both spawn and fork work
  275. "APHRODITE_WORKER_MULTIPROC_METHOD":
  276. lambda: os.getenv("APHRODITE_WORKER_MULTIPROC_METHOD", "fork"),
  277. # Path to the cache for storing downloaded assets
  278. "APHRODITE_ASSETS_CACHE":
  279. lambda: os.path.expanduser(
  280. os.getenv(
  281. "APHRODITE_ASSETS_CACHE",
  282. os.path.join(get_default_cache_root(), "aphrodite", "assets"),
  283. )),
  284. # Timeout for fetching images when serving multimodal models
  285. # Default is 5 seconds
  286. "APHRODITE_IMAGE_FETCH_TIMEOUT":
  287. lambda: int(os.getenv("APHRODITE_IMAGE_FETCH_TIMEOUT", "5")),
  288. # Timeout for fetching audio when serving multimodal models
  289. # Default is 5 seconds
  290. "APHRODITE_AUDIO_FETCH_TIMEOUT":
  291. lambda: int(os.getenv("APHRODITE_AUDIO_FETCH_TIMEOUT", "5")),
  292. # Path to the XLA persistent cache directory.
  293. # Only used for XLA devices such as TPUs.
  294. "APHRODITE_XLA_CACHE_PATH":
  295. lambda: os.path.expanduser(
  296. os.getenv(
  297. "APHRODITE_XLA_CACHE_PATH",
  298. os.path.join(get_default_cache_root(), "aphrodite", "xla_cache"),
  299. )),
  300. "APHRODITE_FUSED_MOE_CHUNK_SIZE":
  301. lambda: int(os.getenv("APHRODITE_FUSED_MOE_CHUNK_SIZE", "65536")),
  302. # If set, aphrodite will skip the deprecation warnings.
  303. "APHRODITE_NO_DEPRECATION_WARNING":
  304. lambda: bool(int(os.getenv("APHRODITE_NO_DEPRECATION_WARNING", "0"))),
  305. # If set, the OpenAI API server will stay alive even after the underlying
  306. # AsyncLLMEngine errors and stops serving requests
  307. "APHRODITE_KEEP_ALIVE_ON_ENGINE_DEATH":
  308. lambda: bool(os.getenv("APHRODITE_KEEP_ALIVE_ON_ENGINE_DEATH", 0)),
  309. # If the env var APHRODITE_DYNAMIC_ROPE_SCALING is set, it allows
  310. # the user to specify a max sequence length greater than
  311. # the max length derived from the model's config.json.
  312. # To enable this, set APHRODITE_DYNAMIC_ROPE_SCALING=1.
  313. "APHRODITE_DYNAMIC_ROPE_SCALING":
  314. lambda:
  315. (os.environ.get(
  316. "APHRODITE_DYNAMIC_ROPE_SCALING",
  317. "0").strip().lower() in ("1", "true")),
  318. # If set, forces FP8 Marlin to be used for FP8 quantization regardless
  319. # of the hardware support for FP8 compute.
  320. "APHRODITE_TEST_FORCE_FP8_MARLIN":
  321. lambda:
  322. (os.environ.get("APHRODITE_TEST_FORCE_FP8_MARLIN", "0").strip().lower() in
  323. ("1", "true")),
  324. # Time in ms for the zmq client to wait for a response from the backend
  325. # server for simple data operations
  326. "APHRODITE_RPC_TIMEOUT":
  327. lambda: int(os.getenv("APHRODITE_RPC_TIMEOUT", "5000")),
  328. # a list of plugin names to load, separated by commas.
  329. # if this is not set, it means all plugins will be loaded
  330. # if this is set to an empty string, no plugins will be loaded
  331. "APHRODITE_PLUGINS":
  332. lambda: None if "APHRODITE_PLUGINS" not in os.environ else os.environ[
  333. "APHRODITE_PLUGINS"].split(","),
  334. # If set, forces prefix cache in single user mode
  335. "APHRODITE_FORCE_SINGLE_USER_PREFIX_CACHE":
  336. lambda: bool(int(os.getenv("APHRODITE_FORCE_SINGLE_USER_PREFIX_CACHE",
  337. "0"))),
  338. # If set, Aphrodite will use Triton implementations of AWQ.
  339. "APHRODITE_USE_TRITON_AWQ":
  340. lambda: bool(int(os.getenv("APHRODITE_USE_TRITON_AWQ", "0"))),
  341. # If set, Aphrodite will use Triton implementations of layernorm.
  342. "APHRODITE_USE_TRITON_BACKEND":
  343. lambda: bool(int(os.getenv("APHRODITE_USE_TRITON_BACKEND", "0"))),
  344. }
  345. # end-env-vars-definition
  346. def __getattr__(name: str):
  347. # lazy evaluation of environment variables
  348. if name in environment_variables:
  349. return environment_variables[name]()
  350. raise AttributeError(f"module {__name__!r} has no attribute {name!r}")
  351. def __dir__():
  352. return list(environment_variables.keys())