TRT/TRT-LLM support for NestedTensor / jagged or ragged tensors for doing away with padding #1469
Replies: 1 comment
-
|
Short answer: no — TensorRT and TensorRT-LLM do not currently support PyTorch NestedTensor or true ragged/jagged tensor execution in the way PyTorch SDPA does. But there are a few important nuances and partial alternatives. 1. Does TensorRT / TensorRT-LLM support NestedTensor?❌ Native support: NO
There is:
2. Why not? (core reason)TensorRT is built around:
That requires:
Ragged tensors break this assumption because:
3. What TensorRT-LLM uses insteadInstead of NestedTensor, TensorRT-LLM uses: ✔ 1. Packed sequences + KV cache indexingInternally, it supports:
This allows logical raggedness, but physical storage is still dense. ✔ 2. In-flight batching (important)TensorRT-LLM runtime (executor) supports:
But still:
✔ 3. FlashAttention-style masked kernelsTensorRT-LLM integrates optimized attention kernels (FlashAttention-like):
So:
4. Does FlashAttention support NestedTensor?Partially yes (PyTorch ecosystem)PyTorch SDPA + NestedTensor:
BUT: ❌ TensorRT-LLM does NOT use PyTorch SDPA❌ and does NOT consume NestedTensor inputsInstead it uses:
5. What about “true ragged execution”?What you're describing:
This would require:
👉 This is currently not supported in TensorRT 6. Closest existing alternatives in TensorRT-LLM✔ Paged KV cache (important)This is the closest concept to “ragged efficiency”:
But:
✔ Token-level schedulingInstead of sequence-level compute:
This improves efficiency but does not remove padding entirely. 7. Why fully ragged execution is hard on GPUsEven if theoretically possible:
So industry compromise is:
8. Bottom line
Final takeawayTensorRT-LLM chooses:
instead of:
So you get most of the performance benefits (via FlashAttention + KV paging), but not full NestedTensor-style compute elimination. 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.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
Does TRT / TRT-LLM support pytorch's concept of NestedTensor or is there some similar concept?
The idea is to not compute FeedForward's on padded-out positions and skip attention computation for them as well
I guess the question also becomes of whether underlying flash attention implementation supports such jagged compact formats.
In PyTorch it seems that they support SDPA with NestedTensor for speedups: pytorch/pytorch#105913 (comment) (can be useful for batched BERT inference)
Thanks!
Beta Was this translation helpful? Give feedback.
All reactions