-
Notifications
You must be signed in to change notification settings - Fork 42
Add TensorRT-LLM support for inference backend #121
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
Open
chungen04
wants to merge
28
commits into
lightseekorg:main
Choose a base branch
from
chungen04:chungen/trtllm
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
28 commits
Select commit
Hold shift + click to select a range
76ccb79
Patches for trt
chungen04 071394f
Exported trtllm as engine class
chungen04 6b02018
Extend factory and config class for trtllm
chungen04 7c66102
dockerfile for trtllm
chungen04 255a9f9
Add qwen3 8b example
chungen04 70e5419
Modified qwen3 8b example
chungen04 8d266f2
marked trtllm support in README.md
chungen04 2a377d0
Apply trtllm patch import-free at build time
chungen04 b6c4b57
docker(trtllm): forward Mooncake/TorchSpec env to MPI workers
chungen04 065c18c
docker(trtllm): key SaveHiddenStates Mooncake store on client_id
chungen04 fb619e8
trtllm: disable KV block reuse for hidden-state capture
chungen04 31b8615
config(trtllm): raise max_num_tokens to match max_seq_length
chungen04 a01d04f
style(trtllm): apply ruff format to trtllm_engine
chungen04 99a1602
trtllm: fold mpi_session patch into trtllm.patch and relax batch cap
chungen04 9050871
trtllm: unify tp_size override across backends in run.sh
chungen04 183f5a6
config(trtllm): tune qwen3-8b for single-node single-GPU
chungen04 811d028
align(trtllm): match remote README launch form and Dockerfile patch step
chungen04 5ef2a13
fix(trtllm): capture hidden states in native context order
chungen04 3ed4c00
fix(trtllm): default placement_strategy=inference_first
chungen04 893df69
fix(trtllm): protect trust_remote_code from extra_args override
chungen04 253df85
style(trtllm): trim and align comments
chungen04 0b4f7c4
fix(trtllm): honor store_last_hidden_states in mooncake capture
chungen04 5224fe0
fix(trtllm): defer tensorrt_llm imports until engine init
chungen04 50c0f31
fix(run.sh): make engine-type probe non-fatal under set -e
chungen04 956eecf
feat(trtllm): support data-parallel tp=1 inference (Ray-scoped placem…
chungen04 dde1128
feat(trtllm): enable DFlash training with the trtllm backend
chungen04 d29cd75
docs(trtllm): make branch comments self-contained
chungen04 7d23aed
Remove comment to instruct docker build
chungen04 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,80 @@ | ||
| # Configuration for train_entry.py with TensorRT-LLM Engine inference (nested config format) | ||
| # | ||
| # GPU allocation: | ||
| # - 2 GPUs for inference (duplicate mode: each engine has full model copy) | ||
| # - 2 GPUs for training (DP/FSDP: model sharded across 2 GPUs) | ||
| # - Total: 4 GPUs | ||
| # | ||
| # Installation: | ||
| # Use the TensorRT-LLM docker image (docker/trtllm/v1.3.0rc18/Dockerfile), | ||
| # which ships tensorrt_llm patched for Mooncake hidden-state capture. | ||
| # | ||
| # Usage (same launcher as the sglang example, for a fair side-by-side): | ||
| # ./examples/qwen3-8b-single-node/run.sh configs/trtllm_qwen3_8b.yaml | ||
| # | ||
| # Note: Uses TensorRT-LLM's SaveHiddenStates speculative mode; the TorchSpec | ||
| # patch redirects captured aux + final hidden states to Mooncake. | ||
|
|
||
| model: | ||
| target_model_path: Qwen/Qwen3-8B | ||
| trust_remote_code: true | ||
|
|
||
| dataset: | ||
| train_data_path: ../examples/data/sample_conversations.jsonl | ||
| # eval_data_path: ../examples/data/eval_conversations.jsonl | ||
| # eval_interval: 100 | ||
| chat_template: qwen | ||
| prompt_key: conversations | ||
|
|
||
| training: | ||
| attention_backend: flex_attention | ||
| # TRT tp-workers bind GPU 0..tp-1; keep inference on those to avoid OOM with training. | ||
| placement_strategy: inference_first | ||
| micro_batch_size: 1 | ||
| draft_accumulation_steps: 1 | ||
| learning_rate: 1e-4 | ||
| max_concurrent_batches: 1 | ||
| max_grad_norm: 0.5 | ||
| max_seq_length: 16384 | ||
| num_epochs: 1 | ||
| seed: 42 | ||
| training_num_gpus_per_node: 2 | ||
| training_num_nodes: 1 | ||
| ttt_length: 7 | ||
| save_per_epoch: true | ||
| warmup_ratio: 0.015 | ||
|
|
||
| inference: | ||
| inference_engine_type: trtllm | ||
| inference_num_gpus: 1 | ||
| inference_num_gpus_per_engine: 1 | ||
| inference_num_gpus_per_node: 1 | ||
| max_sample_pool_size: 64 # Max samples in controller pool | ||
| inference_buffer_threshold: 32 # Fetch prompts when buffer < threshold | ||
| inference_batch_size: 8 | ||
| trtllm: | ||
| tp_size: 1 | ||
| # KV-cache memory fraction. Kept below TRT-LLM's 0.9 default to leave room | ||
| # for the SaveHiddenStates capture buffer, which the KV profiler does not | ||
| # account for. | ||
| mem_fraction_static: 0.7 | ||
| extra_args: | ||
| # Any extra TensorRT-LLM LLM kwarg; e.g. cap the per-iteration token budget. | ||
| # Must be >= training.max_seq_length: chunked prefill is off, so prompts longer than max_num_tokens are dropped. | ||
| max_num_tokens: 16384 | ||
|
|
||
| mooncake: | ||
| master_server_address: null | ||
| metadata_server: null | ||
| protocol: tcp | ||
| global_segment_size: 16GB | ||
| local_buffer_size: 4GB | ||
|
|
||
| output_dir: ./outputs/qwen3-8b-single-node | ||
| cache_dir: ./cache/qwen3-8b-single-node | ||
| model_download_dir: null | ||
|
|
||
| debug: | ||
| save_debug_train_data: null | ||
| debug_train_only: false | ||
| debug_inference_only: false |
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,93 @@ | ||
| # DFlash training config for Qwen3-8B target model — TensorRT-LLM inference backend. | ||
| # | ||
| # Mirrors configs/sglang_qwen3_8b_dflash.yaml; only the inference backend differs | ||
| # (engine type, the trtllm block, and placement_strategy). | ||
| # | ||
| # GPU allocation: mirrors the sglang DFlash layout (4 inference tp=1 + 4 training); | ||
| # adjust inference_num_gpus / training_num_gpus_per_node / tp_size to your budget. | ||
| # | ||
| # Usage: | ||
| # ./examples/qwen3-8b-single-node/run.sh configs/trtllm_qwen3_8b_dflash.yaml | ||
|
|
||
| model: | ||
| target_model_path: Qwen/Qwen3-8B | ||
| trust_remote_code: true | ||
| draft_model_config: torchspec/config/dflash_draft_config.json | ||
|
|
||
| dataset: | ||
| train_data_path: ../examples/data/sample_conversations.jsonl | ||
| eval_data_path: null | ||
| eval_interval: 100 | ||
| chat_template: qwen | ||
| prompt_key: conversations | ||
| min_loss_tokens: 32 | ||
|
|
||
| training: | ||
| attention_backend: flex_attention | ||
| # TRT tp-workers bind GPU 0..tp-1; keep inference on those to avoid OOM with training. | ||
| placement_strategy: inference_first | ||
| micro_batch_size: 1 | ||
| draft_accumulation_steps: 2 # was 4 → 2x more optimizer steps | ||
| learning_rate: 6e-4 | ||
| min_lr: 6e-5 # 10% of peak — prevents LR death in later epochs | ||
| weight_decay: 0.01 # AdamW regularization for better generalization | ||
| max_concurrent_batches: 1 | ||
| max_grad_norm: 1.0 | ||
| max_seq_length: 2048 | ||
| num_epochs: 3 | ||
| seed: 42 | ||
| training_num_gpus_per_node: 4 | ||
| training_num_nodes: 1 | ||
| ttt_length: 7 | ||
| fsdp_strategy: FULL_SHARD | ||
| fsdp_reduce_dtype: bfloat16 | ||
| prefetch_depth: 8 | ||
| save_interval: 1000 | ||
| save_per_epoch: true | ||
| max_checkpoints: 2 | ||
| warmup_ratio: 0.04 | ||
|
|
||
| # DFlash-specific parameters | ||
| dflash_block_size: 16 | ||
| dflash_num_anchors: 512 | ||
| dflash_loss_decay_gamma: 7.0 | ||
| dflash_num_target_layers: 5 | ||
|
|
||
| inference: | ||
| inference_engine_type: trtllm | ||
| store_last_hidden_states: false | ||
| inference_num_gpus: 4 | ||
| inference_num_gpus_per_engine: 1 | ||
| inference_num_gpus_per_node: 4 | ||
| max_sample_pool_size: 64 | ||
| inference_buffer_threshold: 32 | ||
| inference_batch_size: 8 | ||
| trtllm: | ||
| tp_size: 1 | ||
| # KV-cache memory fraction. Kept below TRT-LLM's 0.9 default to leave room | ||
| # for the SaveHiddenStates capture buffer, which the KV profiler does not | ||
| # account for. | ||
| mem_fraction_static: 0.7 | ||
| extra_args: | ||
| # Must be >= training.max_seq_length: chunked prefill is off, so prompts longer than max_num_tokens are dropped. | ||
| max_num_tokens: 2048 | ||
|
|
||
| mooncake: | ||
| master_server_address: null | ||
| metadata_server: null | ||
| protocol: tcp | ||
| global_segment_size: 16GB | ||
| local_buffer_size: 4GB | ||
| # Hard-pin: master-side TTL is disabled; we rely on our explicit | ||
| # batch_remove(force=True) (see mooncake/eagle_store.py). Requires | ||
| # mooncake-transfer-engine >= 0.3.10.post1. | ||
| enable_hard_pin: true | ||
|
|
||
| output_dir: ./outputs/qwen3-8b-dflash | ||
| cache_dir: ./cache/qwen3-8b-dflash | ||
| model_download_dir: null | ||
|
|
||
| debug: | ||
| save_debug_train_data: null | ||
| debug_train_only: false | ||
| debug_inference_only: false |
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,30 @@ | ||
| ARG TRTLLM_IMAGE=nvcr.io/nvidia/tensorrt-llm/release:1.3.0rc18 | ||
| FROM ${TRTLLM_IMAGE} AS trtllm | ||
|
|
||
| WORKDIR /root/ | ||
|
|
||
| RUN apt-get update && \ | ||
| apt-get install -y --no-install-recommends nvtop rsync dnsutils && \ | ||
| rm -rf /var/lib/apt/lists/* | ||
|
|
||
| # Patch the installed tensorrt_llm (dist-packages) for Mooncake hidden-state | ||
| # capture. Don't import tensorrt_llm at build time to locate it — its __init__ | ||
| # loads libcuda.so.1, absent until container runtime; patch the path directly. | ||
| COPY patches/trtllm/v1.3.0rc18/*.patch /tmp/patches/ | ||
| RUN cd /usr/local/lib/python3.12/dist-packages && \ | ||
| for p in /tmp/patches/*.patch; do patch -p1 < "$p"; done && \ | ||
| rm -rf /tmp/patches | ||
|
|
||
| COPY . /root/torchspec | ||
| RUN cd /root/torchspec && pip install --no-cache-dir -e ".[fa]" | ||
|
|
||
| RUN pip uninstall -y mooncake-transfer-engine || true && \ | ||
| pip install --no-cache-dir --no-deps --force-reinstall \ | ||
| mooncake-transfer-engine-cuda13==0.3.11.post1 | ||
|
|
||
| RUN chmod 755 /usr/local/lib/python3.12/dist-packages/mooncake/mooncake_master || true | ||
| RUN if [ -f /usr/local/lib/python3.12/dist-packages/mooncake/cli.py ]; then \ | ||
| sed -i 's/os.chmod(bin_path, 0o755)/pass/' /usr/local/lib/python3.12/dist-packages/mooncake/cli.py; \ | ||
| fi | ||
|
|
||
| WORKDIR /root/torchspec |
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 |
|---|---|---|
|
|
@@ -37,6 +37,14 @@ else | |
| CONFIG_FILE="$ROOT_DIR/configs/sglang_qwen3_8b.yaml" | ||
| fi | ||
|
|
||
| # Derive the tp_size override block from the config's engine type ("sgl" -> "sglang"). | ||
| # `|| true` so a config without a literal inference_engine_type line falls back below instead of tripping set -e. | ||
| ENGINE_TYPE=$(grep -oE "inference_engine_type:[[:space:]]*[a-zA-Z]+" "$CONFIG_FILE" | awk '{print $2}' || true) | ||
| case "$ENGINE_TYPE" in | ||
| sgl) TP_BLOCK=sglang ;; | ||
| *) TP_BLOCK="${ENGINE_TYPE:-sglang}" ;; | ||
| esac | ||
|
|
||
| IFS=',' read -ra GPU_ARRAY <<< "$CUDA_VISIBLE_DEVICES" | ||
| TOTAL_GPUS=${#GPU_ARRAY[@]} | ||
|
|
||
|
|
@@ -56,14 +64,13 @@ echo "Local IP: $LOCAL_IP" | |
| echo "Extra args: $*" | ||
| echo "==============================================" | ||
|
|
||
| # TODO: unify tp_size config across sglang/vllm backends | ||
|
Contributor
Author
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. Previously, vLLM hardcodes the config in its yaml (configs/vllm_qwen3_8b.yaml) |
||
| python3 -m torchspec.train_entry \ | ||
| --config "$CONFIG_FILE" \ | ||
| training.training_num_gpus_per_node="$TRAIN_GPUS" \ | ||
| inference.inference_num_gpus="$INFERENCE_GPUS" \ | ||
| inference.inference_num_gpus_per_engine=2 \ | ||
| inference.inference_num_gpus_per_node="$TOTAL_GPUS" \ | ||
| inference.sglang.tp_size=2 \ | ||
| inference.${TP_BLOCK}.tp_size=2 \ | ||
| "$@" | ||
|
|
||
| echo "==============================================" | ||
|
|
||
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There is no
--configfield inrun.sh. See run.sh docstring.