Repository navigation
Conversation
…inDynamic v4/v5 getFieldsToSerialize() pointed the kINT32 "output_fp16" PluginField at a local bool. TensorRT reads PluginField::data after the call returns, so it copied 4 bytes from a dead 1-byte stack slot, and FP32 engines could be recreated as FP16 at deserialization. Back the field with an int32_t member. The serialized schema is unchanged. Signed-off-by: targabor <tar.gabor14@gmail.com>
pranavm-nvidia
approved these changes
Oct 13, 2026
Author
|
Thanks for the approval, @pranavm-nvidia Just checking whether there's anything else needed from my side before this can be merged. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #4876.
Root cause
EmbLayerNormVarSeqlenPluginBase::getFieldsToSerialize()(used byCustomEmbLayerNormPluginDynamicv4 HFace and v5 MTron) pointed theoutput_fp16PluginField at a localbool:PluginField::dataaftergetFieldsToSerialize()returns, by which time the local is gone.kINT32with length 1, so TensorRT copies 4 bytes from a 1-bytebool.The engine therefore stores stack garbage for
output_fp16. The creator decodes it with!= 0, so an FP32 plugin is recreated as FP16 at deserialization. The first inference then aborts onPLUGIN_ASSERT(outputs[0].type == mType)(.cpp:354for v5,:325for v4). FP16 engines decode correctly only by accident.Fix
int32_t mOutputFp16{}member, set ingetFieldsToSerialize(). This is the same patternembLayerNormPlugin.cppandfftPlugin.cppalready use.kINT32, length 1, same field order. Newly built engines carry exactly 0 or 1.embLayerNormVarSeqlenPlugin.handembLayerNormVarSeqlenPlugin.cppchange (+7/−4), with no build-system or API changes.Validation
Linux, GCC 13.3, CUDA 13.0, TensorRT 11.4.0.106 (
tensorrt-cu13wheel), RTX 5070 Ti (SM 12.0).The full repository CMake configure needs the TensorRT-Enterprise package, which I don't have. I therefore built the plugin sources (
embLayerNormVarSeqlenPlugin*.cpp, the HFace/MTron kernels,plugin/common) into a standalone library against the 11.4 wheel. I validated two builds of that library with the same toolchain and flags: one from unmodifiedmain(16ed063), one with this patch.Regression test (RED/GREEN). A GoogleTest, run on the plugin and on its
clone()for v4/v5 × FP32/FP16. For each case it:getFieldsToSerialize();output_fp16is a singlekINT32equal to exactly 0 or 1;TensorRTPhase::kRUNTIME;stack-use-after-returnon'output_fp16'for each caseASan. The plugin and test were built with
-fsanitize=addressand run withdetect_stack_use_after_return=1. Without the fix, ASan reports a 4-byte read from the 1-byteoutput_fp16ingetFieldsToSerialize()'s dead frame:With the fix there are no ASan reports, in the unit test or in real engine build, deserialization and inference.
Real TensorRT 11.4 engines (build, then deserialize in a fresh process):
output_fp16value TensorRT passes tocreatePlugin(kRUNTIME)is exactly00 00 00 00/01 00 00 00for v4 and v5, FP32 and FP16. Without the fix it is garbage:c9 fd 7f 00with the official 11.4 wheel,00 04 00 00with my unpatched source build. The issue's reproducer shows this directly with itsinspectstep.:354.:325dtype assertion.Additional regression coverage. The GoogleTest above and an engine-level Python test are not part of this PR, to keep it minimal. No plugin in the repo has gtests yet, and wiring one into
plugin/CMake needs a decision on your side. I'm happy to add them in this PR or a follow-up, structured however you prefer.Notes
output_fp16and need to be rebuilt.PLUGIN_ASSERT(outputs[1].dims.nbDims == 0)(.cpp:327), which this PR does not address.