| 1 | # Offline Inference |
| 2 | |
| 3 | Offline inference is possible in your own code using vLLM's [`LLM`][vllm.LLM] class. |
| 4 | |
| 5 | ## Model Types |
| 6 | |
| 7 | vLLM models can be categorized into two types: |
| 8 | |
| 9 | - **[Generative Models](../models/supported_models.md)** - Models that produce text completions or chat responses (e.g., LLaMA, Qwen, DeepSeek). Use `LLM.generate()` and `LLM.chat()` for these models. |
| 10 | |
| 11 | - **[Pooling Models](../models/pooling_models/README.md)** - These models do not generate content. They are primarily used for classification and retrieval tasks, such as bge-m3 and Qwen3 Reranker. |
| 12 | |
| 13 | ## Generative APIs |
| 14 | |
| 15 | For further details on generative models, please refer to [this page](../models/supported_models.md). |
| 16 | |
| 17 | - `LLM.generate` - Generates completions for the given input prompts. |
| 18 | - `LLM.chat` - Generates responses for a chat conversation. |
| 19 | |
| 20 | ## Asynchronous Queue APIs |
| 21 | |
| 22 | - `LLM.enqueue` - Enqueues prompts for generation without waiting for completion. |
| 23 | - `LLM.enqueue_chat` - Enqueues chat conversations for generation without waiting. |
| 24 | - `LLM.wait_for_completion` - Waits for all enqueued requests to complete and returns results. |
| 25 | |
| 26 | ## Pooling APIs |
| 27 | |
| 28 | For further details on pooling models, please refer to [this page](../models/pooling_models/README.md). |
| 29 | |
| 30 | - `LLM.classify` - Only applicable to [classification models](../models/pooling_models/classify.md). |
| 31 | - `LLM.embed` - Only applicable to [embedding models](../models/pooling_models/embed.md). |
| 32 | - `LLM.score` - Applicable to [score models](../models/pooling_models/scoring.md) (cross-encoder, bi-encoder, late-interaction). |
| 33 | - `LLM.encode` - Applicable to all [pooling models](../models/pooling_models/README.md). |
| 34 | |
| 35 | ## Profiling APIs |
| 36 | |
| 37 | For further details on profiling, please refer to [this page](../contributing/profiling.md). |
| 38 | |
| 39 | - `LLM.start_profile` - Starts profiling with an optional custom trace prefix. |
| 40 | - `LLM.stop_profile` - Stops the ongoing profiling session. |
| 41 | |
| 42 | ## Sleep Mode APIs |
| 43 | |
| 44 | For further details on sleep mode, please refer to [this page](../features/sleep_mode.md). |
| 45 | |
| 46 | - `LLM.sleep` - Puts the engine into sleep mode. |
| 47 | - `LLM.wake_up` - Wakes up the engine from sleep mode. |
| 48 | |
| 49 | ## Cache Management APIs |
| 50 | |
| 51 | - `LLM.reset_mm_cache` - Resets the multi-modal cache. |
| 52 | - `LLM.reset_prefix_cache` - Resets the prefix cache. |
| 53 | |
| 54 | ## Metrics APIs |
| 55 | |
| 56 | For further details on metrics, please refer to [this page](../design/metrics.md). |
| 57 | |
| 58 | - `LLM.get_metrics` - Returns a snapshot of aggregated metrics from Prometheus. |
| 59 | |
| 60 | ## Weight Transfer APIs (RL Training) |
| 61 | |
| 62 | For further details on Weight Transfer, please refer to [this page](../training/weight_transfer/README.md). |
| 63 | |
| 64 | - `LLM.init_weight_transfer_engine` - Initializes the weight transfer engine for RL training. |
| 65 | - `LLM.start_weight_update` - Starts a new weight update cycle. |
| 66 | - `LLM.update_weights` - Updates the model weights. |
| 67 | - `LLM.finish_weight_update` - Finishes the current weight update cycle. |
| 68 | - `LLM.update_weight_version` - Sets the weight version without updating model weights. |
| 69 | - `LLM.get_weight_version` - Returns the latest committed weight version. |
| 70 | |
| 71 | ## Additional APIs |
| 72 | |
| 73 | - `LLM.collective_rpc` - Executes a method or callable collectively across all workers. |
| 74 | - `LLM.apply_model` - Applies a function directly to the model inside each worker. |
| 75 | |
| 76 | ## API Reference |
| 77 | |
| 78 | [Offline Inference](../api/README.md#offline-inference) |
| 79 | |
| 80 | ## Ray Data LLM API |
| 81 | |
| 82 | Ray Data LLM is an alternative offline inference API that uses vLLM as the underlying engine. |
| 83 | This API adds several batteries-included capabilities that simplify large-scale, GPU-efficient inference: |
| 84 | |
| 85 | - Streaming execution processes datasets that exceed aggregate cluster memory. |
| 86 | - Automatic sharding, load balancing, and autoscaling distribute work across a Ray cluster with built-in fault tolerance. |
| 87 | - Continuous batching keeps vLLM replicas saturated and maximizes GPU utilization. |
| 88 | - Transparent support for tensor and pipeline parallelism enables efficient multi-GPU inference. |
| 89 | - Reading and writing to most popular file formats and cloud object storage. |
| 90 | - Scaling up the workload without code changes. |
| 91 | |
| 92 | ??? code |
| 93 | |
| 94 | ```python |
| 95 | import ray # Requires ray>=2.44.1 |
| 96 | from ray.data.llm import vLLMEngineProcessorConfig, build_llm_processor |
| 97 | |
| 98 | config = vLLMEngineProcessorConfig(model_source="unsloth/Llama-3.2-1B-Instruct") |
| 99 | processor = build_llm_processor( |
| 100 | config, |
| 101 | preprocess=lambda row: { |
| 102 | "messages": [ |
| 103 | {"role": "system", "content": "You are a bot that completes unfinished haikus."}, |
| 104 | {"role": "user", "content": row["item"]}, |
| 105 | ], |
| 106 | "sampling_params": {"temperature": 0.3, "max_tokens": 250}, |
| 107 | }, |
| 108 | postprocess=lambda row: {"answer": row["generated_text"]}, |
| 109 | ) |
| 110 | |
| 111 | ds = ray.data.from_items(["An old silent pond..."]) |
| 112 | ds = processor(ds) |
| 113 | ds.write_parquet("local:///tmp/data/") |
| 114 | ``` |
| 115 | |
| 116 | For more information about the Ray Data LLM API, see the [Ray Data LLM documentation](https://docs.ray.io/en/latest/data/working-with-llms.html). |