From 3ee0ac9cdf561c05c3d79c977467f1fcda2c1867 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E2=9D=A4=EF=B8=8F?= Date: Thu, 11 Jan 2024 13:22:18 -0500 Subject: [PATCH 1/5] recommend against baking weights into docker images MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: ❤️ --- docs/python.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/python.md b/docs/python.md index cfcb3d345a..ffc33c2714 100644 --- a/docs/python.md +++ b/docs/python.md @@ -50,7 +50,7 @@ Prepare the model so multiple predictions run efficiently. Use this _optional_ method to include any expensive one-off operations in here like loading trained models, instantiate data transformations, etc. -It's best not to download model weights or any other files in this function. You should bake these into the image when you build it. This means your model doesn't depend on any other system being available and accessible. It also means the Docker image ID becomes an immutable identifier for the precise model you're running, instead of the combination of the image ID and whatever files it might have downloaded. +Baking your weights into the image could cause it to be large and increase your build times. Instead, you should download the weights (e.g. using [`pget`](https://github.com/replicate/pget)) or use the `--separate-weights` flag when calling `cog build` to bake these into a [separate layer](https://github.com/replicate/cog/blob/12ac02091d93beebebed037f38a0c99cd8749806/docs/getting-started.md?plain=1#L219). ### `Predictor.predict(**kwargs)` From 22e677bd446eaa31d757043cb9f1d22c012250f8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E2=9D=A4=EF=B8=8F?= Date: Thu, 11 Jan 2024 13:27:12 -0500 Subject: [PATCH 2/5] slight adjustment on copy MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: ❤️ --- docs/python.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/docs/python.md b/docs/python.md index ffc33c2714..0c83e79abc 100644 --- a/docs/python.md +++ b/docs/python.md @@ -50,7 +50,8 @@ Prepare the model so multiple predictions run efficiently. Use this _optional_ method to include any expensive one-off operations in here like loading trained models, instantiate data transformations, etc. -Baking your weights into the image could cause it to be large and increase your build times. Instead, you should download the weights (e.g. using [`pget`](https://github.com/replicate/pget)) or use the `--separate-weights` flag when calling `cog build` to bake these into a [separate layer](https://github.com/replicate/cog/blob/12ac02091d93beebebed037f38a0c99cd8749806/docs/getting-started.md?plain=1#L219). +This method is also where you should download the weights for your model (e.g. using [`pget`](https://github.com/replicate/pget)). Storing your weights with your image directly can cause long `cog build` times and large images. +> If this is not an option for you, you can use the `--separate-weights` flag on `cog build` to store weights in a [separate layer](https://github.com/replicate/cog/blob/12ac02091d93beebebed037f38a0c99cd8749806/docs/getting-started.md?plain=1#L219). ### `Predictor.predict(**kwargs)` From 78b1a1fb1913470aa9d23db316df9372ece890cb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E2=9D=A4=EF=B8=8F?= Date: Thu, 11 Jan 2024 14:04:30 -0500 Subject: [PATCH 3/5] expand documentation to offer two paths for weights MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: ❤️ --- docs/python.md | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/docs/python.md b/docs/python.md index 0c83e79abc..238388afc3 100644 --- a/docs/python.md +++ b/docs/python.md @@ -50,8 +50,22 @@ Prepare the model so multiple predictions run efficiently. Use this _optional_ method to include any expensive one-off operations in here like loading trained models, instantiate data transformations, etc. -This method is also where you should download the weights for your model (e.g. using [`pget`](https://github.com/replicate/pget)). Storing your weights with your image directly can cause long `cog build` times and large images. -> If this is not an option for you, you can use the `--separate-weights` flag on `cog build` to store weights in a [separate layer](https://github.com/replicate/cog/blob/12ac02091d93beebebed037f38a0c99cd8749806/docs/getting-started.md?plain=1#L219). +Many models use this method to download their weights (e.g. using [`pget`](https://github.com/replicate/pget)). + +This has some advantages: +- Smaller image sizes +- Faster build times +- Faster pushes and inference on [Replicate](https://replicate.com) + +However, this may also significantly increase your `setup()` time. + +As an alternative, some choose to store their weights directly in the image. You can simply leave your weights in the directory alongside your `cog.yaml` and ensure they are not excluded in your `.dockerignore` file. + +While this will increase your image size and build time, it offers other advantages: +- Faster `setup()` time +- Ensures idempotency and reduces your model's reliance on external systems- Preserves reproducibility as your model will be self-contained in the image + +> When using this method, you should use the `--separate-weights` flag on `cog build` to store weights in a [separate layer](https://github.com/replicate/cog/blob/12ac02091d93beebebed037f38a0c99cd8749806/docs/getting-started.md?plain=1#L219). ### `Predictor.predict(**kwargs)` From f0eedd9b8cfb0396f4a560a961ac42d315da70db Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E2=9D=A4=EF=B8=8F?= Date: Thu, 11 Jan 2024 14:06:13 -0500 Subject: [PATCH 4/5] fix typo in formatting MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: ❤️ --- docs/python.md | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/docs/python.md b/docs/python.md index 238388afc3..fb5aa9b490 100644 --- a/docs/python.md +++ b/docs/python.md @@ -50,9 +50,7 @@ Prepare the model so multiple predictions run efficiently. Use this _optional_ method to include any expensive one-off operations in here like loading trained models, instantiate data transformations, etc. -Many models use this method to download their weights (e.g. using [`pget`](https://github.com/replicate/pget)). - -This has some advantages: +Many models use this method to download their weights (e.g. using [`pget`](https://github.com/replicate/pget)). This has some advantages: - Smaller image sizes - Faster build times - Faster pushes and inference on [Replicate](https://replicate.com) @@ -63,7 +61,8 @@ As an alternative, some choose to store their weights directly in the image. You While this will increase your image size and build time, it offers other advantages: - Faster `setup()` time -- Ensures idempotency and reduces your model's reliance on external systems- Preserves reproducibility as your model will be self-contained in the image +- Ensures idempotency and reduces your model's reliance on external systems +- - Preserves reproducibility as your model will be self-contained in the image > When using this method, you should use the `--separate-weights` flag on `cog build` to store weights in a [separate layer](https://github.com/replicate/cog/blob/12ac02091d93beebebed037f38a0c99cd8749806/docs/getting-started.md?plain=1#L219). From 98e3a04a5c8426f6977852cc9e49a709dca71c6f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E2=9D=A4=EF=B8=8F?= Date: Thu, 11 Jan 2024 14:06:37 -0500 Subject: [PATCH 5/5] fix double bullet MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: ❤️ --- docs/python.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/python.md b/docs/python.md index fb5aa9b490..7719e3cd36 100644 --- a/docs/python.md +++ b/docs/python.md @@ -62,7 +62,7 @@ As an alternative, some choose to store their weights directly in the image. You While this will increase your image size and build time, it offers other advantages: - Faster `setup()` time - Ensures idempotency and reduces your model's reliance on external systems -- - Preserves reproducibility as your model will be self-contained in the image +- Preserves reproducibility as your model will be self-contained in the image > When using this method, you should use the `--separate-weights` flag on `cog build` to store weights in a [separate layer](https://github.com/replicate/cog/blob/12ac02091d93beebebed037f38a0c99cd8749806/docs/getting-started.md?plain=1#L219).