Skip to main content

A tools convert tensorrt engine to a fake onnx

Project description

TensorRT2ONNX

A tool convert TensorRT engine/plan to a fake onnx

Build an engine from onnx using trtexec tools

trtexec --verbose \
        --nvtxMode=verbose \
        --buildOnly \
        --workspace=8192 \
        --onnx=your_onnx.onnx \
        --saveEngine=your_engine.engine \
        --timingCacheFile=timing.cache \
        --fp16 # use fp16

You will get a your_engine.engine and a timing.cache

Parser network from engine using trtexec tools

trtexec --verbose \
        --noDataTransfers \
        --useCudaGraph \
        --separateProfileRun \
        --useSpinWait \
        --nvtxMode=verbose \
        --loadEngine=your_engine.engine \
        --exportLayerInfo=graph.json \
        --timingCacheFile=timing.cache

You will parser your_engine.engine network information into graph.json

Install TensorRT2ONNX

pip3 install trt2onnx -i https://pypi.org/simple

Build a fake onnx from graph json

import onnx
from trt2onnx import build_onnx

# build a fake onnx from json
onnx_graph = build_onnx('graph.json')

# save the fake onnx as `fake.onnx`
onnx.save(onnx_graph, 'fake.onnx')

Build a fake onnx from engine

import onnx
from trt2onnx import build_onnx

# build a fake onnx from engine
onnx_graph = build_onnx('your_engine.engine')

# save the fake onnx as `fake.onnx`
onnx.save(onnx_graph, 'fake.onnx')

NOTICE !!

If you build engine use your own plugin, please load the *.so before build_onnx function.

import ctypes
# load your plugin first
ctypes.cdll.LoadLibrary('your_plugin_0.so')
ctypes.cdll.LoadLibrary('your_plugin_1.so')
...

Use Netron to view your fake onnx

image

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

trt2onnx-0.0.2.tar.gz (10.0 kB view details)

Uploaded Source

File details

Details for the file trt2onnx-0.0.2.tar.gz.

File metadata

  • Download URL: trt2onnx-0.0.2.tar.gz
  • Upload date:
  • Size: 10.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.1 CPython/3.8.13

File hashes

Hashes for trt2onnx-0.0.2.tar.gz
Algorithm Hash digest
SHA256 21e00faef4cf232532692b701c69fed685255318d314c0535decdbad74b78c58
MD5 e2d5f41188c2692387591fa3fa5ec1b6
BLAKE2b-256 2c3e8a1cd166f3a5823dd6c541ea7d09090423ab41a721f267d0408c308d59f9

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page