Hi @s.priyadarshi629, thanks for sharing the dense vs sparse numbers. These results are plausible, especially the split you are seeing: almost no gain on ResNet50, and a more visible gain on ViT-B/16.
The main thing to keep in mind is that 2:4 sparsity is not a model-level 2x switch. TensorRT can only use sparse tactics on layers whose weights satisfy the 2:4 pattern, whose shapes map well to sparse kernels, and whose runtime is a large enough part of the full network. If the sparse-eligible layers are not the bottleneck, the end-to-end speedup can be small even when the pruning itself is correct.
For your two examples, the direction makes sense:
| Model |
Your result |
How I would read it |
| ResNet50 |
~1.007x |
Very possible if dense convs are already fast, if non-sparse layers dominate, or if TensorRT is not selecting many sparse tactics. |
| ViT-B/16 |
~1.195x |
More believable because the larger GEMM / projection layers tend to expose sparse Tensor Core gains more cleanly. |
I would debug this in three steps.
1. Confirm TensorRT is actually using sparse tactics
For an accuracy-preserving run, use the pruned ONNX and --sparsity=enable, not --sparsity=force. force is useful only as a quick performance ceiling because it can rewrite weights and does not preserve accuracy.
trtexec \
--onnx=asp_resnet50.onnx \
--fp16 \
--sparsity=enable \
--verbose \
--buildOnly \
2>&1 | tee sparse_build.log
If you are building through the TensorRT Python API, make sure the builder config has sparse weights enabled:
config.set_flag(trt.BuilderFlag.SPARSE_WEIGHTS)
Then check the verbose log for how many layers are eligible for sparse tactics and how many sparse tactics are selected.
2. Compare the per-layer profiles, not just the final mean latency
Run dense and sparse with the same precision, same input shape, same batch size, and the same timing setup:
# Dense baseline
trtexec \
--onnx=dense_resnet50.onnx \
--fp16 \
--sparsity=disable \
--shapes=input:128x3x224x224 \
--useCudaGraph \
--noDataTransfers \
--profilingVerbosity=detailed \
--dumpLayerInfo \
--dumpProfile \
--exportLayerInfo=dense_layers.json \
--exportProfile=dense_profile.json \
2>&1 | tee dense.log
# ASP / sparse run
trtexec \
--onnx=asp_resnet50.onnx \
--fp16 \
--sparsity=enable \
--shapes=input:128x3x224x224 \
--useCudaGraph \
--noDataTransfers \
--profilingVerbosity=detailed \
--dumpLayerInfo \
--dumpProfile \
--exportLayerInfo=sparse_layers.json \
--exportProfile=sparse_profile.json \
2>&1 | tee sparse.log
Replace input:128x3x224x224 with the real input tensor name and shape from your model.
3. Measure FP16 and INT8 separately
Sparse FP16 and sparse INT8 do not always show the same end-to-end delta. INT8 dense kernels can already be fast, and calibration / Q-DQ placement can change which layers dominate the profile. I would first get a clean FP16 sparse-vs-dense comparison, then repeat the same profile comparison for INT8 after the calibration path is fixed.
One data point that would help: can you paste the verbose sparsity summary plus the top --dumpProfile rows for one ResNet50 run, dense vs ASP, at batch 128? That will show whether the issue is “sparse tactics are not being selected” or “sparse tactics are selected, but the model bottleneck moved somewhere else.”
Thanks,
Atharva