An LLM for generating texts from given prompts and sampling parameters. This class includes a tokenizer, a language model (possibly distributed across multiple GPUs), and GPU memory space allocated for intermediate states (aka KV cache). Given a batch of prompts and sampling parameters,
| 50 | |
| 51 | |
| 52 | class LLM: |
| 53 | """An LLM for generating texts from given prompts and sampling parameters. |
| 54 | |
| 55 | This class includes a tokenizer, a language model (possibly distributed |
| 56 | across multiple GPUs), and GPU memory space allocated for intermediate |
| 57 | states (aka KV cache). Given a batch of prompts and sampling parameters, |
| 58 | this class generates texts from the model, using an intelligent batching |
| 59 | mechanism and efficient memory management. |
| 60 | |
| 61 | Args: |
| 62 | model: The name or path of a HuggingFace Transformers model. |
| 63 | tokenizer: The name or path of a HuggingFace Transformers tokenizer. |
| 64 | tokenizer_mode: The tokenizer mode. "auto" will use the fast tokenizer |
| 65 | if available, and "slow" will always use the slow tokenizer. |
| 66 | skip_tokenizer_init: If true, skip initialization of tokenizer and |
| 67 | detokenizer. Expect valid prompt_token_ids and None for prompt |
| 68 | from the input. |
| 69 | trust_remote_code: Trust remote code (e.g., from HuggingFace) when |
| 70 | downloading the model and tokenizer. |
| 71 | allowed_local_media_path: Allowing API requests to read local images |
| 72 | or videos from directories specified by the server file system. |
| 73 | This is a security risk. Should only be enabled in trusted |
| 74 | environments. |
| 75 | tensor_parallel_size: The number of GPUs to use for distributed |
| 76 | execution with tensor parallelism. |
| 77 | dtype: The data type for the model weights and activations. Currently, |
| 78 | we support `float32`, `float16`, and `bfloat16`. If `auto`, we use |
| 79 | the `torch_dtype` attribute specified in the model config file. |
| 80 | However, if the `torch_dtype` in the config is `float32`, we will |
| 81 | use `float16` instead. |
| 82 | quantization: The method used to quantize the model weights. Currently, |
| 83 | we support "awq", "gptq", and "fp8" (experimental). |
| 84 | If None, we first check the `quantization_config` attribute in the |
| 85 | model config file. If that is None, we assume the model weights are |
| 86 | not quantized and use `dtype` to determine the data type of |
| 87 | the weights. |
| 88 | revision: The specific model version to use. It can be a branch name, |
| 89 | a tag name, or a commit id. |
| 90 | tokenizer_revision: The specific tokenizer version to use. It can be a |
| 91 | branch name, a tag name, or a commit id. |
| 92 | seed: The seed to initialize the random number generator for sampling. |
| 93 | gpu_memory_utilization: The ratio (between 0 and 1) of GPU memory to |
| 94 | reserve for the model weights, activations, and KV cache. Higher |
| 95 | values will increase the KV cache size and thus improve the model's |
| 96 | throughput. However, if the value is too high, it may cause out-of- |
| 97 | memory (OOM) errors. |
| 98 | swap_space: The size (GiB) of CPU memory per GPU to use as swap space. |
| 99 | This can be used for temporarily storing the states of the requests |
| 100 | when their `best_of` sampling parameters are larger than 1. If all |
| 101 | requests will have `best_of=1`, you can safely set this to 0. |
| 102 | Noting that `best_of` is only supported in V0. Otherwise, too small |
| 103 | values may cause out-of-memory (OOM) errors. |
| 104 | cpu_offload_gb: The size (GiB) of CPU memory to use for offloading |
| 105 | the model weights. This virtually increases the GPU memory space |
| 106 | you can use to hold the model weights, at the cost of CPU-GPU data |
| 107 | transfer for every forward pass. |
| 108 | enforce_eager: Whether to enforce eager execution. If True, we will |
| 109 | disable CUDA graph and always execute the model in eager mode. |
no outgoing calls