ANSFR: purge stale ServerOptimised zip when engine rebuilds from ONNX
A ServerOptimised zip is a per-GPU cache of a previous engine build. When the engine profile changes (batch gate, TRT/CUDA upgrade), the cached engine inside it goes stale: every re-extract (e.g. after Temp cleanup) restores the old engine and costs a full ONNX rebuild, forever, because the server only regenerates the zip when the file is missing. Engine now records rebuiltFromOnnx() + engineFilePath() in buildLoadNetwork (set only on the generate-from-ONNX branch; cache hits and alternative-precision loads don't raise it). After a rebuild, ANSFaceRecognizer::Initialize deletes the stale same-GPU engine variants from the model folder and the supplied optimised zip, so the server's next optimize pass recreates it with the fresh engine. Safety: only zips whose parent folder is ServerOptimised/-ized qualify — base model zips can never match. Engine purge is scoped to the "<model>.engine.<GPU>." prefix, leaving other GPUs' engines intact on multi-GPU machines. All deletes are best-effort (error_code); multi-GPU pool paths never set the flag, so the purge is a no-op there. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
@@ -180,6 +180,14 @@ public:
|
||||
[[nodiscard]] const std::vector<nvinfer1::Dims> &getOutputDims() const override { return m_outputDims; };
|
||||
[[nodiscard]] const ANSCENTER::Options& getOptions() const { return m_options; }
|
||||
|
||||
/// True when the last buildLoadNetwork() had to build the engine from ONNX
|
||||
/// because no cached engine matched the current profile (GPU / precision /
|
||||
/// batch / TRT version). Callers use this to invalidate stale caches that
|
||||
/// carried the old engine (e.g. ServerOptimised model zips).
|
||||
[[nodiscard]] bool rebuiltFromOnnx() const { return m_rebuiltFromOnnx; }
|
||||
/// Full path of the engine file resolved by the last buildLoadNetwork().
|
||||
[[nodiscard]] const std::string& engineFilePath() const { return m_engineFilePath; }
|
||||
|
||||
/// Return the CUDA device index that preprocessing should target.
|
||||
/// In pool mode this returns the device of the first alive slot;
|
||||
/// in single-engine mode it returns m_options.deviceIndex.
|
||||
@@ -393,6 +401,8 @@ private:
|
||||
bool m_usingCachedEngine = false;
|
||||
bool m_skipEngineCache = false; // true = bypass TRTEngineCache (for OptimizeModelStr)
|
||||
bool m_skipOnnxRebuild = false; // true = don't delete/rebuild corrupt engine files (elastic growth)
|
||||
bool m_rebuiltFromOnnx = false; // last buildLoadNetwork built from ONNX (no matching cached engine)
|
||||
std::string m_engineFilePath; // engine file resolved by last buildLoadNetwork
|
||||
bool m_skipOnnxBuild = false; // true = skip ONNX→TRT build if no cached engine (demand growth)
|
||||
bool m_lastLoadFailedVRAM = false; // set by loadNetwork when failure is due to insufficient VRAM
|
||||
bool m_forceNoPool = false; // true = force single-GPU path, skip multi-GPU pool
|
||||
|
||||
Reference in New Issue
Block a user