-
Notifications
You must be signed in to change notification settings - Fork 2k
[None][fix] Refactoring input prep to allow out-of-tree models #6497
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
Merged
rakib-hasan
merged 9 commits into
NVIDIA:main
from
rakib-hasan:fix/input_prep_for_OOT_models
Aug 13, 2025
Merged
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
b23e977
refactoring input prep again to allow out-of-tree models to work with…
rakib-hasan 0f1a5fe
Merge branch 'main' into fix/input_prep_for_OOT_models
rakib-hasan 12c8156
polish: adding docs, tests and addressing review comments
rakib-hasan 8a6cbe2
Merge branch 'main' into fix/input_prep_for_OOT_models
rakib-hasan 109dd85
Merge branch 'main' into fix/input_prep_for_OOT_models
rakib-hasan 8295b85
rebasing and removing the now redundant import of torch models
rakib-hasan 6cd1a3a
Merge branch 'main' into fix/input_prep_for_OOT_models
rakib-hasan 6514028
Merge branch 'main' into fix/input_prep_for_OOT_models
rakib-hasan 16d5e92
Merge branch 'main' into fix/input_prep_for_OOT_models
rakib-hasan 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,52 @@ | ||
| # Out-of-tree Model Development | ||
| The file `modeling_opt.py` shows an example of how a custom model can be defined using TRT-LLM APIs without modifying the source code of TRT-LLM. | ||
|
|
||
| The file `main.py` shows how to run inference for such custom models using the LLM API. | ||
|
|
||
|
|
||
| ## Out-of-tree Multimodal Models | ||
|
|
||
| For multimodal models, TRT-LLM provides `quickstart_multimodal.py` to quickly run a multimodal model that is defined within TRT-LLM. `trtllm-bench` can be used for benchmarking such models. | ||
| However, the following sections describe how to use those tools for out-of-tree models. | ||
|
|
||
| ### Pre-requisite | ||
| To use an out-of-tree model with the quickstart example and trtllm-bench, you need to prepare the model definition files similar to a python module. | ||
| Consider the following file structure as an example: | ||
| ``` | ||
| modeling_custom_phi | ||
| |-- __init__.py | ||
| |-- configuration.py | ||
| |-- modeling_custom_phi.py | ||
| |-- encoder | ||
| |-- __init__.py | ||
| |-- configuration.py | ||
| |-- modeling_encoder.py | ||
| ```` | ||
| The files `__init__.py` should be populated with the right imports for the custom model. For example, the `modeling_custom_phi/__init__.py` can contain something like: | ||
| ``` | ||
| from .modeling_custom_phi import MyVLMForConditionalGeneration | ||
| from . import encoder | ||
| ``` | ||
|
|
||
| ### Quickstart Example | ||
|
|
||
| Once the model definition files are prepared as a python module (as described above), you can use the `--custom_module_dirs` flag in `quickstart_multimodal.py` to load your model and run inference. | ||
|
|
||
| ``` | ||
| python3 quickstart_multimodal.py --model_dir ./model_ckpt --modality image --max_tokens 10 --prompt "Describe the image." --media ./demo_lower.png --image_format pil --custom_module_dirs ../modeling_custom_phi | ||
| ``` | ||
|
|
||
| ### Benchmarking | ||
|
|
||
| Similar to the quickstart example, you can use the same CLI argument with `trtllm-bench` to benchmark a custom model. | ||
|
|
||
| Prepare the dataset: | ||
| ``` | ||
| python ./benchmarks/cpp/prepare_dataset.py --tokenizer ./model_ckpt --stdout dataset --dataset-name lmms-lab/MMMU --dataset-split test --dataset-image-key image --dataset-prompt-key "question" --num-requests 100 --output-len-dist 128,5 > mm_data.jsonl | ||
| ``` | ||
|
|
||
|
|
||
| Run the benchmark: | ||
| ``` | ||
| trtllm-bench --model ./model_ckpt --model_path ./model_ckpt throughput --dataset mm_data.jsonl --backend pytorch --num_requests 100 --max_batch_size 4 --modality image --streaming --custom_module_dirs ../modeling_custom_phi | ||
| ``` |
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
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
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
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
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.