Skip to content

Commit b9e784a

Browse files
authored
Patch for dual-mode-worker.mdx (#294)
1 parent cf7cdd2 commit b9e784a

File tree

1 file changed

+14
-14
lines changed

1 file changed

+14
-14
lines changed

serverless/development/dual-mode-worker.mdx

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ In this tutorial you'll learn how to:
3939

4040
## Requirements
4141

42-
* You've [created a RunPod account](/get-started/manage-accounts).
42+
* You've [created a Runpod account](/get-started/manage-accounts).
4343
* You've installed [Python 3.x](https://www.python.org/downloads/) and [Docker](https://docs.docker.com/get-started/get-docker/) on your local machine and configured them for your command line.
4444
* Basic understanding of Docker concepts and shell scripting.
4545

@@ -57,7 +57,7 @@ touch handler.py start.sh Dockerfile requirements.txt
5757

5858
This creates:
5959

60-
- `handler.py`: Your Python script with the RunPod handler logic.
60+
- `handler.py`: Your Python script with the Runpod handler logic.
6161
- `start.sh`: A shell script that will be the entrypoint for your Docker container.
6262
- `Dockerfile`: Instructions to build your Docker image.
6363
- `requirements.txt`: A file to list Python dependencies.
@@ -105,9 +105,9 @@ Key features:
105105

106106
* `MODE_TO_RUN = os.getenv("MODE_TO_RUN", "pod")`: Reads the mode from an environment variable, defaulting to `pod`.
107107
* `async def handler(event)`: Your core logic.
108-
* `if __name__ == '__main__':`: This block controls what happens when the script is executed directly.
109-
* In `serverless`" mode, it starts the RunPod Serverless worker.
108+
* `if mode_to_run == "pod" ... else`: This conditional controls what happens when the script is executed directly.
110109
* In `pod` mode, it runs a sample test call to your `handler` function, allowing for quick iteration.
110+
* In `serverless`" mode, it starts the Runpod Serverless worker.
111111

112112
## Step 3: Create the `start.sh` script
113113

@@ -214,7 +214,7 @@ sleep infinity
214214
```
215215
Key features:
216216
* `case $MODE_TO_RUN in ... esac`: This structure directs the startup based on the mode.
217-
* `serverless` mode: Executes `handler.py`, which then starts the RunPod Serverless worker. `exec` replaces the shell process with the Python process.
217+
* `serverless` mode: Executes `handler.py`, which then starts the Runpod Serverless worker. `exec` replaces the shell process with the Python process.
218218
* `pod` mode: Starts up the JupyterLab server for Pod development, then runs `sleep infinity` to keep the container alive so you can connect to it (e.g., via SSH or `docker exec`). You would then manually run `python /app/handler.py` inside the Pod to test your handler logic.
219219

220220
## Step 4: Create the `Dockerfile`
@@ -224,7 +224,7 @@ This file defines how to build your Docker image.
224224
Add the following content to `Dockerfile`:
225225

226226
```dockerfile
227-
# Use an official RunPod base image
227+
# Use an official Runpod base image
228228
FROM runpod/pytorch:2.0.1-py3.10-cuda11.8.0-devel-ubuntu22.04
229229

230230
# Environment variables
@@ -267,7 +267,7 @@ COPY requirements.txt ./requirements.txt
267267
RUN pip install --no-cache-dir --upgrade pip && \
268268
pip install --no-cache-dir -r requirements.txt
269269

270-
# Delete's the default start.sh file from RunPod (so we can replace it with our own below)
270+
# Delete's the default start.sh file from Runpod (so we can replace it with our own below)
271271
RUN rm ../start.sh
272272

273273
# Copy all of our files into the container
@@ -284,7 +284,7 @@ RUN ls -la $WORKSPACE_DIR/start.sh
284284
CMD $WORKSPACE_DIR/start.sh
285285
```
286286
Key features:
287-
* `FROM runpod/pytorch:2.0.1-py3.10-cuda11.8.0-devel-ubuntu22.04`: Starts with a RunPod base image that comes with nginx, runpodctl, and other helpful base packages.
287+
* `FROM runpod/pytorch:2.0.1-py3.10-cuda11.8.0-devel-ubuntu22.04`: Starts with a Runpod base image that comes with nginx, runpodctl, and other helpful base packages.
288288
* `ARG WORKSPACE_DIR=/workspace` and `ENV WORKSPACE_DIR=${WORKSPACE_DIR}`: Allows the workspace directory to be set at build time.
289289
* `WORKDIR $WORKSPACE_DIR`: Sets the working directory to the value of `WORKSPACE_DIR`.
290290
* `COPY requirements.txt ./requirements.txt` and `RUN pip install ...`: Installs Python dependencies.
@@ -309,7 +309,7 @@ Now, build your Docker image and push it to a container registry like Docker Hub
309309
```sh
310310
docker build --platform linux/amd64 --tag [YOUR_USERNAME]/dual-mode-worker .
311311
```
312-
The `--platform linux/amd64` flag is important for compatibility with RunPod's infrastructure.
312+
The `--platform linux/amd64` flag is important for compatibility with Runpod's infrastructure.
313313
</Step>
314314

315315
<Step title="Push the image to your container registry">
@@ -330,7 +330,7 @@ Now that you've finished building our Docker image, let's explore how you would
330330

331331
Deploy the image to a Pod by following these steps:
332332

333-
1. Go to the [Pods page](https://www.runpod.io/console/pods) in the RunPod console and click **Create Pod**.
333+
1. Go to the [Pods page](https://www.runpod.io/console/pods) in the Runpod console and click **Create Pod**.
334334
2. Choose a GPU.
335335
3. For "Docker Image Name", enter `[YOUR_USERNAME]/dual-mode-worker:latest`.
336336
4. Under **Pod Template**, select **Edit Template**.
@@ -349,7 +349,7 @@ This will execute the Pod-specific test harness in your `handler.py`, giving you
349349

350350
Once you're confident with your `handler.py` logic tested in Pod mode, you're ready to deploy your dual-mode worker to a Serverless endpoint.
351351

352-
1. Go to the [Serverless section](https://www.runpod.io/console/serverless) of the RunPod console.
352+
1. Go to the [Serverless section](https://www.runpod.io/console/serverless) of the Runpod console.
353353
2. Click **New Endpoint**.
354354
3. Under **Custom Source**, select **Docker Image**, then select **Next**.
355355
4. In the **Container Image** field, enter your Docker image URL: `docker.io/[YOUR_USERNAME]/dual-mode-worker:latest`.
@@ -363,7 +363,7 @@ The *same* image is used, but `start.sh` will now direct it to run in Serverless
363363

364364
After deploying your endpoint in to Serverless mode, you can test it with the following steps:
365365

366-
1. Navigate to your endpoint's detail page in the RunPod console.
366+
1. Navigate to your endpoint's detail page in the Runpod console.
367367
2. Click the **Requests** tab.
368368
3. Use the following JSON as test input:
369369
```json
@@ -395,7 +395,7 @@ Congratulations! You've successfully built, deployed, and tested a dual-mode Ser
395395

396396
<Steps>
397397
<Step title="Develop using Pod mode">
398-
1. Deploy your initial Docker image to a RunPod Pod, ensuring `MODE_TO_RUN` is set to `pod` (or rely on the Dockerfile default).
398+
1. Deploy your initial Docker image to a Runpod Pod, ensuring `MODE_TO_RUN` is set to `pod` (or rely on the Dockerfile default).
399399
2. [Connect to your Pod](/pods/connect-to-pod) (via SSH or web terminal).
400400
3. Navigate to the `/app` directory.
401401
4. As you develop, install any necessary Python packages (`pip install [PACKAGE_NAME]`) or system dependencies (`apt-get install [PACKAGE_NAME]`).
@@ -434,4 +434,4 @@ Now that you've mastered the dual-mode development workflow, you can:
434434
* [Explore advanced handler functions.](/serverless/workers/handler-functions)
435435
* [Learn about sending requests programmatically via API or SDKs.](/serverless/endpoints/send-requests)
436436
* [Understand endpoint configurations for performance and cost optimization.](/serverless/endpoints/endpoint-configurations)
437-
* [Deep dive into local testing and development.](/serverless/development/local-testing)
437+
* [Deep dive into local testing and development.](/serverless/development/local-testing)

0 commit comments

Comments
 (0)