Skip to content

Commit 4b4ef9f

Browse files
authored
Fix brittle layer count (#4576)
1 parent 630497c commit 4b4ef9f

1 file changed

Lines changed: 12 additions & 35 deletions

File tree

tests/py/ts/api/test_classes.py

Lines changed: 12 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -7,25 +7,6 @@
77
from torch_tensorrt.dynamo.runtime._TorchTensorRTModule import TorchTensorRTModule
88

99

10-
def is_blackwell():
11-
"""
12-
Check if running on NVIDIA Blackwell architecture (sm_100+).
13-
14-
Blackwell architecture adds input/output reformat layers in TensorRT engines.
15-
16-
Returns:
17-
bool: True if running on Blackwell (sm_100+), False otherwise
18-
"""
19-
if not torch.cuda.is_available():
20-
return False
21-
22-
device_properties = torch.cuda.get_device_properties(0)
23-
compute_capability = device_properties.major * 10 + device_properties.minor
24-
25-
# Blackwell is sm_100 and above
26-
return compute_capability >= 100
27-
28-
2910
@unittest.skipIf(
3011
not torchtrt.ENABLED_FEATURES.torchscript_frontend,
3112
"TorchScript Frontend is not available",
@@ -357,22 +338,12 @@ def test_get_layer_info(self):
357338

358339
import json
359340

360-
if is_blackwell():
361-
# spellchecker:off
362-
# blackwell has additional layers-
363-
# Layer 0: __mye88_myl0_0 ← Input reformat layer
364-
# Layer 1: aten__matmul(...) fc1 ← First matmul (fc1)
365-
# Layer 2: aten__matmul(...) fc2 ← Second matmul (fc2)
366-
# Layer 3: __mye90_myl0_3 ← Output reformat layer
367-
# spellchecker:on
368-
num_layers = 4
369-
else:
370-
num_layers = 2
371341
for trt_mod in (
372342
TestTorchTensorRTModule._get_trt_mod(),
373343
TestTorchTensorRTModule._get_trt_mod(via_ts=True),
374344
):
375-
trt_json = json.loads(trt_mod.get_layer_info())
345+
layer_info = trt_mod.get_layer_info()
346+
trt_json = json.loads(layer_info)
376347
self.assertIn("Layers", trt_json.keys(), "Key Layers is missing")
377348
io_key = next(
378349
(k for k in ("I/O Tensors", "Bindings") if k in trt_json.keys()),
@@ -381,10 +352,16 @@ def test_get_layer_info(self):
381352
self.assertIsNotNone(
382353
io_key, "Neither 'I/O Tensors' nor 'Bindings' key is present"
383354
)
384-
self.assertTrue(
385-
len(trt_json["Layers"]) == num_layers
386-
), "Not enough layers found"
387-
self.assertTrue(len(trt_json[io_key]) == 2, "Not enough I/O tensors found")
355+
self.assertGreater(
356+
len(trt_json["Layers"]),
357+
0,
358+
f"No layers found in layer info: {layer_info}",
359+
)
360+
self.assertEqual(
361+
len(trt_json[io_key]),
362+
2,
363+
f"Expected 2 I/O tensors, got {trt_json[io_key]}",
364+
)
388365

389366

390367
if __name__ == "__main__":

0 commit comments

Comments
 (0)