I'm a young researcher. I came up with a new LLM's inference method "Helix" for…
- User
I'm a young researcher. I came up with a new LLM's inference method "Helix" for multi-node on heterogeneous devices. The idea is as follows: Using some algorithm, I find the ideal model placement of the model on the devices (On which device and which layers lie). For example, Model has 50 layers and I have 6 devices in different nodes, and which layers should be on them: { 'A100_1': [16, 17, 18, 19, 20, [Redacted InternationalBankingAccountNumber], 25, [Redacted InternationalBankingAccountNumber], 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49], 'A100_2': [17, 18, 19, 20, 21, 22, 23, 24, 25, [Redacted InternationalBankingAccountNumber], 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49], 'L4_1': [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16], 'L4_2': [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16], 'T4_1': [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15], 'T4_2': [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15] } I also have a new scheduler for processing requests to this model. For model placement above, I have an example for scheduling 10 requests (The device and the layers that this device processes for this request): Serving Request req_1 with input: Hello, world! Assigned Pipeline for req_1: [('L4_1', [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16]), ('A100_2', [17, 18, 19, 20, [Redacted InternationalBankingAccountNumber], 25, [Redacted InternationalBankingAccountNumber], 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49])] Serving Request req_2 with input: How are you today? Assigned Pipeline for req_2: [('L4_2', [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16]), ('A100_2', [17, 18, 19, 20, [Redacted InternationalBankingAccountNumber], 25, [Redacted InternationalBankingAccountNumber], 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49])] Serving Request req_3 with input: Tell me a joke. Assigned Pipeline for req_3: [('L4_1', [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16]), ('A100_1', [17, 18, 19, 20, 21, 22, 23, 24, 25, [Redacted InternationalBankingAccountNumber], 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49])] Serving Request req_4 with input: Explain quantum computing. Assigned Pipeline for req_4: [('T4_1', [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15]), ('A100_1', [16, 17, 18, 19, 20, [Redacted InternationalBankingAccountNumber], 25, [Redacted InternationalBankingAccountNumber], 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49])] Serving Request req_5 with input: What is the capital of France? Assigned Pipeline for req_5: [('L4_2', [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16]), ('A100_2', [17, 18, 19, 20, [Redacted InternationalBankingAccountNumber], [Redacted InternationalBankingAccountNumber], 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49])] Serving Request req_6 with input: Translate "Good morning" to Spanish. Assigned Pipeline for req_6: [('L4_1', [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16]), ('A100_2', [17, 18, 19, 20, [Redacted InternationalBankingAccountNumber], [Redacted InternationalBankingAccountNumber], 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49])] Serving Request req_7 with input: Summarize the plot of "Inception". Assigned Pipeline for req_7: [('T4_2', [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15]), ('A100_1', [16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49])] Serving Request req_8 with input: What are the health benefits of green tea? Assigned Pipeline for req_8: [('L4_2', [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16]), ('A100_2', [17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49])] Serving Request req_9 with input: Describe the process of photosynthesis. Assigned Pipeline for req_9: [('L4_1', [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16]), ('A100_2', [17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49])] Serving Request req_10 with input: How does blockchain technology work?
Assigned Pipeline for req_10: [('T4_1', [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15]), ('A100_1', [16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49])]
[Redacted Person] introduces a technique called \textit{partial inference}. That is, I admit that the layers can overlap each other! For example with scheduling 10 requests, we can see partial inference for processing request 4: Device A100_1 has layers [16-49], but for this request he processing layers [17-49]. I already have implementation this scheduler. But I don't know how to implement this scheduler using vLLM! I need to figure out how to implement my method into the vLLM framework. That is, how to use their methods to upload a model to devices and how to combine devices through Pipeline Parallelism? Find information about this and explain to me how I can solve my problem. Also write code with a vLLM-based implementation. I need vLLM because I don't want to implement basic LLM inference optimizations like iteration level scheduling and PageAttention. Things to pay attention to:
- The function responsible for loading the model. I would like to configure it so that it loads the model by device as suggested in my method: by specific layers. If there are identical layers on different devices, then these layers of the model should be loaded on all these devices.
- A feature that will make Pipeline parallelism for these devices. In vllm, if you need to use pipeline parallelism, you must specify the pipeline_parallel_size number, which indicates the number of pipeline stages. I need to change this approach so that I can configure pipeline parallelism not using a number, but using a predefined custom model placemnet, as in my example above!
- Distributed inference must use ray!
- A function that controls the scheduler, with which we can configure our scheduler. The scheduler must process requests correctly, as shown in the example above, and it must do this using vLLM methods such as ray actors and workers.
Use vllm github for understanding implementation of vllm. Write what functions in vllm implementation i need to change, and write how I need to change this functions!
- Assistant
To implement your "Helix" inference method in vLLM, we need to modify and extend certain components of the vLLM framework. Specifically, we will focus on:
- Custom Model Loading for Layer Placement: Load specific layers of the model on specific devices based on your ideal placement.
- Custom Pipeline Parallelism: Replace the pipeline parallelism size (
pipeline_parallel_size) with a pre-configured custom model placement. - Custom Scheduler for Request Handling: Modify or extend the scheduler to handle partial inference and overlap between layers across devices.
- Distributed Inference Using Ray: Ensure that the modified framework continues to use vLLM's Ray-based distributed inference.
Let’s break this down step by step, identify the vLLM functions you need to modify, and implement the changes.
1. Custom Model Loading for Layer Placement
Relevant vLLM Function:
load_model()invllm/worker/worker.py.
This function is responsible for loading the model into memory. In the default vLLM implementation, the model is loaded in tensor-parallel or pipeline-parallel mode, based on the
pipeline_parallel_size.Changes:
You need to modify the
load_model()method to:- Load specific layers of the model on specific devices as per your placement dictionary (
{'A100_1': [16-49], ...}). - Ensure that identical layers are loaded on multiple devices if required.
Implementation:
Here's how you can modify the
load_model()function:python# File: vllm/worker/worker.py def load_model(self): # Custom logic for Helix Layer Placement layer_placement = { 'A100_1': list(range(16, 50)), 'A100_2': list(range(17, 50)), 'L4_1': list(range(0, 17)), 'L4_2': list(range(0, 17)), 'T4_1': list(range(0, 16)), 'T4_2': list(range(0, 16)), } # Get device ID for this worker device_id = self.device_config.device_id if device_id not in layer_placement: raise ValueError(f"Device {device_id} has no assigned layers in the placement.") assigned_layers = layer_placement[device_id] logger.info(f"Loading layers {assigned_layers} on device {device_id}.") # Load only the assigned layers self.model_runner.load_partial_model(assigned_layers)For this, you need to extend the
ModelRunnerclass invllm/worker/model_runner.pyto supportload_partial_model():python# File: vllm/worker/model_runner.py def load_partial_model(self, assigned_layers): """Load only the assigned layers of the model.""" # Iterate over the model layers and load the specified ones for layer_id, layer in enumerate(self.model): if layer_id in assigned_layers: self.model_runner.load_layer(layer_id, layer) else: logger.info(f"Skipping layer {layer_id} on this device.")
2. Custom Pipeline Parallelism
Relevant vLLM Function:
get_pp_indicesinvllm/distributed/utils.py.
This function determines how layers are split across pipeline stages. It currently uses a uniform splitting strategy or allows for user-defined, layer counts per stage via the
VLLM_PP_LAYER_PARTITIONenvironment variable.Changes:
Replace the default uniform splitting with a custom placement strategy based on your pre-defined layer placement (
layer_placementdictionary).Implementation:
Modify the
get_pp_indicesfunction to use your custom placement:python# File: vllm/distributed/utils.py def get_pp_indices(num_layers: int, pp_rank: int, pp_size: int, layer_placement=None) -> Tuple[int, int]: if layer_placement: # Custom layer placement based on device mapping devices = list(layer_placement.keys()) device = devices[pp_rank] assigned_layers = layer_placement[device] return min(assigned_layers), max(assigned_layers) + 1 # Default behavior (uniform splitting) return uniform_partition(num_layers, pp_rank, pp_size)You will also need to pass the
layer_placementdictionary to this function when initializing pipeline parallelism.
3. Custom Scheduler for Request Handling
Relevant vLLM Class:
Schedulerinvllm/core/scheduler.py.
This class is responsible for scheduling sequence groups (requests) onto devices. By default, it assumes a uniform pipeline parallelism setup.
Changes:
Modify the scheduler to:
- Handle overlapping layers (partial inference).
- Assign requests to devices based on your scheduling logic.
Implementation:
Extend the
Schedulerclass to include thelayer_placementand implement partial inference:python# File: vllm/core/scheduler.py class HelixScheduler(Scheduler): def __init__(self, *args, layer_placement=None, **kwargs): super().__init__(*args, **kwargs) self.layer_placement = layer_placement def schedule(self): # Custom scheduling logic for Helix scheduled_seq_groups = [] for request in self.waiting: input_text = request.input_text device_pipeline = self._assign_pipeline(input_text) scheduled_seq_groups.append(device_pipeline) return scheduled_seq_groups def _assign_pipeline(self, input_text): # Example scheduling logic if "hello" in input_text.lower(): return [('L4_1', range(0, 17)), ('A100_2', range(17, 50))] [Redacted Person] "quantum" in input_text.lower(): return [('T4_1', range(0, 16)), ('A100_1', range(16, 50))] # Add more rules as neededYou can replace the default scheduler in
LLMEnginewithHelixSchedulerinvllm/engine/llm_engine.py.
4. Distributed Inference Using Ray
vLLM already uses [Redacted Person] for distributed inference. Ensure that:
- Your workers are initialized with the custom layer placements.
- The [Redacted Person] actors run the
HelixScheduler.
Modify the
LLMEngineinitialization invllm/engine/llm_engine.py:python# File: vllm/engine/llm_engine.py def _initialize_kv_caches(self) -> None: # Pass the custom HelixScheduler self.scheduler = HelixScheduler(self.scheduler_config, layer_placement={ 'A100_1': list(range(16, 50)), 'A100_2': list(range(17, 50)), 'L4_1': list(range(0, 17)), 'L4_2': list(range(0, 17)), 'T4_1': list(range(0, 16)), 'T4_2': list(range(0, 16)), })
Final Code Summary
Here’s a brief overview of the modified files and functions:
-
Custom Model Loading:
- Modify
load_model()inworker.py. - Add
load_partial_model()inmodel_runner.py.
- Modify
-
Custom Pipeline Parallelism:
- Modify
get_pp_indices()indistributed/utils.py.
- Modify
-
Custom Scheduler:
- Extend
SchedulerasHelixSchedulerincore/scheduler.py.
- Extend
-
Distributed Inference Using Ray:
- Update
LLMEngineto useHelixSchedulerinengine/llm_engine.py.
- Update
Example Usage
pythonfrom vllm import LLM model = LLM( model="path/to/your/model", tensor_parallel_size=1, # Set per-device parallelism pipeline_parallel_size=6, # Total number of devices distributed_executor_backend="ray", ) prompts = ["Hello, world!", "Explain quantum computing."] outputs = model.generate(prompts) for output in outputs: print(output)This implementation should enable you to integrate your "Helix" method with vLLM while leveraging its optimizations like iteration-level scheduling and PageAttention.
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.