Add files using upload-large-folder tool
Browse files- .gitattributes +15 -0
- LTA_openwebtext_dualt/mini_owt_logdirichlet/.venv_qwen35_uv/lib/python3.12/site-packages/numpy/core/_multiarray_tests.cpython-312-x86_64-linux-gnu.so +3 -0
- LTA_openwebtext_dualt/mini_owt_logdirichlet/.venv_qwen35_uv/lib/python3.12/site-packages/numpy/core/_multiarray_umath.cpython-312-x86_64-linux-gnu.so +3 -0
- LTA_openwebtext_dualt/mini_owt_logdirichlet/.venv_qwen35_uv/lib/python3.12/site-packages/numpy/core/_simd.cpython-312-x86_64-linux-gnu.so +3 -0
- LTA_openwebtext_dualt/mini_owt_logdirichlet/.venv_qwen35_uv/lib/python3.12/site-packages/numpy/core/tests/data/numpy_2_0_array.pkl +3 -0
- LTA_openwebtext_dualt/mini_owt_logdirichlet/.venv_qwen35_uv/lib/python3.12/site-packages/numpy/linalg/_umath_linalg.cpython-312-x86_64-linux-gnu.so +3 -0
- LTA_openwebtext_dualt/mini_owt_logdirichlet/.venv_qwen35_uv/lib/python3.12/site-packages/safetensors/_safetensors_rust.abi3.so +3 -0
- LTA_openwebtext_dualt/mini_owt_logdirichlet/.venv_qwen35_uv/lib/python3.12/site-packages/tokenizers/tokenizers.abi3.so +3 -0
- LTA_openwebtext_dualt/mini_owt_logdirichlet/.venv_qwen35_uv/lib/python3.12/site-packages/transformers/models/idefics2/__init__.py +30 -0
- LTA_openwebtext_dualt/mini_owt_logdirichlet/.venv_qwen35_uv/lib/python3.12/site-packages/transformers/models/idefics2/configuration_idefics2.py +165 -0
- LTA_openwebtext_dualt/mini_owt_logdirichlet/.venv_qwen35_uv/lib/python3.12/site-packages/transformers/models/idefics2/image_processing_idefics2.py +289 -0
- LTA_openwebtext_dualt/mini_owt_logdirichlet/.venv_qwen35_uv/lib/python3.12/site-packages/transformers/models/idefics2/processing_idefics2.py +190 -0
- LTA_openwebtext_dualt/mini_owt_logdirichlet/logs/vllm_qwen36_35b_a3b_gpu1_port8009.log +3 -0
- LTA_openwebtext_dualt/mini_owt_logdirichlet/logs/vllm_qwen36_35b_a3b_node0_gpu1_port8009.log +3 -0
- LTA_openwebtext_dualt/mini_owt_logdirichlet/logs/vllm_qwen36_35b_a3b_node0_gpu3_port8011.log +3 -0
- LTA_openwebtext_dualt/mini_owt_logdirichlet/logs/vllm_qwen36_35b_a3b_node0_gpu4_port8012.log +3 -0
- LTA_openwebtext_dualt/mini_owt_logdirichlet/logs/vllm_qwen36_35b_a3b_node0_gpu7_port8015.log +3 -0
- LTA_openwebtext_dualt/mini_owt_logdirichlet/logs/vllm_qwen36_35b_a3b_node1_gpu0_port8008.log +3 -0
- LTA_openwebtext_dualt/mini_owt_logdirichlet/logs/vllm_qwen36_35b_a3b_node1_gpu1_port8009.log +3 -0
- LTA_openwebtext_dualt/mini_owt_logdirichlet/logs/vllm_qwen36_35b_a3b_node1_gpu4_port8012.log +3 -0
- LTA_openwebtext_dualt/mini_owt_logdirichlet/logs/vllm_qwen36_35b_a3b_node1_gpu5_port8013.log +3 -0
.gitattributes
CHANGED
|
@@ -97,3 +97,18 @@ LTA_openwebtext_dualt/mini_owt_logdirichlet/cache/owt_llmclean_qwen36_35b_articl
|
|
| 97 |
LTA_openwebtext_dualt/mini_owt_logdirichlet/cache/owt_llmclean_qwen36_35b_articlefull_300k_snapshot_rev8_docs600000_shards32/part-029.jsonl filter=lfs diff=lfs merge=lfs -text
|
| 98 |
LTA_openwebtext_dualt/mini_owt_logdirichlet/cache/owt_llmclean_qwen36_35b_articlefull_300k_snapshot_rev8_docs600000_shards32/part-019.jsonl filter=lfs diff=lfs merge=lfs -text
|
| 99 |
LTA_openwebtext_dualt/mini_owt_logdirichlet/cache/owt_llmclean_qwen36_35b_articlefull_full_rev8/audit.jsonl filter=lfs diff=lfs merge=lfs -text
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 97 |
LTA_openwebtext_dualt/mini_owt_logdirichlet/cache/owt_llmclean_qwen36_35b_articlefull_300k_snapshot_rev8_docs600000_shards32/part-029.jsonl filter=lfs diff=lfs merge=lfs -text
|
| 98 |
LTA_openwebtext_dualt/mini_owt_logdirichlet/cache/owt_llmclean_qwen36_35b_articlefull_300k_snapshot_rev8_docs600000_shards32/part-019.jsonl filter=lfs diff=lfs merge=lfs -text
|
| 99 |
LTA_openwebtext_dualt/mini_owt_logdirichlet/cache/owt_llmclean_qwen36_35b_articlefull_full_rev8/audit.jsonl filter=lfs diff=lfs merge=lfs -text
|
| 100 |
+
LTA_openwebtext_dualt/mini_owt_logdirichlet/.venv_qwen35_uv/lib/python3.12/site-packages/safetensors/_safetensors_rust.abi3.so filter=lfs diff=lfs merge=lfs -text
|
| 101 |
+
LTA_openwebtext_dualt/mini_owt_logdirichlet/.venv_qwen35_uv/lib/python3.12/site-packages/tokenizers/tokenizers.abi3.so filter=lfs diff=lfs merge=lfs -text
|
| 102 |
+
LTA_openwebtext_dualt/mini_owt_logdirichlet/.venv_qwen35_uv/lib/python3.12/site-packages/numpy/linalg/_umath_linalg.cpython-312-x86_64-linux-gnu.so filter=lfs diff=lfs merge=lfs -text
|
| 103 |
+
LTA_openwebtext_dualt/mini_owt_logdirichlet/.venv_qwen35_uv/lib/python3.12/site-packages/numpy/core/_multiarray_umath.cpython-312-x86_64-linux-gnu.so filter=lfs diff=lfs merge=lfs -text
|
| 104 |
+
LTA_openwebtext_dualt/mini_owt_logdirichlet/.venv_qwen35_uv/lib/python3.12/site-packages/numpy/core/_simd.cpython-312-x86_64-linux-gnu.so filter=lfs diff=lfs merge=lfs -text
|
| 105 |
+
LTA_openwebtext_dualt/mini_owt_logdirichlet/.venv_qwen35_uv/lib/python3.12/site-packages/numpy/core/_multiarray_tests.cpython-312-x86_64-linux-gnu.so filter=lfs diff=lfs merge=lfs -text
|
| 106 |
+
LTA_openwebtext_dualt/mini_owt_logdirichlet/logs/vllm_qwen36_35b_a3b_node1_gpu1_port8009.log filter=lfs diff=lfs merge=lfs -text
|
| 107 |
+
LTA_openwebtext_dualt/mini_owt_logdirichlet/logs/vllm_qwen36_35b_a3b_node0_gpu4_port8012.log filter=lfs diff=lfs merge=lfs -text
|
| 108 |
+
LTA_openwebtext_dualt/mini_owt_logdirichlet/logs/vllm_qwen36_35b_a3b_node0_gpu7_port8015.log filter=lfs diff=lfs merge=lfs -text
|
| 109 |
+
LTA_openwebtext_dualt/mini_owt_logdirichlet/logs/vllm_qwen36_35b_a3b_node1_gpu5_port8013.log filter=lfs diff=lfs merge=lfs -text
|
| 110 |
+
LTA_openwebtext_dualt/mini_owt_logdirichlet/logs/vllm_qwen36_35b_a3b_node1_gpu0_port8008.log filter=lfs diff=lfs merge=lfs -text
|
| 111 |
+
LTA_openwebtext_dualt/mini_owt_logdirichlet/logs/vllm_qwen36_35b_a3b_node0_gpu1_port8009.log filter=lfs diff=lfs merge=lfs -text
|
| 112 |
+
LTA_openwebtext_dualt/mini_owt_logdirichlet/logs/vllm_qwen36_35b_a3b_node0_gpu3_port8011.log filter=lfs diff=lfs merge=lfs -text
|
| 113 |
+
LTA_openwebtext_dualt/mini_owt_logdirichlet/logs/vllm_qwen36_35b_a3b_node1_gpu4_port8012.log filter=lfs diff=lfs merge=lfs -text
|
| 114 |
+
LTA_openwebtext_dualt/mini_owt_logdirichlet/logs/vllm_qwen36_35b_a3b_gpu1_port8009.log filter=lfs diff=lfs merge=lfs -text
|
LTA_openwebtext_dualt/mini_owt_logdirichlet/.venv_qwen35_uv/lib/python3.12/site-packages/numpy/core/_multiarray_tests.cpython-312-x86_64-linux-gnu.so
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:0b2cbb7419ffc2f712987aabaf518a3b1d9de8406093f79dcb1d712a34ab6057
|
| 3 |
+
size 175912
|
LTA_openwebtext_dualt/mini_owt_logdirichlet/.venv_qwen35_uv/lib/python3.12/site-packages/numpy/core/_multiarray_umath.cpython-312-x86_64-linux-gnu.so
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:6a650810a8735cbdb988f74729973740a337645dd1585fef696e73e2dbc65beb
|
| 3 |
+
size 7463681
|
LTA_openwebtext_dualt/mini_owt_logdirichlet/.venv_qwen35_uv/lib/python3.12/site-packages/numpy/core/_simd.cpython-312-x86_64-linux-gnu.so
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:9402bc6bcb8a8da62816a3106415a756f8de526f8a0ec9d9cf21ff453865f5da
|
| 3 |
+
size 3535232
|
LTA_openwebtext_dualt/mini_owt_logdirichlet/.venv_qwen35_uv/lib/python3.12/site-packages/numpy/core/tests/data/numpy_2_0_array.pkl
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:561d36b5dc82ca96bc35be10cdd5619c30225c43b6590adcc1cbce7430c5179c
|
| 3 |
+
size 718
|
LTA_openwebtext_dualt/mini_owt_logdirichlet/.venv_qwen35_uv/lib/python3.12/site-packages/numpy/linalg/_umath_linalg.cpython-312-x86_64-linux-gnu.so
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:8822e772d743d405983f1b9c6b34b704dd297780890dc245454f1081adf50a4c
|
| 3 |
+
size 216793
|
LTA_openwebtext_dualt/mini_owt_logdirichlet/.venv_qwen35_uv/lib/python3.12/site-packages/safetensors/_safetensors_rust.abi3.so
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:87da8f4733e6ecf840a5d8e2b1de888cad012c23755118919567ec480a7d7e02
|
| 3 |
+
size 1216632
|
LTA_openwebtext_dualt/mini_owt_logdirichlet/.venv_qwen35_uv/lib/python3.12/site-packages/tokenizers/tokenizers.abi3.so
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:c116fcf1e80d461ce0a35c332974f25949e8359416f50b3d53371810d2ce1ccc
|
| 3 |
+
size 10074176
|
LTA_openwebtext_dualt/mini_owt_logdirichlet/.venv_qwen35_uv/lib/python3.12/site-packages/transformers/models/idefics2/__init__.py
ADDED
|
@@ -0,0 +1,30 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# Copyright 2024 The HuggingFace Team. All rights reserved.
|
| 2 |
+
#
|
| 3 |
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
| 4 |
+
# you may not use this file except in compliance with the License.
|
| 5 |
+
# You may obtain a copy of the License at
|
| 6 |
+
#
|
| 7 |
+
# http://www.apache.org/licenses/LICENSE-2.0
|
| 8 |
+
#
|
| 9 |
+
# Unless required by applicable law or agreed to in writing, software
|
| 10 |
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
| 11 |
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
| 12 |
+
# See the License for the specific language governing permissions and
|
| 13 |
+
# limitations under the License.
|
| 14 |
+
from typing import TYPE_CHECKING
|
| 15 |
+
|
| 16 |
+
from ...utils import _LazyModule
|
| 17 |
+
from ...utils.import_utils import define_import_structure
|
| 18 |
+
|
| 19 |
+
|
| 20 |
+
if TYPE_CHECKING:
|
| 21 |
+
from .configuration_idefics2 import *
|
| 22 |
+
from .image_processing_idefics2 import *
|
| 23 |
+
from .image_processing_pil_idefics2 import *
|
| 24 |
+
from .modeling_idefics2 import *
|
| 25 |
+
from .processing_idefics2 import *
|
| 26 |
+
else:
|
| 27 |
+
import sys
|
| 28 |
+
|
| 29 |
+
_file = globals()["__file__"]
|
| 30 |
+
sys.modules[__name__] = _LazyModule(__name__, _file, define_import_structure(_file), module_spec=__spec__)
|
LTA_openwebtext_dualt/mini_owt_logdirichlet/.venv_qwen35_uv/lib/python3.12/site-packages/transformers/models/idefics2/configuration_idefics2.py
ADDED
|
@@ -0,0 +1,165 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# Copyright 2024 The HuggingFace Inc. team. All rights reserved.
|
| 2 |
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
| 3 |
+
# you may not use this file except in compliance with the License.
|
| 4 |
+
# You may obtain a copy of the License at
|
| 5 |
+
#
|
| 6 |
+
# http://www.apache.org/licenses/LICENSE-2.0
|
| 7 |
+
#
|
| 8 |
+
# Unless required by applicable law or agreed to in writing, software
|
| 9 |
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
| 10 |
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
| 11 |
+
# See the License for the specific language governing permissions and
|
| 12 |
+
# limitations under the License.
|
| 13 |
+
"""Idefics2 model configuration"""
|
| 14 |
+
|
| 15 |
+
from huggingface_hub.dataclasses import strict
|
| 16 |
+
|
| 17 |
+
from ...configuration_utils import PreTrainedConfig
|
| 18 |
+
from ...utils import auto_docstring, logging
|
| 19 |
+
from ..auto import CONFIG_MAPPING, AutoConfig
|
| 20 |
+
|
| 21 |
+
|
| 22 |
+
logger = logging.get_logger(__name__)
|
| 23 |
+
|
| 24 |
+
|
| 25 |
+
@auto_docstring(checkpoint="HuggingFaceM4/idefics2-8b")
|
| 26 |
+
@strict
|
| 27 |
+
class Idefics2VisionConfig(PreTrainedConfig):
|
| 28 |
+
r"""
|
| 29 |
+
Example:
|
| 30 |
+
|
| 31 |
+
```python
|
| 32 |
+
>>> from transformers.models.idefics2.modeling_idefics2 import Idefics2VisionTransformer
|
| 33 |
+
>>> from transformers.models.idefics2.configuration_idefics2 import Idefics2VisionConfig
|
| 34 |
+
|
| 35 |
+
>>> # Initializing a Idefics2VisionConfig with google/siglip-base-patch16-224 style configuration
|
| 36 |
+
>>> configuration = Idefics2VisionConfig()
|
| 37 |
+
|
| 38 |
+
>>> # Initializing a Idefics2VisionTransformer (with random weights) from the google/siglip-base-patch16-224 style configuration
|
| 39 |
+
>>> model = Idefics2VisionTransformer(configuration)
|
| 40 |
+
|
| 41 |
+
>>> # Accessing the model configuration
|
| 42 |
+
>>> configuration = model.config
|
| 43 |
+
```"""
|
| 44 |
+
|
| 45 |
+
model_type = "idefics2_vision"
|
| 46 |
+
base_config_key = "vision_config"
|
| 47 |
+
|
| 48 |
+
hidden_size: int = 768
|
| 49 |
+
intermediate_size: int = 3072
|
| 50 |
+
num_hidden_layers: int = 12
|
| 51 |
+
num_attention_heads: int = 12
|
| 52 |
+
num_channels: int = 3
|
| 53 |
+
image_size: int | list[int] | tuple[int, int] = 224
|
| 54 |
+
patch_size: int | list[int] | tuple[int, int] = 32
|
| 55 |
+
hidden_act: str = "gelu_pytorch_tanh"
|
| 56 |
+
layer_norm_eps: float = 1e-6
|
| 57 |
+
attention_dropout: float | int = 0.0
|
| 58 |
+
initializer_range: float = 0.02
|
| 59 |
+
|
| 60 |
+
|
| 61 |
+
@auto_docstring(checkpoint="HuggingFaceM4/idefics2-8b")
|
| 62 |
+
@strict
|
| 63 |
+
class Idefics2PerceiverConfig(PreTrainedConfig):
|
| 64 |
+
r"""
|
| 65 |
+
resampler_n_latents (`int`, *optional*, defaults to 64):
|
| 66 |
+
Number of latent embeddings to resample ("compress") the input sequence to (usually < 128).
|
| 67 |
+
resampler_depth (`int`, *optional*, defaults to 3):
|
| 68 |
+
Depth of the Perceiver Resampler (Transformer w/ cross attention). Should be shallow (<= 3).
|
| 69 |
+
resampler_n_heads (`int`, *optional*, defaults to 16):
|
| 70 |
+
Number of heads in each Transformer block (for multi-headed self-attention).
|
| 71 |
+
resampler_head_dim (`int`, *optional*, defaults to 96):
|
| 72 |
+
Dimensionality of each head projection in the Transformer block.
|
| 73 |
+
"""
|
| 74 |
+
|
| 75 |
+
model_type = "idefics2_perceiver"
|
| 76 |
+
|
| 77 |
+
hidden_act: str = "silu"
|
| 78 |
+
hidden_size: int = 4096
|
| 79 |
+
rms_norm_eps: float = 1e-06
|
| 80 |
+
resampler_n_latents: int = 64
|
| 81 |
+
resampler_depth: int = 3
|
| 82 |
+
resampler_n_heads: int = 16
|
| 83 |
+
resampler_head_dim: int = 96
|
| 84 |
+
num_key_value_heads: int = 4
|
| 85 |
+
attention_dropout: float | int = 0.0
|
| 86 |
+
initializer_range: float = 0.02
|
| 87 |
+
|
| 88 |
+
def validate_architecture(self):
|
| 89 |
+
"""Part of `@strict`-powered validation. Validates the architecture of the config."""
|
| 90 |
+
if self.num_key_value_heads > self.resampler_n_heads:
|
| 91 |
+
raise ValueError(
|
| 92 |
+
f"num_key_value_heads={self.num_key_value_heads} must be less than or equal to"
|
| 93 |
+
f" resampler_n_heads={self.resampler_n_heads}"
|
| 94 |
+
)
|
| 95 |
+
|
| 96 |
+
|
| 97 |
+
@auto_docstring(checkpoint="HuggingFaceM4/idefics2-8b")
|
| 98 |
+
@strict
|
| 99 |
+
class Idefics2Config(PreTrainedConfig):
|
| 100 |
+
r"""
|
| 101 |
+
perceiver_config (`IdeficsPerceiverConfig` or `dict`, *optional*):
|
| 102 |
+
Custom perceiver config or dict
|
| 103 |
+
|
| 104 |
+
Example:
|
| 105 |
+
```python
|
| 106 |
+
>>> from transformers import Idefics2Model, Idefics2Config
|
| 107 |
+
>>> # Initializing configuration
|
| 108 |
+
>>> configuration = Idefics2Config()
|
| 109 |
+
>>> # Initializing a model from the configuration
|
| 110 |
+
>>> model = Idefics2Model(configuration)
|
| 111 |
+
>>> # Accessing the model configuration
|
| 112 |
+
>>> configuration = model.config
|
| 113 |
+
```"""
|
| 114 |
+
|
| 115 |
+
model_type = "idefics2"
|
| 116 |
+
sub_configs = {
|
| 117 |
+
"text_config": AutoConfig,
|
| 118 |
+
"perceiver_config": Idefics2PerceiverConfig,
|
| 119 |
+
"vision_config": Idefics2VisionConfig,
|
| 120 |
+
}
|
| 121 |
+
|
| 122 |
+
use_cache: bool = True
|
| 123 |
+
image_token_id: int = 32_001
|
| 124 |
+
tie_word_embeddings: bool = False
|
| 125 |
+
vision_config: dict | PreTrainedConfig | None = None
|
| 126 |
+
perceiver_config: dict | PreTrainedConfig | None = None
|
| 127 |
+
text_config: dict | PreTrainedConfig | None = None
|
| 128 |
+
|
| 129 |
+
def __post_init__(self, **kwargs):
|
| 130 |
+
if self.perceiver_config is None:
|
| 131 |
+
self.perceiver_config = Idefics2PerceiverConfig()
|
| 132 |
+
logger.info("perciver_config is None, using default perceiver config")
|
| 133 |
+
elif isinstance(self.perceiver_config, dict):
|
| 134 |
+
self.perceiver_config = Idefics2PerceiverConfig(**self.perceiver_config)
|
| 135 |
+
|
| 136 |
+
if self.vision_config is None:
|
| 137 |
+
self.vision_config = Idefics2VisionConfig()
|
| 138 |
+
logger.info("vision_config is None, using default vision config")
|
| 139 |
+
elif isinstance(self.vision_config, dict):
|
| 140 |
+
self.vision_config = Idefics2VisionConfig(**self.vision_config)
|
| 141 |
+
|
| 142 |
+
if isinstance(self.text_config, dict):
|
| 143 |
+
self.text_config["model_type"] = self.text_config.get("model_type", "mistral")
|
| 144 |
+
self.text_config = CONFIG_MAPPING[self.text_config["model_type"]](**self.text_config)
|
| 145 |
+
elif self.text_config is None:
|
| 146 |
+
logger.info("text_config is None, using default text config")
|
| 147 |
+
self.text_config = CONFIG_MAPPING["mistral"](
|
| 148 |
+
max_position_embeddings=4096 * 8,
|
| 149 |
+
rms_norm_eps=1e-5,
|
| 150 |
+
# None in the original configuration_mistral, we set it to the unk_token_id
|
| 151 |
+
pad_token_id=0,
|
| 152 |
+
)
|
| 153 |
+
|
| 154 |
+
if self.text_config.hidden_size != self.perceiver_config.hidden_size:
|
| 155 |
+
self.perceiver_config.hidden_size = self.text_config.hidden_size
|
| 156 |
+
self.perceiver_config.rms_norm_eps = self.text_config.rms_norm_eps
|
| 157 |
+
logger.warning_once(
|
| 158 |
+
"Perceiver config has a different `hidden_size` than text config, which means default values were used. "
|
| 159 |
+
"In your model's config on the hub, add `hidden_size` and `rms_norm_eps` keys under the `perceiver_config` dict. "
|
| 160 |
+
)
|
| 161 |
+
|
| 162 |
+
super().__post_init__(**kwargs)
|
| 163 |
+
|
| 164 |
+
|
| 165 |
+
__all__ = ["Idefics2Config", "Idefics2PerceiverConfig", "Idefics2VisionConfig"]
|
LTA_openwebtext_dualt/mini_owt_logdirichlet/.venv_qwen35_uv/lib/python3.12/site-packages/transformers/models/idefics2/image_processing_idefics2.py
ADDED
|
@@ -0,0 +1,289 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# Copyright 2025 The HuggingFace Inc. team. All rights reserved.
|
| 2 |
+
#
|
| 3 |
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
| 4 |
+
# you may not use this file except in compliance with the License.
|
| 5 |
+
# You may obtain a copy of the License at
|
| 6 |
+
#
|
| 7 |
+
# http://www.apache.org/licenses/LICENSE-2.0
|
| 8 |
+
#
|
| 9 |
+
# Unless required by applicable law or agreed to in writing, software
|
| 10 |
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
| 11 |
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
| 12 |
+
# See the License for the specific language governing permissions and
|
| 13 |
+
# limitations under the License.
|
| 14 |
+
"""Image processor class for Idefics2."""
|
| 15 |
+
|
| 16 |
+
import numpy as np
|
| 17 |
+
import torch
|
| 18 |
+
|
| 19 |
+
from ...image_processing_backends import TorchvisionBackend
|
| 20 |
+
from ...image_processing_utils import BatchFeature
|
| 21 |
+
from ...image_transforms import group_images_by_shape, reorder_images
|
| 22 |
+
from ...image_utils import (
|
| 23 |
+
IMAGENET_STANDARD_MEAN,
|
| 24 |
+
IMAGENET_STANDARD_STD,
|
| 25 |
+
ImageInput,
|
| 26 |
+
PILImageResampling,
|
| 27 |
+
SizeDict,
|
| 28 |
+
make_nested_list_of_images,
|
| 29 |
+
)
|
| 30 |
+
from ...processing_utils import ImagesKwargs, Unpack
|
| 31 |
+
from ...utils import TensorType, auto_docstring, is_vision_available
|
| 32 |
+
|
| 33 |
+
|
| 34 |
+
if is_vision_available():
|
| 35 |
+
from PIL import Image
|
| 36 |
+
|
| 37 |
+
from torchvision.transforms.v2 import functional as tvF
|
| 38 |
+
|
| 39 |
+
|
| 40 |
+
def get_resize_output_image_size(image, size: SizeDict) -> tuple[int, int]:
|
| 41 |
+
"""
|
| 42 |
+
Get the output size of the image after resizing given a dictionary specifying the max and min sizes.
|
| 43 |
+
Images are always channels-first (CHW).
|
| 44 |
+
"""
|
| 45 |
+
height, width = image.shape[-2:]
|
| 46 |
+
|
| 47 |
+
min_len = size.shortest_edge
|
| 48 |
+
max_len = size.longest_edge
|
| 49 |
+
aspect_ratio = width / height
|
| 50 |
+
|
| 51 |
+
if width >= height and width > max_len:
|
| 52 |
+
width = max_len
|
| 53 |
+
height = int(width / aspect_ratio)
|
| 54 |
+
elif height > width and height > max_len:
|
| 55 |
+
height = max_len
|
| 56 |
+
width = int(height * aspect_ratio)
|
| 57 |
+
height = max(height, min_len)
|
| 58 |
+
width = max(width, min_len)
|
| 59 |
+
return height, width
|
| 60 |
+
|
| 61 |
+
|
| 62 |
+
def convert_to_rgb(image: ImageInput) -> ImageInput:
|
| 63 |
+
"""
|
| 64 |
+
Converts an image to RGB format. Only converts if the image is of type PIL.Image.Image, otherwise returns the image
|
| 65 |
+
as is.
|
| 66 |
+
"""
|
| 67 |
+
if not is_vision_available() or not isinstance(image, Image.Image):
|
| 68 |
+
return image
|
| 69 |
+
|
| 70 |
+
if image.mode == "RGB":
|
| 71 |
+
return image
|
| 72 |
+
|
| 73 |
+
image_rgba = image.convert("RGBA")
|
| 74 |
+
background = Image.new("RGBA", image_rgba.size, (255, 255, 255))
|
| 75 |
+
alpha_composite = Image.alpha_composite(background, image_rgba)
|
| 76 |
+
alpha_composite = alpha_composite.convert("RGB")
|
| 77 |
+
return alpha_composite
|
| 78 |
+
|
| 79 |
+
|
| 80 |
+
class Idefics2ImageProcessorKwargs(ImagesKwargs, total=False):
|
| 81 |
+
r"""
|
| 82 |
+
do_image_splitting (`bool`, *optional*, defaults to `self.do_image_splitting`):
|
| 83 |
+
Whether to split the image into a sequence 4 equal sub-images concatenated with the original image.
|
| 84 |
+
"""
|
| 85 |
+
|
| 86 |
+
do_image_splitting: bool
|
| 87 |
+
|
| 88 |
+
|
| 89 |
+
def get_max_height_width(images_list: list[list["torch.Tensor|np.ndarray"]]) -> tuple[int, int]:
|
| 90 |
+
"""
|
| 91 |
+
Get the maximum height and width across all images in a batch.
|
| 92 |
+
"""
|
| 93 |
+
image_sizes = []
|
| 94 |
+
for images in images_list:
|
| 95 |
+
for image in images:
|
| 96 |
+
image_sizes.append(image.shape[-2:])
|
| 97 |
+
|
| 98 |
+
max_height = max(size[0] for size in image_sizes)
|
| 99 |
+
max_width = max(size[1] for size in image_sizes)
|
| 100 |
+
return (max_height, max_width)
|
| 101 |
+
|
| 102 |
+
|
| 103 |
+
def make_pixel_mask(image: "torch.Tensor", output_size: tuple[int, int]) -> "torch.Tensor":
|
| 104 |
+
"""
|
| 105 |
+
Make a pixel mask for the image, where 1 indicates a valid pixel and 0 indicates padding.
|
| 106 |
+
"""
|
| 107 |
+
input_height, input_width = image.shape[-2:]
|
| 108 |
+
mask = torch.zeros(output_size, dtype=torch.int64, device=image.device)
|
| 109 |
+
mask[:input_height, :input_width] = 1
|
| 110 |
+
return mask
|
| 111 |
+
|
| 112 |
+
|
| 113 |
+
@auto_docstring
|
| 114 |
+
class Idefics2ImageProcessor(TorchvisionBackend):
|
| 115 |
+
valid_kwargs = Idefics2ImageProcessorKwargs
|
| 116 |
+
resample = PILImageResampling.BILINEAR
|
| 117 |
+
image_mean = IMAGENET_STANDARD_MEAN
|
| 118 |
+
image_std = IMAGENET_STANDARD_STD
|
| 119 |
+
do_resize = True
|
| 120 |
+
do_rescale = True
|
| 121 |
+
do_normalize = True
|
| 122 |
+
do_pad = True
|
| 123 |
+
do_convert_rgb = True
|
| 124 |
+
do_image_splitting = False
|
| 125 |
+
default_to_square = False
|
| 126 |
+
size = {"shortest_edge": 378, "longest_edge": 980}
|
| 127 |
+
model_input_names = ["pixel_values", "pixel_attention_mask"]
|
| 128 |
+
|
| 129 |
+
def __init__(self, **kwargs: Unpack[Idefics2ImageProcessorKwargs]):
|
| 130 |
+
super().__init__(**kwargs)
|
| 131 |
+
|
| 132 |
+
@auto_docstring
|
| 133 |
+
def preprocess(self, images: ImageInput, **kwargs: Unpack[Idefics2ImageProcessorKwargs]) -> BatchFeature:
|
| 134 |
+
return super().preprocess(images, **kwargs)
|
| 135 |
+
|
| 136 |
+
def convert_to_rgb(self, image: ImageInput) -> ImageInput:
|
| 137 |
+
"""Convert an image to RGB format."""
|
| 138 |
+
return convert_to_rgb(image)
|
| 139 |
+
|
| 140 |
+
def resize(
|
| 141 |
+
self,
|
| 142 |
+
image: "torch.Tensor",
|
| 143 |
+
size: SizeDict,
|
| 144 |
+
resample: "PILImageResampling | tvF.InterpolationMode | int | None" = None,
|
| 145 |
+
**kwargs,
|
| 146 |
+
) -> "torch.Tensor":
|
| 147 |
+
"""Resize using Idefics2 shortest_edge/longest_edge logic."""
|
| 148 |
+
if size.shortest_edge and size.longest_edge:
|
| 149 |
+
new_size = get_resize_output_image_size(image, size)
|
| 150 |
+
elif size.height and size.width:
|
| 151 |
+
new_size = (size.height, size.width)
|
| 152 |
+
else:
|
| 153 |
+
raise ValueError("Size must contain 'height' and 'width' keys or 'shortest_edge' and 'longest_edge' keys.")
|
| 154 |
+
|
| 155 |
+
return super().resize(image, SizeDict(height=new_size[0], width=new_size[1]), resample=resample, **kwargs)
|
| 156 |
+
|
| 157 |
+
def _prepare_images_structure(self, images: ImageInput, expected_ndims: int = 3) -> ImageInput:
|
| 158 |
+
"""Prepare a nested images structure for processing."""
|
| 159 |
+
images = self.fetch_images(images)
|
| 160 |
+
return make_nested_list_of_images(images, expected_ndims=expected_ndims)
|
| 161 |
+
|
| 162 |
+
def split_images(self, images: "torch.Tensor") -> list[list["torch.Tensor"]]:
|
| 163 |
+
"""
|
| 164 |
+
Split a batch of images into 4 equal sub-images, and concatenate that sequence with the original image.
|
| 165 |
+
"""
|
| 166 |
+
height, width = images.shape[-2:]
|
| 167 |
+
|
| 168 |
+
mid_width = width // 2
|
| 169 |
+
mid_height = height // 2
|
| 170 |
+
|
| 171 |
+
batch_split_images = [
|
| 172 |
+
images[..., :mid_height, :mid_width],
|
| 173 |
+
images[..., :mid_height, mid_width:],
|
| 174 |
+
images[..., mid_height:, :mid_width],
|
| 175 |
+
images[..., mid_height:, mid_width:],
|
| 176 |
+
images,
|
| 177 |
+
]
|
| 178 |
+
|
| 179 |
+
batch_split_images = [[image[i] for image in batch_split_images] for i in range(len(batch_split_images[0]))]
|
| 180 |
+
return batch_split_images
|
| 181 |
+
|
| 182 |
+
def pad(
|
| 183 |
+
self, image: "torch.Tensor", padded_size: tuple[int, int], fill: int = 0
|
| 184 |
+
) -> tuple["torch.Tensor", "torch.Tensor"]:
|
| 185 |
+
"""
|
| 186 |
+
Pad an image to the specified size and create the corresponding pixel mask.
|
| 187 |
+
"""
|
| 188 |
+
original_size = image.shape[-2:]
|
| 189 |
+
padding_bottom = padded_size[0] - original_size[0]
|
| 190 |
+
padding_right = padded_size[1] - original_size[1]
|
| 191 |
+
|
| 192 |
+
if padding_bottom < 0 or padding_right < 0:
|
| 193 |
+
raise ValueError(
|
| 194 |
+
f"Padding dimensions are negative. Please make sure that the padded size is larger than the "
|
| 195 |
+
f"original size. Got padded size: {padded_size}, original size: {original_size}."
|
| 196 |
+
)
|
| 197 |
+
|
| 198 |
+
if original_size != padded_size:
|
| 199 |
+
padding = (0, 0, padding_right, padding_bottom)
|
| 200 |
+
image = tvF.pad(image, padding, fill=fill, padding_mode="constant")
|
| 201 |
+
|
| 202 |
+
pixel_mask = torch.zeros(padded_size, dtype=torch.int64, device=image.device)
|
| 203 |
+
pixel_mask[: original_size[0], : original_size[1]] = 1
|
| 204 |
+
|
| 205 |
+
return image, pixel_mask
|
| 206 |
+
|
| 207 |
+
def _preprocess(
|
| 208 |
+
self,
|
| 209 |
+
images: list[list["torch.Tensor"]],
|
| 210 |
+
do_resize: bool,
|
| 211 |
+
size: SizeDict,
|
| 212 |
+
resample: "PILImageResampling | tvF.InterpolationMode | int | None",
|
| 213 |
+
do_rescale: bool,
|
| 214 |
+
rescale_factor: float,
|
| 215 |
+
do_normalize: bool,
|
| 216 |
+
image_mean: float | list[float] | None,
|
| 217 |
+
image_std: float | list[float] | None,
|
| 218 |
+
do_pad: bool | None,
|
| 219 |
+
do_image_splitting: bool | None,
|
| 220 |
+
disable_grouping: bool | None,
|
| 221 |
+
return_tensors: str | TensorType | None,
|
| 222 |
+
**kwargs,
|
| 223 |
+
) -> BatchFeature:
|
| 224 |
+
grouped_images, grouped_images_index = group_images_by_shape(
|
| 225 |
+
images, disable_grouping=disable_grouping, is_nested=True
|
| 226 |
+
)
|
| 227 |
+
split_images_grouped = {}
|
| 228 |
+
for shape, stacked_images in grouped_images.items():
|
| 229 |
+
if do_image_splitting:
|
| 230 |
+
stacked_images = self.split_images(stacked_images)
|
| 231 |
+
split_images_grouped[shape] = stacked_images
|
| 232 |
+
split_images = reorder_images(split_images_grouped, grouped_images_index, is_nested=True)
|
| 233 |
+
if do_image_splitting:
|
| 234 |
+
for i, group_images in enumerate(split_images):
|
| 235 |
+
split_images[i] = [image for sublist in group_images for image in sublist]
|
| 236 |
+
|
| 237 |
+
grouped_images, grouped_images_index = group_images_by_shape(
|
| 238 |
+
split_images, disable_grouping=disable_grouping, is_nested=True
|
| 239 |
+
)
|
| 240 |
+
resized_images_grouped = {}
|
| 241 |
+
for shape, stacked_images in grouped_images.items():
|
| 242 |
+
if do_resize:
|
| 243 |
+
stacked_images = self.resize(stacked_images, size, resample=resample)
|
| 244 |
+
resized_images_grouped[shape] = stacked_images
|
| 245 |
+
resized_images = reorder_images(resized_images_grouped, grouped_images_index, is_nested=True)
|
| 246 |
+
|
| 247 |
+
grouped_images, grouped_images_index = group_images_by_shape(
|
| 248 |
+
resized_images, disable_grouping=disable_grouping, is_nested=True
|
| 249 |
+
)
|
| 250 |
+
processed_images_grouped = {}
|
| 251 |
+
for shape, stacked_images in grouped_images.items():
|
| 252 |
+
stacked_images = self.rescale_and_normalize(
|
| 253 |
+
stacked_images, do_rescale, rescale_factor, do_normalize, image_mean, image_std
|
| 254 |
+
)
|
| 255 |
+
processed_images_grouped[shape] = stacked_images
|
| 256 |
+
processed_images = reorder_images(processed_images_grouped, grouped_images_index, is_nested=True)
|
| 257 |
+
|
| 258 |
+
if do_pad:
|
| 259 |
+
max_num_images = max(len(images_) for images_ in processed_images)
|
| 260 |
+
max_height, max_width = get_max_height_width(processed_images)
|
| 261 |
+
|
| 262 |
+
processed_images_padded = torch.zeros(
|
| 263 |
+
len(processed_images),
|
| 264 |
+
max_num_images,
|
| 265 |
+
*(processed_images[0][0].shape[0], max_height, max_width),
|
| 266 |
+
device=processed_images[0][0].device,
|
| 267 |
+
)
|
| 268 |
+
pixel_attention_masks = torch.zeros(
|
| 269 |
+
len(processed_images),
|
| 270 |
+
max_num_images,
|
| 271 |
+
*(max_height, max_width),
|
| 272 |
+
device=processed_images[0][0].device,
|
| 273 |
+
)
|
| 274 |
+
for i, images in enumerate(processed_images):
|
| 275 |
+
for j, image in enumerate(images):
|
| 276 |
+
processed_images_padded[i, j], pixel_attention_masks[i, j] = self.pad(
|
| 277 |
+
image, (max_height, max_width)
|
| 278 |
+
)
|
| 279 |
+
processed_images = processed_images_padded
|
| 280 |
+
if do_pad:
|
| 281 |
+
data = {"pixel_values": processed_images, "pixel_attention_mask": pixel_attention_masks}
|
| 282 |
+
elif return_tensors == "pt":
|
| 283 |
+
data = {"pixel_values": torch.stack([torch.stack(images) for images in processed_images])}
|
| 284 |
+
else:
|
| 285 |
+
data = {"pixel_values": processed_images}
|
| 286 |
+
return BatchFeature(data=data, tensor_type=return_tensors)
|
| 287 |
+
|
| 288 |
+
|
| 289 |
+
__all__ = ["Idefics2ImageProcessor"]
|
LTA_openwebtext_dualt/mini_owt_logdirichlet/.venv_qwen35_uv/lib/python3.12/site-packages/transformers/models/idefics2/processing_idefics2.py
ADDED
|
@@ -0,0 +1,190 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# Copyright 2024 The HuggingFace Inc. team.
|
| 2 |
+
#
|
| 3 |
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
| 4 |
+
# you may not use this file except in compliance with the License.
|
| 5 |
+
# You may obtain a copy of the License at
|
| 6 |
+
#
|
| 7 |
+
# http://www.apache.org/licenses/LICENSE-2.0
|
| 8 |
+
#
|
| 9 |
+
# Unless required by applicable law or agreed to in writing, software
|
| 10 |
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
| 11 |
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
| 12 |
+
# See the License for the specific language governing permissions and
|
| 13 |
+
# limitations under the License.
|
| 14 |
+
"""
|
| 15 |
+
Processor class for IDEFICS2.
|
| 16 |
+
"""
|
| 17 |
+
|
| 18 |
+
import re
|
| 19 |
+
from itertools import accumulate
|
| 20 |
+
from typing import TYPE_CHECKING, Union
|
| 21 |
+
|
| 22 |
+
from ...feature_extraction_utils import BatchFeature
|
| 23 |
+
from ...image_utils import ImageInput, is_valid_image, load_image
|
| 24 |
+
from ...processing_utils import (
|
| 25 |
+
ProcessingKwargs,
|
| 26 |
+
ProcessorMixin,
|
| 27 |
+
Unpack,
|
| 28 |
+
)
|
| 29 |
+
from ...tokenization_utils_base import AddedToken, TextInput
|
| 30 |
+
from ...utils import auto_docstring, logging
|
| 31 |
+
|
| 32 |
+
|
| 33 |
+
if TYPE_CHECKING:
|
| 34 |
+
from ...tokenization_utils_base import PreTokenizedInput
|
| 35 |
+
|
| 36 |
+
|
| 37 |
+
logger = logging.get_logger(__name__)
|
| 38 |
+
|
| 39 |
+
|
| 40 |
+
def is_url(val) -> bool:
|
| 41 |
+
return isinstance(val, str) and val.startswith("http")
|
| 42 |
+
|
| 43 |
+
|
| 44 |
+
def is_image_or_image_url(elem):
|
| 45 |
+
return is_url(elem) or is_valid_image(elem)
|
| 46 |
+
|
| 47 |
+
|
| 48 |
+
class Idefics2ProcessorKwargs(ProcessingKwargs, total=False):
|
| 49 |
+
_defaults = {
|
| 50 |
+
"text_kwargs": {
|
| 51 |
+
"add_special_tokens": True,
|
| 52 |
+
"padding": False,
|
| 53 |
+
"is_split_into_words": False,
|
| 54 |
+
},
|
| 55 |
+
}
|
| 56 |
+
|
| 57 |
+
|
| 58 |
+
@auto_docstring
|
| 59 |
+
class Idefics2Processor(ProcessorMixin):
|
| 60 |
+
def __init__(
|
| 61 |
+
self, image_processor, tokenizer=None, image_seq_len: int = 64, chat_template: str | None = None, **kwargs
|
| 62 |
+
):
|
| 63 |
+
r"""
|
| 64 |
+
image_seq_len (`int`, *optional*, defaults to 64):
|
| 65 |
+
The length of the image sequence i.e. the number of <image> tokens per image in the input.
|
| 66 |
+
This parameter is used to build the string from the input prompt and image tokens and should match the
|
| 67 |
+
config.perceiver_config.resampler_n_latents value for the model used.
|
| 68 |
+
"""
|
| 69 |
+
if not hasattr(tokenizer, "image_token"):
|
| 70 |
+
self.fake_image_token = AddedToken("<fake_token_around_image>", normalized=False, special=True).content
|
| 71 |
+
self.image_token = AddedToken("<image>", normalized=False, special=True).content
|
| 72 |
+
tokens_to_add = {"additional_special_tokens": [self.fake_image_token, self.image_token]}
|
| 73 |
+
tokenizer.add_special_tokens(tokens_to_add)
|
| 74 |
+
self.image_token_id = tokenizer.convert_tokens_to_ids(self.image_token)
|
| 75 |
+
else:
|
| 76 |
+
self.fake_image_token = tokenizer.image_boundary_token
|
| 77 |
+
self.image_token = tokenizer.image_token
|
| 78 |
+
self.image_token_id = tokenizer.image_token_id
|
| 79 |
+
|
| 80 |
+
self.end_of_utterance_token = AddedToken("<end_of_utterance>", normalized=False, special=True)
|
| 81 |
+
tokenizer.add_special_tokens({"additional_special_tokens": [self.end_of_utterance_token]})
|
| 82 |
+
self.image_seq_len = image_seq_len
|
| 83 |
+
|
| 84 |
+
super().__init__(image_processor, tokenizer, chat_template=chat_template)
|
| 85 |
+
|
| 86 |
+
def _extract_images_from_prompts(self, prompts):
|
| 87 |
+
prompt_images = []
|
| 88 |
+
for prompt in prompts:
|
| 89 |
+
images = []
|
| 90 |
+
for elem in prompt:
|
| 91 |
+
if is_valid_image(elem):
|
| 92 |
+
images.append(elem)
|
| 93 |
+
elif is_url(elem):
|
| 94 |
+
images.append(load_image(elem))
|
| 95 |
+
prompt_images.append(images)
|
| 96 |
+
return prompt_images
|
| 97 |
+
|
| 98 |
+
@auto_docstring
|
| 99 |
+
def __call__(
|
| 100 |
+
self,
|
| 101 |
+
images: ImageInput | list[ImageInput] | list[list[ImageInput]] = None,
|
| 102 |
+
text: Union[TextInput, "PreTokenizedInput", list[TextInput], list["PreTokenizedInput"]] = None,
|
| 103 |
+
**kwargs: Unpack[Idefics2ProcessorKwargs],
|
| 104 |
+
) -> BatchFeature:
|
| 105 |
+
if text is None and images is None:
|
| 106 |
+
raise ValueError("You must provide either `text` or `images`.")
|
| 107 |
+
|
| 108 |
+
output_kwargs = self._merge_kwargs(
|
| 109 |
+
Idefics2ProcessorKwargs,
|
| 110 |
+
tokenizer_init_kwargs=self.tokenizer.init_kwargs,
|
| 111 |
+
**kwargs,
|
| 112 |
+
)
|
| 113 |
+
return_tensors = output_kwargs["text_kwargs"].pop("return_tensors", None)
|
| 114 |
+
|
| 115 |
+
n_images_in_text = []
|
| 116 |
+
inputs = {}
|
| 117 |
+
|
| 118 |
+
if text is not None:
|
| 119 |
+
if isinstance(text, str):
|
| 120 |
+
text = [text]
|
| 121 |
+
elif not isinstance(text, list) and not isinstance(text[0], str):
|
| 122 |
+
raise ValueError("Invalid input text. Please provide a string, or a list of strings")
|
| 123 |
+
|
| 124 |
+
# Replace the image token with fake tokens around the expanded image token sequence of length `image_seq_len`
|
| 125 |
+
fake_image_token = self.fake_image_token
|
| 126 |
+
image_token = self.image_token
|
| 127 |
+
image_str = f"{fake_image_token}{image_token * self.image_seq_len}{fake_image_token}"
|
| 128 |
+
|
| 129 |
+
if self.image_processor.do_image_splitting:
|
| 130 |
+
# A single image token is split into 4 patches + 1 original image
|
| 131 |
+
image_str = image_str * 5
|
| 132 |
+
|
| 133 |
+
prompt_strings = []
|
| 134 |
+
closing_fake_pattern = re.compile(rf"{re.escape(fake_image_token)}(?=[^\s<])")
|
| 135 |
+
for sample in text:
|
| 136 |
+
n_images_in_text.append(sample.count(image_token))
|
| 137 |
+
sample = sample.replace(image_token, image_str)
|
| 138 |
+
# Remove any double fake tokens if images are adjacent
|
| 139 |
+
sample = sample.replace(f"{fake_image_token}{fake_image_token}", f"{fake_image_token}")
|
| 140 |
+
# Ensure words attached directly after the closing fake token remain word-boundary aligned
|
| 141 |
+
sample = closing_fake_pattern.sub(f"{fake_image_token} ", sample)
|
| 142 |
+
prompt_strings.append(sample)
|
| 143 |
+
|
| 144 |
+
text_inputs = self.tokenizer(prompt_strings, **output_kwargs["text_kwargs"])
|
| 145 |
+
self._check_special_mm_tokens(prompt_strings, text_inputs, modalities=["image"])
|
| 146 |
+
inputs.update(text_inputs)
|
| 147 |
+
|
| 148 |
+
if images is not None:
|
| 149 |
+
if is_image_or_image_url(images):
|
| 150 |
+
images = [[images]]
|
| 151 |
+
elif isinstance(images, (list, tuple)) and is_image_or_image_url(images[0]):
|
| 152 |
+
if text is not None:
|
| 153 |
+
if sum(n_images_in_text) != len(images):
|
| 154 |
+
raise ValueError(
|
| 155 |
+
f"The total number of {image_token} tokens in the prompts should be the same as the number of images passed."
|
| 156 |
+
f" Found {sum(n_images_in_text)} {image_token} tokens and {len(images)} images."
|
| 157 |
+
)
|
| 158 |
+
# Reorganize the images to match the prompts
|
| 159 |
+
cumsum_images_in_text = [0] + list(accumulate(n_images_in_text))
|
| 160 |
+
images = [
|
| 161 |
+
images[cumsum_images_in_text[i] : cumsum_images_in_text[i + 1]]
|
| 162 |
+
for i in range(len(n_images_in_text))
|
| 163 |
+
]
|
| 164 |
+
else:
|
| 165 |
+
images = [images]
|
| 166 |
+
|
| 167 |
+
elif (
|
| 168 |
+
not isinstance(images, (list, tuple))
|
| 169 |
+
and not isinstance(images[0], (list, tuple))
|
| 170 |
+
and not is_image_or_image_url(images[0][0])
|
| 171 |
+
):
|
| 172 |
+
raise ValueError(
|
| 173 |
+
"Invalid input images. Please provide a single image or a list of images or a list of list of images."
|
| 174 |
+
)
|
| 175 |
+
|
| 176 |
+
n_images_in_images = [len(sample) for sample in images]
|
| 177 |
+
if text is not None and not n_images_in_images == n_images_in_text:
|
| 178 |
+
raise ValueError(
|
| 179 |
+
f"The number of images in the text {n_images_in_text} and images {n_images_in_images} should be the same."
|
| 180 |
+
)
|
| 181 |
+
|
| 182 |
+
# Load images if they are URLs
|
| 183 |
+
images = [[load_image(im) for im in sample] for sample in images]
|
| 184 |
+
image_inputs = self.image_processor(images, **output_kwargs["images_kwargs"])
|
| 185 |
+
inputs.update(image_inputs)
|
| 186 |
+
|
| 187 |
+
return BatchFeature(inputs, tensor_type=return_tensors)
|
| 188 |
+
|
| 189 |
+
|
| 190 |
+
__all__ = ["Idefics2Processor"]
|
LTA_openwebtext_dualt/mini_owt_logdirichlet/logs/vllm_qwen36_35b_a3b_gpu1_port8009.log
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:28a1ca4f5290c9e274abd9b5d6af4e69822f46dd480b1d672247ec800047c65c
|
| 3 |
+
size 286284882
|
LTA_openwebtext_dualt/mini_owt_logdirichlet/logs/vllm_qwen36_35b_a3b_node0_gpu1_port8009.log
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:df7799f5216af3beaf4d455fe39a759728e1d60a3348d65d35e08f32688b82fb
|
| 3 |
+
size 138081174
|
LTA_openwebtext_dualt/mini_owt_logdirichlet/logs/vllm_qwen36_35b_a3b_node0_gpu3_port8011.log
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:5a3ffd903a683b72d7d0b0fbdaf55f2df0171b46aef80721903bd5fdfddcb2bc
|
| 3 |
+
size 138161892
|
LTA_openwebtext_dualt/mini_owt_logdirichlet/logs/vllm_qwen36_35b_a3b_node0_gpu4_port8012.log
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:0b9ef0d56ca4a49bdc85f86012361f889b9d6ad2ad4bc116f46d889a61b04756
|
| 3 |
+
size 137943247
|
LTA_openwebtext_dualt/mini_owt_logdirichlet/logs/vllm_qwen36_35b_a3b_node0_gpu7_port8015.log
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:1bb1dd2ef3fb2995640d48e80183cc337a97dcd10d2fc076ca0a6fa003c09a93
|
| 3 |
+
size 138093972
|
LTA_openwebtext_dualt/mini_owt_logdirichlet/logs/vllm_qwen36_35b_a3b_node1_gpu0_port8008.log
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:0e1ae526462e71683846c129e2ce8484c321f00a2002f5420d280943d0032688
|
| 3 |
+
size 137849373
|
LTA_openwebtext_dualt/mini_owt_logdirichlet/logs/vllm_qwen36_35b_a3b_node1_gpu1_port8009.log
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:41a4b4a714a682f5020818de50b4cf9dd80155d453718acd9d4d97c9644d5949
|
| 3 |
+
size 138234178
|
LTA_openwebtext_dualt/mini_owt_logdirichlet/logs/vllm_qwen36_35b_a3b_node1_gpu4_port8012.log
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:3708a36b80b8e42e884261f128a595a8e5d05985800638ffae29ed32f8b6b923
|
| 3 |
+
size 139000169
|
LTA_openwebtext_dualt/mini_owt_logdirichlet/logs/vllm_qwen36_35b_a3b_node1_gpu5_port8013.log
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:cd3bdae47bc876c36b7c0f6da22464333e6613a0cab14f040f08380be92dd5d0
|
| 3 |
+
size 138856982
|