|
5 | 5 | from typing import Any, Callable, Dict, Optional, Sequence
|
6 | 6 |
|
7 | 7 | import torch
|
| 8 | +import torch_tensorrt |
8 | 9 | from torch_tensorrt._Device import Device
|
9 | 10 | from torch_tensorrt._Input import Input
|
10 | 11 | from torch_tensorrt.dynamo import CompilationSettings
|
| 12 | +from torch_tensorrt.dynamo._defaults import PRECISION |
11 | 13 |
|
12 | 14 | from packaging import version
|
13 | 15 |
|
@@ -161,6 +163,28 @@ def parse_dynamo_kwargs(kwargs: Any) -> CompilationSettings:
|
161 | 163 | if settings.debug:
|
162 | 164 | logger.setLevel(logging.DEBUG)
|
163 | 165 |
|
| 166 | + # TODO: Remove once Dynamo precisions refactoring is complete |
| 167 | + if "enabled_precisions" in kwargs: |
| 168 | + enabled_precisions = kwargs["enabled_precisions"] |
| 169 | + |
| 170 | + if ( |
| 171 | + torch.float16 in enabled_precisions |
| 172 | + or torch_tensorrt.dtype.half in enabled_precisions |
| 173 | + ): |
| 174 | + settings.precision = torch.float16 |
| 175 | + elif ( |
| 176 | + torch.float32 in enabled_precisions |
| 177 | + or torch_tensorrt.dtype.float in enabled_precisions |
| 178 | + ): |
| 179 | + settings.precision = torch.float32 |
| 180 | + elif len(enabled_precisions) == 0: |
| 181 | + logger.info(f"No precision specified, defaulting to {PRECISION}") |
| 182 | + settings.precision = PRECISION |
| 183 | + else: |
| 184 | + raise ValueError( |
| 185 | + f"Precision {enabled_precisions} not supported in the Dynamo Path" |
| 186 | + ) |
| 187 | + |
164 | 188 | # Parse input runtime specification
|
165 | 189 | settings.use_python_runtime = use_python_runtime_parser(settings.use_python_runtime)
|
166 | 190 |
|
|
0 commit comments