diff --git a/cpp/include/trtorch/trtorch.h b/cpp/include/trtorch/trtorch.h index c62e947694..1e7adfd072 100644 --- a/cpp/include/trtorch/trtorch.h +++ b/cpp/include/trtorch/trtorch.h @@ -506,64 +506,6 @@ struct TRTORCH_API CompileSpec { bool explicit_set_dtype; }; - /** - * @brief A struct to hold an input range (used by TensorRT Optimization - * profile) - * - * This struct can either hold a single vector representing an input shape, - * signifying a static input shape or a set of three input shapes representing - * the min, optiminal and max input shapes allowed for the engine. - */ - struct TRTORCH_API InputRange { - /// Minimum acceptable input size into the engine - std::vector min; - /// Optimal input size into the engine (gets best performace) - std::vector opt; - /// Maximum acceptable input size into the engine - std::vector max; - /** - * @brief Construct a new Input Range object for static input size from - * vector - * - * @param opt - */ - [[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( - std::vector opt); - /** - * @brief Construct a new Input Range object static input size from - * c10::ArrayRef (the type produced by tensor.sizes()) - * - * @param opt - */ - [[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( - c10::ArrayRef opt); - /** - * @brief Construct a new Input Range object dynamic input size from vectors - * for min, opt, and max supported sizes - * - * @param min - * @param opt - * @param max - */ - [[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( - std::vector min, - std::vector opt, - std::vector max); - /** - * @brief Construct a new Input Range object dynamic input size from - * c10::ArrayRef (the type produced by tensor.sizes()) for min, opt, and max - * supported sizes - * - * @param min - * @param opt - * @param max - */ - [[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( - c10::ArrayRef min, - c10::ArrayRef opt, - c10::ArrayRef max); - }; - /** * @brief A struct to hold fallback info */ @@ -596,18 +538,6 @@ struct TRTORCH_API CompileSpec { TorchFallback(bool enabled, uint64_t min_size) : enabled(enabled), min_block_size(min_size) {} }; - /** - * @brief Construct a new Extra Info object from input ranges. - * Each entry in the vector represents a input and should be provided in call - * order. - * - * Use this constructor if you want to use dynamic shape - * - * @param input_ranges - */ - [[deprecated("trtorch::CompileSpec::CompileSpec(std::vector input_ranges) is being deprecated in favor of trtorch::CompileSpec::CompileSpec(std::vector inputs). Please use CompileSpec(std::vector inputs). trtorch::CompileSpec::CompileSpec(std::vector input_ranges) will be removed in TRTorch v0.5.0")]] CompileSpec( - std::vector input_ranges) - : input_ranges(std::move(input_ranges)) {} /** * @brief Construct a new Extra Info object * Convienence constructor to set fixed input size from vectors describing @@ -657,24 +587,6 @@ struct TRTORCH_API CompileSpec { */ std::vector inputs; - /** - * Sizes for inputs to engine, can either be a single size or a range - * defined by Min, Optimal, Max sizes - * - * Order is should match call order - */ - [[deprecated( - "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:: - vector - input_ranges; - - /** - * Default operating precision for the engine - */ - [[deprecated( - "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 - op_precision = DataType::kFloat; - /** * @brief The set of precisions TensorRT is allowed to use for kernels during compilation * diff --git a/cpp/src/compile_spec.cpp b/cpp/src/compile_spec.cpp index 24c771cad4..9112f6673b 100644 --- a/cpp/src/compile_spec.cpp +++ b/cpp/src/compile_spec.cpp @@ -144,30 +144,6 @@ CompileSpec::Device::DeviceType::DeviceType(c10::DeviceType t) { value = DeviceType::kGPU; } -CompileSpec::InputRange::InputRange(std::vector opt) { - this->opt = opt; - this->min = opt; - this->max = opt; -} - -CompileSpec::InputRange::InputRange(c10::IntArrayRef opt) { - this->opt = core::util::toVec(opt); - this->min = core::util::toVec(opt); - this->max = core::util::toVec(opt); -} - -CompileSpec::InputRange::InputRange(std::vector min, std::vector opt, std::vector max) { - this->opt = opt; - this->min = min; - this->max = max; -} - -CompileSpec::InputRange::InputRange(c10::IntArrayRef min, c10::IntArrayRef opt, c10::IntArrayRef max) { - this->opt = core::util::toVec(opt); - this->min = core::util::toVec(min); - this->max = core::util::toVec(max); -} - CompileSpec::CompileSpec(std::vector> fixed_sizes) { for (auto in : fixed_sizes) { inputs.push_back(Input(in)); @@ -289,22 +265,10 @@ CompileSpec::Input::Input( /* ==========================================*/ -core::ir::Input to_internal_input(CompileSpec::InputRange& i) { - return core::ir::Input(i.min, i.opt, i.max); -} - core::ir::Input to_internal_input(CompileSpec::Input& i) { return core::ir::Input(i.min_shape, i.opt_shape, i.max_shape, toTRTDataType(i.dtype), toTRTTensorFormat(i.format)); } -std::vector to_vec_internal_inputs(std::vector& external) { - std::vector internal; - for (auto range : external) { - internal.push_back(to_internal_input(range)); - } - return internal; -} - std::vector to_vec_internal_inputs(std::vector& external) { std::vector internal; for (auto range : external) { @@ -328,24 +292,9 @@ core::runtime::CudaDevice to_internal_cuda_device(CompileSpec::Device device) { core::CompileSpec to_internal_compile_spec(CompileSpec external) { core::CompileSpec internal(to_vec_internal_inputs(external.inputs)); - if (external.input_ranges.size() > 0 && external.inputs.size() > 0) { - TRTORCH_THROW_ERROR( - "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"); - } else if (external.input_ranges.size() > 0) { - internal = core::CompileSpec(to_vec_internal_inputs(external.input_ranges)); - } else { - TRTORCH_CHECK(external.inputs.size() > 0, "Compilation requires at least one input specification"); - internal = core::CompileSpec(to_vec_internal_inputs(external.inputs)); - } - if (external.enabled_precisions.size() == 1 && - toTRTDataType(*external.enabled_precisions.begin()) == nvinfer1::DataType::kFLOAT && - toTRTDataType(external.op_precision) != nvinfer1::DataType::kFLOAT) { - internal.convert_info.engine_settings.enabled_precisions.insert(toTRTDataType(external.op_precision)); - } else { - for (auto p : external.enabled_precisions) { - internal.convert_info.engine_settings.enabled_precisions.insert(toTRTDataType(p)); - } + for (auto p : external.enabled_precisions) { + internal.convert_info.engine_settings.enabled_precisions.insert(toTRTDataType(p)); } /* We want default behavior for types to match PyTorch, so in the case the user did not explicitly set the dtype for diff --git a/examples/int8/training/vgg16/test_qat.py b/examples/int8/training/vgg16/test_qat.py index ad5d0345c0..778eb6fa40 100644 --- a/examples/int8/training/vgg16/test_qat.py +++ b/examples/int8/training/vgg16/test_qat.py @@ -81,7 +81,7 @@ def test(model, dataloader, crit): import trtorch # trtorch.logging.set_reportable_log_level(trtorch.logging.Level.Debug) compile_settings = { -"input_shapes": [[1, 3, 32, 32]], +"inputs": [trtorch.Input([1, 3, 32, 32])], "op_precision": torch.int8 # Run with FP16 } new_mod = torch.jit.load('trained_vgg16_qat.jit.pt') diff --git a/py/trtorch/_compile_spec.py b/py/trtorch/_compile_spec.py index dc2e7095fa..bff9d5390a 100644 --- a/py/trtorch/_compile_spec.py +++ b/py/trtorch/_compile_spec.py @@ -157,22 +157,11 @@ def _parse_torch_fallback(fallback_info: Dict[str, Any]) -> trtorch._C.TorchFall def _parse_compile_spec(compile_spec: Dict[str, Any]) -> trtorch._C.CompileSpec: info = trtorch._C.CompileSpec() - if "input_shapes" not in compile_spec and "inputs" not in compile_spec: + if "inputs" not in compile_spec: raise KeyError( "Module input definitions are requried to compile module. Provide a list of trtorch.Input keyed to \"inputs\" in the compile spec" ) - if "input_shapes" in compile_spec and "inputs" in compile_spec: - raise KeyError( - "Found both key \"input_shapes\", and \"inputs\" in compile spec, please port forward to using only \"inputs\"" - ) - - if "input_shapes" in compile_spec: - warnings.warn( - "Key \"input_shapes\" is deprecated in favor of \"inputs\". Support for \"input_shapes\" will be removed in TRTorch v0.5.0", - DeprecationWarning) - info.inputs = _parse_input_ranges(compile_spec["input_shapes"]) - if "inputs" in compile_spec: info.inputs = [i._to_internal() for i in compile_spec["inputs"]] @@ -181,12 +170,6 @@ def _parse_compile_spec(compile_spec: Dict[str, Any]) -> trtorch._C.CompileSpec: "Found both key \"op_precision\", and \"enabled_precisions\" in compile spec, please port forward to using only \"enabled_precisions\"" ) - if "op_precision" in compile_spec: - warnings.warn( - "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", - DeprecationWarning) - info.enabled_precisions = _parse_enabled_precisions(compile_spec["op_precision"]) - if "enabled_precisions" in compile_spec: info.enabled_precisions = _parse_enabled_precisions(compile_spec["enabled_precisions"]) # We want default behavior to match PyTorch, so in the case the user did not explicitly set the dtype for inputs they diff --git a/tests/py/test_api.py b/tests/py/test_api.py index 94239b1475..ba4f4ec276 100644 --- a/tests/py/test_api.py +++ b/tests/py/test_api.py @@ -13,38 +13,6 @@ def setUp(self): self.traced_model = torch.jit.trace(self.model, [self.input]) self.scripted_model = torch.jit.script(self.model) - def test_compile_traced_deprecated(self): - compile_spec = { - "input_shapes": [self.input.shape], - "device": { - "device_type": trtorch.DeviceType.GPU, - "gpu_id": 0, - "dla_core": 0, - "allow_gpu_fallback": False, - "disable_tf32": False - } - } - - trt_mod = trtorch.compile(self.traced_model, compile_spec) - same = (trt_mod(self.input) - self.traced_model(self.input)).abs().max() - self.assertTrue(same < 2e-3) - - def test_compile_script_deprecated(self): - compile_spec = { - "input_shapes": [self.input.shape], - "device": { - "device_type": trtorch.DeviceType.GPU, - "gpu_id": 0, - "dla_core": 0, - "allow_gpu_fallback": False, - "disable_tf32": False - } - } - - trt_mod = trtorch.compile(self.scripted_model, compile_spec) - same = (trt_mod(self.input) - self.scripted_model(self.input)).abs().max() - self.assertTrue(same < 2e-3) - def test_compile_traced(self): compile_spec = { "inputs": [trtorch.Input(self.input.shape, dtype=torch.float, format=torch.contiguous_format)],