-
Notifications
You must be signed in to change notification settings - Fork 688
feat: async + parallel spec dec trtllm example #2091
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closed
Closed
Changes from all commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
f3221e1
Added spec dec + trtllm example
6a0fc87
Delete components/backends/trtllm/launch/drafter.sh
jain-ria cb5c6a2
Delete components/backends/trtllm/launch/drafter.sh
jain-ria a745036
Merge branch 'rjain/trtllm-spec-dec' of https://github.com/ai-dynamo/…
jain-ria 2f4bdac
Merge branch 'rjain/trtllm-spec-dec' of https://github.com/ai-dynamo/…
jain-ria c6ad300
Merge branch 'rjain/trtllm-spec-dec' of https://github.com/ai-dynamo/…
jain-ria 7868600
Fixed worker implementation
jain-ria ef23f0c
Merge branch 'main' into rjain/trtllm-spec-dec
jain-ria 04587b2
Merge branch 'main' into rjain/trtllm-spec-dec
jain-ria 945fb9b
Merge branch 'rjain/trtllm-spec-dec' of https://github.com/ai-dynamo/…
jain-ria e9b5a41
more fixes
jain-ria cc7b21a
Added parallel speculation
jain-ria File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,54 @@ | ||
| <!-- | ||
| SPDX-FileCopyrightText: Copyright (c) 2025 NVIDIA CORPORATION & AFFILIATES. All rights reserved. | ||
| SPDX-License-Identifier: Apache-2.0 | ||
|
|
||
| Licensed under the Apache License, Version 2.0 (the "License"); | ||
| you may not use this file except in compliance with the License. | ||
| You may obtain a copy of the License at | ||
|
|
||
| http://www.apache.org/licenses/LICENSE-2.0 | ||
|
|
||
| Unless required by applicable law or agreed to in writing, software | ||
| distributed under the License is distributed on an "AS IS" BASIS, | ||
| WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| See the License for the specific language governing permissions and | ||
| limitations under the License. | ||
| --> | ||
|
|
||
| # Async Speculative Decoding | ||
|
|
||
| This guide demonstrates how to run Draft-Target Model (DTM) speculative decoding asynchronously in Dynamo, where the draft model and target model run as separate Dynamo workers with the TRT-LLM backend. | ||
|
|
||
| ## Setup | ||
|
|
||
| Follow the [Quickstart setup](./README.md#quick-start) instructions. Then, inside the container, run the following example: | ||
|
|
||
| ``` | ||
| cd $DYNAMO_HOME/components/backends/trtllm | ||
| ./launch/spec_dec.sh | ||
| ``` | ||
|
|
||
| To scale up the number of drafters: | ||
|
|
||
| ``` | ||
| cd $DYNAMO_HOME/components/backends/trtllm | ||
| export NUM_DRAFTERS=2 | ||
| export DRAFTER_CUDA_VISIBLE_DEVICES:-"1,2" | ||
| ./launch/spec_dec.sh | ||
| ``` | ||
|
|
||
| ## Parallel Speculative Decoding | ||
|
|
||
| To enable parallel speculative decoding, add the ```--parallel-spec-dec``` to the verifier: | ||
|
|
||
| ``` | ||
| # run verifier worker with speculative decoding | ||
| CUDA_VISIBLE_DEVICES=$VERIFIER_CUDA_VISIBLE_DEVICES \ | ||
| python3 -m dynamo.trtllm \ | ||
| --model-path "$MODEL_PATH" \ | ||
| --served-model-name "$SERVED_MODEL_NAME" \ | ||
| --extra-engine-args "$VERIFIER_ENGINE_ARGS" \ | ||
| --spec-dec-mode "verifier" & \ | ||
| --parallel-spec-dec | ||
| VERIFIER_PID=$! | ||
| ``` | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can you describe the request flow in this setup as well?
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. May be a mermaid diagram? |
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,32 @@ | ||
| # SPDX-FileCopyrightText: Copyright (c) 2025 NVIDIA CORPORATION & AFFILIATES. All rights reserved. | ||
| # SPDX-License-Identifier: Apache-2.0 | ||
| # | ||
| # Licensed under the Apache License, Version 2.0 (the "License"); | ||
| # you may not use this file except in compliance with the License. | ||
| # You may obtain a copy of the License at | ||
| # | ||
| # http://www.apache.org/licenses/LICENSE-2.0 | ||
| # | ||
| # Unless required by applicable law or agreed to in writing, software | ||
| # distributed under the License is distributed on an "AS IS" BASIS, | ||
| # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| # See the License for the specific language governing permissions and | ||
| # limitations under the License. | ||
| tensor_parallel_size: 1 | ||
| moe_expert_parallel_size: 1 | ||
| enable_attention_dp: false | ||
| max_num_tokens: 8192 | ||
| max_batch_size: 16 | ||
| trust_remote_code: true | ||
| backend: pytorch | ||
| enable_chunked_prefill: true | ||
|
|
||
| kv_cache_config: | ||
| free_gpu_memory_fraction: 0.95 | ||
|
|
||
| # NOTE: pytorch_backend_config section flattened since: https://github.com/NVIDIA/TensorRT-LLM/pull/4603 | ||
| # NOTE: overlap_scheduler enabled by default since this commit and changed | ||
| # config field from 'enable_overlap_scheduler' to 'disable_overlap_scheduler': | ||
| # https://github.com/NVIDIA/TensorRT-LLM/commit/b4e5df0ee0024eda3eeb83a6ba822245a30ab428 | ||
| cuda_graph_config: | ||
| max_batch_size: 16 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,36 @@ | ||
| # SPDX-FileCopyrightText: Copyright (c) 2025 NVIDIA CORPORATION & AFFILIATES. All rights reserved. | ||
| # SPDX-License-Identifier: Apache-2.0 | ||
| # | ||
| # Licensed under the Apache License, Version 2.0 (the "License"); | ||
| # you may not use this file except in compliance with the License. | ||
| # You may obtain a copy of the License at | ||
| # | ||
| # http://www.apache.org/licenses/LICENSE-2.0 | ||
| # | ||
| # Unless required by applicable law or agreed to in writing, software | ||
| # distributed under the License is distributed on an "AS IS" BASIS, | ||
| # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| # See the License for the specific language governing permissions and | ||
| # limitations under the License. | ||
| backend: pytorch | ||
| tensor_parallel_size: 4 | ||
| moe_expert_parallel_size: 1 | ||
| enable_attention_dp: false | ||
| max_num_tokens: 1024 | ||
| max_batch_size: 16 | ||
| trust_remote_code: true | ||
| enable_chunked_prefill: true | ||
| # External API does not support overlap scheduler | ||
| disable_overlap_scheduler: true | ||
|
|
||
| drafter_config: | ||
| drafter_endpoint: dyn://dynamo.tensorrt_llm.generate_draft | ||
| max_draft_len: 10 | ||
|
|
||
| kv_cache_config: | ||
| enable_block_reuse: false | ||
|
|
||
| next_client: dyn://dynamo.tensorrt_llm.generate_draft | ||
|
|
||
| cuda_graph_config: | ||
| max_batch_size: 16 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,76 @@ | ||
| #!/bin/bash | ||
| # SPDX-FileCopyrightText: Copyright (c) 2025 NVIDIA CORPORATION & AFFILIATES. All rights reserved. | ||
| # SPDX-License-Identifier: Apache-2.0 | ||
|
|
||
| # Environment variables with defaults | ||
| # Verifier variables | ||
| export MODEL_PATH=${MODEL_PATH:-"meta-llama/Meta-Llama-3.1-8B-Instruct"} | ||
| export SERVED_MODEL_NAME=${SERVED_MODEL_NAME:-"meta-llama/Meta-Llama-3.1-8B-Instruct"} | ||
| export VERIFIER_ENGINE_ARGS=${VERIFIER_ENGINE_ARGS:-"engine_configs/verifier.yaml"} | ||
| export VERIFIER_CUDA_VISIBLE_DEVICES=${VERIFIER_CUDA_VISIBLE_DEVICES:-"0"} | ||
|
|
||
| # Drafter variables | ||
| export NUM_DRAFTERS=${NUM_DRAFTERS:-1} | ||
| export DRAFTER_MODEL_PATH=${DRAFTER_MODEL_PATH:-"meta-llama/Meta-Llama-3.2-1B-Instruct"} | ||
| export DRAFTER_MODEL_NAME=${DRAFTER_MODEL_NAME:-"meta-llama/Meta-Llama-3.2-1B-Instruct"} | ||
| export DRAFTER_ENGINE_ARGS=${DRAFTER_ENGINE_ARGS:-"engine_configs/drafter.yaml"} | ||
| export DRAFTER_CUDA_VISIBLE_DEVICES=${DRAFTER_CUDA_VISIBLE_DEVICES:-"1"} | ||
|
|
||
| declare -a DRAFTER_PIDS=() | ||
|
|
||
| # Check enough GPUs for drafters | ||
| IFS=',' read -ra CUDA_DEVICES <<< "$DRAFTER_CUDA_VISIBLE_DEVICES" | ||
| if [ ${#CUDA_DEVICES[@]} -lt $NUM_DRAFTERS ]; then | ||
| echo "Error: Not enough CUDA devices specified for drafters. Need $NUM_DRAFTERS devices, but only ${#CUDA_DEVICES[@]} provided." | ||
| exit 1 | ||
| fi | ||
|
|
||
| # Check num drafters >= 1 | ||
| if [[ $NUM_DRAFTERS -lt 1 ]]; then | ||
| echo "Error: NUM_DRAFTERS must be >= 1, got: $NUM_DRAFTERS" | ||
| exit 1 | ||
| fi | ||
|
|
||
| # Setup cleanup trap | ||
| cleanup() { | ||
| echo "Cleaning up background processes..." | ||
| kill $DYNAMO_PID $VERIFIER_PID "${DRAFTER_PIDS[@]}" 2>/dev/null || true | ||
| wait $DYNAMO_PID $VERIFIER_PID "${DRAFTER_PIDS[@]}" 2>/dev/null || true | ||
| echo "Cleanup complete." | ||
| } | ||
| trap cleanup EXIT INT TERM | ||
|
|
||
| # run clear_namespace | ||
| python3 utils/clear_namespace.py --namespace dynamo | ||
|
|
||
| # run frontend | ||
| python3 -m dynamo.frontend --http-port 8000 & | ||
| DYNAMO_PID=$! | ||
|
|
||
| # run verifier worker with speculative decoding | ||
| CUDA_VISIBLE_DEVICES=$VERIFIER_CUDA_VISIBLE_DEVICES \ | ||
| python3 -m dynamo.trtllm \ | ||
| --model-path "$MODEL_PATH" \ | ||
| --served-model-name "$SERVED_MODEL_NAME" \ | ||
| --extra-engine-args "$VERIFIER_ENGINE_ARGS" \ | ||
| --spec-dec-mode "verifier" & | ||
| VERIFIER_PID=$! | ||
|
|
||
| # run drafter workers without speculative decoding | ||
| start_drafter() { | ||
| local cuda_device=$1 | ||
| CUDA_VISIBLE_DEVICES=$cuda_device \ | ||
| python3 -m dynamo.trtllm \ | ||
| --endpoint "dyn://dynamo.tensorrt_llm.generate_draft" \ | ||
| --model-path "$DRAFTER_MODEL_PATH" \ | ||
| --served-model-name "$DRAFTER_MODEL_NAME" \ | ||
| --extra-engine-args "$DRAFTER_ENGINE_ARGS" \ | ||
| --spec-dec-mode "drafter" & | ||
| DRAFTER_PIDS+=($!) | ||
jain-ria marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| } | ||
|
|
||
| for ((i=0; i<$NUM_DRAFTERS; i++)); do | ||
| start_drafter ${CUDA_DEVICES[$i]} | ||
| done | ||
|
|
||
| wait | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.