Torch-Tensorrt นำพลังของ Tensorrt ไปยัง Pytorch เร่งการตอบสนองการอนุมานมากถึง 5x เมื่อเทียบกับการดำเนินการที่กระตือรือร้นในรหัสเพียงบรรทัดเดียว
Torch-Tensorrt รุ่นเสถียรถูกเผยแพร่บน PYPI
pip install torch-tensorrtTorch-Tensorrt เวอร์ชันทุกคืนถูกเผยแพร่บนดัชนีแพ็คเกจ Pytorch
pip install --pre torch-tensorrt --index-url https://download.pytorch.org/whl/nightly/cu124Torch-Tensorrt ยังมีการกระจายในคอนเทนเนอร์ Pytorch NVIDIA NVIDIA NGC ที่พร้อมใช้งานซึ่งมีการพึ่งพาทั้งหมดที่มีเวอร์ชันที่เหมาะสมและสมุดบันทึกตัวอย่างรวมอยู่ด้วย
สำหรับวิธีการติดตั้งขั้นสูงเพิ่มเติมโปรดดูที่นี่
คุณสามารถใช้ Torch-Tensorrt ได้ทุกที่ที่คุณใช้ torch.compile :
import torch
import torch_tensorrt
model = MyModel (). eval (). cuda () # define your model here
x = torch . randn (( 1 , 3 , 224 , 224 )). cuda () # define what the inputs to the model will look like
optimized_model = torch . compile ( model , backend = "tensorrt" )
optimized_model ( x ) # compiled on first run
optimized_model ( x ) # this will be fast!หากคุณต้องการเพิ่มประสิทธิภาพโมเดลของคุณล่วงหน้าและ/หรือปรับใช้ในสภาพแวดล้อม C ++ Torch-Tensorrt จะให้เวิร์กโฟลว์สไตล์การส่งออกที่ทำให้โมดูลที่ดีที่สุด โมดูลนี้สามารถปรับใช้ใน pytorch หรือกับ libtorch (เช่นไม่มีการพึ่งพา python)
import torch
import torch_tensorrt
model = MyModel (). eval (). cuda () # define your model here
inputs = [ torch . randn (( 1 , 3 , 224 , 224 )). cuda ()] # define a list of representative inputs here
trt_gm = torch_tensorrt . compile ( model , ir = "dynamo" , inputs = inputs )
torch_tensorrt . save ( trt_gm , "trt.ep" , inputs = inputs ) # PyTorch only supports Python runtime for an ExportedProgram. For C++ deployment, use a TorchScript file
torch_tensorrt . save ( trt_gm , "trt.ts" , output_format = "torchscript" , inputs = inputs ) import torch
import torch_tensorrt
inputs = [ torch . randn (( 1 , 3 , 224 , 224 )). cuda ()] # your inputs go here
# You can run this in a new python session!
model = torch . export . load ( "trt.ep" ). module ()
# model = torch_tensorrt.load("trt.ep").module() # this also works
model ( * inputs )# include " torch/script.h "
# include " torch_tensorrt/torch_tensorrt.h "
auto trt_mod = torch::jit::load( " trt.ts " );
auto input_tensor = [...]; // fill this with your inputs
auto results = trt_mod.forward({input_tensor});| แพลตฟอร์ม | สนับสนุน |
|---|---|
| Linux AMD64 / GPU | ที่ได้รับการสนับสนุน |
| windows / gpu | รองรับ (ไดนาโมเท่านั้น) |
| Linux Aarch64 / GPU | การรวบรวมดั้งเดิมรองรับ Jetpack-4.4+ (ใช้ v1.0.0 ในขณะนี้) |
| Linux Aarch64 / DLA | การรวบรวมดั้งเดิมรองรับ Jetpack-4.4+ (ใช้ v1.0.0 ในขณะนี้) |
| Linux PPC64LE / GPU | ไม่รองรับ |
หมายเหตุ: อ้างอิง Nvidia L4T Pytorch NGC คอนเทนเนอร์สำหรับไลบรารี Pytorch บน Jetpack
นี่คือการพึ่งพาต่อไปนี้ที่ใช้ในการตรวจสอบการทดสอบ Torch-Tensorrt สามารถทำงานร่วมกับเวอร์ชันอื่นได้ แต่การทดสอบไม่รับประกันว่าจะผ่าน
การคัดค้านใช้เพื่อแจ้งให้นักพัฒนาทราบว่า API และเครื่องมือบางอย่างไม่แนะนำให้ใช้อีกต่อไป เริ่มต้นด้วยเวอร์ชัน 2.3 Torch-Tensorrt มีนโยบายการคัดค้านต่อไปนี้:
ประกาศการคัดค้านได้รับการสื่อสารในบันทึกย่อการเปิดตัว ฟังก์ชั่น API ที่เลิกใช้แล้วจะมีคำแถลงในการจัดทำเอกสารต้นฉบับเมื่อพวกเขาเลิกใช้แล้ว วิธีการและชั้นเรียนที่เลิกใช้แล้วจะออกคำเตือนการเสื่อมราคาที่รันไทม์หากใช้ Torch-Tensorrt ให้ระยะเวลาการโยกย้าย 6 เดือนหลังจากการคัดค้าน APIs และเครื่องมือยังคงทำงานต่อไปในช่วงระยะเวลาการโยกย้าย หลังจากระยะเวลาการย้ายถิ่นสิ้นสุดลง API และเครื่องมือจะถูกลบออกในลักษณะที่สอดคล้องกับการกำหนดเวอร์ชันความหมาย
ดูที่การสนับสนุน
ใบอนุญาต Torch-Tensorrt สามารถพบได้ในไฟล์ใบอนุญาต ได้รับใบอนุญาตด้วยใบอนุญาตสไตล์ BSD