Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Compatibility issues with Cog Pydantic < 2.* #1384

Open
sCarita opened this issue Nov 19, 2023 · 6 comments
Open

Compatibility issues with Cog Pydantic < 2.* #1384

sCarita opened this issue Nov 19, 2023 · 6 comments

Comments

@sCarita
Copy link

sCarita commented Nov 19, 2023

Hello everyone,

I am building an image that needs segments-ai python package, which requires pydantic to be above version 2.*. The problem is that if I install the pydantic python package above version 2, I get an error during the "Validating model schema..." phase.

Validating model schema...

Traceback (most recent call last):
  File "/root/.pyenv/versions/3.10.10/lib/python3.10/runpy.py", line 196, in _run_module_as_main
    return _run_code(code, main_globals, None,
  File "/root/.pyenv/versions/3.10.10/lib/python3.10/runpy.py", line 86, in _run_code
    exec(code, run_globals)
  File "/root/.pyenv/versions/3.10.10/lib/python3.10/site-packages/cog/command/openapi_schema.py", line 10, in <module>
    from ..server.http import create_app
  File "/root/.pyenv/versions/3.10.10/lib/python3.10/site-packages/cog/server/http.py", line 16, in <module>
    from fastapi import Body, FastAPI, Header, HTTPException, Path, Response
  File "/root/.pyenv/versions/3.10.10/lib/python3.10/site-packages/fastapi/__init__.py", line 7, in <module>
    from .applications import FastAPI as FastAPI
  File "/root/.pyenv/versions/3.10.10/lib/python3.10/site-packages/fastapi/applications.py", line 16, in <module>
    from fastapi import routing
  File "/root/.pyenv/versions/3.10.10/lib/python3.10/site-packages/fastapi/routing.py", line 22, in <module>
    from fastapi import params
  File "/root/.pyenv/versions/3.10.10/lib/python3.10/site-packages/fastapi/params.py", line 4, in <module>
    from pydantic.fields import FieldInfo, Undefined
ImportError: cannot import name 'Undefined' from 'pydantic.fields' (/root/.pyenv/versions/3.10.10/lib/python3.10/site-packages/pydantic/fields.py)

It seems that the fastapi version used by cog is expecting pydantic to be below version 2, where "Undefined" object exists...

My current cog version is: cog version 0.8.6 (built 2023-08-07T21:51:56Z)

Any ideas on how to workaround this are gladly accepted.

Thank you for your time.

@sCarita
Copy link
Author

sCarita commented Nov 19, 2023

I understood we can control the fastapi version on the cog.yaml via python_packages key. So I did update, but now I get a new error which seems to be related with the internals of cog using pydantic v1 related options.

Traceback (most recent call last):
  File "/root/.pyenv/versions/3.10.10/lib/python3.10/runpy.py", line 196, in _run_module_as_main
    return _run_code(code, main_globals, None,
  File "/root/.pyenv/versions/3.10.10/lib/python3.10/runpy.py", line 86, in _run_code
    exec(code, run_globals)
  File "/root/.pyenv/versions/3.10.10/lib/python3.10/site-packages/cog/command/openapi_schema.py", line 10, in <module>
    from ..server.http import create_app
  File "/root/.pyenv/versions/3.10.10/lib/python3.10/site-packages/cog/server/http.py", line 21, in <module>
    from pydantic.error_wrappers import ErrorWrapper
  File "/root/.pyenv/versions/3.10.10/lib/python3.10/site-packages/pydantic/_migration.py", line 302, in wrapper
    raise PydanticImportError(f'`{import_path}` has been removed in V2.')
pydantic.errors.PydanticImportError: `pydantic.error_wrappers:ErrorWrapper` has been removed in V2.

For further information visit https://errors.pydantic.dev/2.5/u/import-error

So I am trying to understand if all cog versions use:

from pydantic.error_wrappers import ErrorWrapper @ cog/server/http.py

@sCarita
Copy link
Author

sCarita commented Nov 19, 2023

I am updating the source code now. to:

if request.id is not None and request.id != prediction_id:
        errors = [{
            'loc': ('body', 'id'),
            'msg': "prediction ID must match the ID supplied in the URL",
            'type': 'value_error',
        }]
        raise ValidationError(errors, PredictionRequest)
...

But when I am building... $ make

mkdir -p pkg/dockerfile/embed
cp dist/*.whl pkg/dockerfile/embed/cog.whl
CGO_ENABLED=0 go build -o cog \
	-ldflags "-X github.com/replicate/cog/pkg/global.Version=v0.9.0-beta10+dev -X github.com/replicate/cog/pkg/global.BuildTime=2023-11-19T20:42:00+0000 -w" \
	cmd/cog/cog.go
build command-line-arguments: cannot load embed: malformed module path "embed": missing dot in first path element
make: *** [Makefile:34: cog] Error 1

@sCarita
Copy link
Author

sCarita commented Nov 21, 2023

I was able to solve the problem by updating the golang to version 1.20 as stated in go.mod. After it I was able to build my own cog with pydantic fixed. Had a few hiccups along the way, but it is working now.

@sCarita sCarita closed this as completed Nov 21, 2023
@cudanexus
Copy link

@sCarita is there any new release or fix instructions for this, i am also getting the same error

  File "/root/.pyenv/versions/3.11.8/lib/python3.11/site-packages/cog/server/http.py", line 36, in <module>
    from pydantic.error_wrappers import ErrorWrapper
  File "/root/.pyenv/versions/3.11.8/lib/python3.11/site-packages/pydantic/_migration.py", line 302, in wrapper
    raise PydanticImportError(f'`{import_path}` has been removed in V2.')
pydantic.errors.PydanticImportError: `pydantic.error_wrappers:ErrorWrapper` has been removed in V2.

For further information visit https://errors.pydantic.dev/2.6/u/import-error
ⅹ Failed to get container status: exit status 1

@aros0918
Copy link

I am also using cog for push my model to replicate
but at the end of the process I got this error :
Traceback (most recent call last):
File "/root/.pyenv/versions/3.10.13/lib/python3.10/runpy.py", line 196, in _run_module_as_main
return _run_code(code, main_globals, None,
File "/root/.pyenv/versions/3.10.13/lib/python3.10/runpy.py", line 86, in _run_code
exec(code, run_globals)
File "/root/.pyenv/versions/3.10.13/lib/python3.10/site-packages/cog/command/openapi_schema.py", line 25, in
raise CogError(app.state.setup_result.logs)
cog.errors.CogError: Error while loading predictor:

Traceback (most recent call last):
File "/root/.pyenv/versions/3.10.13/lib/python3.10/site-packages/cog/server/http.py", line 137, in create_app
predictor = load_predictor_from_ref(predictor_ref)
File "/root/.pyenv/versions/3.10.13/lib/python3.10/site-packages/cog/predictor.py", line 187, in load_predictor_from_ref
spec.loader.exec_module(module)
File "", line 883, in exec_module
File "", line 241, in _call_with_frames_removed
File "/src/predict.py", line 1, in
import gradio as gr
File "/root/.pyenv/versions/3.10.13/lib/python3.10/site-packages/gradio/init.py", line 3, in
import gradio._simple_templates
File "/root/.pyenv/versions/3.10.13/lib/python3.10/site-packages/gradio/_simple_templates/init.py", line 1, in
from .simpledropdown import SimpleDropdown
File "/root/.pyenv/versions/3.10.13/lib/python3.10/site-packages/gradio/_simple_templates/simpledropdown.py", line 6, in
from gradio.components.base import FormComponent
File "/root/.pyenv/versions/3.10.13/lib/python3.10/site-packages/gradio/components/init.py", line 1, in
from gradio.components.annotated_image import AnnotatedImage
File "/root/.pyenv/versions/3.10.13/lib/python3.10/site-packages/gradio/components/annotated_image.py", line 13, in
from gradio import processing_utils, utils
File "/root/.pyenv/versions/3.10.13/lib/python3.10/site-packages/gradio/processing_utils.py", line 21, in
from gradio import utils, wasm_utils
File "/root/.pyenv/versions/3.10.13/lib/python3.10/site-packages/gradio/utils.py", line 48, in
from gradio.data_classes import FileData
File "/root/.pyenv/versions/3.10.13/lib/python3.10/site-packages/gradio/data_classes.py", line 18, in
from pydantic import BaseModel, RootModel, ValidationError
ImportError: cannot import name 'RootModel' from 'pydantic' (/root/.pyenv/versions/3.10.13/lib/python3.10/site-packages/pydantic/init.cpython-310-x86_64-linux-gnu.so)

how can i fix that problem?

@andreasjansson
Copy link
Member

I don't believe this is fixed -- re-opening.

andreasjansson added a commit to andreasjansson/cog that referenced this issue Apr 15, 2024
This PR vendors all Python packages using the [vendoring](https://pypi.org/project/vendoring/) library.

Vendoring allows users to install packages that rely on versions of libraries that are in conflict with Cog's dependencies (e.g. Pydantic, see replicate#1562, replicate#1384, replicate#1186, replicate#1586, replicate#1336, replicate#785).

This PR is broken up into two commits: First one adds all the files in the `_vendor` directory, second one is the actually changed code.

Closes replicate#409

Signed-off-by: andreasjansson <andreas@replicate.ai>
andreasjansson added a commit to andreasjansson/cog that referenced this issue Apr 16, 2024
This PR vendors all Python packages using the [vendoring](https://pypi.org/project/vendoring/) library.

Vendoring allows users to install packages that rely on versions of libraries that are in conflict with Cog's dependencies (e.g. Pydantic, see replicate#1562, replicate#1384, replicate#1186, replicate#1586, replicate#1336, replicate#785).

This PR is broken up into two commits: First one adds all the files in the `_vendor` directory, second one is the actually changed code.

Closes replicate#409

Signed-off-by: andreasjansson <andreas@replicate.ai>
andreasjansson added a commit to andreasjansson/cog that referenced this issue Apr 16, 2024
This PR vendors all Python packages using the [vendoring](https://pypi.org/project/vendoring/) library.

Vendoring allows users to install packages that rely on versions of libraries that are in conflict with Cog's dependencies (e.g. Pydantic, see replicate#1562, replicate#1384, replicate#1186, replicate#1586, replicate#1336, replicate#785).

Vendored packages are gitignored and are sync'd by the default `make` rule.

Closes replicate#409

Signed-off-by: andreasjansson <andreas@replicate.ai>
andreasjansson added a commit to andreasjansson/cog that referenced this issue Apr 16, 2024
This PR vendors all Python packages using the [vendoring](https://pypi.org/project/vendoring/) library.

Vendoring allows users to install packages that rely on versions of libraries that are in conflict with Cog's dependencies (e.g. Pydantic, see replicate#1562, replicate#1384, replicate#1186, replicate#1586, replicate#1336, replicate#785).

Vendored packages are gitignored and are sync'd by the default `make` rule.

Closes replicate#409

Signed-off-by: andreasjansson <andreas@replicate.ai>
andreasjansson added a commit to andreasjansson/cog that referenced this issue Apr 16, 2024
This PR vendors all Python packages using the [vendoring](https://pypi.org/project/vendoring/) library.

Vendoring allows users to install packages that rely on versions of libraries that are in conflict with Cog's dependencies (e.g. Pydantic, see replicate#1562, replicate#1384, replicate#1186, replicate#1586, replicate#1336, replicate#785).

Vendored packages are gitignored and are sync'd by the default `make` rule.

Closes replicate#409

Signed-off-by: andreasjansson <andreas@replicate.ai>
andreasjansson added a commit to andreasjansson/cog that referenced this issue Apr 16, 2024
This PR vendors all Python packages using the [vendoring](https://pypi.org/project/vendoring/) library.

Vendoring allows users to install packages that rely on versions of libraries that are in conflict with Cog's dependencies (e.g. Pydantic, see replicate#1562, replicate#1384, replicate#1186, replicate#1586, replicate#1336, replicate#785).

Vendored packages are gitignored and are sync'd by the default `make` rule.

Closes replicate#409

Signed-off-by: andreasjansson <andreas@replicate.ai>
andreasjansson added a commit to andreasjansson/cog that referenced this issue Apr 16, 2024
This PR vendors all Python packages using the [vendoring](https://pypi.org/project/vendoring/) library.

Vendoring allows users to install packages that rely on versions of libraries that are in conflict with Cog's dependencies (e.g. Pydantic, see replicate#1562, replicate#1384, replicate#1186, replicate#1586, replicate#1336, replicate#785).

Vendored packages are gitignored and are sync'd by the default `make` rule.

Closes replicate#409

Signed-off-by: andreasjansson <andreas@replicate.ai>
andreasjansson added a commit to andreasjansson/cog that referenced this issue Apr 16, 2024
This PR vendors all Python packages using the [vendoring](https://pypi.org/project/vendoring/) library.

Vendoring allows users to install packages that rely on versions of libraries that are in conflict with Cog's dependencies (e.g. Pydantic, see replicate#1562, replicate#1384, replicate#1186, replicate#1586, replicate#1336, replicate#785).

Vendored packages are gitignored and are sync'd by the default `make` rule.

Closes replicate#409

Signed-off-by: andreasjansson <andreas@replicate.ai>
andreasjansson added a commit to andreasjansson/cog that referenced this issue Apr 17, 2024
This PR vendors all Python packages using the [vendoring](https://pypi.org/project/vendoring/) library.

Vendoring allows users to install packages that rely on versions of libraries that are in conflict with Cog's dependencies (e.g. Pydantic, see replicate#1562, replicate#1384, replicate#1186, replicate#1586, replicate#1336, replicate#785).

Vendored packages are gitignored and are sync'd by the default `make` rule.

Closes replicate#409

Signed-off-by: andreasjansson <andreas@replicate.ai>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants