async def prepare_for_model_debugging(
        self,
        credentials: _Optional[AppSigningCredentials] = None,
        working_directory: _Optional[_Path] = None,
        clean: bool = False,
    ) -> _Type["Device"]:
        """
        Prepares the device for model debugging by building and launching the model runner app.

        This method checks if the device is in the correct state for debugging, sets up the working
        directory, builds the ``modelrunner`` application, and launches it on the device.

        Parameters
        ----------
        credentials : Optional[AppSigningCredentials
            The credentials required for signing ``modelrunner`` application.

        working_directory: Optional[Path]
            The directory utilized for storing files required for building and communicating
            with the ``modelrunner`` application. If None, a temporary director will be created.
            Defaults to None.

        clean : bool
            If True, performs a clean build. Defaults to False.

        Returns
        -------
        Device
            A new Device instance with the prepared session.
        """

        async def report_progress(
            future: _asyncio.Future,
            message: str,
            delay: float = 1.0,
        ):
            with _tqdm.tqdm(desc=message, bar_format="\033[1m{desc} {elapsed}s\033[0m") as pbar:
                while not future.done():
                    await _asyncio.sleep(delay)
                    pbar.update(0)

        if not (self.state == DeviceState.CONNECTED):
            raise ValueError(
                "The device cannot be used for model debugging. "
                f"Current state: {self.state}. "
                "Required: State must be CONNECTED."
            )

        if working_directory is None:
            working_directory = _tempfile.mkdtemp()

        if isinstance(working_directory, str):
            working_directory = _Path(working_directory)

        if not working_directory.is_dir():
            raise ValueError(
                f"The specified working directory '{working_directory}' is invalid. Please ensure it exists and is a directory."
            )

        if credentials is None:
            credentials = AppSigningCredentials(
                development_team="",
                bundle_identifier=None,
                provisioning_profile_uuid=None,
            )

        build_directory = working_directory / "build"
        loop = _asyncio.get_event_loop()

        session_future = loop.run_in_executor(
            None,
            self._build_and_launch_model_runner_app,
            working_directory,
            build_directory,
            credentials,
            clean,
        )

        progress_task = _asyncio.create_task(
            report_progress(
                future=session_future,
                message=f"Setting up '{self.name}' for model debugging. This may take a few moments...",
            )
        )

        try:
            session, _ = await _asyncio.gather(session_future, progress_task)
        finally:
            progress_task.cancel()  # Ensure progress task is cancelled

        return Device(
            name=self.name,
            type=self.type,
            identifier=self.identifier,
            udid=self.udid,
            state=self.state,
            os_version=self.os_version,
            os_build_number=self.os_build_number,
            developer_mode_state=self.developer_mode_state,
            session=session,
        )

        Prepares the device for model debugging by building and launching the model runner app.

        This method checks if the device is in the correct state for debugging, sets up the working
        directory, builds the ``modelrunner`` application, and launches it on the device.

        Parameters
        ----------
        credentials : Optional[AppSigningCredentials
            The credentials required for signing ``modelrunner`` application.

        working_directory: Optional[Path]
            The directory utilized for storing files required for building and communicating
            with the ``modelrunner`` application. If None, a temporary director will be created.
            Defaults to None.

        clean : bool
            If True, performs a clean build. Defaults to False.

        Returns
        -------
        Device
            A new Device instance with the prepared session.
        
coremltools/models/ml_program/experimental/remote_device.py