feat(ANSODEngine): run a sealed model on TensorRT without unsealing it
A .ansmodel reaching the GPU path went to ModelOptimizer, which knows one way to open a model — unzip it — and failed on the first byte. Even past that, the TensorRT engine only ever parsed an ONNX file, so the one thing the format exists to prevent, a decrypted model on disk, was the only way it could have run. The builder now takes its bytes from memory when it has them. The path it is given still names the plan that gets cached beside it, because a plan is a built artefact and carries no model: the second run loads it and never needs the ONNX at all. For a package the plan lands in the folder the zip flow used, so a model converted from a zip reuses the plan that zip already built. OptimizeModelStr recognises a package and skips the unzip-and-optimise leg entirely: the handle below it opens the package in memory and builds the plan from the decrypted bytes, which is the same work by a shorter road. Still on the file path: the other TensorRT handlers (segmentation, pose, classification). Only the YOLO detector reads a package today. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
This commit is contained in:
@@ -8,6 +8,7 @@
|
||||
#include <climits> // INT_MIN
|
||||
#include "ANSLicense.h" // ANS_DBG macro for DebugView
|
||||
#include "ANSODVendorGate.h" // ansod_vendor_gate::IsNvidiaGpuAvailable()
|
||||
#include "ANSModelOpen.h" // modelpkg::IsPackagePath (sealed .ansmodel)
|
||||
|
||||
// Process-wide flag: when true, all engines force single-GPU path (no pool, no idle timers).
|
||||
// Defined here, declared extern in EngineBuildLoadNetwork.inl.
|
||||
@@ -1576,6 +1577,13 @@ ANSODENGINE_API int OptimizeModelStr(const char* modelFilePath, const char* mode
|
||||
modelType, modelDetectionType, fp16, modelFilePath ? modelFilePath : "(null)");
|
||||
try {
|
||||
bool optimizedResult = false;
|
||||
// A sealed .ansmodel is already the artefact: there is no zip to
|
||||
// inflate and no loose ONNX to point an optimiser at. It still goes
|
||||
// through the handle below, which opens it in memory and builds the
|
||||
// TensorRT plan from the decrypted bytes — what it must not go
|
||||
// through is ModelOptimizer, which only knows how to unzip.
|
||||
const bool sealedPackage =
|
||||
ANSCENTER::modelpkg::IsPackagePath(modelFilePath ? modelFilePath : "");
|
||||
// NOTE: odMutex was removed here. OptimizeModelStr creates its own
|
||||
// temporary Engine<float> on the stack — no shared state with running
|
||||
// inference tasks. The global mutex was blocking ALL running tasks'
|
||||
@@ -1628,7 +1636,7 @@ ANSODENGINE_API int OptimizeModelStr(const char* modelFilePath, const char* mode
|
||||
}
|
||||
|
||||
|
||||
if (modelType == 31) // If modelType is RTYOLO (31), handle separately.
|
||||
if (modelType == 31 && !sealedPackage) // If modelType is RTYOLO (31), handle separately.
|
||||
{
|
||||
if (engineType == ANSCENTER::EngineType::NVIDIA_GPU) {
|
||||
if (modelDetectionType == 0) {
|
||||
@@ -1778,7 +1786,10 @@ ANSODENGINE_API int OptimizeModelStr(const char* modelFilePath, const char* mode
|
||||
Handle.reset(); // Destroy engines BEFORE guard restores cache
|
||||
|
||||
|
||||
if (optimizedResult && !modelFolder.empty()) return 1;
|
||||
// A package reports the folder its plan was cached in; when the
|
||||
// handle declined to name one there is still nothing wrong, because
|
||||
// nothing was ever meant to be written.
|
||||
if (optimizedResult && (!modelFolder.empty() || sealedPackage)) return 1;
|
||||
else return 0;
|
||||
}
|
||||
catch (const std::exception& e) {
|
||||
|
||||
Reference in New Issue
Block a user