<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Atanu Roy on Medium]]></title>
        <description><![CDATA[Stories by Atanu Roy on Medium]]></description>
        <link>https://medium.com/@atanu_22076?source=rss-be52c2e9e1ac------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*dmbNkD5D-u45r44go_cf0g.png</url>
            <title>Stories by Atanu Roy on Medium</title>
            <link>https://medium.com/@atanu_22076?source=rss-be52c2e9e1ac------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Mon, 30 Nov 2026 14:01:37 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@atanu_22076/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[Chasing Lower Latency for a Fine-Tuned Whisper: From SageMaker JIT to TensorRT-LLM + Triton]]></title>
            <link>https://medium.com/humaineeti-ai/chasing-lower-latency-for-a-fine-tuned-whisper-from-sagemaker-jit-to-tensorrt-llm-triton-a394c5714c40?source=rss-be52c2e9e1ac------2</link>
            <guid isPermaLink="false">https://medium.com/p/a394c5714c40</guid>
            <category><![CDATA[low-latency-model-serving]]></category>
            <category><![CDATA[ai-inference-optimization]]></category>
            <category><![CDATA[tensorrt-llm]]></category>
            <category><![CDATA[low-latency-asr-model]]></category>
            <dc:creator><![CDATA[Atanu Roy]]></dc:creator>
            <pubDate>Wed, 14 Oct 2026 09:46:12 GMT</pubDate>
            <atom:updated>2026-10-14T09:49:02.781Z</atom:updated>
            <content:encoded><![CDATA[<p>Co-authored by <a href="https://medium.com/u/91564173d5f2">Debjit Khaskel</a> and <a href="https://medium.com/u/be52c2e9e1ac">Atanu Roy</a></p><p><strong>Premise: </strong>A few days back we fine-tuned a Whisper Large-V3-Turbo model for Hinglish (Hindi-English code-switched speech to text) using QLoRA and distributed FSDP on 2 GPU nodes. The model worked decently, with a Word Error Rate of 0.3181. Then came the real problem: our contact center needs transcripts in real time, and a good model that responds slowly is just a nice demo.</p><p>This post walks through what we tried, what blew up, why we changed direction each time, and where we landed: from a <strong>3.4929s </strong>response time to<strong> </strong>a <strong>310–530 ms </strong>response time with a <strong>RTF of 0.0488</strong>. We did this with a specific model, but the lessons apply to plenty of other models (particularly encoder-decoder architecture) and tasks.</p><p>The following diagram shows our journey in a nutshell, and the details are what the rest of the blog is about.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*m9JMQcyEcsVULxk_M5Ed8w.jpeg" /></figure><p><strong>The Starting Point: Plain SageMaker Inference</strong></p><p>We began with the simplest thing possible: load the fine-tuned checkpoint, stand up an Amazon SageMaker real-time endpoint, and call it a day.</p><p>Client-side latency: 3.4929s per request. <em>(keep the transcript line as is)</em></p><p>Fine for offline transcription, painful for anything interactive. The usual fix for slow GPU inference is compiling the model with <strong>TensorRT</strong>, so that’s where we headed.</p><p><strong>Attempt 1: JIT Compilation via Amazon SageMaker LMI</strong></p><p>The <strong>Amazon SageMaker Large Model Inference (LMI) container</strong> is a high-performance image built to serve large language and vision-language models on SageMaker. It uses <strong>DJL-Serving</strong> as the orchestrator, while <strong>backends</strong> like vLLM, TensorRT-LLM, and Transformers NeuronX do the actual model execution.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*dCMmYVkG4YIObGz8ZIxPiQ.jpeg" /></figure><p>The LMI TensorRT-LLM container compiles supported Hugging Face models for you at startup. No build step, no artifacts to manage, just point it at the weights. Setting it up is far less work than standing up NVIDIA Triton, so we were tempted.</p><p>It turned out not to be for us:</p><ul><li>LMI’s JIT conversion supports only a fixed list of <strong>decoder-only</strong> architectures (Llama, Falcon, Mistral, GPT-family and friends), because those are the ones with conversion scripts shipped in TensorRT-LLM.</li><li><strong>Whisper is encoder-decoder.</strong> The generic conversion path doesn’t know how to split it into the two engines Whisper needs. Whisper has its own conversion script that produces <strong>two engines, one for the encoder and one for the decoder</strong>, not the single fused engine JIT assumes.</li></ul><p>Bottom line: LMI’s JIT can’t compile Whisper. For architectures outside its list, you have to build the TensorRT engine <em>outside</em> the serving container and hand the server a finished artifact. That nudged us towards Triton.</p><p><strong>Attempt 2: TensorRT-LLM Engines + NVIDIA Triton Inference Server</strong></p><p><a href="https://developer.nvidia.com/triton-inference-server">Triton Inference Server</a> is NVIDIA’s open-source serving layer. It supports many backends (TensorRT, PyTorch, ONNX, OpenVINO, RAPIDS FIL, and more) across cloud, data center, and edge, on GPUs, x86/ARM CPUs, or AWS Inferentia. It’s built for exactly the low-latency, high-throughput serving we wanted.</p><p><strong>The plan:</strong> compile the encoder and decoder into two TensorRT engines ahead of time, then serve both behind Triton with a Python script handling the handoff. TensorRT turns the model into an optimized computation graph, and that’s where the speedup comes from.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*xUbc6zuxARdUtvFeFTM9vQ.jpeg" /></figure><p><strong>Step 1: Build a compiler container</strong></p><p>First step is to build a container with the right drivers and libraries to compile the whisper encoder and decoder model. We initially built a docker image from Triton’s tensorrtllm-python image nvcr.io/nvidia/tritonserver:26.07-trtllm-python-py3, pinned to TensorRT-LLM release v 1.2.1, and used our own patched convert_checkpoint.py. We needed to patch it as the shipped convert_checkpoint.py used the OpenAI format, while we finetuned the Huggingface Whisper model which has a different format.</p><p><strong>This container failed to load (plot twist #1)</strong></p><p>It compiled happily and even ran perfectly on Docker Desktop, then refused to load on the SageMaker instances:</p><blockquote><em>failed to load ‘tensorrt_llm’ version 1: Not found: unable to load shared library:<br>…/libtensorrt_llm.so: undefined symbol: cuCtxGetId</em></blockquote><p>cuCtxGetId is a CUDA Driver API symbol exported by libcuda.so, which ships with the NVIDIA driver. An <em>undefined symbol</em> there means one thing: the host driver is older than what the container’s CUDA runtime expects.</p><p>So what driver does SageMaker actually ship? <br>You can pin the AMI with <em>InferenceAmiVersion</em> on the SageMaker endpoint config, and the newest one at the time (al2-ami-sagemaker-inference-gpu-3–1) tops out at driver 550.144.01 (CUDA 12.4). Our Triton image was built for CUDA 13.x. There’s the gap.</p><p>We had two ways out:</p><ul><li><strong>Downgrade the whole stack.</strong> Older Triton, older TensorRT-LLM, rebuild the engines. Sounds simple, but Whisper support, tensor names, and required config.pbtxt parameters all shift between versions. You’re not changing a tag, you’re redoing the engine build and serving config against an older, thinner-documented API.</li><li><strong>Use CUDA forward compatibility.</strong> NVIDIA’s container toolkit offers<a href="https://docs.nvidia.com/deploy/cuda-compatibility/forward-compatibility.html"> CUDA forward compatibility</a>, which lets a container built with a newer CUDA Toolkit run on a host with an older kernel driver. The compat libraries live in /usr/local/cuda/compat and need to be activated in the container first by adding them to the library path (AWS’s guide <a href="https://docs.aws.amazon.com/sagemaker/latest/dg/container-nvidia-compliance.html">GPU container guide</a> says the same): <em>LD_LIBRARY_PATH=/usr/local/cuda/compat:$LD_LIBRARY_PATH</em></li></ul><p>We rebuilt the container on CUDA 12.8 and also enabled the CUDA Forward Compatability so if a future rebuild pushes the container’s CUDA further ahead of the driver, it quietly handles it. Here’s the Dockerfile that works:</p><pre># Dockerfile.builder<br># Builder image: contains TensorRT-LLM sources and the Whisper tooling used to<br># convert checkpoints and compile engines. It is never deployed to SageMaker.<br># The trtllm-python tag of Triton 25.01 ships TensorRT-LLM 0.17.0,<br># so TENSORRT_LLM_VERSION below must stay on v0.17.0 to match it.<br>FROM nvcr.io/nvidia/tritonserver:25.01-trtllm-python-py3<br>ARG TENSORRT_LLM_VERSION=v0.17.0<br>WORKDIR /workspace<br><br># Shallow clones of the exact release tag keep the image small and reproducible.<br>RUN git clone - depth 1 - branch ${TENSORRT_LLM_VERSION} \<br>https://github.com/NVIDIA/TensorRT-LLM.git tensorrt_llm_src<br>RUN git clone - depth 1 - branch ${TENSORRT_LLM_VERSION} \<br>https://github.com/triton-inference-server/tensorrtllm_backend.git<br>RUN pip install - no-cache-dir \<br>-r tensorrt_llm_src/examples/whisper/requirements.txt \<br>&quot;transformers&gt;=4.46.0&quot; openai-whisper tiktoken soundfile librosa<br><br># Replace NVIDIA&#39;s original converter with our HF-checkpoint-aware version.<br>COPY convert_checkpoint.py /workspace/tensorrt_llm_src/examples/whisper/convert_checkpoint.py<br>WORKDIR /workspace/tensorrt_llm_src/examples/whisper</pre><p>Finally build the docker image</p><pre>docker build - network sagemaker - file Dockerfile.builder - tag whisper-triton:builder</pre><p><strong>The takeaway:</strong> an “undefined symbol” or “driver too old” error from a CUDA library doesn’t always mean the versions are truly incompatible. It can also mean a compatibility path exists but isn’t wired up. Figure out which one you’re facing before reaching for a full downgrade.</p><p><strong>Step 2: Fetch model assets</strong></p><pre># Create the output directories first so they are owned by your user, not root<br>mkdir -p assets engines model_repo<br>cd assets<br>wget https://raw.githubusercontent.com/openai/whisper/main/whisper/assets/mel_filters.npz<br>wget https://openaipublic.blob.core.windows.net/tiktoken/encodings/multilingual.tiktoken<br>cd ..</pre><p><strong>Step 3: Compile the encoder and decoder engines</strong></p><p>First, create the build script that the container will run as its entrypoint:</p><pre>#!/usr/bin/env bash<br># build_whisper_engines.sh<br># Converts the Whisper large-v3-turbo weights into a TensorRT-LLM checkpoint,<br># then builds the encoder and decoder TensorRT engines.#<br># Intended to run inside the whisper-builder container, where the<br># assets and engines directories are mounted under /workspace.<br># Stop on the first failing command, on unset variables, and on failed pipes.<br>set -euo pipefail<br># - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -<br># Configuration<br># - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -<br>readonly ASSETS_DIR=&quot;/workspace/assets&quot;<br>readonly CHECKPOINT_DIR=&quot;/workspace/checkpoints/turbo&quot;<br>readonly ENGINE_DIR=&quot;/workspace/engines/turbo&quot;<br>readonly MODEL_NAME=&quot;large-v3-turbo&quot;<br>readonly MODEL_DTYPE=&quot;float16&quot;<br># Whisper encoder input: 30 seconds of audio = 3000 mel frames.<br># The encoder length is fixed, so it is reused by both engine builds.<br>readonly ENCODER_INPUT_LENGTH=3000<br>readonly MAX_BATCH_SIZE=8<br># Decoder limits.<br># Sequence length 114 = 14 prompt tokens + up to 100 generated tokens.<br>readonly DECODER_MAX_INPUT_LENGTH=14<br>readonly DECODER_MAX_SEQUENCE_LENGTH=114<br>readonly DECODER_MAX_BEAM_WIDTH=4<br># - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -<br># Steps<br># - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -<br>convert_checkpoint() {<br>echo &quot;[1/3] Converting checkpoint to TensorRT-LLM format…&quot;<br># Produces the &quot;encoder&quot; and &quot;decoder&quot; subdirectories under CHECKPOINT_DIR,<br># which the two engine builds below read from.<br>python3 convert_checkpoint.py \<br> - model_dir &quot;${ASSETS_DIR}&quot; \<br> - model_name &quot;${MODEL_NAME}&quot; \<br> - output_dir &quot;${CHECKPOINT_DIR}&quot; \<br> - dtype &quot;${MODEL_DTYPE}&quot;<br>}<br>build_encoder_engine() {<br> echo &quot;[2/3] Building encoder engine…&quot;<br># The encoder has no mixture-of-experts layers and runs with a fixed<br># input length, so only the BERT-style attention plugin is needed.<br># The GEMM plugin is disabled for the encoder.<br>trtllm-build \<br> - checkpoint_dir &quot;${CHECKPOINT_DIR}/encoder&quot; \<br> - output_dir &quot;${ENGINE_DIR}/encoder&quot; \<br> - moe_plugin disable \<br> - gemm_plugin disable \<br> - bert_attention_plugin float16 \<br> - max_batch_size &quot;${MAX_BATCH_SIZE}&quot; \<br> - max_input_len &quot;${ENCODER_INPUT_LENGTH}&quot; \<br> - max_seq_len &quot;${ENCODER_INPUT_LENGTH}&quot;<br>}<br>build_decoder_engine() {<br> echo &quot;[3/3] Building decoder engine (Turbo has only 4 decoder layers)…&quot;<br> # The decoder needs three attention paths:<br># - bert_attention_plugin: cross-attention over the encoder output<br># - gpt_attention_plugin: causal self-attention over generated tokens|<br># max_encoder_input_len must match the encoder output length.<br>trtllm-build \<br> - checkpoint_dir &quot;${CHECKPOINT_DIR}/decoder&quot; \<br> - output_dir &quot;${ENGINE_DIR}/decoder&quot; \<br> - moe_plugin disable \<br> - max_beam_width &quot;${DECODER_MAX_BEAM_WIDTH}&quot; \<br> - max_batch_size &quot;${MAX_BATCH_SIZE}&quot; \<br> - max_seq_len &quot;${DECODER_MAX_SEQUENCE_LENGTH}&quot; \<br> - max_input_len &quot;${DECODER_MAX_INPUT_LENGTH}&quot; \<br> - max_encoder_input_len &quot;${ENCODER_INPUT_LENGTH}&quot; \<br> - gemm_plugin float16 \<br> - bert_attention_plugin float16 \<br> - gpt_attention_plugin float16<br>}<br># - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -<br># Entry point<br># - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -<br>main() {<br> convert_checkpoint<br> build_encoder_engine<br> build_decoder_engine<br> echo &quot;Done. Engines written to ${ENGINE_DIR}&quot;<br>}<br>main &quot;$@&quot;</pre><p>Now run the container</p><pre># Run the build script inside the container.<br># The script is mounted read-only so the container cannot modify it.<br>docker run \<br> - network sagemaker \<br> - rm \<br> - gpus all \<br>-v &quot;$PWD/assets:/workspace/assets&quot; \<br>-v &quot;$PWD/engines:/workspace/engines&quot; \<br>-v &quot;$PWD/build_whisper_engines.sh:/workspace/build_whisper_engines.sh:ro&quot; \<br>whisper-triton:builder \<br>bash /workspace/build_whisper_engines.sh</pre><p><strong>Step 4: Build a model serving container with the compiled engines and push the image to ECR</strong></p><p>Amazon ECR stores container images, so the serving side can just pull a finished artifact. That means the engines need to be baked into a lighter image than the compiler image we have : a thin layer on top of the same Triton base image we used in Step 1(nvcr.io/nvidia/tritonserver:25.01-trtllm-python-py3).</p><p>Also note, that we are going to deploy this container on Amazon SageMaker for serving so we need to comply with SageMaker’s container contract.</p><pre># Dockerfile.engines<br>#<br># Layers the compiled TensorRT engines on top of the Triton serving image,<br># so the serving container starts with everything it needs and no build step.<br><br># The base image is passed in at build time so the Dockerfile never hardcodes it.<br>ARG BASE_IMAGE<br>FROM ${BASE_IMAGE}<br><br># The build context is the engines directory itself (see the push script),<br># so &quot;.&quot; here means &quot;everything inside engines/&quot;.<br>COPY . /workspace/engines/<br><br># SageMaker specific conntract<br>ENV DEBIAN_FRONTEND=noninteractive<br>ENV PYTHONUNBUFFERED=1<br>EXPOSE 8080<br>COPY requirements.txt /tmp/requirements.txt<br>RUN pip install --no-cache-dir -r /tmp/requirements.txt<br>WORKDIR /opt/ml<br>COPY entrypoint.py /opt/ml/entrypoint.py<br>RUN chmod +x /opt/ml/entrypoint.py<br>ENTRYPOINT [&quot;python3&quot;, &quot;/opt/ml/entrypoint.py&quot;]</pre><p>Now build the docker and push to ECR:</p><pre>#!/usr/bin/env bash<br># push_engines_to_ecr.sh<br>#<br># Packages the compiled TensorRT engines into a Docker image and pushes it<br># to Amazon ECR, so the serving container can pull the finished artifact<br># instead of rebuilding the engines.<br>#<br># Required environment variables:<br>#   AWS_REGION       Region of the ECR registry, e.g. us-east-1<br>#   BASE_IMAGE       Triton serving image the engines are layered onto<br>#   ECR_REPOSITORY   ECR repository name, e.g. whisper-turbo-engines<br>#<br># Optional:<br>#   IMAGE_TAG        Defaults to a UTC timestamp, so each push is unique<br><br># Stop on the first failing command, on unset variables, and on failed pipes.<br>set -euo pipefail<br><br># ---------------------------------------------------------------------------<br># Configuration<br># ---------------------------------------------------------------------------<br>readonly AWS_REGION=&quot;${AWS_REGION:?Set AWS_REGION, e.g. us-east-1}&quot;<br>readonly BASE_IMAGE=&quot;${BASE_IMAGE:?Set BASE_IMAGE to the Triton serving image}&quot;<br>readonly ECR_REPOSITORY=&quot;${ECR_REPOSITORY:?Set ECR_REPOSITORY, e.g. whisper-turbo-engines}&quot;<br><br>readonly SCRIPT_DIR=&quot;$(cd &quot;$(dirname &quot;${BASH_SOURCE[0]}&quot;)&quot; &amp;&amp; pwd)&quot;<br>readonly ENGINES_DIR=&quot;${SCRIPT_DIR}/engines/turbo&quot;<br>readonly DOCKERFILE_PATH=&quot;${SCRIPT_DIR}/Dockerfile.engines&quot;<br><br># Immutable timestamp tags let you roll back to any earlier engine build.<br># A moving tag like &quot;latest&quot; would make deployments hard to reproduce.<br>readonly DEFAULT_IMAGE_TAG=&quot;$(date -u +%Y%m%d-%H%M%S)&quot;<br>readonly IMAGE_TAG=&quot;${IMAGE_TAG:-${DEFAULT_IMAGE_TAG}}&quot;<br><br># ---------------------------------------------------------------------------<br># Steps<br># ---------------------------------------------------------------------------<br>verify_engines_exist() {<br>    echo &quot;[1/5] Verifying compiled engines exist...&quot;<br><br>    local required_directories=(<br>        &quot;${ENGINES_DIR}/encoder&quot;<br>        &quot;${ENGINES_DIR}/decoder&quot;<br>    )<br><br>    for directory in &quot;${required_directories[@]}&quot;; do<br>        if [[ ! -d &quot;${directory}&quot; ]]; then<br>            echo &quot;ERROR: Missing ${directory}. Run build_whisper_engines.sh first.&quot; &gt;&amp;2<br>            exit 1<br>        fi<br>    done<br>}<br><br>resolve_image_uri() {<br>    echo &quot;[2/5] Resolving ECR registry address...&quot;<br><br>    # The account ID is read from the active AWS credentials,<br>    # so it never has to be hardcoded or passed in.<br>    local aws_account_id<br>    aws_account_id=&quot;$(aws sts get-caller-identity --query Account --output text)&quot;<br><br>    ECR_REGISTRY=&quot;${aws_account_id}.dkr.ecr.${AWS_REGION}.amazonaws.com&quot;<br>    IMAGE_URI=&quot;${ECR_REGISTRY}/${ECR_REPOSITORY}:${IMAGE_TAG}&quot;<br>}<br><br>ensure_repository_exists() {<br>    echo &quot;[3/5] Ensuring ECR repository &#39;${ECR_REPOSITORY}&#39; exists...&quot;<br><br>    # describe-repositories exits non-zero when the repository is missing,<br>    # which is how we detect that it needs to be created.<br>    if aws ecr describe-repositories \<br>        --repository-names &quot;${ECR_REPOSITORY}&quot; \<br>        --region &quot;${AWS_REGION}&quot; &gt; /dev/null 2&gt;&amp;1; then<br>        echo &quot;      Repository already exists.&quot;<br>        return<br>    fi<br><br>    aws ecr create-repository \<br>        --repository-name &quot;${ECR_REPOSITORY}&quot; \<br>        --region &quot;${AWS_REGION}&quot; \<br>        --image-scanning-configuration scanOnPush=true \<br>        --image-tag-mutability IMMUTABLE &gt; /dev/null<br>    echo &quot;      Repository created.&quot;<br>}<br><br>login_to_ecr() {<br>    echo &quot;[4/5] Logging in to ECR...&quot;<br><br>    # The password is piped in, so it never appears in the process list<br>    # or in shell history.<br>    aws ecr get-login-password --region &quot;${AWS_REGION}&quot; \<br>        | docker login --username AWS --password-stdin &quot;${ECR_REGISTRY}&quot;<br>}<br><br>build_and_push_image() {<br>    echo &quot;[5/5] Building and pushing ${IMAGE_URI}...&quot;<br><br>    # The build context is the engines directory only, so large unrelated<br>    # files (model assets, checkpoints) are never sent to the Docker daemon.<br>    #<br>    # --platform:        SageMaker GPU instances are x86_64, which matters<br>    #                    when building from an ARM machine such as an M-series Mac.<br>    # --provenance=false: stops buildx from attaching an extra attestation<br>    #                    manifest, which some AWS services cannot pull.<br>    docker build \<br>        --platform linux/amd64 \<br>        --provenance=false \<br>        --build-arg BASE_IMAGE=&quot;${BASE_IMAGE}&quot; \<br>        --file &quot;${DOCKERFILE_PATH}&quot; \<br>        --tag &quot;${IMAGE_URI}&quot; \<br>        &quot;${ENGINES_DIR}&quot;<br><br>    docker push &quot;${IMAGE_URI}&quot;<br>}<br><br># ---------------------------------------------------------------------------<br># Entry point<br># ---------------------------------------------------------------------------<br>main() {<br>    verify_engines_exist<br>    resolve_image_uri<br>    ensure_repository_exists<br>    login_to_ecr<br>    build_and_push_image<br><br>    echo &quot;Done. Pushed: ${IMAGE_URI}&quot;<br>}<br><br>main &quot;$@&quot;</pre><p><strong>Step 5: Enable model orchestration with Triton BLS</strong> <strong>(plot twist #2)</strong></p><p>So far we have separate encoder and decoder engines, baked into a serving image and sitting in ECR. Now for a twist, and why it’s the next step. <strong>Business Logic Scripting (BLS)</strong> is a Triton feature that lets a Python model call other models on the same server from inside its own execute function. Your Python code decides which models to call, in what order, how many times, and what to do with each result. That’s the “orchestration.”<br><strong>Why Whisper needs it:</strong> Whisper is encoder-decoder, and its decoder is autoregressive, producing one token at a time until it emits an end-of-text token. A BLS model can run the encoder once, then loop the decoder, or even pick a different model based on the input (say, detect the language first). NVIDIA’s tensorrtllm_backend uses the same idea in its tensorrt_llm_bls model.<br><strong>What changes in our container?</strong> We already have both engines and the tensorrtllm_backend repo in the builder. What’s missing is the Triton <strong>model repository</strong> that ties them together. The Triton backend ships a Whisper example under all_models/whisper/ with two model folders:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*RYPFEnsZn82s8w-ss5f9gw.png" /></figure><p>Before rebaking the image, we need to:</p><ul><li><strong>Copy</strong> the two model folders out of the cloned backend repo.</li><li><strong>Fill the config.pbtxt templates</strong> with our engine paths and limits, using the backend’s tools/fill_template.py.</li><li><strong>Place the engines</strong> where the configs point.</li><li><strong>Validate</strong> that no ${placeholder} is left unfilled.</li></ul><p>This script does all of it:</p><pre>#!/usr/bin/env bash<br># assemble_model_repository.sh<br>#<br># Builds the Triton model repository for Whisper from the tensorrtllm_backend<br># templates and the compiled engines. Runs inside the builder image.<br><br># Stop on the first failing command, on unset variables, and on failed pipes.<br>set -euo pipefail<br><br># ---------------------------------------------------------------------------<br># Configuration<br># ---------------------------------------------------------------------------<br>readonly BACKEND_DIR=&quot;/workspace/tensorrtllm_backend&quot;<br>readonly TEMPLATE_DIR=&quot;${BACKEND_DIR}/all_models/whisper&quot;<br>readonly FILL_TEMPLATE_SCRIPT=&quot;${BACKEND_DIR}/tools/fill_template.py&quot;<br><br>readonly ENGINE_DIR=&quot;/workspace/engines/turbo&quot;<br>readonly MODEL_REPOSITORY_DIR=&quot;/workspace/model_repository&quot;<br><br># Where the engines will live INSIDE THE SERVING IMAGE. The config files<br># store this path, so it must match the final image layout, not the<br># builder&#39;s layout.<br>readonly SERVING_ENGINE_DIR=&quot;/model_repository/engines/turbo&quot;<br><br># Must match the limits used in build_whisper_engines.sh.<br>readonly MAX_BATCH_SIZE=8<br>readonly MAX_BEAM_WIDTH=4<br><br># ---------------------------------------------------------------------------<br># Steps<br># ---------------------------------------------------------------------------<br>verify_inputs() {<br>    echo &quot;[1/5] Verifying templates and engines exist...&quot;<br><br>    local required_paths=(<br>        &quot;${TEMPLATE_DIR}/tensorrt_llm&quot;<br>        &quot;${TEMPLATE_DIR}/whisper_bls&quot;<br>        &quot;${FILL_TEMPLATE_SCRIPT}&quot;<br>        &quot;${ENGINE_DIR}/encoder&quot;<br>        &quot;${ENGINE_DIR}/decoder&quot;<br>    )<br><br>    for required_path in &quot;${required_paths[@]}&quot;; do<br>        if [[ ! -e &quot;${required_path}&quot; ]]; then<br>            echo &quot;ERROR: Missing ${required_path}&quot; &gt;&amp;2<br>            exit 1<br>        fi<br>    done<br>}<br><br>copy_templates() {<br>    echo &quot;[2/5] Copying model templates...&quot;<br><br>    # Start clean so files from an earlier run cannot leak into this one.<br>    rm -rf &quot;${MODEL_REPOSITORY_DIR}&quot;<br>    mkdir -p &quot;${MODEL_REPOSITORY_DIR}&quot;<br><br>    cp -r &quot;${TEMPLATE_DIR}/tensorrt_llm&quot; &quot;${MODEL_REPOSITORY_DIR}/tensorrt_llm&quot;<br>    cp -r &quot;${TEMPLATE_DIR}/whisper_bls&quot; &quot;${MODEL_REPOSITORY_DIR}/whisper_bls&quot;<br>}<br><br>copy_engines() {<br>    echo &quot;[3/5] Copying engines into the repository...&quot;<br><br>    mkdir -p &quot;${MODEL_REPOSITORY_DIR}/engines&quot;<br>    cp -r &quot;${ENGINE_DIR}&quot; &quot;${MODEL_REPOSITORY_DIR}/engines/turbo&quot;<br>}<br><br>fill_config_templates() {<br>    echo &quot;[4/5] Filling config.pbtxt templates...&quot;<br><br>    # The key names below are the placeholders in the templates. If one is<br>    # wrong or missing, the validation step catches it. Check each template<br>    # for the exact names with: grep -o &#39;\${[a-z_]*}&#39; &lt;config.pbtxt&gt;<br>    python3 &quot;${FILL_TEMPLATE_SCRIPT}&quot; -i \<br>        &quot;${MODEL_REPOSITORY_DIR}/tensorrt_llm/config.pbtxt&quot; \<br>        &quot;triton_max_batch_size:${MAX_BATCH_SIZE},max_beam_width:${MAX_BEAM_WIDTH},engine_dir:${SERVING_ENGINE_DIR}/decoder,encoder_engine_dir:${SERVING_ENGINE_DIR}/encoder&quot;<br><br>    python3 &quot;${FILL_TEMPLATE_SCRIPT}&quot; -i \<br>        &quot;${MODEL_REPOSITORY_DIR}/whisper_bls/config.pbtxt&quot; \<br>        &quot;triton_max_batch_size:${MAX_BATCH_SIZE},engine_dir:${SERVING_ENGINE_DIR}/encoder&quot;<br>}<br><br>validate_configs() {<br>    echo &quot;[5/5] Checking for unfilled placeholders...&quot;<br><br>    # A leftover ${...} means a key was misspelled or never supplied.<br>    # Triton would fail at load time with a less obvious error.<br>    local unfilled_placeholders<br>    unfilled_placeholders=&quot;$(grep -rn --include=config.pbtxt &#39;\${&#39; &quot;${MODEL_REPOSITORY_DIR}&quot; || true)&quot;<br><br>    if [[ -n &quot;${unfilled_placeholders}&quot; ]]; then<br>        echo &quot;ERROR: Unfilled placeholders found:&quot; &gt;&amp;2<br>        echo &quot;${unfilled_placeholders}&quot; &gt;&amp;2<br>        exit 1<br>    fi<br>}<br><br># ---------------------------------------------------------------------------<br># Entry point<br># ---------------------------------------------------------------------------<br>main() {<br>    verify_inputs<br>    copy_templates<br>    copy_engines<br>    fill_config_templates<br>    validate_configs<br>    echo &quot;Done. Model repository: ${MODEL_REPOSITORY_DIR}&quot;<br>}<br><br>main &quot;$@”</pre><p>Now run it in the builder container, with a mount so the result lands on your host:</p><pre>mkdir -p model_repository<br><br>docker run --rm --gpus all \<br>  -v &quot;$PWD/engines:/workspace/engines&quot; \<br>  -v &quot;$PWD/model_repository:/workspace/model_repository&quot; \<br>  -v &quot;$PWD/assemble_model_repository.sh:/workspace/assemble_model_repository.sh:ro&quot; \<br>  whisper-triton:builder \<br>  bash /workspace/assemble_model_repository.sh</pre><p>Finally, rebake the image by updating Dockerfile.engines and rebuilding:</p><pre># Dockerfile.engines<br>#<br># Layers the assembled Triton model repository (configs, BLS code, engines)<br># onto the Triton serving image, so the container starts with everything it needs.<br><br># The base image is passed in at build time so the Dockerfile never hardcodes it.<br>ARG BASE_IMAGE<br>FROM ${BASE_IMAGE}<br><br># The build context is the model_repository directory itself (see the push script),<br># so &quot;.&quot; means &quot;everything inside model_repository/&quot;.<br>COPY . /model_repository/<br><br># SageMaker specific conntract<br>ENV DEBIAN_FRONTEND=noninteractive<br>ENV PYTHONUNBUFFERED=1<br>EXPOSE 8080<br>COPY requirements.txt /tmp/requirements.txt<br>RUN pip install --no-cache-dir -r /tmp/requirements.txt<br>WORKDIR /opt/ml<br>COPY entrypoint.py /opt/ml/entrypoint.py<br>RUN chmod +x /opt/ml/entrypoint.py<br>ENTRYPOINT [&quot;python3&quot;, &quot;/opt/ml/entrypoint.py&quot;]<br><br># Start Triton against the repository. Check how SageMaker launches the container<br># (see the note below) before relying on this.<br>CMD [&quot;tritonserver&quot;, &quot;--model-repository=/model_repository&quot;]</pre><p>Then docker build.</p><pre># The build context is the model_repository directory, so large unrelated <br># files (model assets, checkpoints) are never sent to the Docker daemon. <br># # --platform: SageMaker GPU instances are x86_64, which matters <br># when building from an ARM machine such as an M-series Mac. <br># --provenance=false: stops buildx from attaching an extra attestation # manifest, which some AWS services cannot pull. <br>docker build \ <br>--platform linux/amd64 \ <br>--provenance=false \ <br>--build-arg BASE_IMAGE=&quot;${BASE_IMAGE}&quot; \ <br>--file &quot;${DOCKERFILE_PATH}&quot; \ <br>--tag &quot;${IMAGE_URI}&quot; \ <br>&quot;${MODEL_REPOSITORY_DIR}&quot;</pre><h3>Step 5: Stand up the endpoint</h3><p>Now that we have our Triton BLS image sitting in ECR, let’s create the SageMaker endpoint.</p><pre>aws sagemaker create-model --region us-east-1 \<br>  --model-name whisper-2501 \<br>  --execution-role-arn &lt;execution-role-arn&gt; \<br>  --primary-container &quot;{<br>      \&quot;Image\&quot;: \&quot;&lt;ECR image URI&gt;\&quot;,<br>      \&quot;ModelDataUrl\&quot;: \&quot;s3://whisper-triton-us-east/triton-2501/model-2501.tar.gz\&quot;,<br>      \&quot;Environment\&quot;: {\&quot;SAGEMAKER_TRITON_DEFAULT_MODEL_NAME\&quot;: \&quot;whisper_bls\&quot;,<br>      \&quot;TRITON_MODEL_NAME\&quot;: \&quot;whisper_bls\&quot;}<br>  }&quot;<br><br>aws sagemaker create-endpoint-config --region us-east-1 \<br>  --endpoint-config-name whisper-2501-config \<br>  --production-variants &quot;[{<br>      \&quot;VariantName\&quot;: \&quot;AllTraffic\&quot;,<br>      \&quot;ModelName\&quot;: \&quot;whisper-2501\&quot;,<br>      \&quot;InstanceType\&quot;: \&quot;ml.g5.2xlarge\&quot;,<br>      \&quot;InitialInstanceCount\&quot;: 1,<br>      \&quot;InferenceAmiVersion\&quot;: \&quot;al2-ami-sagemaker-inference-gpu-3-1\&quot;,<br>      \&quot;ModelDataDownloadTimeoutInSeconds\&quot;: 1200,<br>      \&quot;ContainerStartupHealthCheckTimeoutInSeconds\&quot;: 900<br>  }]&quot;<br><br>aws sagemaker create-endpoint --region us-east-1 \<br>  --endpoint-name whisper-2501-endpoint \<br>  --endpoint-config-name whisper-2501-config<br><br>aws sagemaker wait endpoint-in-service --region us-east-1 --endpoint-name whisper-2501-endpoint</pre><h3>Step 5: Inference</h3><p>Phew!! We have everything setup now, so let’s call the model and test the latency.</p><pre>import boto3<br>import json<br>import soundfile as sf<br>import numpy as np<br>import time<br><br>audio_path = &quot;&lt;audio path&gt;&quot;<br>waveform, sample_rate = sf.read(audio_path)<br><br>assert sample_rate == 16000, f&quot;Expected 16kHz, got {sample_rate}&quot;<br>waveform = waveform.astype(np.float32)<br><br>text_prefix = &quot;&lt;|startoftranscript|&gt;&quot;<br><br>payload = {<br>    &quot;inputs&quot;: [<br>        {&quot;name&quot;: &quot;TEXT_PREFIX&quot;, &quot;shape&quot;: [1, 1], &quot;datatype&quot;: &quot;BYTES&quot;,<br>         &quot;data&quot;: [text_prefix]},<br>        {&quot;name&quot;: &quot;WAV&quot;, &quot;shape&quot;: [1, len(waveform)], &quot;datatype&quot;: &quot;FP32&quot;,<br>         &quot;data&quot;: waveform.tolist()},<br>        {&quot;name&quot;: &quot;WAV_LENS&quot;, &quot;shape&quot;: [1, 1], &quot;datatype&quot;: &quot;INT32&quot;,<br>         &quot;data&quot;: [len(waveform)]},<br>    ]<br>}<br><br>runtime = boto3.client(&quot;sagemaker-runtime&quot;, region_name=&quot;us-east-1&quot;)<br><br>start = time.perf_counter()<br>response = runtime.invoke_endpoint(<br>    EndpointName=&quot;whisper-2501-endpoint&quot;,<br>    ContentType=&quot;application/json&quot;,<br>    Body=json.dumps(payload),<br>)<br>end = time.perf_counter()<br><br>result = json.loads(response[&quot;Body&quot;].read().decode(&quot;utf8&quot;))<br><br>print(f&quot;Latency: {(end-start)*1000} ms&quot;)<br><br># Response format matches Triton&#39;s KServe JSON output<br>transcript = result[&quot;outputs&quot;][0][&quot;data&quot;][0]<br><br>print(&quot;Transcript:&quot;, transcript)</pre><p>One deliberate choice here: since the audio is Hindi-English code-switched, we leave TEXT_PREFIX as just &lt;|startoftranscript|&gt;, no forced language token and let Whisper’s own language auto-detection handle it per utterance.</p><h3>Results</h3><p>Running a real Hindi-English code-switched sample against the compiled TensorRT-LLM + Triton pipeline:</p><pre>{&#39;model_name&#39;: &#39;whisper_bls&#39;, <br>&#39;model_version&#39;: &#39;1&#39;, <br>&#39;outputs&#39;: [<br>  {&#39;name&#39;: &#39;TRANSCRIPTS&#39;, <br>  &#39;datatype&#39;: &#39;BYTES&#39;, <br>  &#39;shape&#39;: [1],<br>  &#39;data&#39;: [&quot;So the question is what&#39;s your favourite festival? How did you celebrate your last festival? What do you feel about that?&quot;]<br>  }]<br>}</pre><p><strong>SageMaker endpoint:</strong></p><ul><li>Client-side latency: <strong>526.8 ms</strong></li><li>Model latency: <strong>309 ms</strong></li></ul><p><strong>Local Docker container (dry run):</strong></p><ul><li>Latency: <strong>339.3 ms</strong></li><li>RTF (real-time factor): <strong>0.0488</strong>, a 7-second clip transcribed in 0.342s of processing time. <em>[Note: </em><strong><em>RTF &lt; 1.0 (Faster than real-time):</em></strong><em> The system processes audio quicker than it is spoken or played. Essential for streaming and efficient batch processing. It is calculated as: </em><strong><em>RTF = Processing Time / Audio Duration.]</em></strong></li></ul><p>That’s a drop from the original <strong>3.4929s</strong> plain-endpoint baseline down to roughly <strong>310–530 ms</strong> end-to-end, depending on whether you’re measuring model-only time or full client round-trip, a <strong>6–10x</strong> latency reduction, and an RTF well under 0.05 means the pipeline transcribes audio in a small fraction of its playback duration.</p><h3>Takeaways</h3><ul><li><strong>Not every architecture gets JIT compilation for free.</strong> SageMaker LMI’s convenience only extends to decoder-only architectures with existing TensorRT-LLM conversion scripts. Encoder-decoder models like Whisper need an ahead-of-time build.</li><li><strong>Ahead-of-time (AOT) compilation means owning the artifact lifecycle.</strong> Two separately compiled engines, pushed to ECR, decoupled from the serving container, the tradeoff for the latency win is more moving parts to manage.</li><li><strong>BLS is the glue.</strong> For any model that isn’t a single forward pass, Triton’s Business Logic Scripting is what lets you express “run the encoder, then feed its output into the decoder” as an orchestrated request rather than two separate calls.</li><li><strong>CUDA version matching matters more than it looks like it should.</strong> SageMaker’s forward compatibility and the Triton image’s CUDA version need to agree, and newer inference AMIs no longer auto-mount the CUDA library path.</li><li><strong>The AOT investment paid off.</strong> Going from a 3.4929s plain-endpoint baseline to ~310–530ms end-to-end is a 6–10x latency reduction, the extra build/deploy complexity of TensorRT-LLM + Triton was worth it for a real-time use case.</li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=a394c5714c40" width="1" height="1" alt=""><hr><p><a href="https://medium.com/humaineeti-ai/chasing-lower-latency-for-a-fine-tuned-whisper-from-sagemaker-jit-to-tensorrt-llm-triton-a394c5714c40">Chasing Lower Latency for a Fine-Tuned Whisper: From SageMaker JIT to TensorRT-LLM + Triton</a> was originally published in <a href="https://medium.com/humaineeti-ai">humaineeti-ai</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
    </channel>
</rss>