Deep AI modules developed by MOGO RTX team
Project description
rtx_deep: Deep AI modules developed by MOGO RTX team, aims to accelerate the distributed training, int8-aware distributed training, distributed evaluation and inference, model tracing and optimization, and TensorRT deployment.
1 Dependency
torch>=1.10.0
tensorrt>=7.0
graphviz
2 Installation
pip3 install graphviz
apt-get install graphviz
python3 setup.py install
3 Examples
3.1 Graph Tracing and Model Optimization
import torch
import torch.nn as nn
import torch.nn.functional as F
import rtx_deep
class conv3x3_bn_relu(nn.Module):
def __init__(self, in_planes, out_planes, stride=1, dilation=1, groups=1):
super(conv3x3_bn_relu, self).__init__()
self.net = nn.Sequential(
nn.Conv2d(in_planes, out_planes, kernel_size=3, stride=stride, padding=dilation, dilation=dilation, groups=groups, bias=False),
nn.BatchNorm2d(out_planes),
nn.ReLU(inplace=True)
)
def forward(self, x):
x1 = self.net(x)
return x1
class Model(nn.Module):
def __init__(self):
super(Model, self).__init__()
self.net = nn.Sequential(
conv3x3_bn_relu(64, 64),
conv3x3_bn_relu(64, 64)
)
def forward(self, x):
x1 = self.net(x)
return x1
model = Model()
model.eval()
model.cuda()
input_data = torch.randn(1, 64, 1024, 1024).cuda()
# graph tracing
model_fx = rtx_deep.graph_tracer.ad_trace.graph_trace(model, function_name=None)
# Model Optimization
# conduct graph tracing in graph_optim_from_module automatically
model_fx_optim = rtx_deep.graph_tracer.graph_utils.graph_optim_from_module(model, function_name=None, sample_inputs=(input_data,))
3.2 Quantization-Aware Training
import torch
import torch.nn as nn
import torch.nn.functional as F
import rtx_deep
class conv3x3_bn_relu(nn.Module):
def __init__(self, in_planes, out_planes, stride=1, dilation=1, groups=1):
super(conv3x3_bn_relu, self).__init__()
self.net = nn.Sequential(
nn.Conv2d(in_planes, out_planes, kernel_size=3, stride=stride, padding=dilation, dilation=dilation, groups=groups, bias=False),
nn.BatchNorm2d(out_planes),
nn.ReLU(inplace=True)
)
def forward(self, x):
x1 = self.net(x)
return x1
class Model(nn.Module):
def __init__(self):
super(Model, self).__init__()
self.net = nn.Sequential(
conv3x3_bn_relu(64, 64),
conv3x3_bn_relu(64, 64)
)
def forward(self, x):
x1 = self.net(x)
return x1
model = Model()
model.eval()
model.cuda()
input_data = torch.randn(1, 64, 1024, 1024).cuda()
# Model Optimization
# conduct graph tracing in graph_optim_from_module automatically
model_fx_optim = rtx_deep.graph_tracer.graph_utils.graph_optim_from_module(model, function_name=None)
# qat
model_qat = rtx_deep.quant_lib.quant_utils.prepare_qat(model_fx_optim,
sample_inputs=[input_data],
observe_config_dic=dict(averaging_constant=0.05),
quant_config_dic=dict(quant_min=-127, quant_max=127, is_symmetric=True, is_quant=True),
disable_prefix=[])
# vis model network
rtx_deep.graph_tracer.vis_model.vis(model_fx_optim, './model_fx_optim.png')
rtx_deep.graph_tracer.vis_model.vis(model_qat, './model_qat.png')
# qat training
...
3.3 TensorRT Deployment
import torch
import torch.nn as nn
import torch.nn.functional as F
import rtx_deep
import rtx_deep_plugin
from rtx_deep.deploy_lib.convert_trt import InputTensor, torch2trt
class conv3x3_bn_relu(nn.Module):
def __init__(self, in_planes, out_planes, stride=1, dilation=1, groups=1):
super(conv3x3_bn_relu, self).__init__()
self.net = nn.Sequential(
nn.Conv2d(in_planes, out_planes, kernel_size=3, stride=stride, padding=dilation, dilation=dilation, groups=groups, bias=False),
nn.BatchNorm2d(out_planes),
nn.ReLU(inplace=True)
)
def forward(self, x):
x1 = self.net(x)
return x1
class Model(nn.Module):
def __init__(self):
super(Model, self).__init__()
self.net = nn.Sequential(
conv3x3_bn_relu(64, 64),
conv3x3_bn_relu(64, 64)
)
def forward(self, x):
x1 = self.net(x)
x2 = rtx_deep_plugin.max_op(x1, dim=1)
return x2
model = Model()
model.eval()
model.cuda()
input_data = torch.randn(1, 64, 1024, 1024).cuda()
# Model Optimization
# conduct graph tracing in graph_optim_from_module automatically
model_fx_optim = rtx_deep.graph_tracer.graph_utils.graph_optim_from_module(model, function_name=None, sample_inputs=(input_data,))
# TensorRT Deployment
model_trt = torch2trt(
model=model_fx_optim,
input_specs=[InputTensor(input_data, 'input_data')],
output_names=['max_value', 'max_index'],
fp16_mode=True,
#dla_core=0,
strict_type_constraints=True,
explicit_precision=True
)
# vis tensorrt network
rtx_deep.deploy_lib.tools.vis_trt.vis(model_trt.network, 'test.png')
error = model(input_data)[0] - model_trt(input_data)[0]
print(error.abs().max())
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distributions
No source distribution files available for this release.See tutorial on generating distribution archives.
Built Distributions
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
rtx_deep-1.3.9-py311-none-any.whl
(125.5 kB
view details)
rtx_deep-1.3.9-py39-none-any.whl
(80.7 kB
view details)
rtx_deep-1.3.9-py38-none-any.whl
(81.0 kB
view details)
rtx_deep-1.3.9-py37-none-any.whl
(81.0 kB
view details)
rtx_deep-1.3.9-py36-none-any.whl
(80.6 kB
view details)
File details
Details for the file rtx_deep-1.3.9-py311-none-any.whl.
File metadata
- Download URL: rtx_deep-1.3.9-py311-none-any.whl
- Upload date:
- Size: 125.5 kB
- Tags: Python 3.11
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.7.5
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
4b9d5766369dd8ca5f0950bdc3062458ded00c146ea17b0e605d1350352ca49b
|
|
| MD5 |
05b48aa905373f101390a36c43147bac
|
|
| BLAKE2b-256 |
8de94c62e1fa0bc6a315b997237643eb446df246ab1a196ac198757b6719d9f8
|
File details
Details for the file rtx_deep-1.3.9-py310-none-any.whl.
File metadata
- Download URL: rtx_deep-1.3.9-py310-none-any.whl
- Upload date:
- Size: 81.3 kB
- Tags: Python 3.10
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.7.5
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
8ef4284c058d6b99e497fa3a3dc5dc40f2f3ec885d36d9d58b0f34a16e7766eb
|
|
| MD5 |
5701d4015527f9d0f6e6293839702fe8
|
|
| BLAKE2b-256 |
db0b3d826f1084357401e7b923840ad7724cf33002afcb3990ea66885927a616
|
File details
Details for the file rtx_deep-1.3.9-py39-none-any.whl.
File metadata
- Download URL: rtx_deep-1.3.9-py39-none-any.whl
- Upload date:
- Size: 80.7 kB
- Tags: Python 3.9
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.7.5
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
9e539742f1039895ae626dcd8c095741954012000a79f3307550166ca8350e39
|
|
| MD5 |
9f084026156ab3453ca0b31af4d60f35
|
|
| BLAKE2b-256 |
9fd9e0892af7e7c8670c173078d10c71b9fc31cab8a6ad0a9acbb1c798001841
|
File details
Details for the file rtx_deep-1.3.9-py38-none-any.whl.
File metadata
- Download URL: rtx_deep-1.3.9-py38-none-any.whl
- Upload date:
- Size: 81.0 kB
- Tags: Python 3.8
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.7.5
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
55d563fc1248e42ceede4cd2380f1b29e68e20556409ebe8866437e1f772dab3
|
|
| MD5 |
d4e8d3acedac1315ceb481cd81ae2c98
|
|
| BLAKE2b-256 |
8e192bd4d350b185854214a64e191ff2664ebb5b30c37b1224552fd741559bf9
|
File details
Details for the file rtx_deep-1.3.9-py37-none-any.whl.
File metadata
- Download URL: rtx_deep-1.3.9-py37-none-any.whl
- Upload date:
- Size: 81.0 kB
- Tags: Python 3.7
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.7.5
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
deaed7cc35fb375faef24cc42ca4f91ff93771798e31ed3ec0e529e35993d04b
|
|
| MD5 |
20f54baeb42a8f5353e5b7ab37fbb3b9
|
|
| BLAKE2b-256 |
f04a94622756befa4eae9a4f343c504c475ffcc31a469e5e74d110b1cb3468ab
|
File details
Details for the file rtx_deep-1.3.9-py36-none-any.whl.
File metadata
- Download URL: rtx_deep-1.3.9-py36-none-any.whl
- Upload date:
- Size: 80.6 kB
- Tags: Python 3.6
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.7.5
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
fe9ad92b1ffe9c8d2eecef2e9cca76afd51257267e3159121046e66fc9f80c17
|
|
| MD5 |
a20c23096bae41c6542fc2c275f01dae
|
|
| BLAKE2b-256 |
47d117c49ddb529ca01e7bffd913301486edbdaa4a85f0748b9f3c177799423f
|