diff --git a/src/diffusers/models/vq_model.py b/src/diffusers/models/vq_model.py deleted file mode 100644 index 635db5310258..000000000000 --- a/src/diffusers/models/vq_model.py +++ /dev/null @@ -1,29 +0,0 @@ -# Copyright 2026 The HuggingFace Team. All rights reserved. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -from ..utils import deprecate -from .autoencoders.vq_model import VQEncoderOutput, VQModel - - -class VQEncoderOutput(VQEncoderOutput): - def __init__(self, *args, **kwargs): - deprecation_message = "Importing `VQEncoderOutput` from `diffusers.models.vq_model` is deprecated and this will be removed in a future version. Please use `from diffusers.models.autoencoders.vq_model import VQEncoderOutput`, instead." - deprecate("VQEncoderOutput", "0.31", deprecation_message) - super().__init__(*args, **kwargs) - - -class VQModel(VQModel): - def __init__(self, *args, **kwargs): - deprecation_message = "Importing `VQModel` from `diffusers.models.vq_model` is deprecated and this will be removed in a future version. Please use `from diffusers.models.autoencoders.vq_model import VQModel`, instead." - deprecate("VQModel", "0.31", deprecation_message) - super().__init__(*args, **kwargs) diff --git a/src/diffusers/pipelines/deprecated/wuerstchen/modeling_paella_vq_model.py b/src/diffusers/pipelines/deprecated/wuerstchen/modeling_paella_vq_model.py index a18ab8eed6ec..d62b7787643b 100644 --- a/src/diffusers/pipelines/deprecated/wuerstchen/modeling_paella_vq_model.py +++ b/src/diffusers/pipelines/deprecated/wuerstchen/modeling_paella_vq_model.py @@ -19,8 +19,8 @@ from ....configuration_utils import ConfigMixin, register_to_config from ....models.autoencoders.vae import DecoderOutput, VectorQuantizer +from ....models.autoencoders.vq_model import VQEncoderOutput from ....models.modeling_utils import ModelMixin -from ....models.vq_model import VQEncoderOutput from ....utils.accelerate_utils import apply_forward_hook diff --git a/tests/regression/test_issue_14365_vq_model_shim.py b/tests/regression/test_issue_14365_vq_model_shim.py new file mode 100644 index 000000000000..cbc9fa6d1abb --- /dev/null +++ b/tests/regression/test_issue_14365_vq_model_shim.py @@ -0,0 +1,96 @@ +"""Regression tests for issue #14365 — removal of the vq_model.py shim file. + +The shim at ``src/diffusers/models/vq_model.py`` wraps the real implementations in +``src/diffusers/models/autoencoders/vq_model.py`` with deprecation warnings. This +shim must be deleted so that the old import path raises a clear ``ImportError`` and +the deprecated Wuerstchen PaellaVQModel is updated to import directly from the +canonical autoencoders location. +""" + +import os + +import pytest + + +# --------------------------------------------------------------------------- +# Test A — public API must work +# --------------------------------------------------------------------------- + + +def test_vq_model_importable_from_public_api(): + """``from diffusers import VQModel`` must succeed and return the real class.""" + from diffusers import VQModel + + assert isinstance(VQModel, type), "VQModel must be a class" + assert VQModel.__module__ == "diffusers.models.autoencoders.vq_model", ( + f"Expected __module__ 'diffusers.models.autoencoders.vq_model', got {VQModel.__module__!r}" + ) + + +# --------------------------------------------------------------------------- +# Test B — VQEncoderOutput importable from autoencoders path +# --------------------------------------------------------------------------- + + +def test_vq_encoder_output_available(): + """``from diffusers.models.autoencoders.vq_model import VQEncoderOutput`` must succeed.""" + from diffusers.models.autoencoders.vq_model import VQEncoderOutput + + assert isinstance(VQEncoderOutput, type), "VQEncoderOutput must be a class" + + +# --------------------------------------------------------------------------- +# Test C — deprecated shim file must NOT exist +# --------------------------------------------------------------------------- + + +def test_deprecated_shim_file_removed(): + """The shim file ``src/diffusers/models/vq_model.py`` must not exist on disk.""" + import diffusers.models + + base = os.path.dirname(diffusers.models.__file__) + shim_path = os.path.join(base, "vq_model.py") + assert not os.path.exists(shim_path), ( + f"Shim file still exists at {shim_path!r}. It must be removed so that the old import path raises ImportError." + ) + + +# --------------------------------------------------------------------------- +# Test D — old import path must raise ImportError +# --------------------------------------------------------------------------- + + +def test_deprecated_vq_model_import_fails(): + """``from diffusers.models.vq_model import VQModel`` must raise ImportError.""" + with pytest.raises((ImportError, ModuleNotFoundError)): + # Use __import__ so we control the name passed to the import machinery + __import__("diffusers.models.vq_model", fromlist=["VQModel"]) + + +# --------------------------------------------------------------------------- +# Test E — PaellaVQModel must use VQEncoderOutput from autoencoders +# --------------------------------------------------------------------------- + + +def test_paella_vq_model_vq_encoder_output_works(): + """PaellaVQModel must import and use VQEncoderOutput from the canonical path. + + This requires that PaellaVQModel imports VQEncoderOutput from the canonical + ``diffusers.models.autoencoders.vq_model`` path, not from the deprecated shim. + + BEFORE the fix: importing PaellaVQModel raises ``ValueError`` because the + shim's ``deprecate()`` deadline has passed. + + AFTER the fix: PaellaVQModel imports successfully and its VQEncoderOutput + reference resolves to the canonical autoencoders path. + """ + from diffusers.pipelines.deprecated.wuerstchen.modeling_paella_vq_model import PaellaVQModel + + assert PaellaVQModel is not None, "PaellaVQModel must be importable" + + import diffusers.pipelines.deprecated.wuerstchen.modeling_paella_vq_model as _paella_mod + from diffusers.models.autoencoders.vq_model import VQEncoderOutput as CanonicalOutput + + assert _paella_mod.VQEncoderOutput is CanonicalOutput, ( + f"PaellaVQModel must use VQEncoderOutput from autoencoders.vq_model, got {_paella_mod.VQEncoderOutput}" + )