Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -537,6 +537,14 @@ if(TRTMC_BUILD_TESTS)
target_compile_options(test_cli PRIVATE -Wall -Wextra -Wpedantic)
add_test(NAME cli COMMAND test_cli)

add_executable(test_video_classification_cli apps/cli/tests/test_video_classification_cli.cpp)
target_include_directories(test_video_classification_cli PRIVATE ${PROJECT_SOURCE_DIR}/apps)
target_link_libraries(test_video_classification_cli PRIVATE trtmc_cli nlohmann_json::nlohmann_json)
target_compile_options(test_video_classification_cli PRIVATE -Wall -Wextra -Wpedantic)
add_test(NAME video_classification_cli COMMAND test_video_classification_cli
${CMAKE_BINARY_DIR}/video-classification-cli-test)


if(TRTMC_BUILD_SERVER)
add_executable(test_server_worker apps/server/tests/test_native_worker.cpp)
target_include_directories(test_server_worker PRIVATE
Expand Down
104 changes: 64 additions & 40 deletions apps/cli/cli.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@ const std::unordered_map<std::string, CommandSpec>& command_specs() {
{"--text", "--token-ids", "--image", "--title", "--body", "--role"}}},
{"rerank", {CommandKind::kRerank, {"--query", "--document", "--image", "--documents"}}},
{"classify", {CommandKind::kClassify, {"--image", "--audio"}}},
{"classify-video", {CommandKind::kClassifyVideo, {"--frame"}}},
{"detect", {CommandKind::kDetect, {"--image", "--prompt"}}},
{"layout", {CommandKind::kLayout, {"--image"}}},
{"extract-features", {CommandKind::kExtractFeatures, {"--image"}}},
Expand Down Expand Up @@ -893,6 +894,26 @@ int dispatch(const Command& command, ITask& task, std::ostream& output) {
{"top_score", result.top_score}});
return EXIT_SUCCESS;
}
case CommandKind::kClassifyVideo: {
if (command.frames.empty())
throw std::invalid_argument("classify-video requires at least one --frame");
std::vector<io::LoadedImage> images;
images.reserve(command.frames.size());
for (const auto& path : command.frames)
images.push_back(read_image(path));
VideoClassificationRequest request;
for (const auto& image : images)
request.frames.push_back({image.pixels.data(), image.pixels.size(), image.height,
image.width, VideoFrameFormat::kRgbFloat32});
const auto result = require_interface<IVideoClassification>(task).classify(request);
require_finite(result.logits, "video classification logits");
if (!std::isfinite(result.top_score))
throw std::runtime_error("video classification returned a non-finite top score");
write_json(output, {{"logits", result.logits},
{"top_class", result.top_class},
{"top_score", result.top_score}});
return EXIT_SUCCESS;
}
case CommandKind::kDetect: {
const io::LoadedImage image = read_image(require_option(command, "--image"));
const auto result = require_interface<IObjectDetection>(task).detect(
Expand Down Expand Up @@ -1631,46 +1652,49 @@ int dispatch(const Command& command, const Model& model, std::ostream& output) {
}

void print_usage(std::ostream& output) {
output << "Usage:\n"
" trtmc version\n"
" trtmc inspect BUNDLE\n"
" trtmc COMMAND BUNDLE [--runtime-root DIR] [OPTIONS]\n\n"
"Execution commands:\n"
" run, encode, embed, rerank, classify, detect, layout, extract-features,\n"
" predict-structure, disparity, depth, geometry,\n"
" segment,\n"
" segment-prompted, video-segment, generate-audio, transcribe,\n"
" transcribe-batch, transcribe-streaming, speak, speech-session, generate-image,\n"
" generate-image-batch, generate-video,\n"
" solve, forecast, control, generate-world\n\n"
"Text diffusion replay options:\n"
" [--generation-mode MODE] [--block-length N] [--threshold S]\n"
" --initial-latents-raw PATH [--condition-latents-raw PATH\n"
" --condition-mask-raw PATH] [--sampling-steps-raw PATH]\n"
" [--sde-noise-raw PATH] [--num-steps N] [--guidance-scale S]\n"
" [--cfg-scale S] [--sde-gamma S]\n\n"
"Text generation options:\n"
" [--source-language-token-id N] [--forced-bos-token-id N]\n\n"
"Offline transcription options:\n"
" [--beam-size N] [--length-penalty F] [--punctuation true|false]\n"
" [--max-input-seconds F] [--segment-length-seconds F]\n"
" [--segment-min-seconds F] [--segment-overlap-seconds F]\n"
" [--lcs-merge true|false]\n\n"
"Molecular structure input:\n"
" predict-structure BUNDLE --input REQUEST [--input-encoding ENCODING]\n"
" .yaml/.yml, .json and .b2rq select their declared encodings.\n"
" SDK output defaults to prediction.cif or prediction.pdb.\n\n"
"Audio classification input:\n"
" classify BUNDLE --audio WAV scores an audio model's own classes;\n"
" classify BUNDLE --image FILE stays the image path.\n\n"
"BYOK options:\n"
" --byok-library DSO --byok-function FUNCTION --byok-name KERNEL\n\n"
"Runtime-sized KV cache:\n"
" [--kv-cache-size BYTES|GB|GiB]\n\n"
"TensorRT-RTX runtime options:\n"
" [--runtime-cache PATH] [--cuda-graphs]\n\n"
"Task SDK options: [--task TASK_ID] [--set NAME=VALUE]...\n"
"Without --runtime-root, plugins load from the installed runtime directory.\n";
output
<< "Usage:\n"
" trtmc version\n"
" trtmc inspect BUNDLE\n"
" trtmc COMMAND BUNDLE [--runtime-root DIR] [OPTIONS]\n\n"
"Execution commands:\n"
" run, encode, embed, rerank, classify, classify-video, detect, layout, "
"extract-features,\n"
" predict-structure, disparity, depth, geometry,\n"
" segment,\n"
" segment-prompted, video-segment, generate-audio, transcribe,\n"
" transcribe-batch, transcribe-streaming, speak, speech-session, generate-image,\n"
" generate-image-batch, generate-video,\n"
" solve, forecast, control, generate-world\n\n"
"Text diffusion replay options:\n"
" [--generation-mode MODE] [--block-length N] [--threshold S]\n"
" --initial-latents-raw PATH [--condition-latents-raw PATH\n"
" --condition-mask-raw PATH] [--sampling-steps-raw PATH]\n"
" [--sde-noise-raw PATH] [--num-steps N] [--guidance-scale S]\n"
" [--cfg-scale S] [--sde-gamma S]\n\n"
"Text generation options:\n"
" [--source-language-token-id N] [--forced-bos-token-id N]\n\n"
"Offline transcription options:\n"
" [--beam-size N] [--length-penalty F] [--punctuation true|false]\n"
" [--max-input-seconds F] [--segment-length-seconds F]\n"
" [--segment-min-seconds F] [--segment-overlap-seconds F]\n"
" [--lcs-merge true|false]\n\n"
"Molecular structure input:\n"
" predict-structure BUNDLE --input REQUEST [--input-encoding ENCODING]\n"
" .yaml/.yml, .json and .b2rq select their declared encodings.\n"
" SDK output defaults to prediction.cif or prediction.pdb.\n\n"
"Audio classification input:\n"
" classify BUNDLE --audio WAV scores an audio model's own classes;\n"
" classify BUNDLE --image FILE stays the image path.\n"
" classify-video BUNDLE --frame FILE [--frame FILE ...] scores ordered RGB frames.\n\n"
"BYOK options:\n"
" --byok-library DSO --byok-function FUNCTION --byok-name KERNEL\n\n"
"Runtime-sized KV cache:\n"
" [--kv-cache-size BYTES|GB|GiB]\n\n"
"TensorRT-RTX runtime options:\n"
" [--runtime-cache PATH] [--cuda-graphs]\n\n"
"Task SDK options: [--task TASK_ID] [--set NAME=VALUE]...\n"
"Without --runtime-root, plugins load from the installed runtime directory.\n";
}

int run(int argc, char** argv, std::ostream& output, std::ostream& error) {
Expand Down
1 change: 1 addition & 0 deletions apps/cli/cli.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ enum class CommandKind {
kEmbed,
kRerank,
kClassify,
kClassifyVideo,
kDetect,
kLayout,
kExtractFeatures,
Expand Down
85 changes: 85 additions & 0 deletions apps/cli/tests/test_video_classification_cli.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
/*
* SPDX-FileCopyrightText: Copyright (c) 2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
* SPDX-License-Identifier: Apache-2.0
*/
#include "cli/cli.h"
#include "cli/io.h"
#include "task_runtime.h"

#include <filesystem>
#include <iostream>
#include <nlohmann/json.hpp>
#include <sstream>
#include <stdexcept>
#include <type_traits>
static_assert(std::is_abstract_v<trtmc::IVideoClassification>);
namespace {
void check(bool x, const char* message) {
if (!x)
throw std::runtime_error(message);
}
trtmc::cli::Command parse(std::vector<std::string> args) {
std::vector<char*> argv;
for (auto& s : args)
argv.push_back(s.data());
return trtmc::cli::parse_args(static_cast<int>(argv.size()), argv.data());
}
class Video final : public trtmc::IVideoClassification {
public:
int calls{0};
trtmc::ClassificationResult
classify(const trtmc::VideoClassificationRequest& request) override {
++calls;
check(request.frames.size() == 2, "frame sequence size changed");
const auto& a = request.frames[0];
const auto& b = request.frames[1];
check(a.height == 1 && a.width == 1 && a.element_count == 3 &&
a.format == trtmc::VideoFrameFormat::kRgbFloat32,
"frame format changed");
check(static_cast<const float*>(a.pixels)[0] == 1 &&
static_cast<const float*>(a.pixels)[2] == 0 &&
static_cast<const float*>(b.pixels)[0] == 0 &&
static_cast<const float*>(b.pixels)[2] == 1,
"frame order or RGB values changed");
return {{-2, 3}, 1, 0.9F};
}
};
} // namespace
int main(int argc, char** argv) {
try {
if (argc != 2)
throw std::invalid_argument("usage: test_video_classification_cli TEMP_DIR");
const std::filesystem::path root(argv[1]);
std::filesystem::create_directories(root);
const auto a = (root / "first.png").string(), b = (root / "second.png").string();
trtmc::cli::io::save_png(a, {1, 0, 0}, 1, 1);
trtmc::cli::io::save_png(b, {0, 0, 1}, 1, 1);
Video task;
check(trtmc::app::uses_existing_task_runtime(task.task()),
"video Task loader selection missing");
const auto command =
parse({"trtmc", "classify-video", "fixture.bundle", "--frame", a, "--frame", b});
check(command.kind == trtmc::cli::CommandKind::kClassifyVideo &&
command.frames == std::vector<std::string>{a, b},
"frame arguments reordered");
std::ostringstream output;
check(trtmc::cli::dispatch(command, task, output) == 0, "dispatch failed");
const auto result = nlohmann::json::parse(output.str());
check(result.at("logits") == std::vector<float>{-2, 3} && result.at("top_class") == 1,
"class scores changed");
bool rejected = false;
try {
std::ostringstream ignored;
(void)trtmc::cli::dispatch(parse({"trtmc", "classify-video", "fixture.bundle"}), task,
ignored);
} catch (const std::invalid_argument&) {
rejected = true;
}
check(rejected && task.calls == 1, "empty clip reached the family");
std::cout << "Ordered RGB frames and video classification CLI passed\n";
return 0;
} catch (const std::exception& e) {
std::cerr << e.what() << '\n';
return 1;
}
}
1 change: 1 addition & 0 deletions apps/task_runtime.h
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ inline bool uses_existing_task_runtime(std::string_view primary_task) noexcept {
IMonocularDepth::kTask,
IMonocularGeometry::kTask,
IImageClassification::kTask,
IVideoClassification::kTask,
IObjectDetection::kTask,
IDocumentLayout::kTask,
IPoseHypothesisRefinement::kTask,
Expand Down
13 changes: 13 additions & 0 deletions core/runtime/include/trtmc/task.h
Original file line number Diff line number Diff line change
Expand Up @@ -327,6 +327,12 @@ struct VideoFrameView {
VideoFrameFormat format{VideoFrameFormat::kRgb8};
};

// Frames are ordered in time. RGB8 uses scalar byte count; RGB float uses
// scalar float count and values in [0,1]. The caller retains storage during classify().
struct VideoClassificationRequest {
std::vector<VideoFrameView> frames;
};

struct VideoSegmentationRequest {
std::vector<VideoFrameView> frames;
std::string text_prompt;
Expand Down Expand Up @@ -785,6 +791,13 @@ class IImageClassification : public virtual ITask {
std::int32_t width) = 0;
};

class IVideoClassification : public virtual ITask {
public:
static constexpr const char* kTask = "video_classification";
const char* task() const noexcept override { return kTask; }
virtual ClassificationResult classify(const VideoClassificationRequest& request) = 0;
};

class IObjectDetection : public virtual ITask {
public:
static constexpr const char* kTask = "object_detection";
Expand Down
37 changes: 37 additions & 0 deletions families/vivit/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
# ViViT

This family runs `google/vivit-b-16x2` at revision
`fc341053d36b42d446b3ffccdbd52452712a23f3` as FP32 TensorRT video classification.
The profile takes exactly 32 ordered RGB frames, uses the published bilinear
shortest-edge resize to 256 and center crop to 224, and returns all 400 Kinetics
class logits, the top class index, and its softmax probability.

The native `IVideoClassification` Task accepts interleaved RGB bytes or finite
RGB floats in [0,1]. Frames may have different source dimensions. The caller
selects and orders frames; the family does not decode or sample video files.
The CLI accepts the same sequence through repeated `--frame` arguments:

```bash
frames=()
for frame in frames/frame-{00..31}.png; do frames+=(--frame "$frame"); done
trtmc classify-video model.bundle "${frames[@]}"
```

The family owns Conv3D tubelets, positional embeddings, all twelve encoder
layers, the classification head, preprocessing and native orchestration. All
GPU computation uses TensorRT operators. Batch size is one; FP16, quantization,
parallel execution, other frame counts, resolution changes and KV caches are
explicitly rejected. The published PyTorch state dictionary is loaded with
`weights_only=True`.

Select the pinned E2E with:

```bash
python -m pytest families/vivit/tests --e2e-model vivit -q
```

The test compares upstream intermediate tensors on a nondegenerate small
model, all logits and probabilities on natural-image and moving-pattern clips,
Pillow preprocessing, both public frame formats, the CLI, repeated requests,
and recovery after malformed clips. Plans and validation artifacts are external
to the source branch.
3 changes: 3 additions & 0 deletions families/vivit/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# SPDX-FileCopyrightText: Copyright (c) 2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
# SPDX-License-Identifier: Apache-2.0
"""ViViT video classification family."""
Loading
Loading