Custom cog with missing torchvision
I have created a custom cog with cog version 0.9.13. After building I have pushed the cog in replicate. However, after the first inference, an error appeared during setup.
Traceback (most recent call last):
File "/root/.pyenv/versions/3.12.4/lib/python3.12/site-packages/cog/server/worker.py", line 186, in _setup
self._predictor = load_predictor_from_ref(self._predictor_ref)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/root/.pyenv/versions/3.12.4/lib/python3.12/site-packages/cog/predictor.py", line 248, in load_predictor_from_ref
module = load_full_predictor_from_file(module_path, module_name)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/root/.pyenv/versions/3.12.4/lib/python3.12/site-packages/cog/predictor.py", line 200, in load_full_predictor_from_file
spec.loader.exec_module(module)
File "<frozen importlib._bootstrap_external>", line 995, in exec_module
File "<frozen importlib._bootstrap>", line 488, in _call_with_frames_removed
File "/src/predict.py", line 6, in <module>
from torchvision import transforms
ModuleNotFoundError: No module named 'torchvision'
Traceback (most recent call last):
File "/root/.pyenv/versions/3.12.4/lib/python3.12/site-packages/cog/server/runner.py", line 329, in setup
for event in worker.setup():
File "/root/.pyenv/versions/3.12.4/lib/python3.12/site-packages/cog/server/worker.py", line 130, in _wait
raise FatalWorkerException(raise_on_error + ": " + done.error_detail)
cog.server.exceptions.FatalWorkerException: Predictor errored during setup: No module named 'torchvision'
It mentions that torchvision is missing. I have added it to python packages:
# Configuration for Cog ⚙️
# Reference: https://cog.run/yaml
build:
# set to true if your model requires a GPU
gpu: true
system_packages:
- "libgl1-mesa-glx"
- "libglib2.0-0"
python_version: "3.12"
# a list of packages in the format <package-name>==<version>
python_packages:
- "opencv-python-headless==4.10.0.84"
- "numpy==1.26.4"
- "torchvision==0.18.1"
- "torch==2.3.1"
- "albumentations==1.3.1"
# commands run after the environment is setup
# run:
# - "echo env is ready!"
# - "echo another command if needed"
# predict.py defines how predictions are run on your model
predict: "predict.py:Predictor"
Hi @delyan-boychev. Sorry that this isn't working for you. Could you please share a link to the model and/or to a failing prediction?
This may have to do with a recent change that made --use-cog-base-image the default. So could you try re-running cog push with --use-cog-base-image=false? Another thing I'd be interested to see is whether adding pip install torchvision as a run step resolves your issue.
Thank you! --use-cog-base-image=false worked!