Skip to content

Commit 9351629

Browse files
committed
Addressed the comments
1 parent 7c0a9b2 commit 9351629

File tree

2 files changed

+24
-8
lines changed

2 files changed

+24
-8
lines changed

py/torch_tensorrt/dynamo/runtime/_TorchTensorRTModule.py

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -188,11 +188,12 @@ def _pack_engine_info(self) -> List[str | bytes]:
188188
engine_info[REQUIRES_OUTPUT_ALLOCATOR_IDX] = str(
189189
int(self.requires_output_allocator)
190190
)
191-
print(f"PROVIDED RESOURCE ALLOCATION STRATEGY: {self.dynamically_allocate_resources}")
191+
logger.info(
192+
f"PROVIDED RESOURCE ALLOCATION STRATEGY: {self.dynamically_allocate_resources}"
193+
)
192194
engine_info[RESOURCE_ALLOCATION_STRATEGY_IDX] = str(
193195
int(self.dynamically_allocate_resources)
194196
)
195-
print(engine_info[RESOURCE_ALLOCATION_STRATEGY_IDX])
196197

197198
return engine_info
198199

@@ -221,9 +222,13 @@ def set_device_memory_budget(self, budget_bytes: int) -> int:
221222
def _reset_captured_graph(self) -> None:
222223
self.engine.reset_captured_graph()
223224

224-
def use_dynamically_allocated_resources(self, dynamically_allocate_resources: bool = False) -> None:
225+
def use_dynamically_allocated_resources(
226+
self, dynamically_allocate_resources: bool = False
227+
) -> None:
225228
self.dynamically_allocate_resources = dynamically_allocate_resources
226-
self.engine.use_dynamically_allocated_resources(self.dynamically_allocate_resources)
229+
self.engine.use_dynamically_allocated_resources(
230+
self.dynamically_allocate_resources
231+
)
227232

228233
def setup_engine(self) -> None:
229234
"""

tests/py/dynamo/runtime/test_005_dynamic_allocation.py

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,18 +2,29 @@
22
import unittest
33

44
import torch
5+
import torch.nn.functional as F
56
import torch_tensorrt as torch_trt
7+
from torch import nn
68
from torch.testing._internal.common_utils import TestCase
79
from torch_tensorrt.dynamo.utils import COSINE_THRESHOLD, cosine_similarity
810

911
assertions = unittest.TestCase()
1012

11-
if importlib.util.find_spec("torchvision"):
12-
import torchvision.models as models
13-
1413

1514
class TestDynamicAllocation(TestCase):
1615
def test_dynamic_allocation(self):
16+
17+
class net(nn.Module):
18+
def __init__(self):
19+
super().__init__()
20+
self.conv1 = nn.Conv2d(3, 6, 3, 1)
21+
self.conv2 = nn.Conv2d(6, 16, 3, 1)
22+
23+
def forward(self, x):
24+
x = F.relu(self.conv1(x))
25+
x = F.relu(self.conv2(x))
26+
return x
27+
1728
inputs = [torch.rand((100, 3, 224, 224)).to("cuda")]
1829

1930
settings = {
@@ -25,7 +36,7 @@ def test_dynamic_allocation(self):
2536
"dynamically_allocate_resources": True,
2637
}
2738

28-
model = models.resnet152(pretrained=True).eval().to("cuda")
39+
model = net().eval().to("cuda")
2940
compiled_module = torch_trt.compile(model, inputs=inputs, **settings)
3041
compiled_module(*inputs)
3142

0 commit comments

Comments
 (0)