Download configuration_quicksviewer2.py from EdgePro001/TextVR_ckpt4000: direct link, hf CLI and curl.
- Browser
- Download file 5.27 kB
-
https://huggingface.co/EdgePro001/TextVR_ckpt4000/resolve/main/configuration_quicksviewer2.py
- Command line
-
hf download hf://EdgePro001/TextVR_ckpt4000/configuration_quicksviewer2.py
-
curl -L -o configuration_quicksviewer2.py https://huggingface.co/EdgePro001/TextVR_ckpt4000/resolve/main/configuration_quicksviewer2.py
5.27 kB
| # coding=utf-8 | |
| # Copyright 2025 The ZhipuAI Inc. team and HuggingFace Inc. team. | |
| # | |
| # 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 __future__ import annotations | |
| from transformers.models.glm4v.configuration_glm4v import Glm4vConfig, Glm4vTextConfig, Glm4vVisionConfig | |
| # ==== Quicksviewer2 配置包装 ==== | |
| class Quicksviewer2VisionConfig(Glm4vVisionConfig): | |
| """ | |
| Thin wrapper around :class:`~transformers.Glm4vVisionConfig` with a distinct ``model_type`` so the | |
| auto configuration registry can differentiate Quicksviewer2 from the GLM-4.1V baseline. The intent | |
| is to keep behaviour identical while we progressively extend the config with cubing/resampler | |
| settings. | |
| """ | |
| model_type = "quicksviewer2" | |
| def __init__(self, **kwargs): | |
| super().__init__(**kwargs) | |
| class Quicksviewer2TextConfig(Glm4vTextConfig): | |
| """ | |
| Text backbone configuration alias for Quicksviewer2. It mirrors the GLM-4.1V implementation and only | |
| overrides ``model_type`` so downstream registries can register Quicksviewer2 specific heads. | |
| """ | |
| model_type = "quicksviewer2_text" | |
| def __init__(self, rope_scaling=None, rope_parameters=None, **kwargs): | |
| if rope_scaling is None and rope_parameters is None: | |
| rope_scaling = {"type": "default", "mrope_section": [16, 24, 24]} | |
| super().__init__(rope_scaling=rope_scaling, rope_parameters=rope_parameters, **kwargs) | |
| class Quicksviewer2Config(Glm4vConfig): | |
| """ | |
| Composite configuration that binds the vision and text backbones used by Quicksviewer2. This class | |
| simply reuses :class:`~transformers.Glm4vConfig` while swapping the sub-config registry to the | |
| Quicksviewer2 wrappers above. Future Quicksviewer2-only options should surface here. | |
| """ | |
| model_type = "quicksviewer2" | |
| is_composition = True | |
| sub_configs = {"vision_config": Quicksviewer2VisionConfig, "text_config": Quicksviewer2TextConfig} | |
| def __init__( | |
| self, | |
| text_config=None, | |
| vision_config=None, | |
| bos_token_id=151331, | |
| image_token_id=151343, | |
| video_token_id=151344, | |
| image_start_token_id=151339, | |
| image_end_token_id=151340, | |
| video_start_token_id=151341, | |
| video_end_token_id=151342, | |
| use_cubing=True, | |
| cubing_alpha=0.8, | |
| cubing_fpq=14, | |
| cubing_temperature=0.5, | |
| cubing_lr_gumbel_start=1.0, | |
| cubing_lr_gumbel_end=0.001, | |
| cubing_use_thumbnail=True, | |
| thumbnail_num_queries=64, | |
| resampler_num_queries=64, | |
| resampler_num_heads=32, | |
| resampler_max_size=(300, 24, 24), | |
| reference_fps=10.0, | |
| video_fps=2.0, | |
| **kwargs, | |
| ): | |
| super().__init__( | |
| text_config=text_config, | |
| vision_config=vision_config, | |
| image_token_id=image_token_id, | |
| video_token_id=video_token_id, | |
| image_start_token_id=image_start_token_id, | |
| image_end_token_id=image_end_token_id, | |
| video_start_token_id=video_start_token_id, | |
| video_end_token_id=video_end_token_id, | |
| **kwargs, | |
| ) | |
| self.bos_token_id = bos_token_id | |
| temporal_patch_size = max(int(getattr(self.vision_config, "temporal_patch_size", 2)), 1) | |
| # ==== Cubing 配置 ==== | |
| self.use_cubing = use_cubing | |
| self.cubing_alpha = cubing_alpha | |
| self.cubing_fpq = cubing_fpq | |
| self.effective_cubing_fpq = cubing_fpq // temporal_patch_size | |
| self.cubing_temperature = cubing_temperature | |
| self.cubing_lr_gumbel_start = cubing_lr_gumbel_start | |
| self.cubing_lr_gumbel_end = cubing_lr_gumbel_end | |
| self.cubing_use_thumbnail = cubing_use_thumbnail | |
| self.thumbnail_num_queries = thumbnail_num_queries | |
| # ==== FPS 配置 ==== | |
| self.reference_fps = float(reference_fps) | |
| self.video_fps = float(video_fps) | |
| self.effective_video_fps = self.video_fps / temporal_patch_size | |
| # ==== Resampler 配置 ==== | |
| self.resampler_num_queries = resampler_num_queries | |
| self.resampler_num_heads = resampler_num_heads | |
| self.resampler_max_size = ( | |
| tuple(resampler_max_size) if isinstance(resampler_max_size, (list, tuple)) else resampler_max_size | |
| ) | |
| # ==== AutoProcessor/AutoConfig 注册 ==== | |
| if not hasattr(self, "processor_class"): | |
| self.processor_class = "Quicksviewer2Processor" | |
| auto_map = dict(getattr(self, "auto_map", {})) | |
| auto_map.setdefault("AutoConfig", "transformers.Quicksviewer2Config") | |
| auto_map.setdefault("AutoProcessor", "transformers.Quicksviewer2Processor") | |
| self.auto_map = auto_map | |
| __all__ = ["Quicksviewer2Config", "Quicksviewer2TextConfig", "Quicksviewer2VisionConfig"] | |