This guide aims to assist developers working on the AI runner, offering detailed instructions for debugging and setting up the development environment. For general information about the AI runner, refer to the AI Runner README.
Leverage the VSCode DevContainer for an efficient debugging experience with the AI runner. This configuration automatically prepares a development environment equipped with all necessary tools and dependencies.
Prerequisites:
Quickstart with DevContainer:
- Install VSCode and the Remote - Containers extension.
- Clone the repository and open it in VSCode.
- Navigate to the
runner
directory. - Open in Container: Click "Reopen in Container" when prompted, or manually initiate it by pressing
F1
, typing "Reopen in Container", and pressingEnter
. - Initialization: The initial build may take a few minutes. Subsequent starts are faster.
- Begin Debugging: The AI runner is now set up for debugging.
For more, see the VSCode documentation on DevContainers.
To debug the AI runner when it operates within a container orchestrated by external services, such as go-livepeer, follow these steps to attach to the container:
-
Update AI Runner Module Path: In the
go.mod
file of your local go-livepeer folder, modify the module path for the AI runner to point to your local version:go mod edit -replace github.com/livepeer/ai-worker=../path/to/ai-worker
-
Directory: Ensure you're in the
runner
directory. -
Build the AI Runner Image:
docker build -t livepeer/ai-runner:base .
-
Build the Debug Image:
docker build -f ./dev/Dockerfile.debug -t livepeer/ai-runner:latest .
-
Apply the Debug Patch: Implement the required code modifications to facilitate debugger attachment and expose the necessary ports.
cd .. && git apply ./runner/dev/patches/debug.patch && cd runner
-
Attach and Debug: Debugging the AI runner involves attaching to an active container. Ensure that VSCode is open in the
runner
directory. Follow these instructions to attach to a running container with the appropriate configuration:{ "version": "0.2.0", "configurations": [ { "name": "Python Debugger: Remote Attach", "type": "debugpy", "request": "attach", "connect": { "host": "0.0.0.0", "port": 5678 }, "pathMappings": [ { "localRoot": "${workspaceFolder}", "remoteRoot": "." } ] } ] }
-
Revert Changes: After debugging, undo the debug patch.
cd .. && git apply -R ./runner/dev/patches/debug.patch && cd runner
-
Rebuild the Image: Execute a rebuild of the image, ensuring to exclude the debug changes.
docker build -t livepeer/ai-runner:latest .
Mocking the pipelines is a practical approach for accelerating development and testing phases. This method simulates the pipeline execution, eliminating the need to run the actual model on a dedicated GPU. Follow the steps below to implement mocking:
-
Navigate to the Correct Directory: Ensure you are within the
runner
directory to apply changes effectively. -
Applying the Mock Patch: Use the command below to apply the necessary code modifications for mocking the pipelines. This step introduces a mock environment for your development process.
cd .. && git apply ./runner/dev/patches/mock.patch && cd runner
-
Starting the AI Runner with Mocking: Launch the AI runner with the environment variable
MOCK_PIPELINE
set toTrue
. This enables the mock mode for pipeline execution. -
Reverting Mock Changes: Once testing is complete and you wish to return to the actual pipeline execution, revert the applied mock changes using the following command:
cd .. && git apply -R ./runner/dev/patches/mock.patch && cd runner