diff --git a/py/torch_tensorrt/dynamo/_compiler.py b/py/torch_tensorrt/dynamo/_compiler.py index b870de4174..028fcdaadb 100644 --- a/py/torch_tensorrt/dynamo/_compiler.py +++ b/py/torch_tensorrt/dynamo/_compiler.py @@ -1351,6 +1351,9 @@ def compile_module( num_supported_ops, total_ops = partitioning.get_graph_converter_support( gm, settings.torch_executed_ops ) + skip_conversion_validation = ( + settings.require_full_compilation and num_supported_ops == total_ops + ) dryrun_tracker.total_ops_in_graph = total_ops dryrun_tracker.supported_ops_in_graph = num_supported_ops @@ -1422,6 +1425,7 @@ def contains_metadata(gm: torch.fx.GraphModule) -> bool: settings=settings, name="_run_on_acc_0", engine_cache=engine_cache, + skip_conversion_validation=skip_conversion_validation, ) # Store the original input spec for later use @@ -1622,6 +1626,7 @@ def preserve_module_specs( settings=settings, name=name, engine_cache=engine_cache, + skip_conversion_validation=skip_conversion_validation, ) trt_modules[name] = trt_module diff --git a/py/torch_tensorrt/dynamo/conversion/_TRTInterpreter.py b/py/torch_tensorrt/dynamo/conversion/_TRTInterpreter.py index 4c0ca15913..fcca2e155b 100644 --- a/py/torch_tensorrt/dynamo/conversion/_TRTInterpreter.py +++ b/py/torch_tensorrt/dynamo/conversion/_TRTInterpreter.py @@ -168,6 +168,7 @@ def __init__( input_binding_names: Optional[Sequence[str]] = None, output_binding_names: Optional[Sequence[str]] = None, _debugger_config: Optional[DebuggerConfig] = None, + skip_conversion_validation: bool = False, ): super().__init__(module) @@ -194,12 +195,16 @@ def __init__( # an xdist worker), making those ops incorrectly appear as disallowed. CONVERTERS.set_compilation_settings(compilation_settings) self.validate_compile_settings() - missing_ops = self.validate_conversion() - if missing_ops: - warnings.warn( - "Interpretation will fail due to missing operations \n" - + "\n".join(f"{i}" for i in missing_ops) - ) + # compile_module already walked CONVERTERS via get_graph_converter_support. + # When that count was complete under require_full_compilation, this extra + # get() pass cannot find missing ops; skip it. + if not skip_conversion_validation: + missing_ops = self.validate_conversion() + if missing_ops: + warnings.warn( + "Interpretation will fail due to missing operations \n" + + "\n".join(f"{i}" for i in missing_ops) + ) # Optimization profiles. Profiles are an ordered list on # ``Input.profiles``; profile index i is built from each input's diff --git a/py/torch_tensorrt/dynamo/conversion/_conversion.py b/py/torch_tensorrt/dynamo/conversion/_conversion.py index 2823ec7ac9..c809a8fb74 100644 --- a/py/torch_tensorrt/dynamo/conversion/_conversion.py +++ b/py/torch_tensorrt/dynamo/conversion/_conversion.py @@ -212,6 +212,7 @@ def interpret_module_to_result( *, input_binding_names: Optional[Sequence[str]] = None, output_binding_names: Optional[Sequence[str]] = None, + skip_conversion_validation: bool = False, ) -> SerializedInterpreterResult: """Interpret an FX module to a TRTInterpreterResult Args: @@ -219,6 +220,8 @@ def interpret_module_to_result( inputs: It requires a sequence of FLATTENED Inputs representing inputs to the module. It should include both arg_inputs and kwarg_inputs, if applicable. settings: Compilation settings engine_cache: Engine cache instance + skip_conversion_validation: If True, skip TRTInterpreter.validate_conversion. + Set by compile_module when require_full_compilation already proved full converter coverage. Returns: SerializedInterpreterResult """ @@ -291,6 +294,7 @@ def interpret_module_to_result( engine_cache=engine_cache, input_binding_names=input_binding_names, output_binding_names=output_binding_names, + skip_conversion_validation=skip_conversion_validation, ) interpreter_result = interpreter.run() @@ -349,6 +353,7 @@ def convert_module( settings: CompilationSettings = CompilationSettings(), name: str = "", engine_cache: Optional[BaseEngineCache] = None, + skip_conversion_validation: bool = False, ) -> TorchTensorRTModule: """Convert an FX module to a TRT module Args: @@ -357,11 +362,16 @@ def convert_module( settings: Compilation settings name: TRT engine name engine_cache: Engine cache instance + skip_conversion_validation: If True, skip TRTInterpreter.validate_conversion. Returns: TorchTensorRTModule """ serialized_interpreter_result = interpret_module_to_result( - module, inputs, settings, engine_cache=engine_cache + module, + inputs, + settings, + engine_cache=engine_cache, + skip_conversion_validation=skip_conversion_validation, ) if not ENABLED_FEATURES.torch_tensorrt_runtime: