diff --git a/docs/python.md b/docs/python.md index cfcb3d345a..7719e3cd36 100644 --- a/docs/python.md +++ b/docs/python.md @@ -50,7 +50,21 @@ 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. +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)`