def inspect(
        self,
        inputs: Tuple[torch.Tensor],
        module_info_keys: List[TorchScriptModuleInfo.Key],
    ) -> List[Tuple[(TorchScriptModuleInfo.Key, Optional[Any])]]:
        """
        Inspects specified modules during a forward pass of the model.

        This method registers forward hooks on the specified modules, performs a forward pass
        with the given inputs, and collects the output tensors for each specified module.

        Parameters
        ----------
        inputs : Tuple[torch.Tensor]
            The input tensors for the model's forward pass.

        module_infos : List[ModuleInfo]
            A list of ModuleInfo objects specifying which modules to inspect.

        Returns
        -------
        List[Tuple[ModuleInfo, Optional[torch.Tensor]]]
            A list of tuples, each containing a ModuleInfo object and its corresponding output tensor (if available).

        Note
        ----
        The method uses forward hooks to capture module outputs. These hooks are removed after the inspection process.
        """

        module_call_sequences = {}
        result = OrderedDict()

        for module_info_key in module_info_keys:
            result[module_info_key] = (module_info_key, None)

        def register_forward_hook(module: torch.nn.Module, name: str) -> Any:
            def set_module_output(
                curr_module: torch.nn.Module,
                inputs: Tuple[torch.Tensor],
                output: torch.Tensor,
            ) -> None:
                nonlocal module_call_sequences
                nonlocal result

                sequence = module_call_sequences.get(name, 0)
                module_call_sequences[name] = sequence + 1
                value = result.get((name, sequence), None)
                if value is not None:
                    result[(name, sequence)] = (value[0], output)

                return output

            return module.register_forward_hook(set_module_output, always_call=False)

        hooks = []
        interested_module_names = [module_info_key[0] for module_info_key in module_info_keys]
        for (name, module) in self._model.named_modules():
            if name in interested_module_names:
                hook = register_forward_hook(module=module, name=name)
                hooks.append(hook)

        self._model(*inputs)
        for hook in hooks:
            hook.remove()

        return result.values()

        Inspects specified modules during a forward pass of the model.

        This method registers forward hooks on the specified modules, performs a forward pass
        with the given inputs, and collects the output tensors for each specified module.

        Parameters
        ----------
        inputs : Tuple[torch.Tensor]
            The input tensors for the model's forward pass.

        module_infos : List[ModuleInfo]
            A list of ModuleInfo objects specifying which modules to inspect.

        Returns
        -------
        List[Tuple[ModuleInfo, Optional[torch.Tensor]]]
            A list of tuples, each containing a ModuleInfo object and its corresponding output tensor (if available).

        Note
        ----
        The method uses forward hooks to capture module outputs. These hooks are removed after the inspection process.
        
coremltools/models/ml_program/experimental/torch/debugging_utils.py