types.rs 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146
  1. use serde::Deserialize;
  2. use std::collections::HashMap;
  3. pub use crate::pre_serve::{
  4. BeforeServeTable, DistributedBackend, ModsTable, OnFailure, PreServeCommand, RecipeArgs,
  5. };
  6. #[derive(Clone, Debug, Deserialize)]
  7. pub struct Node {
  8. pub name: String,
  9. pub ssh_ip: String,
  10. pub ib_ip: String,
  11. pub rank: u32,
  12. #[serde(default)]
  13. pub host_key: Option<String>,
  14. #[serde(default)]
  15. pub entity: Option<String>,
  16. }
  17. #[derive(Clone, Debug, Deserialize)]
  18. pub struct NcclConfig {
  19. pub ib_hca: String,
  20. pub socket_ifname: String,
  21. pub ib_gid_index: u32,
  22. pub ib_disable: u32,
  23. #[serde(default)]
  24. pub gloo_socket_ifname: Option<String>,
  25. #[serde(default)]
  26. pub ucx_net_devices: Option<String>,
  27. #[serde(default)]
  28. pub nccl_cross_nic: Option<u32>,
  29. #[serde(default)]
  30. pub nccl_proto: Option<String>,
  31. #[serde(default)]
  32. pub nccl_p2p_level: Option<String>,
  33. }
  34. #[derive(Clone, Debug, Deserialize)]
  35. pub struct Cluster {
  36. pub name: String,
  37. pub master_ib_ip: String,
  38. pub nodes: Vec<Node>,
  39. #[serde(default)]
  40. pub extra_entities: Vec<String>,
  41. }
  42. #[derive(Clone, Deserialize)]
  43. pub struct Config {
  44. pub ssh_user: String,
  45. pub ssh_key_path: std::path::PathBuf,
  46. pub clusters: Vec<Cluster>,
  47. #[serde(default)]
  48. pub nccl: HashMap<String, NcclConfig>,
  49. #[serde(default)]
  50. pub hf_cache_dir: Option<String>,
  51. #[serde(default = "default_init_port")]
  52. pub init_port: u16,
  53. #[serde(default)]
  54. pub before_serve: HashMap<String, BeforeServeTable>,
  55. #[serde(default)]
  56. pub exec_aliases: HashMap<String, String>,
  57. #[serde(default)]
  58. pub home_assistant: Option<HomeAssistantConfig>,
  59. #[serde(default)]
  60. pub global_mods_dir: Option<std::path::PathBuf>,
  61. }
  62. #[derive(Clone, Deserialize)]
  63. pub struct HomeAssistantConfig {
  64. pub url: String,
  65. pub token: String,
  66. #[serde(default = "default_shutdown_delay")]
  67. pub shutdown_delay_seconds: u64,
  68. }
  69. fn default_shutdown_delay() -> u64 {
  70. 30
  71. }
  72. fn default_init_port() -> u16 {
  73. 25000
  74. }
  75. fn default_port() -> u16 {
  76. 30000
  77. }
  78. fn default_engine() -> String {
  79. "vllm".to_string()
  80. }
  81. fn default_shm_size() -> String {
  82. String::new()
  83. }
  84. fn default_tensor_parallel_size() -> u32 {
  85. 1
  86. }
  87. fn default_sync_image() -> bool {
  88. true
  89. }
  90. #[derive(Clone, Deserialize)]
  91. pub struct Recipe {
  92. #[serde(default = "default_engine")]
  93. pub engine: String,
  94. pub name: String,
  95. #[serde(default)]
  96. pub docker_image: String,
  97. #[serde(default)]
  98. pub model: String,
  99. #[serde(default = "default_port")]
  100. pub port: u16,
  101. #[serde(default)]
  102. pub required_nodes: Option<u32>,
  103. #[serde(default)]
  104. pub pipeline_parallel_size: Option<u32>,
  105. #[serde(default = "default_tensor_parallel_size")]
  106. pub tensor_parallel_size: u32,
  107. #[serde(default)]
  108. pub args: RecipeArgs,
  109. #[serde(default)]
  110. pub env: HashMap<String, String>,
  111. #[serde(default)]
  112. pub cluster: Option<String>,
  113. #[serde(default)]
  114. pub entrypoint: Vec<String>,
  115. pub distributed_backend: Option<DistributedBackend>,
  116. #[serde(default = "default_shm_size")]
  117. pub shm_size: String,
  118. #[serde(default)]
  119. pub before_serve: Vec<PreServeCommand>,
  120. #[serde(default)]
  121. pub mods: ModsTable,
  122. #[serde(default = "default_sync_image")]
  123. pub sync_image: bool,
  124. }
  125. impl Config {
  126. pub fn resolved_hf_cache_dir(&self) -> std::path::PathBuf {
  127. if let Some(ref dir) = self.hf_cache_dir {
  128. return std::path::PathBuf::from(dir);
  129. }
  130. let home = if self.ssh_user == "root" {
  131. "/root"
  132. } else {
  133. return std::path::PathBuf::from(format!("/home/{}/.cache/huggingface", self.ssh_user));
  134. };
  135. std::path::PathBuf::from(format!("{}/.cache/huggingface", home))
  136. }
  137. }