Skip to content

Commit e0a2fd3

Browse files
authored
Merge pull request #607 from NVIDIA/remove_deprecated_apis
refactor!: Removing deprecated InputRange, op_precision and input_shapes
2 parents 1cbc27c + f8b1866 commit e0a2fd3

File tree

6 files changed

+5
-193
lines changed

6 files changed

+5
-193
lines changed

cpp/include/trtorch/trtorch.h

Lines changed: 0 additions & 88 deletions
Original file line numberDiff line numberDiff line change
@@ -516,64 +516,6 @@ struct TRTORCH_API CompileSpec {
516516
bool explicit_set_dtype;
517517
};
518518

519-
/**
520-
* @brief A struct to hold an input range (used by TensorRT Optimization
521-
* profile)
522-
*
523-
* This struct can either hold a single vector representing an input shape,
524-
* signifying a static input shape or a set of three input shapes representing
525-
* the min, optiminal and max input shapes allowed for the engine.
526-
*/
527-
struct TRTORCH_API InputRange {
528-
/// Minimum acceptable input size into the engine
529-
std::vector<int64_t> min;
530-
/// Optimal input size into the engine (gets best performace)
531-
std::vector<int64_t> opt;
532-
/// Maximum acceptable input size into the engine
533-
std::vector<int64_t> max;
534-
/**
535-
* @brief Construct a new Input Range object for static input size from
536-
* vector
537-
*
538-
* @param opt
539-
*/
540-
[[deprecated("trtorch::CompileSpec::InputRange is being deprecated in favor of trtorch::CompileSpec::Input. trtorch::CompileSpec::InputRange will be removed in TRTorch v0.5.0")]] InputRange(
541-
std::vector<int64_t> opt);
542-
/**
543-
* @brief Construct a new Input Range object static input size from
544-
* c10::ArrayRef (the type produced by tensor.sizes())
545-
*
546-
* @param opt
547-
*/
548-
[[deprecated("trtorch::CompileSpec::InputRange is being deprecated in favor of trtorch::CompileSpec::Input. trtorch::CompileSpec::InputRange will be removed in TRTorch v0.5.0")]] InputRange(
549-
c10::ArrayRef<int64_t> opt);
550-
/**
551-
* @brief Construct a new Input Range object dynamic input size from vectors
552-
* for min, opt, and max supported sizes
553-
*
554-
* @param min
555-
* @param opt
556-
* @param max
557-
*/
558-
[[deprecated("trtorch::CompileSpec::InputRange is being deprecated in favor of trtorch::CompileSpec::Input. trtorch::CompileSpec::InputRange will be removed in TRTorch v0.5.0")]] InputRange(
559-
std::vector<int64_t> min,
560-
std::vector<int64_t> opt,
561-
std::vector<int64_t> max);
562-
/**
563-
* @brief Construct a new Input Range object dynamic input size from
564-
* c10::ArrayRef (the type produced by tensor.sizes()) for min, opt, and max
565-
* supported sizes
566-
*
567-
* @param min
568-
* @param opt
569-
* @param max
570-
*/
571-
[[deprecated("trtorch::CompileSpec::InputRange is being deprecated in favor of trtorch::CompileSpec::Input. trtorch::CompileSpec::InputRange will be removed in TRTorch v0.5.0")]] InputRange(
572-
c10::ArrayRef<int64_t> min,
573-
c10::ArrayRef<int64_t> opt,
574-
c10::ArrayRef<int64_t> max);
575-
};
576-
577519
/**
578520
* @brief A struct to hold fallback info
579521
*/
@@ -606,18 +548,6 @@ struct TRTORCH_API CompileSpec {
606548
TorchFallback(bool enabled, uint64_t min_size) : enabled(enabled), min_block_size(min_size) {}
607549
};
608550

609-
/**
610-
* @brief Construct a new Extra Info object from input ranges.
611-
* Each entry in the vector represents a input and should be provided in call
612-
* order.
613-
*
614-
* Use this constructor if you want to use dynamic shape
615-
*
616-
* @param input_ranges
617-
*/
618-
[[deprecated("trtorch::CompileSpec::CompileSpec(std::vector<InputRange> input_ranges) is being deprecated in favor of trtorch::CompileSpec::CompileSpec(std::vector<Input> inputs). Please use CompileSpec(std::vector<Input> inputs). trtorch::CompileSpec::CompileSpec(std::vector<InputRange> input_ranges) will be removed in TRTorch v0.5.0")]] CompileSpec(
619-
std::vector<InputRange> input_ranges)
620-
: input_ranges(std::move(input_ranges)) {}
621551
/**
622552
* @brief Construct a new Extra Info object
623553
* Convienence constructor to set fixed input size from vectors describing
@@ -667,24 +597,6 @@ struct TRTORCH_API CompileSpec {
667597
*/
668598
std::vector<Input> inputs;
669599

670-
/**
671-
* Sizes for inputs to engine, can either be a single size or a range
672-
* defined by Min, Optimal, Max sizes
673-
*
674-
* Order is should match call order
675-
*/
676-
[[deprecated(
677-
"trtorch::CompileSpec::input_ranges is being deprecated in favor of trtorch::CompileSpec::inputs. trtorch::CompileSpec::input_ranges will be removed in TRTorch v0.5.0")]] std::
678-
vector<InputRange>
679-
input_ranges;
680-
681-
/**
682-
* Default operating precision for the engine
683-
*/
684-
[[deprecated(
685-
"trtorch::CompileSpec::op_precision is being deprecated in favor of trtorch::CompileSpec::enabled_precisions, a set of all enabled precisions to use during compilation, trtorch::CompileSpec::op_precision will be removed in TRTorch v0.5.0")]] DataType
686-
op_precision = DataType::kFloat;
687-
688600
/**
689601
* @brief The set of precisions TensorRT is allowed to use for kernels during compilation
690602
*

cpp/src/compile_spec.cpp

Lines changed: 2 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -144,30 +144,6 @@ CompileSpec::Device::DeviceType::DeviceType(c10::DeviceType t) {
144144
value = DeviceType::kGPU;
145145
}
146146

147-
CompileSpec::InputRange::InputRange(std::vector<int64_t> opt) {
148-
this->opt = opt;
149-
this->min = opt;
150-
this->max = opt;
151-
}
152-
153-
CompileSpec::InputRange::InputRange(c10::IntArrayRef opt) {
154-
this->opt = core::util::toVec(opt);
155-
this->min = core::util::toVec(opt);
156-
this->max = core::util::toVec(opt);
157-
}
158-
159-
CompileSpec::InputRange::InputRange(std::vector<int64_t> min, std::vector<int64_t> opt, std::vector<int64_t> max) {
160-
this->opt = opt;
161-
this->min = min;
162-
this->max = max;
163-
}
164-
165-
CompileSpec::InputRange::InputRange(c10::IntArrayRef min, c10::IntArrayRef opt, c10::IntArrayRef max) {
166-
this->opt = core::util::toVec(opt);
167-
this->min = core::util::toVec(min);
168-
this->max = core::util::toVec(max);
169-
}
170-
171147
CompileSpec::CompileSpec(std::vector<c10::ArrayRef<int64_t>> fixed_sizes) {
172148
for (auto in : fixed_sizes) {
173149
inputs.push_back(Input(in));
@@ -309,22 +285,10 @@ CompileSpec::Input::Input(at::Tensor tensor) {
309285

310286
/* ==========================================*/
311287

312-
core::ir::Input to_internal_input(CompileSpec::InputRange& i) {
313-
return core::ir::Input(i.min, i.opt, i.max);
314-
}
315-
316288
core::ir::Input to_internal_input(CompileSpec::Input& i) {
317289
return core::ir::Input(i.min_shape, i.opt_shape, i.max_shape, toTRTDataType(i.dtype), toTRTTensorFormat(i.format));
318290
}
319291

320-
std::vector<core::ir::Input> to_vec_internal_inputs(std::vector<CompileSpec::InputRange>& external) {
321-
std::vector<core::ir::Input> internal;
322-
for (auto range : external) {
323-
internal.push_back(to_internal_input(range));
324-
}
325-
return internal;
326-
}
327-
328292
std::vector<core::ir::Input> to_vec_internal_inputs(std::vector<CompileSpec::Input>& external) {
329293
std::vector<core::ir::Input> internal;
330294
for (auto range : external) {
@@ -348,24 +312,9 @@ core::runtime::CudaDevice to_internal_cuda_device(CompileSpec::Device device) {
348312

349313
core::CompileSpec to_internal_compile_spec(CompileSpec external) {
350314
core::CompileSpec internal(to_vec_internal_inputs(external.inputs));
351-
if (external.input_ranges.size() > 0 && external.inputs.size() > 0) {
352-
TRTORCH_THROW_ERROR(
353-
"Saw both input specs listed for inputs and input_ranges in CompileSpec. input_ranges is deprecated and will be removed in v0.5.0. Please port forward to using inputs");
354-
} else if (external.input_ranges.size() > 0) {
355-
internal = core::CompileSpec(to_vec_internal_inputs(external.input_ranges));
356-
} else {
357-
TRTORCH_CHECK(external.inputs.size() > 0, "Compilation requires at least one input specification");
358-
internal = core::CompileSpec(to_vec_internal_inputs(external.inputs));
359-
}
360315

361-
if (external.enabled_precisions.size() == 1 &&
362-
toTRTDataType(*external.enabled_precisions.begin()) == nvinfer1::DataType::kFLOAT &&
363-
toTRTDataType(external.op_precision) != nvinfer1::DataType::kFLOAT) {
364-
internal.convert_info.engine_settings.enabled_precisions.insert(toTRTDataType(external.op_precision));
365-
} else {
366-
for (auto p : external.enabled_precisions) {
367-
internal.convert_info.engine_settings.enabled_precisions.insert(toTRTDataType(p));
368-
}
316+
for (auto p : external.enabled_precisions) {
317+
internal.convert_info.engine_settings.enabled_precisions.insert(toTRTDataType(p));
369318
}
370319

371320
/* We want default behavior for types to match PyTorch, so in the case the user did not explicitly set the dtype for

examples/int8/training/vgg16/test_qat.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ def test(model, dataloader, crit):
8181
import trtorch
8282
# trtorch.logging.set_reportable_log_level(trtorch.logging.Level.Debug)
8383
compile_settings = {
84-
"input_shapes": [[1, 3, 32, 32]],
84+
"inputs": [trtorch.Input([1, 3, 32, 32])],
8585
"op_precision": torch.int8 # Run with FP16
8686
}
8787
new_mod = torch.jit.load('trained_vgg16_qat.jit.pt')

py/trtorch/_compile_spec.py

Lines changed: 1 addition & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -157,22 +157,11 @@ def _parse_torch_fallback(fallback_info: Dict[str, Any]) -> trtorch._C.TorchFall
157157

158158
def _parse_compile_spec(compile_spec: Dict[str, Any]) -> trtorch._C.CompileSpec:
159159
info = trtorch._C.CompileSpec()
160-
if "input_shapes" not in compile_spec and "inputs" not in compile_spec:
160+
if "inputs" not in compile_spec:
161161
raise KeyError(
162162
"Module input definitions are requried to compile module. Provide a list of trtorch.Input keyed to \"inputs\" in the compile spec"
163163
)
164164

165-
if "input_shapes" in compile_spec and "inputs" in compile_spec:
166-
raise KeyError(
167-
"Found both key \"input_shapes\", and \"inputs\" in compile spec, please port forward to using only \"inputs\""
168-
)
169-
170-
if "input_shapes" in compile_spec:
171-
warnings.warn(
172-
"Key \"input_shapes\" is deprecated in favor of \"inputs\". Support for \"input_shapes\" will be removed in TRTorch v0.5.0",
173-
DeprecationWarning)
174-
info.inputs = _parse_input_ranges(compile_spec["input_shapes"])
175-
176165
if "inputs" in compile_spec:
177166
if not all([isinstance(i, torch.Tensor) or isinstance(i, trtorch.Input) for i in compile_spec["inputs"]]):
178167
raise KeyError("Input specs should be either trtorch.Input or torch.Tensor, found types: {}".format(
@@ -186,12 +175,6 @@ def _parse_compile_spec(compile_spec: Dict[str, Any]) -> trtorch._C.CompileSpec:
186175
"Found both key \"op_precision\", and \"enabled_precisions\" in compile spec, please port forward to using only \"enabled_precisions\""
187176
)
188177

189-
if "op_precision" in compile_spec:
190-
warnings.warn(
191-
"Key \"op_precision\" is being deprecated in favor of \"enabled_precision\" which expects a set of precisions to be enabled during compilation (FP32 will always be enabled), Support for \"op_precision\" will be removed in TRTorch v0.5.0",
192-
DeprecationWarning)
193-
info.enabled_precisions = _parse_enabled_precisions(compile_spec["op_precision"])
194-
195178
if "enabled_precisions" in compile_spec:
196179
info.enabled_precisions = _parse_enabled_precisions(compile_spec["enabled_precisions"])
197180
# We want default behavior to match PyTorch, so in the case the user did not explicitly set the dtype for inputs they

tests/py/test_api.py

Lines changed: 0 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -13,38 +13,6 @@ def setUp(self):
1313
self.traced_model = torch.jit.trace(self.model, [self.input])
1414
self.scripted_model = torch.jit.script(self.model)
1515

16-
def test_compile_traced_deprecated(self):
17-
compile_spec = {
18-
"input_shapes": [self.input.shape],
19-
"device": {
20-
"device_type": trtorch.DeviceType.GPU,
21-
"gpu_id": 0,
22-
"dla_core": 0,
23-
"allow_gpu_fallback": False,
24-
"disable_tf32": False
25-
}
26-
}
27-
28-
trt_mod = trtorch.compile(self.traced_model, compile_spec)
29-
same = (trt_mod(self.input) - self.traced_model(self.input)).abs().max()
30-
self.assertTrue(same < 2e-3)
31-
32-
def test_compile_script_deprecated(self):
33-
compile_spec = {
34-
"input_shapes": [self.input.shape],
35-
"device": {
36-
"device_type": trtorch.DeviceType.GPU,
37-
"gpu_id": 0,
38-
"dla_core": 0,
39-
"allow_gpu_fallback": False,
40-
"disable_tf32": False
41-
}
42-
}
43-
44-
trt_mod = trtorch.compile(self.scripted_model, compile_spec)
45-
same = (trt_mod(self.input) - self.scripted_model(self.input)).abs().max()
46-
self.assertTrue(same < 2e-3)
47-
4816
def test_compile_traced(self):
4917
compile_spec = {
5018
"inputs": [trtorch.Input(self.input.shape, dtype=torch.float, format=torch.contiguous_format)],

tests/py/test_qat_trt_accuracy.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ def test_compile_script(self):
5555

5656
compile_spec = {
5757
"inputs": [trtorch.Input([16, 3, 32, 32])],
58-
"op_precision": torch.int8,
58+
"enabled_precisions": {torch.int8},
5959
# "enabled_precision": {torch.float32, torch.int8},
6060
}
6161

0 commit comments

Comments
 (0)