| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent ddbd10c commit fa83cc5
5 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -17,7 +17,7 @@ jobs: | |||
| 17 | 17 | python-version: ["3.8", "3.9", "3.10", "3.11"] | |
| 18 | 18 | ||
| 19 | 19 | steps: | |
| 20 | - - uses: actions/checkout@v3 | ||
| 20 | + - uses: actions/checkout@v4 | ||
| 21 | 21 | with: | |
| 22 | 22 | submodules: "true" | |
| 23 | 23 | - name: Set up Python ${{ matrix.python-version }} | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -230,8 +230,14 @@ def __init__( | |||
| 230 | 230 | n_batch: int = 512, | |
| 231 | 231 | n_threads: Optional[int] = None, | |
| 232 | 232 | n_threads_batch: Optional[int] = None, | |
| 233 | + rope_scaling_type: Optional[int] = llama_cpp.LLAMA_ROPE_SCALING_UNSPECIFIED, | ||
| 233 | 234 | rope_freq_base: float = 0.0, | |
| 234 | 235 | rope_freq_scale: float = 0.0, | |
| 236 | + yarn_ext_factor: float = float("nan"), | ||
| 237 | + yarn_attn_factor: float = 1.0, | ||
| 238 | + yarn_beta_fast: float = 32.0, | ||
| 239 | + yarn_beta_slow: float = 1.0, | ||
| 240 | + yarn_orig_ctx: int = 0, | ||
| 235 | 241 | mul_mat_q: bool = True, | |
| 236 | 242 | f16_kv: bool = True, | |
| 237 | 243 | logits_all: bool = False, | |
@@ -255,30 +261,30 @@ def __init__( | |||
| 255 | 261 | ||
| 256 | 262 | Args: | |
| 257 | 263 | model_path: Path to the model. | |
| 258 | - seed: Random seed. -1 for random. | ||
| 259 | - n_ctx: Maximum context size. | ||
| 260 | - n_batch: Maximum number of prompt tokens to batch together when calling llama_eval. | ||
| 261 | 264 | n_gpu_layers: Number of layers to offload to GPU (-ngl). If -1, all layers are offloaded. | |
| 262 | - main_gpu: Main GPU to use. | ||
| 263 | - tensor_split: Optional list of floats to split the model across multiple GPUs. If None, the model is not split. | ||
| 265 | + main_gpu: The GPU that is used for scratch and small tensors. | ||
| 266 | + tensor_split: How split tensors should be distributed across GPUs. If None, the model is not split. | ||
| 267 | + vocab_only: Only load the vocabulary no weights. | ||
| 268 | + use_mmap: Use mmap if possible. | ||
| 269 | + use_mlock: Force the system to keep the model in RAM. | ||
| 270 | + seed: Random seed. -1 for random. | ||
| 271 | + n_ctx: Context size. | ||
| 272 | + n_batch: Batch size for prompt processing (must be >= 32 to use BLAS) | ||
| 273 | + n_threads: Number of threads to use. If None, the number of threads is automatically determined. | ||
| 274 | + n_threads_batch: Number of threads to use for batch processing. If None, use n_threads. | ||
| 275 | + rope_scaling_type: Type of rope scaling to use. | ||
| 264 | 276 | rope_freq_base: Base frequency for rope sampling. | |
| 265 | 277 | rope_freq_scale: Scale factor for rope sampling. | |
| 266 | - low_vram: Use low VRAM mode. | ||
| 267 | 278 | mul_mat_q: if true, use experimental mul_mat_q kernels | |
| 268 | 279 | f16_kv: Use half-precision for key/value cache. | |
| 269 | 280 | logits_all: Return logits for all tokens, not just the last token. | |
| 270 | - vocab_only: Only load the vocabulary no weights. | ||
| 271 | - use_mmap: Use mmap if possible. | ||
| 272 | - use_mlock: Force the system to keep the model in RAM. | ||
| 273 | 281 | embedding: Embedding mode only. | |
| 274 | - n_threads: Number of threads to use. If None, the number of threads is automatically determined. | ||
| 275 | 282 | last_n_tokens_size: Maximum number of tokens to keep in the last_n_tokens deque. | |
| 276 | 283 | lora_base: Optional path to base model, useful if using a quantized base model and you want to apply LoRA to an f16 model. | |
| 277 | 284 | lora_path: Path to a LoRA file to apply to the model. | |
| 278 | 285 | numa: Enable NUMA support. (NOTE: The initial value of this parameter is used for the remainder of the program as this value is set in llama_backend_init) | |
| 279 | 286 | chat_format: String specifying the chat format to use when calling create_chat_completion. | |
| 280 | 287 | verbose: Print verbose output to stderr. | |
| 281 | - kwargs: Unused keyword arguments (for additional backwards compatibility). | ||
| 282 | 288 | ||
| 283 | 289 | Raises: | |
| 284 | 290 | ValueError: If the model path does not exist. | |
@@ -332,12 +338,30 @@ def __init__( | |||
| 332 | 338 | self.context_params.n_batch = self.n_batch | |
| 333 | 339 | self.context_params.n_threads = self.n_threads | |
| 334 | 340 | self.context_params.n_threads_batch = self.n_threads_batch | |
| 341 | + self.context_params.rope_scaling_type = ( | ||
| 342 | + rope_scaling_type if rope_scaling_type is not None else llama_cpp.LLAMA_ROPE_SCALING_UNSPECIFIED | ||
| 343 | + ) | ||
| 335 | 344 | self.context_params.rope_freq_base = ( | |
| 336 | 345 | rope_freq_base if rope_freq_base != 0.0 else 0 | |
| 337 | 346 | ) | |
| 338 | 347 | self.context_params.rope_freq_scale = ( | |
| 339 | 348 | rope_freq_scale if rope_freq_scale != 0.0 else 0 | |
| 340 | 349 | ) | |
| 350 | + self.context_params.yarn_ext_factor = ( | ||
| 351 | + yarn_ext_factor if yarn_ext_factor != 0.0 else 0 | ||
| 352 | + ) | ||
| 353 | + self.context_params.yarn_attn_factor = ( | ||
| 354 | + yarn_attn_factor if yarn_attn_factor != 0.0 else 0 | ||
| 355 | + ) | ||
| 356 | + self.context_params.yarn_beta_fast = ( | ||
| 357 | + yarn_beta_fast if yarn_beta_fast != 0.0 else 0 | ||
| 358 | + ) | ||
| 359 | + self.context_params.yarn_beta_slow = ( | ||
| 360 | + yarn_beta_slow if yarn_beta_slow != 0.0 else 0 | ||
| 361 | + ) | ||
| 362 | + self.context_params.yarn_orig_ctx = ( | ||
| 363 | + yarn_orig_ctx if yarn_orig_ctx != 0 else 0 | ||
| 364 | + ) | ||
| 341 | 365 | self.context_params.mul_mat_q = mul_mat_q | |
| 342 | 366 | self.context_params.f16_kv = f16_kv | |
| 343 | 367 | self.context_params.logits_all = logits_all | |
@@ -1671,8 +1695,14 @@ def __getstate__(self): | |||
| 1671 | 1695 | n_batch=self.n_batch, | |
| 1672 | 1696 | n_threads=self.context_params.n_threads, | |
| 1673 | 1697 | n_threads_batch=self.context_params.n_threads_batch, | |
| 1698 | + rope_scaling_type=self.context_params.rope_scaling_type, | ||
| 1674 | 1699 | rope_freq_base=self.context_params.rope_freq_base, | |
| 1675 | 1700 | rope_freq_scale=self.context_params.rope_freq_scale, | |
| 1701 | + yarn_ext_factor=self.context_params.yarn_ext_factor, | ||
| 1702 | + yarn_attn_factor=self.context_params.yarn_attn_factor, | ||
| 1703 | + yarn_beta_fast=self.context_params.yarn_beta_fast, | ||
| 1704 | + yarn_beta_slow=self.context_params.yarn_beta_slow, | ||
| 1705 | + yarn_orig_ctx=self.context_params.yarn_orig_ctx, | ||
| 1676 | 1706 | mul_mat_q=self.context_params.mul_mat_q, | |
| 1677 | 1707 | f16_kv=self.context_params.f16_kv, | |
| 1678 | 1708 | logits_all=self.context_params.logits_all, | |
@@ -1709,6 +1739,12 @@ def __setstate__(self, state): | |||
| 1709 | 1739 | n_threads_batch=state["n_threads_batch"], | |
| 1710 | 1740 | rope_freq_base=state["rope_freq_base"], | |
| 1711 | 1741 | rope_freq_scale=state["rope_freq_scale"], | |
| 1742 | + rope_scaling_type=state["rope_scaling_type"], | ||
| 1743 | + yarn_ext_factor=state["yarn_ext_factor"], | ||
| 1744 | + yarn_attn_factor=state["yarn_attn_factor"], | ||
| 1745 | + yarn_beta_fast=state["yarn_beta_fast"], | ||
| 1746 | + yarn_beta_slow=state["yarn_beta_slow"], | ||
| 1747 | + yarn_orig_ctx=state["yarn_orig_ctx"], | ||
| 1712 | 1748 | mul_mat_q=state["mul_mat_q"], | |
| 1713 | 1749 | f16_kv=state["f16_kv"], | |
| 1714 | 1750 | logits_all=state["logits_all"], | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -192,6 +192,18 @@ def _load_shared_library(lib_base_name: str): | |||
| 192 | 192 | LLAMA_FTYPE_MOSTLY_Q6_K = 18 | |
| 193 | 193 | LLAMA_FTYPE_GUESSED = 1024 | |
| 194 | 194 | ||
| 195 | + # enum llama_rope_scaling_type { | ||
| 196 | + # LLAMA_ROPE_SCALING_UNSPECIFIED = -1, | ||
| 197 | + # LLAMA_ROPE_SCALING_NONE = 0, | ||
| 198 | + # LLAMA_ROPE_SCALING_LINEAR = 1, | ||
| 199 | + # LLAMA_ROPE_SCALING_YARN = 2, | ||
| 200 | + # LLAMA_ROPE_SCALING_MAX_VALUE = LLAMA_ROPE_SCALING_YARN, | ||
| 201 | + # }; | ||
| 202 | + LLAMA_ROPE_SCALING_UNSPECIFIED = -1 | ||
| 203 | + LLAMA_ROPE_SCALING_NONE = 0 | ||
| 204 | + LLAMA_ROPE_SCALING_LINEAR = 1 | ||
| 205 | + LLAMA_ROPE_SCALING_YARN = 2 | ||
| 206 | + LLAMA_ROPE_SCALING_MAX_VALUE = LLAMA_ROPE_SCALING_YARN | ||
| 195 | 207 | ||
| 196 | 208 | # typedef struct llama_token_data { | |
| 197 | 209 | # llama_token id; // token id | |
@@ -308,10 +320,16 @@ class llama_model_params(Structure): | |||
| 308 | 320 | # uint32_t n_batch; // prompt processing maximum batch size | |
| 309 | 321 | # uint32_t n_threads; // number of threads to use for generation | |
| 310 | 322 | # uint32_t n_threads_batch; // number of threads to use for batch processing | |
| 323 | + # int8_t rope_scaling_type; // RoPE scaling type, from `enum llama_rope_scaling_type` | ||
| 311 | 324 | ||
| 312 | 325 | # // ref: https://github.com/ggerganov/llama.cpp/pull/2054 | |
| 313 | - # float rope_freq_base; // RoPE base frequency, 0 = from model | ||
| 314 | - # float rope_freq_scale; // RoPE frequency scaling factor, 0 = from model | ||
| 326 | + # float rope_freq_base; // RoPE base frequency, 0 = from model | ||
| 327 | + # float rope_freq_scale; // RoPE frequency scaling factor, 0 = from model | ||
| 328 | + # float yarn_ext_factor; // YaRN extrapolation mix factor, NaN = from model | ||
| 329 | + # float yarn_attn_factor; // YaRN magnitude scaling factor | ||
| 330 | + # float yarn_beta_fast; // YaRN low correction dim | ||
| 331 | + # float yarn_beta_slow; // YaRN high correction dim | ||
| 332 | + # uint32_t yarn_orig_ctx; // YaRN original context size | ||
| 315 | 333 | ||
| 316 | 334 | ||
| 317 | 335 | # // Keep the booleans together to avoid misalignment during copy-by-value. | |
@@ -327,8 +345,14 @@ class llama_context_params(Structure): | |||
| 327 | 345 | ("n_batch", c_uint32), | |
| 328 | 346 | ("n_threads", c_uint32), | |
| 329 | 347 | ("n_threads_batch", c_uint32), | |
| 348 | + ("rope_scaling_type", c_int8), | ||
| 330 | 349 | ("rope_freq_base", c_float), | |
| 331 | 350 | ("rope_freq_scale", c_float), | |
| 351 | + ("yarn_ext_factor", c_float), | ||
| 352 | + ("yarn_attn_factor", c_float), | ||
| 353 | + ("yarn_beta_fast", c_float), | ||
| 354 | + ("yarn_beta_slow", c_float), | ||
| 355 | + ("yarn_orig_ctx", c_uint32), | ||
| 332 | 356 | ("mul_mat_q", c_bool), | |
| 333 | 357 | ("f16_kv", c_bool), | |
| 334 | 358 | ("logits_all", c_bool), | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -41,11 +41,7 @@ class Settings(BaseSettings): | |||
| 41 | 41 | default=None, | |
| 42 | 42 | description="The alias of the model to use for generating completions.", | |
| 43 | 43 | ) | |
| 44 | - seed: int = Field(default=llama_cpp.LLAMA_DEFAULT_SEED, description="Random seed. -1 for random.") | ||
| 45 | - n_ctx: int = Field(default=2048, ge=1, description="The context size.") | ||
| 46 | - n_batch: int = Field( | ||
| 47 | - default=512, ge=1, description="The batch size to use per eval." | ||
| 48 | - ) | ||
| 44 | + # Model Params | ||
| 49 | 45 | n_gpu_layers: int = Field( | |
| 50 | 46 | default=0, | |
| 51 | 47 | ge=-1, | |
@@ -60,17 +56,6 @@ class Settings(BaseSettings): | |||
| 60 | 56 | default=None, | |
| 61 | 57 | description="Split layers across multiple GPUs in proportion.", | |
| 62 | 58 | ) | |
| 63 | - rope_freq_base: float = Field( | ||
| 64 | - default=0.0, description="RoPE base frequency" | ||
| 65 | - ) | ||
| 66 | - rope_freq_scale: float = Field( | ||
| 67 | - default=0.0, description="RoPE frequency scaling factor" | ||
| 68 | - ) | ||
| 69 | - mul_mat_q: bool = Field( | ||
| 70 | - default=True, description="if true, use experimental mul_mat_q kernels" | ||
| 71 | - ) | ||
| 72 | - f16_kv: bool = Field(default=True, description="Whether to use f16 key/value.") | ||
| 73 | - logits_all: bool = Field(default=True, description="Whether to return logits.") | ||
| 74 | 59 | vocab_only: bool = Field( | |
| 75 | 60 | default=False, description="Whether to only return the vocabulary." | |
| 76 | 61 | ) | |
@@ -82,17 +67,59 @@ class Settings(BaseSettings): | |||
| 82 | 67 | default=llama_cpp.llama_mlock_supported(), | |
| 83 | 68 | description="Use mlock.", | |
| 84 | 69 | ) | |
| 85 | - embedding: bool = Field(default=True, description="Whether to use embeddings.") | ||
| 70 | + # Context Params | ||
| 71 | + seed: int = Field(default=llama_cpp.LLAMA_DEFAULT_SEED, description="Random seed. -1 for random.") | ||
| 72 | + n_ctx: int = Field(default=2048, ge=1, description="The context size.") | ||
| 73 | + n_batch: int = Field( | ||
| 74 | + default=512, ge=1, description="The batch size to use per eval." | ||
| 75 | + ) | ||
| 86 | 76 | n_threads: int = Field( | |
| 87 | 77 | default=max(multiprocessing.cpu_count() // 2, 1), | |
| 88 | 78 | ge=1, | |
| 89 | 79 | description="The number of threads to use.", | |
| 90 | 80 | ) | |
| 81 | + n_threads_batch: int = Field( | ||
| 82 | + default=max(multiprocessing.cpu_count() // 2, 1), | ||
| 83 | + ge=0, | ||
| 84 | + description="The number of threads to use when batch processing.", | ||
| 85 | + ) | ||
| 86 | + rope_scaling_type: int = Field( | ||
| 87 | + default=llama_cpp.LLAMA_ROPE_SCALING_UNSPECIFIED | ||
| 88 | + ) | ||
| 89 | + rope_freq_base: float = Field( | ||
| 90 | + default=0.0, description="RoPE base frequency" | ||
| 91 | + ) | ||
| 92 | + rope_freq_scale: float = Field( | ||
| 93 | + default=0.0, description="RoPE frequency scaling factor" | ||
| 94 | + ) | ||
| 95 | + yarn_ext_factor: float = Field( | ||
| 96 | + default=float("nan") | ||
| 97 | + ) | ||
| 98 | + yarn_attn_factor: float = Field( | ||
| 99 | + default=1.0 | ||
| 100 | + ) | ||
| 101 | + yarn_beta_fast: float = Field( | ||
| 102 | + default=32.0 | ||
| 103 | + ) | ||
| 104 | + yarn_beta_slow: float = Field( | ||
| 105 | + default=1.0 | ||
| 106 | + ) | ||
| 107 | + yarn_orig_ctx: int = Field( | ||
| 108 | + default=0 | ||
| 109 | + ) | ||
| 110 | + mul_mat_q: bool = Field( | ||
| 111 | + default=True, description="if true, use experimental mul_mat_q kernels" | ||
| 112 | + ) | ||
| 113 | + f16_kv: bool = Field(default=True, description="Whether to use f16 key/value.") | ||
| 114 | + logits_all: bool = Field(default=True, description="Whether to return logits.") | ||
| 115 | + embedding: bool = Field(default=True, description="Whether to use embeddings.") | ||
| 116 | + # Sampling Params | ||
| 91 | 117 | last_n_tokens_size: int = Field( | |
| 92 | 118 | default=64, | |
| 93 | 119 | ge=0, | |
| 94 | 120 | description="Last n tokens to keep for repeat penalty calculation.", | |
| 95 | 121 | ) | |
| 122 | + # LoRA Params | ||
| 96 | 123 | lora_base: Optional[str] = Field( | |
| 97 | 124 | default=None, | |
| 98 | 125 | description="Optional path to base model, useful if using a quantized base model and you want to apply LoRA to an f16 model." | |
@@ -101,14 +128,17 @@ class Settings(BaseSettings): | |||
| 101 | 128 | default=None, | |
| 102 | 129 | description="Path to a LoRA file to apply to the model.", | |
| 103 | 130 | ) | |
| 131 | + # Backend Params | ||
| 104 | 132 | numa: bool = Field( | |
| 105 | 133 | default=False, | |
| 106 | 134 | description="Enable NUMA support.", | |
| 107 | 135 | ) | |
| 136 | + # Chat Format Params | ||
| 108 | 137 | chat_format: str = Field( | |
| 109 | 138 | default="llama-2", | |
| 110 | 139 | description="Chat format to use.", | |
| 111 | 140 | ) | |
| 141 | + # Cache Params | ||
| 112 | 142 | cache: bool = Field( | |
| 113 | 143 | default=False, | |
| 114 | 144 | description="Use a cache to reduce processing times for evaluated prompts.", | |
@@ -121,9 +151,11 @@ class Settings(BaseSettings): | |||
| 121 | 151 | default=2 << 30, | |
| 122 | 152 | description="The size of the cache in bytes. Only used if cache is True.", | |
| 123 | 153 | ) | |
| 154 | + # Misc | ||
| 124 | 155 | verbose: bool = Field( | |
| 125 | 156 | default=True, description="Whether to print debug information." | |
| 126 | 157 | ) | |
| 158 | + # Server Params | ||
| 127 | 159 | host: str = Field(default="localhost", description="Listen address") | |
| 128 | 160 | port: int = Field(default=8000, description="Listen port") | |
| 129 | 161 | interrupt_requests: bool = Field( | |
@@ -345,27 +377,41 @@ def create_app(settings: Optional[Settings] = None): | |||
| 345 | 377 | global llama | |
| 346 | 378 | llama = llama_cpp.Llama( | |
| 347 | 379 | model_path=settings.model, | |
| 348 | - seed=settings.seed, | ||
| 349 | - n_ctx=settings.n_ctx, | ||
| 350 | - n_batch=settings.n_batch, | ||
| 380 | + # Model Params | ||
| 351 | 381 | n_gpu_layers=settings.n_gpu_layers, | |
| 352 | 382 | main_gpu=settings.main_gpu, | |
| 353 | 383 | tensor_split=settings.tensor_split, | |
| 384 | + vocab_only=settings.vocab_only, | ||
| 385 | + use_mmap=settings.use_mmap, | ||
| 386 | + use_mlock=settings.use_mlock, | ||
| 387 | + # Context Params | ||
| 388 | + seed=settings.seed, | ||
| 389 | + n_ctx=settings.n_ctx, | ||
| 390 | + n_batch=settings.n_batch, | ||
| 391 | + n_threads=settings.n_threads, | ||
| 392 | + n_threads_batch=settings.n_threads_batch, | ||
| 393 | + rope_scaling_type=settings.rope_scaling_type, | ||
| 354 | 394 | rope_freq_base=settings.rope_freq_base, | |
| 355 | 395 | rope_freq_scale=settings.rope_freq_scale, | |
| 396 | + yarn_ext_factor=settings.yarn_ext_factor, | ||
| 397 | + yarn_attn_factor=settings.yarn_attn_factor, | ||
| 398 | + yarn_beta_fast=settings.yarn_beta_fast, | ||
| 399 | + yarn_beta_slow=settings.yarn_beta_slow, | ||
| 400 | + yarn_orig_ctx=settings.yarn_orig_ctx, | ||
| 356 | 401 | mul_mat_q=settings.mul_mat_q, | |
| 357 | 402 | f16_kv=settings.f16_kv, | |
| 358 | 403 | logits_all=settings.logits_all, | |
| 359 | - vocab_only=settings.vocab_only, | ||
| 360 | - use_mmap=settings.use_mmap, | ||
| 361 | - use_mlock=settings.use_mlock, | ||
| 362 | 404 | embedding=settings.embedding, | |
| 363 | - n_threads=settings.n_threads, | ||
| 405 | + # Sampling Params | ||
| 364 | 406 | last_n_tokens_size=settings.last_n_tokens_size, | |
| 407 | + # LoRA Params | ||
| 365 | 408 | lora_base=settings.lora_base, | |
| 366 | 409 | lora_path=settings.lora_path, | |
| 410 | + # Backend Params | ||
| 367 | 411 | numa=settings.numa, | |
| 412 | + # Chat Format Params | ||
| 368 | 413 | chat_format=settings.chat_format, | |
| 414 | + # Misc | ||
| 369 | 415 | verbose=settings.verbose, | |
| 370 | 416 | ) | |
| 371 | 417 | if settings.cache: | |
| Back | FazBrowse Home | New Git URL |
0 commit comments