Skip to content

Commit

Permalink
chore: add pipeline mock development guide
Browse files Browse the repository at this point in the history
This commit adds all the components needed to be able to mock the
pipelines.
  • Loading branch information
rickstaa committed Jun 26, 2024
1 parent bd77a8b commit f3d44b1
Show file tree
Hide file tree
Showing 3 changed files with 57 additions and 1 deletion.
2 changes: 1 addition & 1 deletion dev/README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Development Guide

This guide provides instructions for setting up the development environment and debugging the [AI worker](https://github.com/livepeer/ai-worker) repository.
This document offers a comprehensive guide for configuring the development environment and debugging the [worker](worker) component within the [AI worker](https://github.com/livepeer/ai-worker) repository. For an in-depth exploration of developing the [runner](runner), please consult the [AI runner development guide](runner/dev/README.md).

## Debugging

Expand Down
21 changes: 21 additions & 0 deletions runner/dev/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -85,3 +85,24 @@ To debug the AI runner when it operates within a container orchestrated by exter
```bash
docker build -t livepeer/ai-runner:latest .
```

### Mocking the Pipelines

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:

1. **Navigate to the Correct Directory**:
Ensure you are within the `runner` directory to apply changes effectively.

2. **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.

```bash
cd .. && git apply ./runner/dev/patches/mock.patch && cd runner
```

3. **Starting the AI Runner with Mocking**: Launch the AI runner with the environment variable `MOCK_PIPELINE` set to `True`. This enables the mock mode for pipeline execution.
4. **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:

```bash
cd .. && git apply -R ./runner/dev/patches/mock.patch && cd runner
```
35 changes: 35 additions & 0 deletions runner/dev/patches/mock.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
commit bd77a8bc1ec9afbc86682beff5b71ef13703753c
Author: Rick Staa <[email protected]>
Date: Wed Jun 26 12:25:37 2024 +0100

refactor: improve code formating

This commit improves the I2I code formatting.

diff --git a/runner/app/pipelines/text_to_image.py b/runner/app/pipelines/text_to_image.py
index ac2334a..278c04e 100644
--- a/runner/app/pipelines/text_to_image.py
+++ b/runner/app/pipelines/text_to_image.py
@@ -14,7 +14,13 @@ from huggingface_hub import file_download, hf_hub_download
from safetensors.torch import load_file

from app.pipelines.base import Pipeline
-from app.pipelines.util import get_model_dir, get_torch_device, SafetyChecker, is_lightning_model, is_turbo_model
+from app.pipelines.util import (
+ get_model_dir,
+ get_torch_device,
+ SafetyChecker,
+ is_lightning_model,
+ is_turbo_model,
+)

logger = logging.getLogger(__name__)

@@ -52,7 +58,6 @@ class TextToImagePipeline(Pipeline):
logger.info("TextToImagePipeline using bfloat16 precision for %s", model_id)
kwargs["torch_dtype"] = torch.bfloat16

-
# Special case SDXL-Lightning because the unet for SDXL needs to be swapped
if SDXL_LIGHTNING_MODEL_ID in model_id:
base = "stabilityai/stable-diffusion-xl-base-1.0"

0 comments on commit f3d44b1

Please sign in to comment.