My llava1.5 7b can get output, but how to set it up to get the same output as transformers #1180
-
|
I can use the transformer interface to input text and images for output。The parameters passed in by tensorrt-llm are not the same. How to ensure that the same model can obtain same results that are consistent with transformers or tensorrt-llm.trt model.generate()'s param not same with transformers LlavaForConditionalGeneration.Is there a one-to-one corresponding parameter pair? |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment
-
|
This is a very common issue when comparing Hugging Face Transformers vs TensorRT-LLM outputs for LLaVA. Even when using the same model weights, getting bitwise or even token-identical outputs is non-trivial because the two runtimes differ in decoding, sampling, and sometimes even preprocessing. 1. Why outputs differ in the first placeEven if the model is identical, differences come from: 🔴 A. Tokenization + prompt formattingTransformers LLaVA typically uses:
TensorRT-LLM uses:
👉 Even small prompt differences = different outputs 🔴 B. Sampling implementation differencesTransformers: model.generate(
temperature=0.7,
top_p=0.9,
repetition_penalty=1.1
)TensorRT-LLM:
🔴 C. Numerical differences (FP16 / FP32 / fused kernels)TensorRT-LLM uses:
👉 small numeric drift → different token choices 2. Is there a 1-to-1 mapping of parameters?❌ No exact 1-to-1 mapping existsBut there is a functional equivalence mapping. 3. Approximate parameter mappingTransformers → TensorRT-LLM
4. Critical differences for LLaVA specificallyLLaVA adds extra complexity: 🔴 Image processing must match exactlyYou must ensure:
Even a slight mismatch → different text output 🔴 Image token placementTransformers: TensorRT-LLM:
5. How to get closest possible matching outputs✔ Step 1: Disable randomnessMake both deterministic: Transformers: do_sample=FalseTensorRT-LLM: temperature = 0
top_k = 1✔ Step 2: Match prompt exactlyEnsure identical:
Even whitespace matters. ✔ Step 3: Use greedy decoding in bothThis is the only practical way to get near-identical outputs. ✔ Step 4: Match precisionTry:
Avoid mixing fp32/fp16. ✔ Step 5: Fix RNG seed (if sampling)If sampling:
But note: So still not guaranteed identical. 6. Why perfect matching is not realisticEven if everything is identical:
👉 leads to divergence after a few tokens This is expected in LLM inference engines. 7. What you can achieve in practice
8. Best practice recommendationIf your goal is validation: 👉 Use Transformers as ground truth And compare at:
Bottom line
If this answer helped or pointed you in the right direction, I'd appreciate it if you could mark it as the accepted answer so it's easier for others with the same issue to find. Also, if you found my contribution useful, I'd appreciate it if you could check out my GitHub profile, follow me, and star any repositories you find interesting. GitHub: https://github.com/Advait251206 |
Beta Was this translation helpful? Give feedback.
This is a very common issue when comparing Hugging Face Transformers vs TensorRT-LLM outputs for LLaVA. Even when using the same model weights, getting bitwise or even token-identical outputs is non-trivial because the two runtimes differ in decoding, sampling, and sometimes even preprocessing.
1. Why outputs differ in the first place
Even if the model is identical, differences come from:
🔴 A. Tokenization + prompt formatting
Transformers LLaVA typically uses:
apply_chat_template()<image>,<|im_start|>etc.)TensorRT-LLM uses:
👉 Ev…