How vivek02sharma/sam3-triton works
Purpose and Entry Points
This repository serves Segment Anything 3 (SAM3) inference through NVIDIA Triton Inference Server, using TensorRT-backed model stages. The primary operational sequence is:
1. Build TensorRT engines with compile.sh.
2. Run Triton via docker-compose.yml.
3. Use the Streamlit client UI in app.py.
The container definition is Dockerfile; Python dependencies are managed through pyproject.toml and uv.lock.
Client Application
app.py is the interactive Streamlit entry point and Triton HTTP client. It submits inference requests to the server, using a pool of 32 HTTP connections to support concurrent interactions. The UI is outside Triton’s model execution boundary: it prepares requests, calls served models, and presents segmentation results.
Relevant path:
• app.py
Triton Model Repository
model_repository/ is Triton’s deployment boundary. It contains separately declared model stages and their config.pbtxt contracts, which define how Triton exposes, schedules, and connects each model.
Core model paths:
• model_repository/sam3_model/config.pbtxt
• model_repository/vision_encoder/config.pbtxt
• model_repository/text_encoder/config.pbtxt
• model_repository/mask_decoder/config.pbtxt
SAM3 Orchestration Layer
The top-level SAM3 Triton Python model coordinates the segmentation pipeline. It receives the high-level inference request and invokes the vision encoder, text encoder, and mask decoder stages. It transfers tensors between those stages using DLPack, avoiding host/PCIe copies and preserving GPU-resident data.
Relevant paths:
• model_repository/sam3_model/1/model.py
• model_repository/sam3_model/config.pbtxt
This is the principal control-flow boundary between client-facing SAM3 inference and the specialized TensorRT model components.
Encoder and Decoder Stages
SAM3 is decomposed into three serving components:
• The vision encoder derives image features.
• The text encoder derives prompt/text features.
• The mask decoder combines encoded inputs to produce segmentation masks.
Their Triton interfaces are defined independently, enabling Triton to schedule and dynamically batch requests at model boundaries.
Relevant paths:
• model_repository/vision_encoder/config.pbtxt
• model_repository/text_encoder/config.pbtxt
• model_repository/mask_decoder/config.pbtxt
Runtime, GPU, and External Assets
The runtime is NVIDIA Triton with TensorRT engines generated before server startup. Docker Compose runs the service and pins it to GPU 0; changing GPU allocation requires editing docker-compose.yml. The server readiness endpoint is exposed on port 9000 (/v2/health/ready).
Model source assets are external SAM3 ONNX artifacts referenced by the README; compilation converts or prepares them for the Triton/TensorRT deployment layout.
Relevant paths:
• compile.sh
• docker-compose.yml
• Dockerfile
Main entry points: model.py SAM3 orchestrator · config.pbtxt Mask decoder · compile.sh Engine compiler · docker-compose.yml Triton service launcher
Components 12
Build & Deployment
- SAM3 ONNX assets · External source artifacts used to build deployable engines.
- Engine compiler · Builds TensorRT engines for the model repository.
compile.sh - TensorRT engines · Prebuilt inference engines loaded by Triton.
- Triton service launcher · Runs Triton on GPU 0 and exposes readiness on port 9000.
docker-compose.yml - Runtime image
Dockerfile
Client
- Streamlit UI · Interactive UI and Triton HTTP client with a 32-connection pool.
app.py
Triton Model Repository
- NVIDIA Triton · Hosts and schedules the SAM3 model stages.
- SAM3 API contract · Client-facing SAM3 model interface.
model_repository/sam3_model/config.pbtxt - SAM3 orchestrator · Coordinates stages and transfers tensors through DLPack on GPU.
model_repository/sam3_model/1/model.py - Vision encoder · Produces image features.
model_repository/vision_encoder/config.pbtxt - Text encoder · Produces text prompt features.
model_repository/text_encoder/config.pbtxt - Mask decoder · Combines image and text features into segmentation masks.
model_repository/mask_decoder/config.pbtxt
Connections 14
- SAM3 ONNX assets → Engine compiler: input artifacts
- Engine compiler → TensorRT engines: builds
- Runtime image → Triton service launcher: defines image
- Triton service launcher → NVIDIA Triton: starts on GPU 0
- TensorRT engines → NVIDIA Triton: loaded at startup
- Streamlit UI → NVIDIA Triton: HTTP inference requests
- NVIDIA Triton → SAM3 API contract: exposes
- SAM3 API contract → SAM3 orchestrator: routes requests
- SAM3 orchestrator → Vision encoder: image tensors via DLPack
- SAM3 orchestrator → Text encoder: prompt tensors via DLPack
- Vision encoder → Mask decoder: image features
- Text encoder → Mask decoder: text features
- Mask decoder → SAM3 orchestrator: segmentation masks
- SAM3 orchestrator → Streamlit UI: inference results