Skip to content

Commit 08511a4

Browse files
Log VQ remapping configuration through the model logger
1 parent 614ae4b commit 08511a4

2 files changed

Lines changed: 21 additions & 2 deletions

File tree

src/diffusers/models/autoencoders/vae.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
import torch
1818
import torch.nn as nn
1919

20-
from ...utils import BaseOutput
20+
from ...utils import BaseOutput, logging
2121
from ...utils.torch_utils import randn_tensor
2222
from ..activations import get_activation
2323
from ..attention_processor import SpatialNorm
@@ -29,6 +29,9 @@
2929
)
3030

3131

32+
logger = logging.get_logger(__name__)
33+
34+
3235
@dataclass
3336
class EncoderOutput(BaseOutput):
3437
r"""
@@ -599,7 +602,7 @@ def __init__(
599602
if self.unknown_index == "extra":
600603
self.unknown_index = self.re_embed
601604
self.re_embed = self.re_embed + 1
602-
print(
605+
logger.info(
603606
f"Remapping {self.n_e} indices to {self.re_embed} indices. "
604607
f"Using {self.unknown_index} for unknown indices."
605608
)

tests/models/autoencoders/test_models_vq.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,14 @@
1313
# See the License for the specific language governing permissions and
1414
# limitations under the License.
1515

16+
import logging
17+
18+
import numpy as np
1619
import pytest
1720
import torch
1821

1922
from diffusers import VQModel
23+
from diffusers.models.autoencoders.vae import VectorQuantizer
2024
from diffusers.utils.torch_utils import randn_tensor
2125

2226
from ...testing_utils import backend_manual_seed, enable_full_determinism, torch_device
@@ -119,6 +123,18 @@ def test_loss_pretrained(self):
119123
# fmt: on
120124
assert torch.allclose(output, expected_output, atol=1e-3)
121125

126+
def test_vector_quantizer_logs_remap_configuration(self, caplog, tmp_path):
127+
remap_path = tmp_path / "used.npy"
128+
np.save(remap_path, np.array([0, 2, 4], dtype=np.int64))
129+
130+
with caplog.at_level(logging.INFO, logger="diffusers.models.autoencoders.vae"):
131+
VectorQuantizer(n_e=8, vq_embed_dim=4, beta=0.25, remap=str(remap_path), unknown_index="extra")
132+
133+
assert any(
134+
"Remapping 8 indices to 4 indices. Using 3 for unknown indices." in record.message
135+
for record in caplog.records
136+
)
137+
122138

123139
class TestVQModelTraining(VQModelTesterConfig, TrainingTesterMixin):
124140
"""Training tests for VQModel."""

0 commit comments

Comments
 (0)