rtx-deep


Namertx-deep JSON
Version 1.4.6 PyPI version JSON
download
home_page
SummaryDeep AI modules developed by MOGO RTX team
upload_time2023-08-31 10:45:53
maintainer
docs_urlNone
authorAndy
requires_python>=3.10, <3.11
licenseGPLv3
keywords
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            ## `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
```bash
torch>=1.10.0
tensorrt>=7.0
graphviz
```

#### 2 Installation
```bash
pip3 install graphviz
apt-get install graphviz
python3 setup.py install
```

#### 3 Examples
##### 3.1 Graph Tracing and Model Optimization
```bash
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
```bash
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
```bash
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())
```


            

Raw data

            {
    "_id": null,
    "home_page": "",
    "name": "rtx-deep",
    "maintainer": "",
    "docs_url": null,
    "requires_python": ">=3.10, <3.11",
    "maintainer_email": "",
    "keywords": "",
    "author": "Andy",
    "author_email": "",
    "download_url": "",
    "platform": null,
    "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.\n\n#### 1 Dependency\n```bash\ntorch>=1.10.0\ntensorrt>=7.0\ngraphviz\n```\n\n#### 2 Installation\n```bash\npip3 install graphviz\napt-get install graphviz\npython3 setup.py install\n```\n\n#### 3 Examples\n##### 3.1 Graph Tracing and Model Optimization\n```bash\nimport torch\nimport torch.nn as nn\nimport torch.nn.functional as F\n\nimport rtx_deep\n\n\nclass conv3x3_bn_relu(nn.Module):\n    def __init__(self, in_planes, out_planes, stride=1, dilation=1, groups=1):\n        super(conv3x3_bn_relu, self).__init__()\n        self.net = nn.Sequential(\n            nn.Conv2d(in_planes, out_planes, kernel_size=3, stride=stride, padding=dilation, dilation=dilation, groups=groups, bias=False),\n            nn.BatchNorm2d(out_planes),\n            nn.ReLU(inplace=True)\n        )\n    \n    def forward(self, x):\n        x1 = self.net(x)\n        return x1\n\n\nclass Model(nn.Module):\n    def __init__(self):\n        super(Model, self).__init__()\n        self.net = nn.Sequential(\n            conv3x3_bn_relu(64, 64),\n            conv3x3_bn_relu(64, 64)\n        )\n    \n    def forward(self, x):\n        x1 = self.net(x)\n        return x1\n\nmodel = Model()\nmodel.eval()\nmodel.cuda()\n\ninput_data = torch.randn(1, 64, 1024, 1024).cuda()\n\n# graph tracing\nmodel_fx = rtx_deep.graph_tracer.ad_trace.graph_trace(model, function_name=None)\n\n# Model Optimization\n# conduct graph tracing in graph_optim_from_module automatically\nmodel_fx_optim = rtx_deep.graph_tracer.graph_utils.graph_optim_from_module(model, function_name=None, sample_inputs=(input_data,))\n```\n\n##### 3.2 Quantization-Aware Training\n```bash\nimport torch\nimport torch.nn as nn\nimport torch.nn.functional as F\n\nimport rtx_deep\n\n\nclass conv3x3_bn_relu(nn.Module):\n    def __init__(self, in_planes, out_planes, stride=1, dilation=1, groups=1):\n        super(conv3x3_bn_relu, self).__init__()\n        self.net = nn.Sequential(\n            nn.Conv2d(in_planes, out_planes, kernel_size=3, stride=stride, padding=dilation, dilation=dilation, groups=groups, bias=False),\n            nn.BatchNorm2d(out_planes),\n            nn.ReLU(inplace=True)\n        )\n    \n    def forward(self, x):\n        x1 = self.net(x)\n        return x1\n\n\nclass Model(nn.Module):\n    def __init__(self):\n        super(Model, self).__init__()\n        self.net = nn.Sequential(\n            conv3x3_bn_relu(64, 64),\n            conv3x3_bn_relu(64, 64)\n        )\n    \n    def forward(self, x):\n        x1 = self.net(x)\n        return x1\n\nmodel = Model()\nmodel.eval()\nmodel.cuda()\n\ninput_data = torch.randn(1, 64, 1024, 1024).cuda()\n\n# Model Optimization\n# conduct graph tracing in graph_optim_from_module automatically\nmodel_fx_optim = rtx_deep.graph_tracer.graph_utils.graph_optim_from_module(model, function_name=None)\n\n# qat\nmodel_qat = rtx_deep.quant_lib.quant_utils.prepare_qat(model_fx_optim,\n    sample_inputs=[input_data],\n    observe_config_dic=dict(averaging_constant=0.05),\n    quant_config_dic=dict(quant_min=-127, quant_max=127, is_symmetric=True, is_quant=True),\n    disable_prefix=[])\n\n\n# vis model network\nrtx_deep.graph_tracer.vis_model.vis(model_fx_optim, './model_fx_optim.png')\nrtx_deep.graph_tracer.vis_model.vis(model_qat, './model_qat.png')\n\n# qat training\n...\n```\n\n##### 3.3 TensorRT Deployment\n```bash\nimport torch\nimport torch.nn as nn\nimport torch.nn.functional as F\n\nimport rtx_deep\nimport rtx_deep_plugin\nfrom rtx_deep.deploy_lib.convert_trt import InputTensor, torch2trt\n\nclass conv3x3_bn_relu(nn.Module):\n    def __init__(self, in_planes, out_planes, stride=1, dilation=1, groups=1):\n        super(conv3x3_bn_relu, self).__init__()\n        self.net = nn.Sequential(\n            nn.Conv2d(in_planes, out_planes, kernel_size=3, stride=stride, padding=dilation, dilation=dilation, groups=groups, bias=False),\n            nn.BatchNorm2d(out_planes),\n            nn.ReLU(inplace=True)\n        )\n    \n    def forward(self, x):\n        x1 = self.net(x)\n        return x1\n\n\nclass Model(nn.Module):\n    def __init__(self):\n        super(Model, self).__init__()\n        self.net = nn.Sequential(\n            conv3x3_bn_relu(64, 64),\n            conv3x3_bn_relu(64, 64)\n        )\n    \n    def forward(self, x):\n        x1 = self.net(x)\n        x2 = rtx_deep_plugin.max_op(x1, dim=1)\n        return x2\n\nmodel = Model()\nmodel.eval()\nmodel.cuda()\n\ninput_data = torch.randn(1, 64, 1024, 1024).cuda()\n\n# Model Optimization\n# conduct graph tracing in graph_optim_from_module automatically\nmodel_fx_optim = rtx_deep.graph_tracer.graph_utils.graph_optim_from_module(model, function_name=None, sample_inputs=(input_data,))\n\n# TensorRT Deployment\nmodel_trt = torch2trt(\n    model=model_fx_optim,\n    input_specs=[InputTensor(input_data, 'input_data')],\n    output_names=['max_value', 'max_index'],\n    fp16_mode=True,\n    #dla_core=0,\n    strict_type_constraints=True,\n    explicit_precision=True\n)\n\n# vis tensorrt network\nrtx_deep.deploy_lib.tools.vis_trt.vis(model_trt.network, 'test.png')\n\nerror = model(input_data)[0] - model_trt(input_data)[0]\nprint(error.abs().max())\n```\n\n",
    "bugtrack_url": null,
    "license": "GPLv3",
    "summary": "Deep AI modules developed by MOGO RTX team",
    "version": "1.4.6",
    "project_urls": null,
    "split_keywords": [],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "7e536cce5e9d6911f1a070bd816cd92ae15cd148f30dc85e2a7d1267c3193687",
                "md5": "c9d8ee1886d2cda3507c91f686f81b60",
                "sha256": "38d1eb2f3a5ac30580d4b5fa01633b8140693dd71a10301254b9e794e7cf6483"
            },
            "downloads": -1,
            "filename": "rtx_deep-1.4.6-py310-none-any.whl",
            "has_sig": false,
            "md5_digest": "c9d8ee1886d2cda3507c91f686f81b60",
            "packagetype": "bdist_wheel",
            "python_version": "py310",
            "requires_python": ">=3.10, <3.11",
            "size": 81773,
            "upload_time": "2023-08-31T10:45:53",
            "upload_time_iso_8601": "2023-08-31T10:45:53.055253Z",
            "url": "https://files.pythonhosted.org/packages/7e/53/6cce5e9d6911f1a070bd816cd92ae15cd148f30dc85e2a7d1267c3193687/rtx_deep-1.4.6-py310-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "644b70d339e9ae1af7fafadba3fa4aaa55269229fde3731edefc546e68423a16",
                "md5": "4c6c100ba11276bd03fd1c83a7ada0b4",
                "sha256": "7fe0f511679aebf8377694d0ca4898a05a508e632b5a2723b47c7a4439642485"
            },
            "downloads": -1,
            "filename": "rtx_deep-1.4.6-py311-none-any.whl",
            "has_sig": false,
            "md5_digest": "4c6c100ba11276bd03fd1c83a7ada0b4",
            "packagetype": "bdist_wheel",
            "python_version": "py311",
            "requires_python": ">=3.10, <3.11",
            "size": 126270,
            "upload_time": "2023-08-31T10:45:55",
            "upload_time_iso_8601": "2023-08-31T10:45:55.486051Z",
            "url": "https://files.pythonhosted.org/packages/64/4b/70d339e9ae1af7fafadba3fa4aaa55269229fde3731edefc546e68423a16/rtx_deep-1.4.6-py311-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "30df2896f82d5bcfc3707ba46eccace37ad26774946c24aeb6ff873d9d0fbe23",
                "md5": "e2e112816f82c78d05ef540e20c3f1e4",
                "sha256": "2173a5ab5d38c6f2fe9fbff51dc73f63769d47a4ec0967bcbd2acfd1c32eccea"
            },
            "downloads": -1,
            "filename": "rtx_deep-1.4.6-py36-none-any.whl",
            "has_sig": false,
            "md5_digest": "e2e112816f82c78d05ef540e20c3f1e4",
            "packagetype": "bdist_wheel",
            "python_version": "py36",
            "requires_python": ">=3.10, <3.11",
            "size": 81054,
            "upload_time": "2023-08-31T10:45:57",
            "upload_time_iso_8601": "2023-08-31T10:45:57.537058Z",
            "url": "https://files.pythonhosted.org/packages/30/df/2896f82d5bcfc3707ba46eccace37ad26774946c24aeb6ff873d9d0fbe23/rtx_deep-1.4.6-py36-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "ee4eb72993d646249864d002801e7639a78c4b118991b91ecef061a6c72acfba",
                "md5": "9433cb892e98c415e08dc860eb0505ef",
                "sha256": "0262ebe97c03010d62b0c84dced187324f029f203917124b17d9b4e271c137ef"
            },
            "downloads": -1,
            "filename": "rtx_deep-1.4.6-py37-none-any.whl",
            "has_sig": false,
            "md5_digest": "9433cb892e98c415e08dc860eb0505ef",
            "packagetype": "bdist_wheel",
            "python_version": "py37",
            "requires_python": ">=3.10, <3.11",
            "size": 81474,
            "upload_time": "2023-08-31T10:45:59",
            "upload_time_iso_8601": "2023-08-31T10:45:59.278012Z",
            "url": "https://files.pythonhosted.org/packages/ee/4e/b72993d646249864d002801e7639a78c4b118991b91ecef061a6c72acfba/rtx_deep-1.4.6-py37-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "bfacdaf978843b3e42c1678ec726dc284685bdf15ab042b76e93f12b447549f0",
                "md5": "b9d17ddefa3813d742576be20526380b",
                "sha256": "eca4919f63083b74d34fd05196d1df9d9bf737c9e24911a030e976e06f029fa8"
            },
            "downloads": -1,
            "filename": "rtx_deep-1.4.6-py38-none-any.whl",
            "has_sig": false,
            "md5_digest": "b9d17ddefa3813d742576be20526380b",
            "packagetype": "bdist_wheel",
            "python_version": "py38",
            "requires_python": ">=3.10, <3.11",
            "size": 81422,
            "upload_time": "2023-08-31T10:46:01",
            "upload_time_iso_8601": "2023-08-31T10:46:01.763543Z",
            "url": "https://files.pythonhosted.org/packages/bf/ac/daf978843b3e42c1678ec726dc284685bdf15ab042b76e93f12b447549f0/rtx_deep-1.4.6-py38-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "10a911d8e7531263a84739a39361eed75adfc1e7b3e3d5d10018ec20420e11e0",
                "md5": "eb83bc07d305029949d9b273b7db75e3",
                "sha256": "84eb6006195f124b658b8a7c45c3d9ffac7c40616d65202518fe1a9f56268856"
            },
            "downloads": -1,
            "filename": "rtx_deep-1.4.6-py39-none-any.whl",
            "has_sig": false,
            "md5_digest": "eb83bc07d305029949d9b273b7db75e3",
            "packagetype": "bdist_wheel",
            "python_version": "py39",
            "requires_python": ">=3.10, <3.11",
            "size": 81175,
            "upload_time": "2023-08-31T10:46:03",
            "upload_time_iso_8601": "2023-08-31T10:46:03.757742Z",
            "url": "https://files.pythonhosted.org/packages/10/a9/11d8e7531263a84739a39361eed75adfc1e7b3e3d5d10018ec20420e11e0/rtx_deep-1.4.6-py39-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2023-08-31 10:45:53",
    "github": false,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "lcname": "rtx-deep"
}
        
Elapsed time: 0.36234s