https://github.com/bentoml/bentotrtllm
Science Score: 26.0%
This score indicates how likely this project is to be science-related based on various indicators:
-
○CITATION.cff file
-
✓codemeta.json file
Found codemeta.json file -
✓.zenodo.json file
Found .zenodo.json file -
○DOI references
-
○Academic publication links
-
○Committers with academic emails
-
○Institutional organization owner
-
○JOSS paper metadata
-
○Scientific vocabulary similarity
Low similarity (16.1%) to scientific vocabulary
Keywords from Contributors
Repository
Basic Info
- Host: GitHub
- Owner: bentoml
- Language: Python
- Default Branch: main
- Size: 40 KB
Statistics
- Stars: 10
- Watchers: 5
- Forks: 1
- Open Issues: 3
- Releases: 0
Metadata Files
README.md
Self-host LLMs with TensorRT-LLM and BentoML
This is a BentoML example project, showing you how to serve and deploy open-source Large Language Models (LLMs) using TensorRT-LLM, a Python API that optimizes LLM inference on NVIDIA GPUs using TensorRT engine.
See here for a full list of BentoML example projects.
💡 This example is served as a basis for advanced code customization, such as custom model, inference logic or LMDeploy options. For simple LLM hosting with OpenAI compatible endpoint without writing any code, see OpenLLM.
Prerequisites
- You have installed Python 3.10+ and
pip. See the Python downloads page to learn more. - You have a basic understanding of key concepts in BentoML, such as Services. We recommend you read Quickstart first.
- You have installed Docker, which will be used to create a container environment to run TensorRT-LLM.
- If you want to test the Service locally, you need a Nvidia GPU with at least 20G VRAM.
- This example uses Llama 3. Make sure you have gained access to the model.
- (Optional) We recommend you create a virtual environment for dependency isolation for this project. See the Conda documentation or the Python documentation for details.
Set up the environment
Clone the project repo and TensorRT-LLM repo.
bash
git clone https://github.com/bentoml/BentoTRTLLM.git
cd BentoTRTLLM/llama-3-8b-instruct
git clone -b v0.10.0 https://github.com/NVIDIA/TensorRT-LLM.git
cd TensorRT-LLM
Note: To deploy Llama 3 70B AWQ, go to the llama-3-70b-instruct directory.
Create the base Docker environment to compile the model.
bash
git lfs install
git clone https://huggingface.co/meta-llama/Meta-Llama-3-8B-Instruct
docker run --rm --runtime=nvidia --gpus all --volume ${PWD}:/TensorRT-LLM --entrypoint /bin/bash -it --workdir /TensorRT-LLM nvidia/cuda:12.1.0-devel-ubuntu22.04
Install dependencies inside the Docker container. Note that TensorRT-LLM requires Python 3.10.
```bash apt-get update && apt-get -y install python3.10 python3-pip openmpi-bin libopenmpi-dev
Install the stable version (corresponding to the cloned branch) of TensorRT-LLM.
pip3 install tensorrt_llm==0.10.0 -U --extra-index-url https://pypi.nvidia.com pip3 install --force-reinstall -U --extra-index-url https://pypi.nvidia.com tensorrt-cu12==10.0.1
Log in to huggingface-cli
You can get your token from huggingface.co/settings/token
apt-get install -y git huggingface-cli login --token ***** ```
Build the Llama 8B model using a single GPU and BF16.
```bash python3 examples/llama/convertcheckpoint.py --modeldir ./Meta-Llama-3-8B-Instruct \ --outputdir ./tllmcheckpoint1gpubf16 \ --dtype bfloat16
trtllm-build --checkpointdir ./tllmcheckpoint1gpubf16 \ --outputdir ./tmp/llama/8B/trtengines/bf16/1-gpu \ --gptattentionplugin bfloat16 \ --gemmplugin bfloat16 \ --maxbatchsize 2048 \ --maxinputlen 2048 \ --maxnumtokens 2048 \ --multipleprofiles enable \ --pagedkvcache enable \ --usepagedcontext_fmha enable ```
The model should be successfully built now. Exit the Docker image.
bash
exit
Clone the tensorrtllm_backend repo.
bash
cd ..
git clone -b v0.10.0 https://github.com/triton-inference-server/tensorrtllm_backend.git
Now, the BentoTRTLLM/ directory should have one TenosrRT-LLM/ directory and one tensorrtllm_backend/ directory.
Copy the model.
bash
cd tensorrtllm_backend
cp ../TensorRT-LLM/tmp/llama/8B/trt_engines/bf16/1-gpu/* all_models/inflight_batcher_llm/tensorrt_llm/1/
Set the tokenizer_dir and engine_dir paths.
```bash HFLLAMAMODEL=TensorRT-LLM/Meta-Llama-3-8B-Instruct ENGINEPATH=tensorrtllmbackend/allmodels/inflightbatcherllm/tensorrtllm/1
python3 tools/filltemplate.py -i allmodels/inflightbatcherllm/preprocessing/config.pbtxt tokenizerdir:${HFLLAMAMODEL},tokenizertype:auto,tritonmaxbatchsize:2048,preprocessinginstance_count:1
python3 tools/filltemplate.py -i allmodels/inflightbatcherllm/postprocessing/config.pbtxt tokenizerdir:${HFLLAMAMODEL},tokenizertype:auto,tritonmaxbatchsize:2048,postprocessinginstance_count:8
python3 tools/filltemplate.py -i allmodels/inflightbatcherllm/tensorrtllmbls/config.pbtxt tritonmaxbatchsize:2048,decoupledmode:True,blsinstancecount:1,accumulate_tokens:False
python3 tools/filltemplate.py -i allmodels/inflightbatcherllm/ensemble/config.pbtxt tritonmaxbatch_size:2048
python3 tools/filltemplate.py -i allmodels/inflightbatcherllm/tensorrtllm/config.pbtxt tritonbackend:tensorrtllm,tritonmaxbatchsize:2048,decoupledmode:True,maxbeamwidth:1,enginedir:${ENGINEPATH},maxtokensinpagedkvcache:,maxattentionwindowsize:2560,kvcachefreegpumemfraction:0.9,excludeinputinoutput:True,batchingstrategy:inflightfusedbatching,maxqueuedelaymicroseconds:0,enablechunkedcontext:True ```
Import the model
Install BentoML.
bash
pip install bentoml
Make sure you are in the llama-3-8b-instruct directory and import the model to the BentoML Model Store.
bash
python pack_model.py
To verify it, run:
```bash $ bentoml models list
Tag Size Creation Time meta-llama--meta-llama-3-8b-instruct-trtllm-rtx4000:7eu4l2reqwohx3lu 45.80 GiB 2024-06-07 04:25:30 ```
Run the BentoML Service
We have defined a BentoML Service in service.py. To serve it locally, first create a Docker container environment for TensorRT-LLM:
bash
docker run --runtime=nvidia --gpus all -v ${PWD}:/BentoTRTLLM -v ~/bentoml:/root/bentoml -p 3000:3000 --entrypoint /bin/bash -it --workdir /BentoTRTLLM nvcr.io/nvidia/tritonserver:24.06-trtllm-python-py3
Install the dependencies.
bash
pip install -r requirements.txt
Start the Service.
bash
$ bentoml serve .
2024-06-07T05:16:38+0000 [INFO] [cli] Starting production HTTP BentoServer from "service:TRTLLM" listening on http://localhost:3000 (Press CTRL+C to quit)
I0607 05:16:39.805180 117 pinned_memory_manager.cc:275] Pinned memory pool is created at '0x7f7c64000000' with size 268435456
I0607 05:16:39.805431 117 cuda_memory_manager.cc:107] CUDA memory pool is created on device 0 with size 67108864
I0607 05:16:39.810192 117 model_lifecycle.cc:469] loading: postprocessing:1
I0607 05:16:39.810243 117 model_lifecycle.cc:469] loading: preprocessing:1
I0607 05:16:39.810385 117 model_lifecycle.cc:469] loading: tensorrt_llm:1
I0607 05:16:39.810426 117 model_lifecycle.cc:469] loading: tensorrt_llm_bls:1
I0607 05:16:39.841462 117 python_be.cc:2391] TRITONBACKEND_ModelInstanceInitialize: postprocessing_0_0 (CPU device 0)
I0607 05:16:39.841462 117 python_be.cc:2391] TRITONBACKEND_ModelInstanceInitialize: preprocessing_0_0 (CPU device 0)
[TensorRT-LLM][WARNING] gpu_device_ids is not specified, will be automatically set
[TensorRT-LLM][WARNING] max_tokens_in_paged_kv_cache is not specified, will use default value
[TensorRT-LLM][WARNING] batch_scheduler_policy parameter was not found or is invalid (must be max_utilization or guaranteed_no_evict)
[TensorRT-LLM][WARNING] enable_chunked_context is not specified, will be set to false.
...
The server is now active at http://localhost:3000. You can interact with it using the Swagger UI or in other different ways.
CURL
```bash curl -X 'POST' \ 'http://localhost:3000/generate' \ -H 'accept: text/event-stream' \ -H 'Content-Type: application/json' \ -d '{ "prompt": "Explain superconductors like I'\''m five years old", "max_tokens": 1024 }' ```Python client
```python import bentoml with bentoml.SyncHTTPClient("http://localhost:3000") as client: response_generator = client.generate( prompt="Explain superconductors like I'm five years old", max_tokens=1024 ) for response in response_generator: print(response, end='') ```Deploy to BentoCloud
After the Service is ready, you can deploy the application to BentoCloud for better management and scalability. Sign up if you haven't got a BentoCloud account.
Make sure you have logged in to BentoCloud, then run the following command to deploy it. Note that you need to specify the CUDA version in bentofile.yaml.
bash
bentoml deploy .
Once the application is up and running on BentoCloud, you can access it via the exposed URL.
Note: For custom deployment in your own infrastructure, use BentoML to generate an OCI-compliant image.
Owner
- Name: BentoML
- Login: bentoml
- Kind: organization
- Location: San Francisco
- Website: https://bentoml.com
- Twitter: bentomlai
- Repositories: 76
- Profile: https://github.com/bentoml
The most flexible way to serve AI models in production
GitHub Events
Total
- Issues event: 1
- Watch event: 4
- Push event: 1
- Pull request review event: 2
- Pull request event: 3
Last Year
- Issues event: 1
- Watch event: 4
- Push event: 1
- Pull request review event: 2
- Pull request event: 3
Committers
Last synced: about 1 year ago
Top Committers
| Name | Commits | |
|---|---|---|
| Rick Zhou | r****u@g****m | 7 |
| Zhao Shenyang | d****v@z****m | 2 |
| Sherlock Xu | 6****3 | 2 |
Committer Domains (Top 20 + Academic)
Issues and Pull Requests
Last synced: 12 months ago
All Time
- Total issues: 1
- Total pull requests: 8
- Average time to close issues: N/A
- Average time to close pull requests: 5 days
- Total issue authors: 1
- Total pull request authors: 2
- Average comments per issue: 0.0
- Average comments per pull request: 0.38
- Merged pull requests: 8
- Bot issues: 0
- Bot pull requests: 0
Past Year
- Issues: 1
- Pull requests: 8
- Average time to close issues: N/A
- Average time to close pull requests: 5 days
- Issue authors: 1
- Pull request authors: 2
- Average comments per issue: 0.0
- Average comments per pull request: 0.38
- Merged pull requests: 8
- Bot issues: 0
- Bot pull requests: 0
Top Authors
Issue Authors
- Rumeysakeskin (1)
- jackNhat (1)
Pull Request Authors
- rickzx (9)
- Sherlock113 (4)