TensorRT icon indicating copy to clipboard operation
TensorRT copied to clipboard

Myelin error on onnx model: Assertion `i < crds_.size()' failed

Open lazycal opened this issue 4 years ago • 3 comments

Description

I got different result than PyTorch or a crash with error trtexec: /root/gpgpu/MachineLearning/myelin/src/compiler/.././compiler/kernel_gen/cuda_codegen/cuda_codegen.hpp:322: const string& myelin::kgen::cuda_codegen_t::crd_t::operator[](size_t) const: Assertion `i < crds_.size()' failed. when running on an onnx model that does reshape->sqrt->squeeze. The minimal reproducible model:

import numpy as np
import torch

inputs = {
    'i3': np.random.uniform(0, 1, size=(20, 20, 1)).astype(np.float32),
    # 'i3': np.random.uniform(0, 1, size=(1, 20, 20, 1)).astype(np.float32), # incorrect result
}


class Model(torch.nn.Module):
    def __init__(self) -> None:
        super().__init__()

    @torch.no_grad()
    def forward(self, i3):
        r = i3.reshape(20 * 20, 1, 1)
        # r = i3.reshape(1, 20 * 20, 1, 1) # incorrect result
        a0 = torch.sqrt(r)
        a = torch.squeeze(a0, -1)
        g = r > 0
        return (a, g)


model = Model()
model.eval()
torch_inp = {k: torch.from_numpy(v) for k, v in inputs.items()}
torch.onnx.export(
    model, tuple(torch_inp.values()),
    "output.onnx", input_names=list(inputs.keys()),
    verbose=False, opset_version=14)
import onnx
import onnx.checker

onnx_model = onnx.load("output.onnx")
onnx.checker.check_model(onnx_model)

image

If use those two commented-out lines to replace their previous line, I got different result compared to PyTorch. And I tried removing any of those 4 ops, and that will make this error disappear.

Environment

TensorRT Version: v8201 NVIDIA GPU: RTX 2080 NVIDIA Driver Version: 495.29.05 CUDA Version: 11.5 CUDNN Version: 8.3.0 Operating System: Ubuntu 18.04 Python Version (if applicable): 3.8.10 Tensorflow Version (if applicable): PyTorch Version (if applicable): 1.10.2+cpu Baremetal or Container (if so, version): Container

Relevant Files

model.zip

Steps To Reproduce

trtexec --onnx=output.onnx --verbose

The output

&&&& RUNNING TensorRT.trtexec [TensorRT v8201] # trtexec --onnx=output.onnx --verbose
[02/06/2022-22:11:48] [I] === Model Options ===
[02/06/2022-22:11:48] [I] Format: ONNX
[02/06/2022-22:11:48] [I] Model: output.onnx
[02/06/2022-22:11:48] [I] Output:
[02/06/2022-22:11:48] [I] === Build Options ===
[02/06/2022-22:11:48] [I] Max batch: explicit batch
[02/06/2022-22:11:48] [I] Workspace: 16 MiB
[02/06/2022-22:11:48] [I] minTiming: 1
[02/06/2022-22:11:48] [I] avgTiming: 8
[02/06/2022-22:11:48] [I] Precision: FP32
[02/06/2022-22:11:48] [I] Calibration: 
[02/06/2022-22:11:48] [I] Refit: Disabled
[02/06/2022-22:11:48] [I] Sparsity: Disabled
[02/06/2022-22:11:48] [I] Safe mode: Disabled
[02/06/2022-22:11:48] [I] DirectIO mode: Disabled
[02/06/2022-22:11:48] [I] Restricted mode: Disabled
[02/06/2022-22:11:48] [I] Save engine: 
[02/06/2022-22:11:48] [I] Load engine: 
[02/06/2022-22:11:48] [I] Profiling verbosity: 0
[02/06/2022-22:11:48] [I] Tactic sources: Using default tactic sources
[02/06/2022-22:11:48] [I] timingCacheMode: local
[02/06/2022-22:11:48] [I] timingCacheFile: 
[02/06/2022-22:11:48] [I] Input(s)s format: fp32:CHW
[02/06/2022-22:11:48] [I] Output(s)s format: fp32:CHW
[02/06/2022-22:11:48] [I] Input build shapes: model
[02/06/2022-22:11:48] [I] Input calibration shapes: model
[02/06/2022-22:11:48] [I] === System Options ===
[02/06/2022-22:11:48] [I] Device: 0
[02/06/2022-22:11:48] [I] DLACore: 
[02/06/2022-22:11:48] [I] Plugins:
[02/06/2022-22:11:48] [I] === Inference Options ===
[02/06/2022-22:11:48] [I] Batch: Explicit
[02/06/2022-22:11:48] [I] Input inference shapes: model
[02/06/2022-22:11:48] [I] Iterations: 10
[02/06/2022-22:11:48] [I] Duration: 3s (+ 200ms warm up)
[02/06/2022-22:11:48] [I] Sleep time: 0ms
[02/06/2022-22:11:48] [I] Idle time: 0ms
[02/06/2022-22:11:48] [I] Streams: 1
[02/06/2022-22:11:48] [I] ExposeDMA: Disabled
[02/06/2022-22:11:48] [I] Data transfers: Enabled
[02/06/2022-22:11:48] [I] Spin-wait: Disabled
[02/06/2022-22:11:48] [I] Multithreading: Disabled
[02/06/2022-22:11:48] [I] CUDA Graph: Disabled
[02/06/2022-22:11:48] [I] Separate profiling: Disabled
[02/06/2022-22:11:48] [I] Time Deserialize: Disabled
[02/06/2022-22:11:48] [I] Time Refit: Disabled
[02/06/2022-22:11:48] [I] Skip inference: Disabled
[02/06/2022-22:11:48] [I] Inputs:
[02/06/2022-22:11:48] [I] === Reporting Options ===
[02/06/2022-22:11:48] [I] Verbose: Enabled
[02/06/2022-22:11:48] [I] Averages: 10 inferences
[02/06/2022-22:11:48] [I] Percentile: 99
[02/06/2022-22:11:48] [I] Dump refittable layers:Disabled
[02/06/2022-22:11:48] [I] Dump output: Disabled
[02/06/2022-22:11:48] [I] Profile: Disabled
[02/06/2022-22:11:48] [I] Export timing to JSON file: 
[02/06/2022-22:11:48] [I] Export output to JSON file: 
[02/06/2022-22:11:48] [I] Export profile to JSON file: 
[02/06/2022-22:11:48] [I] 
[02/06/2022-22:11:48] [I] === Device Information ===
[02/06/2022-22:11:48] [I] Selected Device: NVIDIA GeForce RTX 2080
[02/06/2022-22:11:48] [I] Compute Capability: 7.5
[02/06/2022-22:11:48] [I] SMs: 46
[02/06/2022-22:11:48] [I] Compute Clock Rate: 1.71 GHz
[02/06/2022-22:11:48] [I] Device Global Memory: 7982 MiB
[02/06/2022-22:11:48] [I] Shared Memory per SM: 64 KiB
[02/06/2022-22:11:48] [I] Memory Bus Width: 256 bits (ECC disabled)
[02/06/2022-22:11:48] [I] Memory Clock Rate: 7 GHz
[02/06/2022-22:11:48] [I] 
[02/06/2022-22:11:48] [I] TensorRT version: 8.2.1
[02/06/2022-22:11:48] [V] [TRT] Registered plugin creator - ::GridAnchor_TRT version 1
[02/06/2022-22:11:48] [V] [TRT] Registered plugin creator - ::GridAnchorRect_TRT version 1
[02/06/2022-22:11:48] [V] [TRT] Registered plugin creator - ::NMS_TRT version 1
[02/06/2022-22:11:48] [V] [TRT] Registered plugin creator - ::Reorg_TRT version 1
[02/06/2022-22:11:48] [V] [TRT] Registered plugin creator - ::Region_TRT version 1
[02/06/2022-22:11:48] [V] [TRT] Registered plugin creator - ::Clip_TRT version 1
[02/06/2022-22:11:48] [V] [TRT] Registered plugin creator - ::LReLU_TRT version 1
[02/06/2022-22:11:48] [V] [TRT] Registered plugin creator - ::PriorBox_TRT version 1
[02/06/2022-22:11:48] [V] [TRT] Registered plugin creator - ::Normalize_TRT version 1
[02/06/2022-22:11:48] [V] [TRT] Registered plugin creator - ::ScatterND version 1
[02/06/2022-22:11:48] [V] [TRT] Registered plugin creator - ::RPROI_TRT version 1
[02/06/2022-22:11:48] [V] [TRT] Registered plugin creator - ::BatchedNMS_TRT version 1
[02/06/2022-22:11:48] [V] [TRT] Registered plugin creator - ::BatchedNMSDynamic_TRT version 1
[02/06/2022-22:11:48] [V] [TRT] Registered plugin creator - ::FlattenConcat_TRT version 1
[02/06/2022-22:11:48] [V] [TRT] Registered plugin creator - ::CropAndResize version 1
[02/06/2022-22:11:48] [V] [TRT] Registered plugin creator - ::DetectionLayer_TRT version 1
[02/06/2022-22:11:48] [V] [TRT] Registered plugin creator - ::EfficientNMS_TRT version 1
[02/06/2022-22:11:48] [V] [TRT] Registered plugin creator - ::EfficientNMS_ONNX_TRT version 1
[02/06/2022-22:11:48] [V] [TRT] Registered plugin creator - ::EfficientNMS_TFTRT_TRT version 1
[02/06/2022-22:11:48] [V] [TRT] Registered plugin creator - ::Proposal version 1
[02/06/2022-22:11:48] [V] [TRT] Registered plugin creator - ::ProposalLayer_TRT version 1
[02/06/2022-22:11:48] [V] [TRT] Registered plugin creator - ::PyramidROIAlign_TRT version 1
[02/06/2022-22:11:48] [V] [TRT] Registered plugin creator - ::ResizeNearest_TRT version 1
[02/06/2022-22:11:48] [V] [TRT] Registered plugin creator - ::Split version 1
[02/06/2022-22:11:48] [V] [TRT] Registered plugin creator - ::SpecialSlice_TRT version 1
[02/06/2022-22:11:48] [V] [TRT] Registered plugin creator - ::InstanceNormalization_TRT version 1
[02/06/2022-22:11:48] [I] [TRT] [MemUsageChange] Init CUDA: CPU +321, GPU +0, now: CPU 333, GPU 265 (MiB)
[02/06/2022-22:11:48] [I] [TRT] [MemUsageSnapshot] Begin constructing builder kernel library: CPU 333 MiB, GPU 265 MiB
[02/06/2022-22:11:48] [I] [TRT] [MemUsageSnapshot] End constructing builder kernel library: CPU 468 MiB, GPU 299 MiB
[02/06/2022-22:11:48] [I] Start parsing network model
[02/06/2022-22:11:48] [I] [TRT] ----------------------------------------------------------------
[02/06/2022-22:11:48] [I] [TRT] Input filename:   output.onnx
[02/06/2022-22:11:48] [I] [TRT] ONNX IR version:  0.0.7
[02/06/2022-22:11:48] [I] [TRT] Opset version:    14
[02/06/2022-22:11:48] [I] [TRT] Producer name:    pytorch
[02/06/2022-22:11:48] [I] [TRT] Producer version: 1.10
[02/06/2022-22:11:48] [I] [TRT] Domain:           
[02/06/2022-22:11:48] [I] [TRT] Model version:    0
[02/06/2022-22:11:48] [I] [TRT] Doc string:       
[02/06/2022-22:11:48] [I] [TRT] ----------------------------------------------------------------
[02/06/2022-22:11:48] [V] [TRT] Plugin creator already registered - ::GridAnchor_TRT version 1
[02/06/2022-22:11:48] [V] [TRT] Plugin creator already registered - ::GridAnchorRect_TRT version 1
[02/06/2022-22:11:48] [V] [TRT] Plugin creator already registered - ::NMS_TRT version 1
[02/06/2022-22:11:48] [V] [TRT] Plugin creator already registered - ::Reorg_TRT version 1
[02/06/2022-22:11:48] [V] [TRT] Plugin creator already registered - ::Region_TRT version 1
[02/06/2022-22:11:48] [V] [TRT] Plugin creator already registered - ::Clip_TRT version 1
[02/06/2022-22:11:48] [V] [TRT] Plugin creator already registered - ::LReLU_TRT version 1
[02/06/2022-22:11:48] [V] [TRT] Plugin creator already registered - ::PriorBox_TRT version 1
[02/06/2022-22:11:48] [V] [TRT] Plugin creator already registered - ::Normalize_TRT version 1
[02/06/2022-22:11:48] [V] [TRT] Plugin creator already registered - ::ScatterND version 1
[02/06/2022-22:11:48] [V] [TRT] Plugin creator already registered - ::RPROI_TRT version 1
[02/06/2022-22:11:48] [V] [TRT] Plugin creator already registered - ::BatchedNMS_TRT version 1
[02/06/2022-22:11:48] [V] [TRT] Plugin creator already registered - ::BatchedNMSDynamic_TRT version 1
[02/06/2022-22:11:48] [V] [TRT] Plugin creator already registered - ::FlattenConcat_TRT version 1
[02/06/2022-22:11:48] [V] [TRT] Plugin creator already registered - ::CropAndResize version 1
[02/06/2022-22:11:48] [V] [TRT] Plugin creator already registered - ::DetectionLayer_TRT version 1
[02/06/2022-22:11:48] [V] [TRT] Plugin creator already registered - ::EfficientNMS_TRT version 1
[02/06/2022-22:11:48] [V] [TRT] Plugin creator already registered - ::EfficientNMS_ONNX_TRT version 1
[02/06/2022-22:11:48] [V] [TRT] Plugin creator already registered - ::EfficientNMS_TFTRT_TRT version 1
[02/06/2022-22:11:48] [V] [TRT] Plugin creator already registered - ::Proposal version 1
[02/06/2022-22:11:48] [V] [TRT] Plugin creator already registered - ::ProposalLayer_TRT version 1
[02/06/2022-22:11:48] [V] [TRT] Plugin creator already registered - ::PyramidROIAlign_TRT version 1
[02/06/2022-22:11:48] [V] [TRT] Plugin creator already registered - ::ResizeNearest_TRT version 1
[02/06/2022-22:11:48] [V] [TRT] Plugin creator already registered - ::Split version 1
[02/06/2022-22:11:48] [V] [TRT] Plugin creator already registered - ::SpecialSlice_TRT version 1
[02/06/2022-22:11:48] [V] [TRT] Plugin creator already registered - ::InstanceNormalization_TRT version 1
[02/06/2022-22:11:48] [V] [TRT] Adding network input: i3 with dtype: float32, dimensions: (20, 20, 1)
[02/06/2022-22:11:48] [V] [TRT] Registering tensor: i3 for ONNX tensor: i3
[02/06/2022-22:11:48] [V] [TRT] Parsing node: Constant_0 [Constant]
[02/06/2022-22:11:48] [V] [TRT] Constant_0 [Constant] inputs: 
[02/06/2022-22:11:48] [W] [TRT] onnx2trt_utils.cpp:366: Your ONNX model has been generated with INT64 weights, while TensorRT does not natively support INT64. Attempting to cast down to INT32.
[02/06/2022-22:11:48] [V] [TRT] Constant_0 [Constant] outputs: [1 -> (3)[INT32]], 
[02/06/2022-22:11:48] [V] [TRT] Parsing node: Reshape_1 [Reshape]
[02/06/2022-22:11:48] [V] [TRT] Searching for input: i3
[02/06/2022-22:11:48] [V] [TRT] Searching for input: 1
[02/06/2022-22:11:48] [V] [TRT] Reshape_1 [Reshape] inputs: [i3 -> (20, 20, 1)[FLOAT]], [1 -> (3)[INT32]], 
[02/06/2022-22:11:48] [V] [TRT] Registering layer: Reshape_1 for ONNX node: Reshape_1
[02/06/2022-22:11:48] [V] [TRT] Registering tensor: 2 for ONNX tensor: 2
[02/06/2022-22:11:48] [V] [TRT] Reshape_1 [Reshape] outputs: [2 -> (400, 1, 1)[FLOAT]], 
[02/06/2022-22:11:48] [V] [TRT] Parsing node: Sqrt_2 [Sqrt]
[02/06/2022-22:11:48] [V] [TRT] Searching for input: 2
[02/06/2022-22:11:48] [V] [TRT] Sqrt_2 [Sqrt] inputs: [2 -> (400, 1, 1)[FLOAT]], 
[02/06/2022-22:11:48] [V] [TRT] Registering layer: Sqrt_2 for ONNX node: Sqrt_2
[02/06/2022-22:11:48] [V] [TRT] Registering tensor: 3 for ONNX tensor: 3
[02/06/2022-22:11:48] [V] [TRT] Sqrt_2 [Sqrt] outputs: [3 -> (400, 1, 1)[FLOAT]], 
[02/06/2022-22:11:48] [V] [TRT] Parsing node: Constant_3 [Constant]
[02/06/2022-22:11:48] [V] [TRT] Constant_3 [Constant] inputs: 
[02/06/2022-22:11:48] [V] [TRT] Constant_3 [Constant] outputs: [4 -> (1)[INT32]], 
[02/06/2022-22:11:48] [V] [TRT] Parsing node: Squeeze_4 [Squeeze]
[02/06/2022-22:11:48] [V] [TRT] Searching for input: 3
[02/06/2022-22:11:48] [V] [TRT] Searching for input: 4
[02/06/2022-22:11:48] [V] [TRT] Squeeze_4 [Squeeze] inputs: [3 -> (400, 1, 1)[FLOAT]], [4 -> (1)[INT32]], 
[02/06/2022-22:11:48] [V] [TRT] Original shape: (400, 1, 1), squeezing to: (400, 1)
[02/06/2022-22:11:48] [V] [TRT] Registering layer: Squeeze_4 for ONNX node: Squeeze_4
[02/06/2022-22:11:48] [V] [TRT] Registering tensor: 5_0 for ONNX tensor: 5
[02/06/2022-22:11:48] [V] [TRT] Squeeze_4 [Squeeze] outputs: [5 -> (400, 1)[FLOAT]], 
[02/06/2022-22:11:48] [V] [TRT] Parsing node: Constant_5 [Constant]
[02/06/2022-22:11:48] [V] [TRT] Constant_5 [Constant] inputs: 
[02/06/2022-22:11:48] [V] [TRT] Constant_5 [Constant] outputs: [6 -> ()[FLOAT]], 
[02/06/2022-22:11:48] [V] [TRT] Parsing node: Greater_6 [Greater]
[02/06/2022-22:11:48] [V] [TRT] Searching for input: 2
[02/06/2022-22:11:48] [V] [TRT] Searching for input: 6
[02/06/2022-22:11:48] [V] [TRT] Greater_6 [Greater] inputs: [2 -> (400, 1, 1)[FLOAT]], [6 -> ()[FLOAT]], 
[02/06/2022-22:11:48] [V] [TRT] Registering layer: 6 for ONNX node: 6
[02/06/2022-22:11:48] [V] [TRT] Registering layer: Greater_6 for ONNX node: Greater_6
[02/06/2022-22:11:48] [V] [TRT] Registering tensor: 7_1 for ONNX tensor: 7
[02/06/2022-22:11:48] [V] [TRT] Greater_6 [Greater] outputs: [7 -> (400, 1, 1)[BOOL]], 
[02/06/2022-22:11:48] [V] [TRT] Marking 5_0 as output: 5
[02/06/2022-22:11:48] [V] [TRT] Marking 7_1 as output: 7
[02/06/2022-22:11:48] [I] Finish parsing network model
[02/06/2022-22:11:48] [V] [TRT] Applying generic optimizations to the graph for inference.
[02/06/2022-22:11:48] [V] [TRT] Original: 6 layers
[02/06/2022-22:11:48] [V] [TRT] After dead-layer removal: 6 layers
[02/06/2022-22:11:48] [V] [TRT] Running: ConstShuffleFusion
[02/06/2022-22:11:48] [V] [TRT] ConstShuffleFusion: Fusing 6 with (Unnamed Layer* 4) [Shuffle]
[02/06/2022-22:11:48] [V] [TRT] After Myelin optimization: 1 layers
[02/06/2022-22:11:48] [V] [TRT] Applying ScaleNodes fusions.
[02/06/2022-22:11:48] [V] [TRT] After scale fusion: 1 layers
[02/06/2022-22:11:48] [V] [TRT] After vertical fusions: 1 layers
[02/06/2022-22:11:48] [V] [TRT] After dupe layer removal: 1 layers
[02/06/2022-22:11:48] [V] [TRT] After final dead-layer removal: 1 layers
[02/06/2022-22:11:48] [V] [TRT] After tensor merging: 1 layers
[02/06/2022-22:11:48] [V] [TRT] After concat removal: 1 layers
[02/06/2022-22:11:48] [V] [TRT] Graph construction and optimization completed in 0.000819079 seconds.
[02/06/2022-22:11:49] [V] [TRT] Using cublasLt as a tactic source
[02/06/2022-22:11:49] [I] [TRT] [MemUsageChange] Init cuBLAS/cuBLASLt: CPU +508, GPU +222, now: CPU 976, GPU 521 (MiB)
[02/06/2022-22:11:49] [V] [TRT] Using cuDNN as a tactic source
[02/06/2022-22:11:49] [I] [TRT] [MemUsageChange] Init cuDNN: CPU +113, GPU +52, now: CPU 1089, GPU 573 (MiB)
[02/06/2022-22:11:49] [I] [TRT] Local timing cache in use. Profiling results in this builder pass will not be stored.
[02/06/2022-22:11:49] [V] [TRT] Constructing optimization profile number 0 [1/1].
[02/06/2022-22:11:49] [V] [TRT] Reserving memory for activation tensors. Host: 0 bytes Device: 4800 bytes
[02/06/2022-22:11:49] [V] [TRT] =============== Computing reformatting costs
[02/06/2022-22:11:49] [V] [TRT] =============== Computing reformatting costs
[02/06/2022-22:11:49] [V] [TRT] =============== Computing reformatting costs
[02/06/2022-22:11:49] [V] [TRT] =============== Computing costs for 
[02/06/2022-22:11:49] [V] [TRT] *************** Autotuning format combination: Float(20,1,1) -> Bool(1,1,1), Float(1,1) ***************
[02/06/2022-22:11:49] [V] [TRT] --------------- Timing Runner: {ForeignNode[Reshape_1...Squeeze_4]} (Myelin)
trtexec: /root/gpgpu/MachineLearning/myelin/src/compiler/.././compiler/kernel_gen/cuda_codegen/cuda_codegen.hpp:322: const string& myelin::kgen::cuda_codegen_t::crd_t::operator[](size_t) const: Assertion `i < crds_.size()' failed.

lazycal avatar Feb 06 '22 22:02 lazycal

This bug has been fixed in TRT 8.4, please wait for the release come out :-)

zerollzeng avatar Feb 12 '22 06:02 zerollzeng

@zerollzeng Thanks for your reply! May I ask is this a known bug, or I helped TensorRT find a previously unknown bug :-)?

lazycal avatar Feb 12 '22 16:02 lazycal

This should be a known bug, and thanks for reporting this anyway :-)

zerollzeng avatar Feb 13 '22 06:02 zerollzeng