Skip to content

Update py/README.md #706

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Nov 11, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 13 additions & 15 deletions py/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,26 +7,24 @@ Torch-TensorRT is a compiler for PyTorch/TorchScript, targeting NVIDIA GPUs via
## Example Usage

``` python
import torch
import torchvision
import torch_tensorrt

# Get a model
model = torchvision.models.alexnet(pretrained=True).eval().cuda()
...

# Create some example data
data = torch.randn((1, 3, 224, 224)).to("cuda")
trt_ts_module = torch_tensorrt.compile(torch_script_module,
inputs = [example_tensor, # Provide example tensor for input shape or...
torch_tensorrt.Input( # Specify input object with shape and dtype
min_shape=[1, 3, 224, 224],
opt_shape=[1, 3, 512, 512],
max_shape=[1, 3, 1024, 1024],
# For static size shape=[1, 3, 224, 224]
dtype=torch.half) # Datatype of input tensor. Allowed options torch.(float|half|int8|int32|bool)
],
enabled_precisions = {torch.half}, # Run with FP16)

# Trace the module with example data
traced_model = torch.jit.trace(model, [data])
result = trt_ts_module(input_data) # run inference
torch.jit.save(trt_ts_module, "trt_torchscript_module.ts") # save the TRT embedded Torchscript

# Compile module
compiled_trt_model = torch_tensorrt.compile(traced_model, {
"inputs": [torch_tensorrt.Input(data.shape)],
"enabled_precisions": {torch.float, torch.half}, # Run with FP16
})

results = compiled_trt_model(data.half())
```

## Installation
Expand Down