def compress(self, inplace: bool = False) -> _torch.nn.Module:
        """
        Compress the supported layers in the module by quantizing each weight value of the layer.

        Args:
            inplace (:obj:`bool`): If ``True``, model transformations are carried out in-place and
                the original module is mutated, otherwise a copy of the model is mutated and returned.
                Defaults to ``False``.
        """
        self._model = super().compress(inplace=inplace)
        for submod_name, submodule in _get_atomic_layers(
            self._model, layer_types=list(self._supported_modules)
        ).items():
            submod_config = self._config.get_module_config(submod_name, submodule)
            if submod_config is None:
                continue

            # TODO: Replace this with supported modules abstraction
            # --- Conv, ConvTranspose & Linear layers ---
            if isinstance(submodule, self._supported_modules) and not isinstance(
                submodule, _nn.MultiheadAttention
            ):
                assert hasattr(
                    submodule, "weight"
                ), f"No parameter named weight in submodule {submod_name}"
                self._quantize_weight(submod_name, submodule, submod_config, "weight")

            # --- MultiheadAttention layer ---
            elif isinstance(submodule, _nn.MultiheadAttention):
                param_names = [
                    "in_proj_weight",
                    "q_proj_weight",
                    "k_proj_weight",
                    "v_proj_weight",
                ]
                for param_name in param_names:
                    if not hasattr(submodule, param_name):
                        continue
                    if getattr(submodule, param_name) is None:
                        continue
                    self._quantize_weight(submod_name, submodule, submod_config, param_name)

                if hasattr(submodule, "out_proj") and submodule.out_proj.weight is not None:
                    self._quantize_weight(
                        f"{submod_name}.out_proj",
                        submodule.out_proj,
                        submod_config,
                        "weight",
                    )
        return self._model

        Compress the supported layers in the module by quantizing each weight value of the layer.

        Args:
            inplace (:obj:`bool`): If ``True``, model transformations are carried out in-place and
                the original module is mutated, otherwise a copy of the model is mutated and returned.
                Defaults to ``False``.
        
coremltools/optimize/torch/quantization/post_training_quantization.py