Skip to content

Commit e923627

Browse files
committed
chore: updates
1 parent 6693778 commit e923627

File tree

10 files changed

+44
-354
lines changed

10 files changed

+44
-354
lines changed

.github/workflows/build-test-linux.yml

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -173,7 +173,13 @@ jobs:
173173
cd tests/py
174174
python -m pip install -r requirements.txt
175175
cd dynamo
176-
python -m pytest -ra --junitxml=${RUNNER_TEST_RESULTS_DIR}/dyn_models_export.xml --ir dynamo models/
176+
python -m pytest -ra --junitxml=${RUNNER_TEST_RESULTS_DIR}/dynamo_models.xml --ir dynamo models/test_models.py
177+
python -m pytest -ra --junitxml=${RUNNER_TEST_RESULTS_DIR}/dynamo_models_dynamic.xml --ir dynamo models/test_dyn_models.py
178+
python -m pytest -ra --junitxml=${RUNNER_TEST_RESULTS_DIR}/engine_cache.xml --ir dynamo models/test_engine_cache.py
179+
python -m pytest -ra --junitxml=${RUNNER_TEST_RESULTS_DIR}/dtype_support.xml --ir dynamo models/test_dtype_support.py
180+
python -m pytest -ra --junitxml=${RUNNER_TEST_RESULTS_DIR}/model_refit.xml --ir dynamo models/test_model_refit.py
181+
python -m pytest -ra --junitxml=${RUNNER_TEST_RESULTS_DIR}/modelopt_models.xml --ir dynamo models/test_modelopt_models.py
182+
python -m pytest -ra --junitxml=${RUNNER_TEST_RESULTS_DIR}/weight_stripped_engine.xml --ir dynamo models/test_weight_stripped_engine.py
177183
popd
178184
179185
tests-py-dynamo-serde:
@@ -206,6 +212,7 @@ jobs:
206212
cd dynamo
207213
python -m pytest -ra --junitxml=${RUNNER_TEST_RESULTS_DIR}/export_serde_test_results.xml --ir dynamo models/test_export_serde.py
208214
python -m pytest -ra --junitxml=${RUNNER_TEST_RESULTS_DIR}/reexport_test_results.xml --ir dynamo models/test_reexport.py
215+
python -m pytest -ra --junitxml=${RUNNER_TEST_RESULTS_DIR}/export_kwargs_serde_test_results.xml --ir dynamo models/test_export_kwargs_serde.py
209216
popd
210217
211218
tests-py-torch-compile-be:

py/torch_tensorrt/dynamo/conversion/_TRTInterpreter.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -898,7 +898,7 @@ def get_attr(self, target: str, args: Any, kwargs: Any) -> np.ndarray:
898898
else:
899899
constant_tensor = frozen_attr
900900

901-
return to_torch(constant_tensor)
901+
return to_torch(constant_tensor)
902902

903903
def call_method(self, target: str, args: Any, kwargs: Any) -> Any:
904904
assert isinstance(target, str)

py/torch_tensorrt/dynamo/conversion/converter_utils.py

Lines changed: 33 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -344,10 +344,6 @@ def create_constant(
344344
with unset_fake_temporarily():
345345

346346
torch_value = to_torch(value, dtype)
347-
if torch_value is None:
348-
raise ValueError(
349-
f"Cannot convert tensor '{name}' to a TensorRT constant because its value is None."
350-
)
351347
if torch_value.dtype == torch.float64:
352348
raise ValueError(
353349
"TensorRT does not support float64 (double) precision. To resolve this, please set truncate_double=True in your compilation settings and re-run the model."
@@ -589,42 +585,45 @@ def to_numpy(
589585
Returns:
590586
A Numpy array or None, if the input was None.
591587
"""
592-
output = None
593-
594-
if value is None or isinstance(value, np.ndarray):
595-
output = value
588+
with unset_fake_temporarily():
589+
output = None
596590

597-
elif isinstance(value, torch.Tensor):
598-
if value.is_quantized:
599-
value = value.dequantize()
600-
elif value.dtype == torch.bfloat16:
601-
# TODO: Remove when numpy has a BF16 type
602-
_LOGGER.warning(
603-
"Requested a conversion of bfloat16 tensor from torch to numpy which isn't supported. Casting this tensor to FP32 precision currently. Please use to_torch() API for better data representation",
604-
)
605-
value = value.to(torch.float)
591+
if value is None or isinstance(value, np.ndarray):
592+
output = value
606593

607-
output = value.cpu().detach().contiguous().numpy()
594+
elif isinstance(value, torch.Tensor):
595+
if value.is_quantized:
596+
value = value.dequantize()
597+
elif value.dtype == torch.bfloat16:
598+
# TODO: Remove when numpy has a BF16 type
599+
_LOGGER.warning(
600+
"Requested a conversion of bfloat16 tensor from torch to numpy which isn't supported. Casting this tensor to FP32 precision currently. Please use to_torch() API for better data representation",
601+
)
602+
value = value.to(torch.float)
608603

609-
elif isinstance(value, int):
610-
output = np.array([value], dtype=np.int32)
604+
output = value.cpu().detach().contiguous().numpy()
611605

612-
elif isinstance(value, float):
613-
output = np.array([value], dtype=np.float32)
606+
elif isinstance(value, int):
607+
output = np.array([value], dtype=np.int32)
614608

615-
elif isinstance(value, bool):
616-
output = np.array([value], dtype=np.bool_)
609+
elif isinstance(value, float):
610+
output = np.array([value], dtype=np.float32)
617611

618-
if isinstance(output, np.ndarray) or output is None:
619-
return (
620-
output
621-
if (dtype is None or output is None)
622-
else output.astype(_enums.dtype._from(dtype).to(np.dtype, use_default=True))
623-
)
624-
else:
625-
raise AssertionError(
626-
f"to_numpy can only be called on None, bool, int, float, np.ndarray, or torch.Tensor, got: {value}"
627-
)
612+
elif isinstance(value, bool):
613+
output = np.array([value], dtype=np.bool_)
614+
615+
if isinstance(output, np.ndarray) or output is None:
616+
return (
617+
output
618+
if (dtype is None or output is None)
619+
else output.astype(
620+
_enums.dtype._from(dtype).to(np.dtype, use_default=True)
621+
)
622+
)
623+
else:
624+
raise AssertionError(
625+
f"to_numpy can only be called on None, bool, int, float, np.ndarray, or torch.Tensor, got: {value}"
626+
)
628627

629628

630629
def to_torch(

tests/py/dynamo/backend/test_backend_compiler.py

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,10 @@
22
from copy import deepcopy
33

44
import torch
5+
import torch_tensorrt
56
from torch.testing._internal.common_utils import TestCase, run_tests
67
from torch_tensorrt.dynamo.partitioning import fast_partition
78

8-
import torch_tensorrt
9-
109
from ..testing_utilities import DECIMALS_OF_AGREEMENT, lower_graph_testing
1110

1211

@@ -51,7 +50,6 @@ def forward(self, x, y):
5150
pass_through_build_failures=True,
5251
torch_executed_ops={"torch.ops.aten.add.Tensor"},
5352
use_python_runtime=False,
54-
debug=True,
5553
)
5654
optimized_model_results = optimized_model(*inputs).detach().cpu()
5755
torch_model_results = fx_graph(*inputs).detach().cpu()
@@ -132,7 +130,6 @@ def forward(self, x, y):
132130
pass_through_build_failures=True,
133131
torch_executed_ops={"torch.ops.aten.add.Tensor"},
134132
use_python_runtime=False,
135-
debug=True,
136133
)
137134
optimized_model_results = optimized_model(*inputs).detach().cpu()
138135
torch_model_results = model(*inputs).detach().cpu()
@@ -177,7 +174,6 @@ def forward(self, x, y):
177174
optimization_level=4,
178175
version_compatible=True,
179176
max_aux_streams=5,
180-
debug=True,
181177
)
182178
optimized_model_results = optimized_model(*inputs).detach().cpu()
183179
torch_model_results = fx_graph(*inputs).detach().cpu()
@@ -225,7 +221,6 @@ def forward(self, x, y):
225221
min_block_size=1,
226222
pass_through_build_failures=True,
227223
truncate_double=True,
228-
debug=True,
229224
)
230225
optimized_model_results = optimized_model(*inputs).detach().cpu()
231226
torch_model_results = fx_graph(*inputs).detach().cpu()
@@ -298,7 +293,6 @@ def forward(self, x, y):
298293
min_block_size=1,
299294
pass_through_build_failures=True,
300295
truncate_double=False,
301-
debug=True,
302296
torch_executed_ops={"torch.ops.aten.add.Tensor"},
303297
)
304298
optimized_model_results = optimized_model(*inputs).detach().cpu()

tests/py/dynamo/conversion/harness.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -415,7 +415,6 @@ def run_test(
415415
compilation_settings = CompilationSettings(
416416
enabled_precisions={dtype._from(precision)},
417417
truncate_double=True,
418-
debug=True,
419418
immutable_weights=immutable_weights,
420419
)
421420

@@ -507,7 +506,6 @@ def run_test_compare_tensor_attributes_only(
507506
compilation_settings = CompilationSettings(
508507
enabled_precisions={dtype._from(precision)},
509508
truncate_double=True,
510-
debug=True,
511509
immutable_weights=immutable_weights,
512510
)
513511

tests/py/dynamo/models/test_dtype_support.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -297,7 +297,6 @@ def forward(self, x):
297297
ir="torch_compile",
298298
inputs=inputs,
299299
enabled_precisions={torch.bfloat16},
300-
debug=True,
301300
min_block_size=1,
302301
device=device,
303302
cache_built_engines=False,

tests/py/dynamo/models/test_model_refit.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -815,7 +815,6 @@ def forward(self, x):
815815
exp_program,
816816
tuple(inputs),
817817
enabled_precisions={torch.float},
818-
debug=True,
819818
min_block_size=1,
820819
immutable_weights=False,
821820
)

0 commit comments

Comments
 (0)