"ImportError: cannot import name 'computed_field' from 'pydantic' despite using version 2.10.6 in StableDiffusionImg2ImgPipeline"

Summary

I am encountering an ImportError when running StableDiffusionImg2ImgPipeline in diffusers. The error states that computed_field cannot be imported from pydantic, even though I am using version 2.10.6.

Error Message

ImportError: cannot import name ‘computed_field’ from ‘pydantic’ (/usr/local/lib/python3.11/dist-packages/pydantic/init.cpython-311-x86_64-linux-gnu.so)

Steps I Have Tried

  1. Checked pydantic version
    • pip show pydantic returns Version: 2.10.6
  2. Upgraded pydantic and diffusers
    • pip install --upgrade pydantic diffusers
  3. Uninstalled and reinstalled pydantic
    • pip uninstall pydantic && pip install pydantic
  4. Restarted runtime (Google Colab)
  5. Checked Python environment dependencies
    • pip list | grep pydantic shows only pydantic 2.10.6 installed.

Code Example

from diffusers import StableDiffusionImg2ImgPipeline
from pydantic import computed_field  # <- This causes ImportError

pipe = StableDiffusionImg2ImgPipeline.from_pretrained("runwayml/stable-diffusion-v1-5", torch_dtype=torch.float16)
pipe = pipe.to("cuda")

Environment Details
Python: 3.11
Diffusers: latest (installed via pip)
Pydantic: 2.10.6
Running on: Google Colab
Questions
Why does computed_field not exist even though I am using pydantic 2.10.6?
Is there any workaround for this issue?
Is this a known bug in diffusers or pydantic?
Any insights would be greatly appreciated. Thanks in advance!
1 Like

I didn’t have any problems with 2.10.6 on my local environment. After searching, it seems to be a problem that often occurs with Colab.

1 Like

Thank you so much for your help! :pray:

1 Like

This topic was automatically closed 12 hours after the last reply. New replies are no longer allowed.