def compress(self, num_kmeans_workers: int = 1, inplace: bool = False) -> _torch.nn.Module:
        """
        The compress method performs a `k-means` operation on all supported modules.

        Args:
            num_kmeans_workers (:obj:`int`): Number of worker processes used for
                performing post-training palettization. It is recommended to use more than one worker
                process to parallelize the clustering, especially when multiple CPUs are available.
                Defaults to ``1``.
            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)
        kmeans_config_dict = dict()
        for name, submodule in self._model.named_modules():
            submod_config = self._config.get_module_config(name, submodule)
            if submod_config is None:
                continue

            k_means_module_cls = _KMeansSupportedModulesRegistry.get_kmeans_module(submodule)
            if k_means_module_cls is None:
                continue

            for param_name in k_means_module_cls.parameter_names:
                # Validate configuration for parameter
                param = submodule.get_parameter(param_name)
                updated_config = _validate_param_config(
                    name + "." + param_name,
                    param,
                    submodule,
                    submod_config,
                    ["palettization_group_size", "palettization_cluster_dim"],
                )
                if not updated_config:
                    continue

                if name not in kmeans_config_dict:
                    kmeans_config_dict[name] = {}

                kmeans_config_dict[name][param_name] = _KMeansConfig(
                    n_bits=updated_config.n_bits,
                    axis=updated_config.channel_axis,
                    lut_dtype=updated_config.lut_dtype,
                    block_size=updated_config.group_size,
                    cluster_dim=updated_config.cluster_dim,
                    enable_per_channel_scale=updated_config.enable_per_channel_scale,
                    enable_fast_kmeans_mode=updated_config.enable_fast_kmeans_mode,
                    rounding_precision=updated_config.rounding_precision,
                )

        if num_kmeans_workers > 1:
            return _ParallelKMeans.cluster_weights(
                self._model, kmeans_config_dict, num_workers=num_kmeans_workers
            )
        else:
            return _SequentialKMeans.cluster_weights(self._model, kmeans_config_dict)

        The compress method performs a `k-means` operation on all supported modules.

        Args:
            num_kmeans_workers (:obj:`int`): Number of worker processes used for
                performing post-training palettization. It is recommended to use more than one worker
                process to parallelize the clustering, especially when multiple CPUs are available.
                Defaults to ``1``.
            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/palettization/post_training_palettization.py