Add files using upload-large-folder tool
Browse files- LTA_openwebtext_dualt/mini_owt_logdirichlet/.venv_qwen35/lib/python3.12/site-packages/pip/_vendor/chardet/charsetprober.py +147 -0
- LTA_openwebtext_dualt/mini_owt_logdirichlet/.venv_qwen35/lib/python3.12/site-packages/pip/_vendor/chardet/euckrprober.py +47 -0
- LTA_openwebtext_dualt/mini_owt_logdirichlet/.venv_qwen35/lib/python3.12/site-packages/pip/_vendor/chardet/gb2312freq.py +284 -0
- LTA_openwebtext_dualt/mini_owt_logdirichlet/.venv_qwen35_uv/lib/python3.12/site-packages/transformers/models/auto/__init__.py +33 -0
- LTA_openwebtext_dualt/mini_owt_logdirichlet/.venv_qwen35_uv/lib/python3.12/site-packages/transformers/models/auto/auto_factory.py +680 -0
- LTA_openwebtext_dualt/mini_owt_logdirichlet/.venv_qwen35_uv/lib/python3.12/site-packages/transformers/models/auto/auto_mappings.py +1008 -0
- LTA_openwebtext_dualt/mini_owt_logdirichlet/.venv_qwen35_uv/lib/python3.12/site-packages/transformers/models/auto/feature_extraction_auto.py +388 -0
- LTA_openwebtext_dualt/mini_owt_logdirichlet/.venv_qwen35_uv/lib/python3.12/site-packages/transformers/models/auto/image_processing_auto.py +706 -0
- LTA_openwebtext_dualt/mini_owt_logdirichlet/.venv_qwen35_uv/lib/python3.12/site-packages/transformers/models/auto/modeling_auto.py +0 -0
- LTA_openwebtext_dualt/mini_owt_logdirichlet/.venv_qwen35_uv/lib/python3.12/site-packages/transformers/models/auto/processing_auto.py +474 -0
- LTA_openwebtext_dualt/mini_owt_logdirichlet/.venv_qwen35_uv/lib/python3.12/site-packages/transformers/models/auto/tokenization_auto.py +893 -0
- LTA_openwebtext_dualt/mini_owt_logdirichlet/.venv_qwen35_uv/lib/python3.12/site-packages/transformers/models/auto/video_processing_auto.py +408 -0
- LTA_openwebtext_dualt/mini_owt_logdirichlet/.venv_qwen35_uv/lib/python3.12/site-packages/transformers/models/distilbert/tokenization_distilbert.py +42 -0
- LTA_openwebtext_dualt/mini_owt_logdirichlet/.venv_qwen35_uv/lib/python3.12/site-packages/transformers/models/slanext/configuration_slanext.py +103 -0
- LTA_openwebtext_dualt/mini_owt_logdirichlet/.venv_qwen35_uv/lib/python3.12/site-packages/transformers/models/slanext/image_processing_slanext.py +257 -0
- LTA_openwebtext_dualt/mini_owt_logdirichlet/.venv_qwen35_uv/lib/python3.12/site-packages/transformers/models/vitdet/__init__.py +27 -0
- LTA_openwebtext_dualt/mini_owt_logdirichlet/runs/owt_t5_elftokenized_full_len1024_C1_to_1024_pow1_d768_l12_h12_gbs512_8gpu_50ep_lr3e4_elfopt_t5embed_unfixed_stateprobadd_selfcond_ce_fast_20260531_230026/step_029000.pt +3 -0
- LTA_openwebtext_dualt/mini_owt_logdirichlet/runs/owt_t5_elftokenized_full_len1024_C1_to_1024_pow1_d768_l12_h12_gbs512_8gpu_50ep_lr3e4_elfopt_t5embed_unfixed_stateprobadd_selfcond_ce_fast_20260531_230026/step_096000.pt +3 -0
- LTA_openwebtext_dualt/mini_owt_logdirichlet/runs/owt_t5_elftokenized_full_len1024_C1_to_1024_pow1_d768_l12_h12_gbs512_8gpu_50ep_lr3e4_elfopt_t5embed_unfixed_stateprobadd_selfcond_ce_fast_20260531_230026/step_167000.pt +3 -0
- LTA_openwebtext_dualt/mini_owt_logdirichlet/runs/owt_t5_elftokenized_full_len1024_C1_to_1024_pow1_d768_l12_h12_gbs512_8gpu_50ep_lr3e4_elfopt_t5embed_unfixed_stateprobadd_selfcond_ce_fast_20260531_230026/step_210000.pt +3 -0
LTA_openwebtext_dualt/mini_owt_logdirichlet/.venv_qwen35/lib/python3.12/site-packages/pip/_vendor/chardet/charsetprober.py
ADDED
|
@@ -0,0 +1,147 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
######################## BEGIN LICENSE BLOCK ########################
|
| 2 |
+
# The Original Code is Mozilla Universal charset detector code.
|
| 3 |
+
#
|
| 4 |
+
# The Initial Developer of the Original Code is
|
| 5 |
+
# Netscape Communications Corporation.
|
| 6 |
+
# Portions created by the Initial Developer are Copyright (C) 2001
|
| 7 |
+
# the Initial Developer. All Rights Reserved.
|
| 8 |
+
#
|
| 9 |
+
# Contributor(s):
|
| 10 |
+
# Mark Pilgrim - port to Python
|
| 11 |
+
# Shy Shalom - original C code
|
| 12 |
+
#
|
| 13 |
+
# This library is free software; you can redistribute it and/or
|
| 14 |
+
# modify it under the terms of the GNU Lesser General Public
|
| 15 |
+
# License as published by the Free Software Foundation; either
|
| 16 |
+
# version 2.1 of the License, or (at your option) any later version.
|
| 17 |
+
#
|
| 18 |
+
# This library is distributed in the hope that it will be useful,
|
| 19 |
+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
| 20 |
+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
| 21 |
+
# Lesser General Public License for more details.
|
| 22 |
+
#
|
| 23 |
+
# You should have received a copy of the GNU Lesser General Public
|
| 24 |
+
# License along with this library; if not, write to the Free Software
|
| 25 |
+
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
|
| 26 |
+
# 02110-1301 USA
|
| 27 |
+
######################### END LICENSE BLOCK #########################
|
| 28 |
+
|
| 29 |
+
import logging
|
| 30 |
+
import re
|
| 31 |
+
from typing import Optional, Union
|
| 32 |
+
|
| 33 |
+
from .enums import LanguageFilter, ProbingState
|
| 34 |
+
|
| 35 |
+
INTERNATIONAL_WORDS_PATTERN = re.compile(
|
| 36 |
+
b"[a-zA-Z]*[\x80-\xFF]+[a-zA-Z]*[^a-zA-Z\x80-\xFF]?"
|
| 37 |
+
)
|
| 38 |
+
|
| 39 |
+
|
| 40 |
+
class CharSetProber:
|
| 41 |
+
|
| 42 |
+
SHORTCUT_THRESHOLD = 0.95
|
| 43 |
+
|
| 44 |
+
def __init__(self, lang_filter: LanguageFilter = LanguageFilter.NONE) -> None:
|
| 45 |
+
self._state = ProbingState.DETECTING
|
| 46 |
+
self.active = True
|
| 47 |
+
self.lang_filter = lang_filter
|
| 48 |
+
self.logger = logging.getLogger(__name__)
|
| 49 |
+
|
| 50 |
+
def reset(self) -> None:
|
| 51 |
+
self._state = ProbingState.DETECTING
|
| 52 |
+
|
| 53 |
+
@property
|
| 54 |
+
def charset_name(self) -> Optional[str]:
|
| 55 |
+
return None
|
| 56 |
+
|
| 57 |
+
@property
|
| 58 |
+
def language(self) -> Optional[str]:
|
| 59 |
+
raise NotImplementedError
|
| 60 |
+
|
| 61 |
+
def feed(self, byte_str: Union[bytes, bytearray]) -> ProbingState:
|
| 62 |
+
raise NotImplementedError
|
| 63 |
+
|
| 64 |
+
@property
|
| 65 |
+
def state(self) -> ProbingState:
|
| 66 |
+
return self._state
|
| 67 |
+
|
| 68 |
+
def get_confidence(self) -> float:
|
| 69 |
+
return 0.0
|
| 70 |
+
|
| 71 |
+
@staticmethod
|
| 72 |
+
def filter_high_byte_only(buf: Union[bytes, bytearray]) -> bytes:
|
| 73 |
+
buf = re.sub(b"([\x00-\x7F])+", b" ", buf)
|
| 74 |
+
return buf
|
| 75 |
+
|
| 76 |
+
@staticmethod
|
| 77 |
+
def filter_international_words(buf: Union[bytes, bytearray]) -> bytearray:
|
| 78 |
+
"""
|
| 79 |
+
We define three types of bytes:
|
| 80 |
+
alphabet: english alphabets [a-zA-Z]
|
| 81 |
+
international: international characters [\x80-\xFF]
|
| 82 |
+
marker: everything else [^a-zA-Z\x80-\xFF]
|
| 83 |
+
The input buffer can be thought to contain a series of words delimited
|
| 84 |
+
by markers. This function works to filter all words that contain at
|
| 85 |
+
least one international character. All contiguous sequences of markers
|
| 86 |
+
are replaced by a single space ascii character.
|
| 87 |
+
This filter applies to all scripts which do not use English characters.
|
| 88 |
+
"""
|
| 89 |
+
filtered = bytearray()
|
| 90 |
+
|
| 91 |
+
# This regex expression filters out only words that have at-least one
|
| 92 |
+
# international character. The word may include one marker character at
|
| 93 |
+
# the end.
|
| 94 |
+
words = INTERNATIONAL_WORDS_PATTERN.findall(buf)
|
| 95 |
+
|
| 96 |
+
for word in words:
|
| 97 |
+
filtered.extend(word[:-1])
|
| 98 |
+
|
| 99 |
+
# If the last character in the word is a marker, replace it with a
|
| 100 |
+
# space as markers shouldn't affect our analysis (they are used
|
| 101 |
+
# similarly across all languages and may thus have similar
|
| 102 |
+
# frequencies).
|
| 103 |
+
last_char = word[-1:]
|
| 104 |
+
if not last_char.isalpha() and last_char < b"\x80":
|
| 105 |
+
last_char = b" "
|
| 106 |
+
filtered.extend(last_char)
|
| 107 |
+
|
| 108 |
+
return filtered
|
| 109 |
+
|
| 110 |
+
@staticmethod
|
| 111 |
+
def remove_xml_tags(buf: Union[bytes, bytearray]) -> bytes:
|
| 112 |
+
"""
|
| 113 |
+
Returns a copy of ``buf`` that retains only the sequences of English
|
| 114 |
+
alphabet and high byte characters that are not between <> characters.
|
| 115 |
+
This filter can be applied to all scripts which contain both English
|
| 116 |
+
characters and extended ASCII characters, but is currently only used by
|
| 117 |
+
``Latin1Prober``.
|
| 118 |
+
"""
|
| 119 |
+
filtered = bytearray()
|
| 120 |
+
in_tag = False
|
| 121 |
+
prev = 0
|
| 122 |
+
buf = memoryview(buf).cast("c")
|
| 123 |
+
|
| 124 |
+
for curr, buf_char in enumerate(buf):
|
| 125 |
+
# Check if we're coming out of or entering an XML tag
|
| 126 |
+
|
| 127 |
+
# https://github.com/python/typeshed/issues/8182
|
| 128 |
+
if buf_char == b">": # type: ignore[comparison-overlap]
|
| 129 |
+
prev = curr + 1
|
| 130 |
+
in_tag = False
|
| 131 |
+
# https://github.com/python/typeshed/issues/8182
|
| 132 |
+
elif buf_char == b"<": # type: ignore[comparison-overlap]
|
| 133 |
+
if curr > prev and not in_tag:
|
| 134 |
+
# Keep everything after last non-extended-ASCII,
|
| 135 |
+
# non-alphabetic character
|
| 136 |
+
filtered.extend(buf[prev:curr])
|
| 137 |
+
# Output a space to delimit stretch we kept
|
| 138 |
+
filtered.extend(b" ")
|
| 139 |
+
in_tag = True
|
| 140 |
+
|
| 141 |
+
# If we're not in a tag...
|
| 142 |
+
if not in_tag:
|
| 143 |
+
# Keep everything after last non-extended-ASCII, non-alphabetic
|
| 144 |
+
# character
|
| 145 |
+
filtered.extend(buf[prev:])
|
| 146 |
+
|
| 147 |
+
return filtered
|
LTA_openwebtext_dualt/mini_owt_logdirichlet/.venv_qwen35/lib/python3.12/site-packages/pip/_vendor/chardet/euckrprober.py
ADDED
|
@@ -0,0 +1,47 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
######################## BEGIN LICENSE BLOCK ########################
|
| 2 |
+
# The Original Code is mozilla.org code.
|
| 3 |
+
#
|
| 4 |
+
# The Initial Developer of the Original Code is
|
| 5 |
+
# Netscape Communications Corporation.
|
| 6 |
+
# Portions created by the Initial Developer are Copyright (C) 1998
|
| 7 |
+
# the Initial Developer. All Rights Reserved.
|
| 8 |
+
#
|
| 9 |
+
# Contributor(s):
|
| 10 |
+
# Mark Pilgrim - port to Python
|
| 11 |
+
#
|
| 12 |
+
# This library is free software; you can redistribute it and/or
|
| 13 |
+
# modify it under the terms of the GNU Lesser General Public
|
| 14 |
+
# License as published by the Free Software Foundation; either
|
| 15 |
+
# version 2.1 of the License, or (at your option) any later version.
|
| 16 |
+
#
|
| 17 |
+
# This library is distributed in the hope that it will be useful,
|
| 18 |
+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
| 19 |
+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
| 20 |
+
# Lesser General Public License for more details.
|
| 21 |
+
#
|
| 22 |
+
# You should have received a copy of the GNU Lesser General Public
|
| 23 |
+
# License along with this library; if not, write to the Free Software
|
| 24 |
+
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
|
| 25 |
+
# 02110-1301 USA
|
| 26 |
+
######################### END LICENSE BLOCK #########################
|
| 27 |
+
|
| 28 |
+
from .chardistribution import EUCKRDistributionAnalysis
|
| 29 |
+
from .codingstatemachine import CodingStateMachine
|
| 30 |
+
from .mbcharsetprober import MultiByteCharSetProber
|
| 31 |
+
from .mbcssm import EUCKR_SM_MODEL
|
| 32 |
+
|
| 33 |
+
|
| 34 |
+
class EUCKRProber(MultiByteCharSetProber):
|
| 35 |
+
def __init__(self) -> None:
|
| 36 |
+
super().__init__()
|
| 37 |
+
self.coding_sm = CodingStateMachine(EUCKR_SM_MODEL)
|
| 38 |
+
self.distribution_analyzer = EUCKRDistributionAnalysis()
|
| 39 |
+
self.reset()
|
| 40 |
+
|
| 41 |
+
@property
|
| 42 |
+
def charset_name(self) -> str:
|
| 43 |
+
return "EUC-KR"
|
| 44 |
+
|
| 45 |
+
@property
|
| 46 |
+
def language(self) -> str:
|
| 47 |
+
return "Korean"
|
LTA_openwebtext_dualt/mini_owt_logdirichlet/.venv_qwen35/lib/python3.12/site-packages/pip/_vendor/chardet/gb2312freq.py
ADDED
|
@@ -0,0 +1,284 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
######################## BEGIN LICENSE BLOCK ########################
|
| 2 |
+
# The Original Code is Mozilla Communicator client code.
|
| 3 |
+
#
|
| 4 |
+
# The Initial Developer of the Original Code is
|
| 5 |
+
# Netscape Communications Corporation.
|
| 6 |
+
# Portions created by the Initial Developer are Copyright (C) 1998
|
| 7 |
+
# the Initial Developer. All Rights Reserved.
|
| 8 |
+
#
|
| 9 |
+
# Contributor(s):
|
| 10 |
+
# Mark Pilgrim - port to Python
|
| 11 |
+
#
|
| 12 |
+
# This library is free software; you can redistribute it and/or
|
| 13 |
+
# modify it under the terms of the GNU Lesser General Public
|
| 14 |
+
# License as published by the Free Software Foundation; either
|
| 15 |
+
# version 2.1 of the License, or (at your option) any later version.
|
| 16 |
+
#
|
| 17 |
+
# This library is distributed in the hope that it will be useful,
|
| 18 |
+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
| 19 |
+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
| 20 |
+
# Lesser General Public License for more details.
|
| 21 |
+
#
|
| 22 |
+
# You should have received a copy of the GNU Lesser General Public
|
| 23 |
+
# License along with this library; if not, write to the Free Software
|
| 24 |
+
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
|
| 25 |
+
# 02110-1301 USA
|
| 26 |
+
######################### END LICENSE BLOCK #########################
|
| 27 |
+
|
| 28 |
+
# GB2312 most frequently used character table
|
| 29 |
+
#
|
| 30 |
+
# Char to FreqOrder table , from hz6763
|
| 31 |
+
|
| 32 |
+
# 512 --> 0.79 -- 0.79
|
| 33 |
+
# 1024 --> 0.92 -- 0.13
|
| 34 |
+
# 2048 --> 0.98 -- 0.06
|
| 35 |
+
# 6768 --> 1.00 -- 0.02
|
| 36 |
+
#
|
| 37 |
+
# Ideal Distribution Ratio = 0.79135/(1-0.79135) = 3.79
|
| 38 |
+
# Random Distribution Ration = 512 / (3755 - 512) = 0.157
|
| 39 |
+
#
|
| 40 |
+
# Typical Distribution Ratio about 25% of Ideal one, still much higher that RDR
|
| 41 |
+
|
| 42 |
+
GB2312_TYPICAL_DISTRIBUTION_RATIO = 0.9
|
| 43 |
+
|
| 44 |
+
GB2312_TABLE_SIZE = 3760
|
| 45 |
+
|
| 46 |
+
# fmt: off
|
| 47 |
+
GB2312_CHAR_TO_FREQ_ORDER = (
|
| 48 |
+
1671, 749,1443,2364,3924,3807,2330,3921,1704,3463,2691,1511,1515, 572,3191,2205,
|
| 49 |
+
2361, 224,2558, 479,1711, 963,3162, 440,4060,1905,2966,2947,3580,2647,3961,3842,
|
| 50 |
+
2204, 869,4207, 970,2678,5626,2944,2956,1479,4048, 514,3595, 588,1346,2820,3409,
|
| 51 |
+
249,4088,1746,1873,2047,1774, 581,1813, 358,1174,3590,1014,1561,4844,2245, 670,
|
| 52 |
+
1636,3112, 889,1286, 953, 556,2327,3060,1290,3141, 613, 185,3477,1367, 850,3820,
|
| 53 |
+
1715,2428,2642,2303,2732,3041,2562,2648,3566,3946,1349, 388,3098,2091,1360,3585,
|
| 54 |
+
152,1687,1539, 738,1559, 59,1232,2925,2267,1388,1249,1741,1679,2960, 151,1566,
|
| 55 |
+
1125,1352,4271, 924,4296, 385,3166,4459, 310,1245,2850, 70,3285,2729,3534,3575,
|
| 56 |
+
2398,3298,3466,1960,2265, 217,3647, 864,1909,2084,4401,2773,1010,3269,5152, 853,
|
| 57 |
+
3051,3121,1244,4251,1895, 364,1499,1540,2313,1180,3655,2268, 562, 715,2417,3061,
|
| 58 |
+
544, 336,3768,2380,1752,4075, 950, 280,2425,4382, 183,2759,3272, 333,4297,2155,
|
| 59 |
+
1688,2356,1444,1039,4540, 736,1177,3349,2443,2368,2144,2225, 565, 196,1482,3406,
|
| 60 |
+
927,1335,4147, 692, 878,1311,1653,3911,3622,1378,4200,1840,2969,3149,2126,1816,
|
| 61 |
+
2534,1546,2393,2760, 737,2494, 13, 447, 245,2747, 38,2765,2129,2589,1079, 606,
|
| 62 |
+
360, 471,3755,2890, 404, 848, 699,1785,1236, 370,2221,1023,3746,2074,2026,2023,
|
| 63 |
+
2388,1581,2119, 812,1141,3091,2536,1519, 804,2053, 406,1596,1090, 784, 548,4414,
|
| 64 |
+
1806,2264,2936,1100, 343,4114,5096, 622,3358, 743,3668,1510,1626,5020,3567,2513,
|
| 65 |
+
3195,4115,5627,2489,2991, 24,2065,2697,1087,2719, 48,1634, 315, 68, 985,2052,
|
| 66 |
+
198,2239,1347,1107,1439, 597,2366,2172, 871,3307, 919,2487,2790,1867, 236,2570,
|
| 67 |
+
1413,3794, 906,3365,3381,1701,1982,1818,1524,2924,1205, 616,2586,2072,2004, 575,
|
| 68 |
+
253,3099, 32,1365,1182, 197,1714,2454,1201, 554,3388,3224,2748, 756,2587, 250,
|
| 69 |
+
2567,1507,1517,3529,1922,2761,2337,3416,1961,1677,2452,2238,3153, 615, 911,1506,
|
| 70 |
+
1474,2495,1265,1906,2749,3756,3280,2161, 898,2714,1759,3450,2243,2444, 563, 26,
|
| 71 |
+
3286,2266,3769,3344,2707,3677, 611,1402, 531,1028,2871,4548,1375, 261,2948, 835,
|
| 72 |
+
1190,4134, 353, 840,2684,1900,3082,1435,2109,1207,1674, 329,1872,2781,4055,2686,
|
| 73 |
+
2104, 608,3318,2423,2957,2768,1108,3739,3512,3271,3985,2203,1771,3520,1418,2054,
|
| 74 |
+
1681,1153, 225,1627,2929, 162,2050,2511,3687,1954, 124,1859,2431,1684,3032,2894,
|
| 75 |
+
585,4805,3969,2869,2704,2088,2032,2095,3656,2635,4362,2209, 256, 518,2042,2105,
|
| 76 |
+
3777,3657, 643,2298,1148,1779, 190, 989,3544, 414, 11,2135,2063,2979,1471, 403,
|
| 77 |
+
3678, 126, 770,1563, 671,2499,3216,2877, 600,1179, 307,2805,4937,1268,1297,2694,
|
| 78 |
+
252,4032,1448,1494,1331,1394, 127,2256, 222,1647,1035,1481,3056,1915,1048, 873,
|
| 79 |
+
3651, 210, 33,1608,2516, 200,1520, 415, 102, 0,3389,1287, 817, 91,3299,2940,
|
| 80 |
+
836,1814, 549,2197,1396,1669,2987,3582,2297,2848,4528,1070, 687, 20,1819, 121,
|
| 81 |
+
1552,1364,1461,1968,2617,3540,2824,2083, 177, 948,4938,2291, 110,4549,2066, 648,
|
| 82 |
+
3359,1755,2110,2114,4642,4845,1693,3937,3308,1257,1869,2123, 208,1804,3159,2992,
|
| 83 |
+
2531,2549,3361,2418,1350,2347,2800,2568,1291,2036,2680, 72, 842,1990, 212,1233,
|
| 84 |
+
1154,1586, 75,2027,3410,4900,1823,1337,2710,2676, 728,2810,1522,3026,4995, 157,
|
| 85 |
+
755,1050,4022, 710, 785,1936,2194,2085,1406,2777,2400, 150,1250,4049,1206, 807,
|
| 86 |
+
1910, 534, 529,3309,1721,1660, 274, 39,2827, 661,2670,1578, 925,3248,3815,1094,
|
| 87 |
+
4278,4901,4252, 41,1150,3747,2572,2227,4501,3658,4902,3813,3357,3617,2884,2258,
|
| 88 |
+
887, 538,4187,3199,1294,2439,3042,2329,2343,2497,1255, 107, 543,1527, 521,3478,
|
| 89 |
+
3568, 194,5062, 15, 961,3870,1241,1192,2664, 66,5215,3260,2111,1295,1127,2152,
|
| 90 |
+
3805,4135, 901,1164,1976, 398,1278, 530,1460, 748, 904,1054,1966,1426, 53,2909,
|
| 91 |
+
509, 523,2279,1534, 536,1019, 239,1685, 460,2353, 673,1065,2401,3600,4298,2272,
|
| 92 |
+
1272,2363, 284,1753,3679,4064,1695, 81, 815,2677,2757,2731,1386, 859, 500,4221,
|
| 93 |
+
2190,2566, 757,1006,2519,2068,1166,1455, 337,2654,3203,1863,1682,1914,3025,1252,
|
| 94 |
+
1409,1366, 847, 714,2834,2038,3209, 964,2970,1901, 885,2553,1078,1756,3049, 301,
|
| 95 |
+
1572,3326, 688,2130,1996,2429,1805,1648,2930,3421,2750,3652,3088, 262,1158,1254,
|
| 96 |
+
389,1641,1812, 526,1719, 923,2073,1073,1902, 468, 489,4625,1140, 857,2375,3070,
|
| 97 |
+
3319,2863, 380, 116,1328,2693,1161,2244, 273,1212,1884,2769,3011,1775,1142, 461,
|
| 98 |
+
3066,1200,2147,2212, 790, 702,2695,4222,1601,1058, 434,2338,5153,3640, 67,2360,
|
| 99 |
+
4099,2502, 618,3472,1329, 416,1132, 830,2782,1807,2653,3211,3510,1662, 192,2124,
|
| 100 |
+
296,3979,1739,1611,3684, 23, 118, 324, 446,1239,1225, 293,2520,3814,3795,2535,
|
| 101 |
+
3116, 17,1074, 467,2692,2201, 387,2922, 45,1326,3055,1645,3659,2817, 958, 243,
|
| 102 |
+
1903,2320,1339,2825,1784,3289, 356, 576, 865,2315,2381,3377,3916,1088,3122,1713,
|
| 103 |
+
1655, 935, 628,4689,1034,1327, 441, 800, 720, 894,1979,2183,1528,5289,2702,1071,
|
| 104 |
+
4046,3572,2399,1571,3281, 79, 761,1103, 327, 134, 758,1899,1371,1615, 879, 442,
|
| 105 |
+
215,2605,2579, 173,2048,2485,1057,2975,3317,1097,2253,3801,4263,1403,1650,2946,
|
| 106 |
+
814,4968,3487,1548,2644,1567,1285, 2, 295,2636, 97, 946,3576, 832, 141,4257,
|
| 107 |
+
3273, 760,3821,3521,3156,2607, 949,1024,1733,1516,1803,1920,2125,2283,2665,3180,
|
| 108 |
+
1501,2064,3560,2171,1592, 803,3518,1416, 732,3897,4258,1363,1362,2458, 119,1427,
|
| 109 |
+
602,1525,2608,1605,1639,3175, 694,3064, 10, 465, 76,2000,4846,4208, 444,3781,
|
| 110 |
+
1619,3353,2206,1273,3796, 740,2483, 320,1723,2377,3660,2619,1359,1137,1762,1724,
|
| 111 |
+
2345,2842,1850,1862, 912, 821,1866, 612,2625,1735,2573,3369,1093, 844, 89, 937,
|
| 112 |
+
930,1424,3564,2413,2972,1004,3046,3019,2011, 711,3171,1452,4178, 428, 801,1943,
|
| 113 |
+
432, 445,2811, 206,4136,1472, 730, 349, 73, 397,2802,2547, 998,1637,1167, 789,
|
| 114 |
+
396,3217, 154,1218, 716,1120,1780,2819,4826,1931,3334,3762,2139,1215,2627, 552,
|
| 115 |
+
3664,3628,3232,1405,2383,3111,1356,2652,3577,3320,3101,1703, 640,1045,1370,1246,
|
| 116 |
+
4996, 371,1575,2436,1621,2210, 984,4033,1734,2638, 16,4529, 663,2755,3255,1451,
|
| 117 |
+
3917,2257,1253,1955,2234,1263,2951, 214,1229, 617, 485, 359,1831,1969, 473,2310,
|
| 118 |
+
750,2058, 165, 80,2864,2419, 361,4344,2416,2479,1134, 796,3726,1266,2943, 860,
|
| 119 |
+
2715, 938, 390,2734,1313,1384, 248, 202, 877,1064,2854, 522,3907, 279,1602, 297,
|
| 120 |
+
2357, 395,3740, 137,2075, 944,4089,2584,1267,3802, 62,1533,2285, 178, 176, 780,
|
| 121 |
+
2440, 201,3707, 590, 478,1560,4354,2117,1075, 30, 74,4643,4004,1635,1441,2745,
|
| 122 |
+
776,2596, 238,1077,1692,1912,2844, 605, 499,1742,3947, 241,3053, 980,1749, 936,
|
| 123 |
+
2640,4511,2582, 515,1543,2162,5322,2892,2993, 890,2148,1924, 665,1827,3581,1032,
|
| 124 |
+
968,3163, 339,1044,1896, 270, 583,1791,1720,4367,1194,3488,3669, 43,2523,1657,
|
| 125 |
+
163,2167, 290,1209,1622,3378, 550, 634,2508,2510, 695,2634,2384,2512,1476,1414,
|
| 126 |
+
220,1469,2341,2138,2852,3183,2900,4939,2865,3502,1211,3680, 854,3227,1299,2976,
|
| 127 |
+
3172, 186,2998,1459, 443,1067,3251,1495, 321,1932,3054, 909, 753,1410,1828, 436,
|
| 128 |
+
2441,1119,1587,3164,2186,1258, 227, 231,1425,1890,3200,3942, 247, 959, 725,5254,
|
| 129 |
+
2741, 577,2158,2079, 929, 120, 174, 838,2813, 591,1115, 417,2024, 40,3240,1536,
|
| 130 |
+
1037, 291,4151,2354, 632,1298,2406,2500,3535,1825,1846,3451, 205,1171, 345,4238,
|
| 131 |
+
18,1163, 811, 685,2208,1217, 425,1312,1508,1175,4308,2552,1033, 587,1381,3059,
|
| 132 |
+
2984,3482, 340,1316,4023,3972, 792,3176, 519, 777,4690, 918, 933,4130,2981,3741,
|
| 133 |
+
90,3360,2911,2200,5184,4550, 609,3079,2030, 272,3379,2736, 363,3881,1130,1447,
|
| 134 |
+
286, 779, 357,1169,3350,3137,1630,1220,2687,2391, 747,1277,3688,2618,2682,2601,
|
| 135 |
+
1156,3196,5290,4034,3102,1689,3596,3128, 874, 219,2783, 798, 508,1843,2461, 269,
|
| 136 |
+
1658,1776,1392,1913,2983,3287,2866,2159,2372, 829,4076, 46,4253,2873,1889,1894,
|
| 137 |
+
915,1834,1631,2181,2318, 298, 664,2818,3555,2735, 954,3228,3117, 527,3511,2173,
|
| 138 |
+
681,2712,3033,2247,2346,3467,1652, 155,2164,3382, 113,1994, 450, 899, 494, 994,
|
| 139 |
+
1237,2958,1875,2336,1926,3727, 545,1577,1550, 633,3473, 204,1305,3072,2410,1956,
|
| 140 |
+
2471, 707,2134, 841,2195,2196,2663,3843,1026,4940, 990,3252,4997, 368,1092, 437,
|
| 141 |
+
3212,3258,1933,1829, 675,2977,2893, 412, 943,3723,4644,3294,3283,2230,2373,5154,
|
| 142 |
+
2389,2241,2661,2323,1404,2524, 593, 787, 677,3008,1275,2059, 438,2709,2609,2240,
|
| 143 |
+
2269,2246,1446, 36,1568,1373,3892,1574,2301,1456,3962, 693,2276,5216,2035,1143,
|
| 144 |
+
2720,1919,1797,1811,2763,4137,2597,1830,1699,1488,1198,2090, 424,1694, 312,3634,
|
| 145 |
+
3390,4179,3335,2252,1214, 561,1059,3243,2295,2561, 975,5155,2321,2751,3772, 472,
|
| 146 |
+
1537,3282,3398,1047,2077,2348,2878,1323,3340,3076, 690,2906, 51, 369, 170,3541,
|
| 147 |
+
1060,2187,2688,3670,2541,1083,1683, 928,3918, 459, 109,4427, 599,3744,4286, 143,
|
| 148 |
+
2101,2730,2490, 82,1588,3036,2121, 281,1860, 477,4035,1238,2812,3020,2716,3312,
|
| 149 |
+
1530,2188,2055,1317, 843, 636,1808,1173,3495, 649, 181,1002, 147,3641,1159,2414,
|
| 150 |
+
3750,2289,2795, 813,3123,2610,1136,4368, 5,3391,4541,2174, 420, 429,1728, 754,
|
| 151 |
+
1228,2115,2219, 347,2223,2733, 735,1518,3003,2355,3134,1764,3948,3329,1888,2424,
|
| 152 |
+
1001,1234,1972,3321,3363,1672,1021,1450,1584, 226, 765, 655,2526,3404,3244,2302,
|
| 153 |
+
3665, 731, 594,2184, 319,1576, 621, 658,2656,4299,2099,3864,1279,2071,2598,2739,
|
| 154 |
+
795,3086,3699,3908,1707,2352,2402,1382,3136,2475,1465,4847,3496,3865,1085,3004,
|
| 155 |
+
2591,1084, 213,2287,1963,3565,2250, 822, 793,4574,3187,1772,1789,3050, 595,1484,
|
| 156 |
+
1959,2770,1080,2650, 456, 422,2996, 940,3322,4328,4345,3092,2742, 965,2784, 739,
|
| 157 |
+
4124, 952,1358,2498,2949,2565, 332,2698,2378, 660,2260,2473,4194,3856,2919, 535,
|
| 158 |
+
1260,2651,1208,1428,1300,1949,1303,2942, 433,2455,2450,1251,1946, 614,1269, 641,
|
| 159 |
+
1306,1810,2737,3078,2912, 564,2365,1419,1415,1497,4460,2367,2185,1379,3005,1307,
|
| 160 |
+
3218,2175,1897,3063, 682,1157,4040,4005,1712,1160,1941,1399, 394, 402,2952,1573,
|
| 161 |
+
1151,2986,2404, 862, 299,2033,1489,3006, 346, 171,2886,3401,1726,2932, 168,2533,
|
| 162 |
+
47,2507,1030,3735,1145,3370,1395,1318,1579,3609,4560,2857,4116,1457,2529,1965,
|
| 163 |
+
504,1036,2690,2988,2405, 745,5871, 849,2397,2056,3081, 863,2359,3857,2096, 99,
|
| 164 |
+
1397,1769,2300,4428,1643,3455,1978,1757,3718,1440, 35,4879,3742,1296,4228,2280,
|
| 165 |
+
160,5063,1599,2013, 166, 520,3479,1646,3345,3012, 490,1937,1545,1264,2182,2505,
|
| 166 |
+
1096,1188,1369,1436,2421,1667,2792,2460,1270,2122, 727,3167,2143, 806,1706,1012,
|
| 167 |
+
1800,3037, 960,2218,1882, 805, 139,2456,1139,1521, 851,1052,3093,3089, 342,2039,
|
| 168 |
+
744,5097,1468,1502,1585,2087, 223, 939, 326,2140,2577, 892,2481,1623,4077, 982,
|
| 169 |
+
3708, 135,2131, 87,2503,3114,2326,1106, 876,1616, 547,2997,2831,2093,3441,4530,
|
| 170 |
+
4314, 9,3256,4229,4148, 659,1462,1986,1710,2046,2913,2231,4090,4880,5255,3392,
|
| 171 |
+
3274,1368,3689,4645,1477, 705,3384,3635,1068,1529,2941,1458,3782,1509, 100,1656,
|
| 172 |
+
2548, 718,2339, 408,1590,2780,3548,1838,4117,3719,1345,3530, 717,3442,2778,3220,
|
| 173 |
+
2898,1892,4590,3614,3371,2043,1998,1224,3483, 891, 635, 584,2559,3355, 733,1766,
|
| 174 |
+
1729,1172,3789,1891,2307, 781,2982,2271,1957,1580,5773,2633,2005,4195,3097,1535,
|
| 175 |
+
3213,1189,1934,5693,3262, 586,3118,1324,1598, 517,1564,2217,1868,1893,4445,3728,
|
| 176 |
+
2703,3139,1526,1787,1992,3882,2875,1549,1199,1056,2224,1904,2711,5098,4287, 338,
|
| 177 |
+
1993,3129,3489,2689,1809,2815,1997, 957,1855,3898,2550,3275,3057,1105,1319, 627,
|
| 178 |
+
1505,1911,1883,3526, 698,3629,3456,1833,1431, 746, 77,1261,2017,2296,1977,1885,
|
| 179 |
+
125,1334,1600, 525,1798,1109,2222,1470,1945, 559,2236,1186,3443,2476,1929,1411,
|
| 180 |
+
2411,3135,1777,3372,2621,1841,1613,3229, 668,1430,1839,2643,2916, 195,1989,2671,
|
| 181 |
+
2358,1387, 629,3205,2293,5256,4439, 123,1310, 888,1879,4300,3021,3605,1003,1162,
|
| 182 |
+
3192,2910,2010, 140,2395,2859, 55,1082,2012,2901, 662, 419,2081,1438, 680,2774,
|
| 183 |
+
4654,3912,1620,1731,1625,5035,4065,2328, 512,1344, 802,5443,2163,2311,2537, 524,
|
| 184 |
+
3399, 98,1155,2103,1918,2606,3925,2816,1393,2465,1504,3773,2177,3963,1478,4346,
|
| 185 |
+
180,1113,4655,3461,2028,1698, 833,2696,1235,1322,1594,4408,3623,3013,3225,2040,
|
| 186 |
+
3022, 541,2881, 607,3632,2029,1665,1219, 639,1385,1686,1099,2803,3231,1938,3188,
|
| 187 |
+
2858, 427, 676,2772,1168,2025, 454,3253,2486,3556, 230,1950, 580, 791,1991,1280,
|
| 188 |
+
1086,1974,2034, 630, 257,3338,2788,4903,1017, 86,4790, 966,2789,1995,1696,1131,
|
| 189 |
+
259,3095,4188,1308, 179,1463,5257, 289,4107,1248, 42,3413,1725,2288, 896,1947,
|
| 190 |
+
774,4474,4254, 604,3430,4264, 392,2514,2588, 452, 237,1408,3018, 988,4531,1970,
|
| 191 |
+
3034,3310, 540,2370,1562,1288,2990, 502,4765,1147, 4,1853,2708, 207, 294,2814,
|
| 192 |
+
4078,2902,2509, 684, 34,3105,3532,2551, 644, 709,2801,2344, 573,1727,3573,3557,
|
| 193 |
+
2021,1081,3100,4315,2100,3681, 199,2263,1837,2385, 146,3484,1195,2776,3949, 997,
|
| 194 |
+
1939,3973,1008,1091,1202,1962,1847,1149,4209,5444,1076, 493, 117,5400,2521, 972,
|
| 195 |
+
1490,2934,1796,4542,2374,1512,2933,2657, 413,2888,1135,2762,2314,2156,1355,2369,
|
| 196 |
+
766,2007,2527,2170,3124,2491,2593,2632,4757,2437, 234,3125,3591,1898,1750,1376,
|
| 197 |
+
1942,3468,3138, 570,2127,2145,3276,4131, 962, 132,1445,4196, 19, 941,3624,3480,
|
| 198 |
+
3366,1973,1374,4461,3431,2629, 283,2415,2275, 808,2887,3620,2112,2563,1353,3610,
|
| 199 |
+
955,1089,3103,1053, 96, 88,4097, 823,3808,1583, 399, 292,4091,3313, 421,1128,
|
| 200 |
+
642,4006, 903,2539,1877,2082, 596, 29,4066,1790, 722,2157, 130, 995,1569, 769,
|
| 201 |
+
1485, 464, 513,2213, 288,1923,1101,2453,4316, 133, 486,2445, 50, 625, 487,2207,
|
| 202 |
+
57, 423, 481,2962, 159,3729,1558, 491, 303, 482, 501, 240,2837, 112,3648,2392,
|
| 203 |
+
1783, 362, 8,3433,3422, 610,2793,3277,1390,1284,1654, 21,3823, 734, 367, 623,
|
| 204 |
+
193, 287, 374,1009,1483, 816, 476, 313,2255,2340,1262,2150,2899,1146,2581, 782,
|
| 205 |
+
2116,1659,2018,1880, 255,3586,3314,1110,2867,2137,2564, 986,2767,5185,2006, 650,
|
| 206 |
+
158, 926, 762, 881,3157,2717,2362,3587, 306,3690,3245,1542,3077,2427,1691,2478,
|
| 207 |
+
2118,2985,3490,2438, 539,2305, 983, 129,1754, 355,4201,2386, 827,2923, 104,1773,
|
| 208 |
+
2838,2771, 411,2905,3919, 376, 767, 122,1114, 828,2422,1817,3506, 266,3460,1007,
|
| 209 |
+
1609,4998, 945,2612,4429,2274, 726,1247,1964,2914,2199,2070,4002,4108, 657,3323,
|
| 210 |
+
1422, 579, 455,2764,4737,1222,2895,1670, 824,1223,1487,2525, 558, 861,3080, 598,
|
| 211 |
+
2659,2515,1967, 752,2583,2376,2214,4180, 977, 704,2464,4999,2622,4109,1210,2961,
|
| 212 |
+
819,1541, 142,2284, 44, 418, 457,1126,3730,4347,4626,1644,1876,3671,1864, 302,
|
| 213 |
+
1063,5694, 624, 723,1984,3745,1314,1676,2488,1610,1449,3558,3569,2166,2098, 409,
|
| 214 |
+
1011,2325,3704,2306, 818,1732,1383,1824,1844,3757, 999,2705,3497,1216,1423,2683,
|
| 215 |
+
2426,2954,2501,2726,2229,1475,2554,5064,1971,1794,1666,2014,1343, 783, 724, 191,
|
| 216 |
+
2434,1354,2220,5065,1763,2752,2472,4152, 131, 175,2885,3434, 92,1466,4920,2616,
|
| 217 |
+
3871,3872,3866, 128,1551,1632, 669,1854,3682,4691,4125,1230, 188,2973,3290,1302,
|
| 218 |
+
1213, 560,3266, 917, 763,3909,3249,1760, 868,1958, 764,1782,2097, 145,2277,3774,
|
| 219 |
+
4462, 64,1491,3062, 971,2132,3606,2442, 221,1226,1617, 218, 323,1185,3207,3147,
|
| 220 |
+
571, 619,1473,1005,1744,2281, 449,1887,2396,3685, 275, 375,3816,1743,3844,3731,
|
| 221 |
+
845,1983,2350,4210,1377, 773, 967,3499,3052,3743,2725,4007,1697,1022,3943,1464,
|
| 222 |
+
3264,2855,2722,1952,1029,2839,2467, 84,4383,2215, 820,1391,2015,2448,3672, 377,
|
| 223 |
+
1948,2168, 797,2545,3536,2578,2645, 94,2874,1678, 405,1259,3071, 771, 546,1315,
|
| 224 |
+
470,1243,3083, 895,2468, 981, 969,2037, 846,4181, 653,1276,2928, 14,2594, 557,
|
| 225 |
+
3007,2474, 156, 902,1338,1740,2574, 537,2518, 973,2282,2216,2433,1928, 138,2903,
|
| 226 |
+
1293,2631,1612, 646,3457, 839,2935, 111, 496,2191,2847, 589,3186, 149,3994,2060,
|
| 227 |
+
4031,2641,4067,3145,1870, 37,3597,2136,1025,2051,3009,3383,3549,1121,1016,3261,
|
| 228 |
+
1301, 251,2446,2599,2153, 872,3246, 637, 334,3705, 831, 884, 921,3065,3140,4092,
|
| 229 |
+
2198,1944, 246,2964, 108,2045,1152,1921,2308,1031, 203,3173,4170,1907,3890, 810,
|
| 230 |
+
1401,2003,1690, 506, 647,1242,2828,1761,1649,3208,2249,1589,3709,2931,5156,1708,
|
| 231 |
+
498, 666,2613, 834,3817,1231, 184,2851,1124, 883,3197,2261,3710,1765,1553,2658,
|
| 232 |
+
1178,2639,2351, 93,1193, 942,2538,2141,4402, 235,1821, 870,1591,2192,1709,1871,
|
| 233 |
+
3341,1618,4126,2595,2334, 603, 651, 69, 701, 268,2662,3411,2555,1380,1606, 503,
|
| 234 |
+
448, 254,2371,2646, 574,1187,2309,1770, 322,2235,1292,1801, 305, 566,1133, 229,
|
| 235 |
+
2067,2057, 706, 167, 483,2002,2672,3295,1820,3561,3067, 316, 378,2746,3452,1112,
|
| 236 |
+
136,1981, 507,1651,2917,1117, 285,4591, 182,2580,3522,1304, 335,3303,1835,2504,
|
| 237 |
+
1795,1792,2248, 674,1018,2106,2449,1857,2292,2845, 976,3047,1781,2600,2727,1389,
|
| 238 |
+
1281, 52,3152, 153, 265,3950, 672,3485,3951,4463, 430,1183, 365, 278,2169, 27,
|
| 239 |
+
1407,1336,2304, 209,1340,1730,2202,1852,2403,2883, 979,1737,1062, 631,2829,2542,
|
| 240 |
+
3876,2592, 825,2086,2226,3048,3625, 352,1417,3724, 542, 991, 431,1351,3938,1861,
|
| 241 |
+
2294, 826,1361,2927,3142,3503,1738, 463,2462,2723, 582,1916,1595,2808, 400,3845,
|
| 242 |
+
3891,2868,3621,2254, 58,2492,1123, 910,2160,2614,1372,1603,1196,1072,3385,1700,
|
| 243 |
+
3267,1980, 696, 480,2430, 920, 799,1570,2920,1951,2041,4047,2540,1321,4223,2469,
|
| 244 |
+
3562,2228,1271,2602, 401,2833,3351,2575,5157, 907,2312,1256, 410, 263,3507,1582,
|
| 245 |
+
996, 678,1849,2316,1480, 908,3545,2237, 703,2322, 667,1826,2849,1531,2604,2999,
|
| 246 |
+
2407,3146,2151,2630,1786,3711, 469,3542, 497,3899,2409, 858, 837,4446,3393,1274,
|
| 247 |
+
786, 620,1845,2001,3311, 484, 308,3367,1204,1815,3691,2332,1532,2557,1842,2020,
|
| 248 |
+
2724,1927,2333,4440, 567, 22,1673,2728,4475,1987,1858,1144,1597, 101,1832,3601,
|
| 249 |
+
12, 974,3783,4391, 951,1412, 1,3720, 453,4608,4041, 528,1041,1027,3230,2628,
|
| 250 |
+
1129, 875,1051,3291,1203,2262,1069,2860,2799,2149,2615,3278, 144,1758,3040, 31,
|
| 251 |
+
475,1680, 366,2685,3184, 311,1642,4008,2466,5036,1593,1493,2809, 216,1420,1668,
|
| 252 |
+
233, 304,2128,3284, 232,1429,1768,1040,2008,3407,2740,2967,2543, 242,2133, 778,
|
| 253 |
+
1565,2022,2620, 505,2189,2756,1098,2273, 372,1614, 708, 553,2846,2094,2278, 169,
|
| 254 |
+
3626,2835,4161, 228,2674,3165, 809,1454,1309, 466,1705,1095, 900,3423, 880,2667,
|
| 255 |
+
3751,5258,2317,3109,2571,4317,2766,1503,1342, 866,4447,1118, 63,2076, 314,1881,
|
| 256 |
+
1348,1061, 172, 978,3515,1747, 532, 511,3970, 6, 601, 905,2699,3300,1751, 276,
|
| 257 |
+
1467,3725,2668, 65,4239,2544,2779,2556,1604, 578,2451,1802, 992,2331,2624,1320,
|
| 258 |
+
3446, 713,1513,1013, 103,2786,2447,1661, 886,1702, 916, 654,3574,2031,1556, 751,
|
| 259 |
+
2178,2821,2179,1498,1538,2176, 271, 914,2251,2080,1325, 638,1953,2937,3877,2432,
|
| 260 |
+
2754, 95,3265,1716, 260,1227,4083, 775, 106,1357,3254, 426,1607, 555,2480, 772,
|
| 261 |
+
1985, 244,2546, 474, 495,1046,2611,1851,2061, 71,2089,1675,2590, 742,3758,2843,
|
| 262 |
+
3222,1433, 267,2180,2576,2826,2233,2092,3913,2435, 956,1745,3075, 856,2113,1116,
|
| 263 |
+
451, 3,1988,2896,1398, 993,2463,1878,2049,1341,2718,2721,2870,2108, 712,2904,
|
| 264 |
+
4363,2753,2324, 277,2872,2349,2649, 384, 987, 435, 691,3000, 922, 164,3939, 652,
|
| 265 |
+
1500,1184,4153,2482,3373,2165,4848,2335,3775,3508,3154,2806,2830,1554,2102,1664,
|
| 266 |
+
2530,1434,2408, 893,1547,2623,3447,2832,2242,2532,3169,2856,3223,2078, 49,3770,
|
| 267 |
+
3469, 462, 318, 656,2259,3250,3069, 679,1629,2758, 344,1138,1104,3120,1836,1283,
|
| 268 |
+
3115,2154,1437,4448, 934, 759,1999, 794,2862,1038, 533,2560,1722,2342, 855,2626,
|
| 269 |
+
1197,1663,4476,3127, 85,4240,2528, 25,1111,1181,3673, 407,3470,4561,2679,2713,
|
| 270 |
+
768,1925,2841,3986,1544,1165, 932, 373,1240,2146,1930,2673, 721,4766, 354,4333,
|
| 271 |
+
391,2963, 187, 61,3364,1442,1102, 330,1940,1767, 341,3809,4118, 393,2496,2062,
|
| 272 |
+
2211, 105, 331, 300, 439, 913,1332, 626, 379,3304,1557, 328, 689,3952, 309,1555,
|
| 273 |
+
931, 317,2517,3027, 325, 569, 686,2107,3084, 60,1042,1333,2794, 264,3177,4014,
|
| 274 |
+
1628, 258,3712, 7,4464,1176,1043,1778, 683, 114,1975, 78,1492, 383,1886, 510,
|
| 275 |
+
386, 645,5291,2891,2069,3305,4138,3867,2939,2603,2493,1935,1066,1848,3588,1015,
|
| 276 |
+
1282,1289,4609, 697,1453,3044,2666,3611,1856,2412, 54, 719,1330, 568,3778,2459,
|
| 277 |
+
1748, 788, 492, 551,1191,1000, 488,3394,3763, 282,1799, 348,2016,1523,3155,2390,
|
| 278 |
+
1049, 382,2019,1788,1170, 729,2968,3523, 897,3926,2785,2938,3292, 350,2319,3238,
|
| 279 |
+
1718,1717,2655,3453,3143,4465, 161,2889,2980,2009,1421, 56,1908,1640,2387,2232,
|
| 280 |
+
1917,1874,2477,4921, 148, 83,3438, 592,4245,2882,1822,1055, 741, 115,1496,1624,
|
| 281 |
+
381,1638,4592,1020, 516,3214, 458, 947,4575,1432, 211,1514,2926,1865,2142, 189,
|
| 282 |
+
852,1221,1400,1486, 882,2299,4036, 351, 28,1122, 700,6479,6480,6481,6482,6483, #last 512
|
| 283 |
+
)
|
| 284 |
+
# fmt: on
|
LTA_openwebtext_dualt/mini_owt_logdirichlet/.venv_qwen35_uv/lib/python3.12/site-packages/transformers/models/auto/__init__.py
ADDED
|
@@ -0,0 +1,33 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# Copyright 2020 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 .auto_factory import *
|
| 22 |
+
from .configuration_auto import *
|
| 23 |
+
from .feature_extraction_auto import *
|
| 24 |
+
from .image_processing_auto import *
|
| 25 |
+
from .modeling_auto import *
|
| 26 |
+
from .processing_auto import *
|
| 27 |
+
from .tokenization_auto import *
|
| 28 |
+
from .video_processing_auto import *
|
| 29 |
+
else:
|
| 30 |
+
import sys
|
| 31 |
+
|
| 32 |
+
_file = globals()["__file__"]
|
| 33 |
+
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/auto/auto_factory.py
ADDED
|
@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
|
|
|
| 1 |
+
# Copyright 2021 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 |
+
"""Factory function to build auto-model classes."""
|
| 15 |
+
|
| 16 |
+
import copy
|
| 17 |
+
import importlib
|
| 18 |
+
import json
|
| 19 |
+
import os
|
| 20 |
+
from collections import OrderedDict
|
| 21 |
+
from collections.abc import Iterator
|
| 22 |
+
from typing import Any, TypeVar
|
| 23 |
+
|
| 24 |
+
from huggingface_hub import repo_exists
|
| 25 |
+
|
| 26 |
+
from ...configuration_utils import PreTrainedConfig
|
| 27 |
+
from ...dynamic_module_utils import get_class_from_dynamic_module, resolve_trust_remote_code
|
| 28 |
+
from ...utils import (
|
| 29 |
+
CONFIG_NAME,
|
| 30 |
+
cached_file,
|
| 31 |
+
copy_func,
|
| 32 |
+
extract_commit_hash,
|
| 33 |
+
find_adapter_config_file,
|
| 34 |
+
is_peft_available,
|
| 35 |
+
is_torch_available,
|
| 36 |
+
logging,
|
| 37 |
+
requires_backends,
|
| 38 |
+
)
|
| 39 |
+
from .configuration_auto import AutoConfig, model_type_to_module_name, replace_list_option_in_docstrings
|
| 40 |
+
|
| 41 |
+
|
| 42 |
+
if is_torch_available():
|
| 43 |
+
from ...generation import GenerationMixin
|
| 44 |
+
|
| 45 |
+
|
| 46 |
+
logger = logging.get_logger(__name__)
|
| 47 |
+
|
| 48 |
+
_T = TypeVar("_T")
|
| 49 |
+
# Tokenizers will depend on packages installed, too much variance and there are no common base or Protocol
|
| 50 |
+
_LazyAutoMappingValue = tuple[type[Any] | None, type[Any] | None]
|
| 51 |
+
|
| 52 |
+
CLASS_DOCSTRING = """
|
| 53 |
+
This is a generic model class that will be instantiated as one of the model classes of the library when created
|
| 54 |
+
with the [`~BaseAutoModelClass.from_pretrained`] class method or the [`~BaseAutoModelClass.from_config`] class
|
| 55 |
+
method.
|
| 56 |
+
|
| 57 |
+
This class cannot be instantiated directly using `__init__()` (throws an error).
|
| 58 |
+
"""
|
| 59 |
+
|
| 60 |
+
FROM_CONFIG_DOCSTRING = """
|
| 61 |
+
Instantiates one of the model classes of the library from a configuration.
|
| 62 |
+
|
| 63 |
+
Note:
|
| 64 |
+
Loading a model from its configuration file does **not** load the model weights. It only affects the
|
| 65 |
+
model's configuration. Use [`~BaseAutoModelClass.from_pretrained`] to load the model weights.
|
| 66 |
+
|
| 67 |
+
Args:
|
| 68 |
+
config ([`PreTrainedConfig`]):
|
| 69 |
+
The model class to instantiate is selected based on the configuration class:
|
| 70 |
+
|
| 71 |
+
List options
|
| 72 |
+
attn_implementation (`str`, *optional*):
|
| 73 |
+
The attention implementation to use in the model (if relevant). Can be any of `"eager"` (manual implementation of the attention), `"sdpa"` (using [`F.scaled_dot_product_attention`](https://pytorch.org/docs/master/generated/torch.nn.functional.scaled_dot_product_attention.html)), `"flash_attention_2"` (using [Dao-AILab/flash-attention](https://github.com/Dao-AILab/flash-attention)), or `"flash_attention_3"` (using [Dao-AILab/flash-attention/hopper](https://github.com/Dao-AILab/flash-attention/tree/main/hopper)). By default, if available, SDPA will be used for torch>=2.1.1. The default is otherwise the manual `"eager"` implementation.
|
| 74 |
+
|
| 75 |
+
Examples:
|
| 76 |
+
|
| 77 |
+
```python
|
| 78 |
+
>>> from transformers import AutoConfig, BaseAutoModelClass
|
| 79 |
+
|
| 80 |
+
>>> # Download configuration from huggingface.co and cache.
|
| 81 |
+
>>> config = AutoConfig.from_pretrained("checkpoint_placeholder")
|
| 82 |
+
>>> model = BaseAutoModelClass.from_config(config)
|
| 83 |
+
```
|
| 84 |
+
"""
|
| 85 |
+
|
| 86 |
+
FROM_PRETRAINED_TORCH_DOCSTRING = """
|
| 87 |
+
Instantiate one of the model classes of the library from a pretrained model.
|
| 88 |
+
|
| 89 |
+
The model class to instantiate is selected based on the `model_type` property of the config object (either
|
| 90 |
+
passed as an argument or loaded from `pretrained_model_name_or_path` if possible), or when it's missing, by
|
| 91 |
+
falling back to using pattern matching on `pretrained_model_name_or_path`:
|
| 92 |
+
|
| 93 |
+
List options
|
| 94 |
+
|
| 95 |
+
The model is set in evaluation mode by default using `model.eval()` (so for instance, dropout modules are
|
| 96 |
+
deactivated). To train the model, you should first set it back in training mode with `model.train()`
|
| 97 |
+
|
| 98 |
+
Args:
|
| 99 |
+
pretrained_model_name_or_path (`str` or `os.PathLike`):
|
| 100 |
+
Can be either:
|
| 101 |
+
|
| 102 |
+
- A string, the *model id* of a pretrained model hosted inside a model repo on huggingface.co.
|
| 103 |
+
- A path to a *directory* containing model weights saved using
|
| 104 |
+
[`~PreTrainedModel.save_pretrained`], e.g., `./my_model_directory/`.
|
| 105 |
+
model_args (additional positional arguments, *optional*):
|
| 106 |
+
Will be passed along to the underlying model `__init__()` method.
|
| 107 |
+
config ([`PreTrainedConfig`], *optional*):
|
| 108 |
+
Configuration for the model to use instead of an automatically loaded configuration. Configuration can
|
| 109 |
+
be automatically loaded when:
|
| 110 |
+
|
| 111 |
+
- The model is a model provided by the library (loaded with the *model id* string of a pretrained
|
| 112 |
+
model).
|
| 113 |
+
- The model was saved using [`~PreTrainedModel.save_pretrained`] and is reloaded by supplying the
|
| 114 |
+
save directory.
|
| 115 |
+
- The model is loaded by supplying a local directory as `pretrained_model_name_or_path` and a
|
| 116 |
+
configuration JSON file named *config.json* is found in the directory.
|
| 117 |
+
state_dict (*dict[str, torch.Tensor]*, *optional*):
|
| 118 |
+
A state dictionary to use instead of a state dictionary loaded from saved weights file.
|
| 119 |
+
|
| 120 |
+
This option can be used if you want to create a model from a pretrained configuration but load your own
|
| 121 |
+
weights. In this case though, you should check if using [`~PreTrainedModel.save_pretrained`] and
|
| 122 |
+
[`~PreTrainedModel.from_pretrained`] is not a simpler option.
|
| 123 |
+
cache_dir (`str` or `os.PathLike`, *optional*):
|
| 124 |
+
Path to a directory in which a downloaded pretrained model configuration should be cached if the
|
| 125 |
+
standard cache should not be used.
|
| 126 |
+
force_download (`bool`, *optional*, defaults to `False`):
|
| 127 |
+
Whether or not to force the (re-)download of the model weights and configuration files, overriding the
|
| 128 |
+
cached versions if they exist.
|
| 129 |
+
proxies (`dict[str, str]`, *optional*):
|
| 130 |
+
A dictionary of proxy servers to use by protocol or endpoint, e.g., `{'http': 'foo.bar:3128',
|
| 131 |
+
'http://hostname': 'foo.bar:4012'}`. The proxies are used on each request.
|
| 132 |
+
output_loading_info(`bool`, *optional*, defaults to `False`):
|
| 133 |
+
Whether or not to also return a dictionary containing missing keys, unexpected keys and error messages.
|
| 134 |
+
local_files_only(`bool`, *optional*, defaults to `False`):
|
| 135 |
+
Whether or not to only look at local files (e.g., not try downloading the model).
|
| 136 |
+
revision (`str`, *optional*, defaults to `"main"`):
|
| 137 |
+
The specific model version to use. It can be a branch name, a tag name, or a commit id, since we use a
|
| 138 |
+
git-based system for storing models and other artifacts on huggingface.co, so `revision` can be any
|
| 139 |
+
identifier allowed by git.
|
| 140 |
+
trust_remote_code (`bool`, *optional*, defaults to `False`):
|
| 141 |
+
Whether or not to allow for custom models defined on the Hub in their own modeling files. This option
|
| 142 |
+
should only be set to `True` for repositories you trust and in which you have read the code, as it will
|
| 143 |
+
execute code present on the Hub on your local machine.
|
| 144 |
+
code_revision (`str`, *optional*, defaults to `"main"`):
|
| 145 |
+
The specific revision to use for the code on the Hub, if the code leaves in a different repository than
|
| 146 |
+
the rest of the model. It can be a branch name, a tag name, or a commit id, since we use a git-based
|
| 147 |
+
system for storing models and other artifacts on huggingface.co, so `revision` can be any identifier
|
| 148 |
+
allowed by git.
|
| 149 |
+
kwargs (additional keyword arguments, *optional*):
|
| 150 |
+
Can be used to update the configuration object (after it being loaded) and initiate the model (e.g.,
|
| 151 |
+
`output_attentions=True`). Behaves differently depending on whether a `config` is provided or
|
| 152 |
+
automatically loaded:
|
| 153 |
+
|
| 154 |
+
- If a configuration is provided with `config`, `**kwargs` will be directly passed to the
|
| 155 |
+
underlying model's `__init__` method (we assume all relevant updates to the configuration have
|
| 156 |
+
already been done)
|
| 157 |
+
- If a configuration is not provided, `kwargs` will be first passed to the configuration class
|
| 158 |
+
initialization function ([`~PreTrainedConfig.from_pretrained`]). Each key of `kwargs` that
|
| 159 |
+
corresponds to a configuration attribute will be used to override said attribute with the
|
| 160 |
+
supplied `kwargs` value. Remaining keys that do not correspond to any configuration attribute
|
| 161 |
+
will be passed to the underlying model's `__init__` function.
|
| 162 |
+
|
| 163 |
+
Examples:
|
| 164 |
+
|
| 165 |
+
```python
|
| 166 |
+
>>> from transformers import AutoConfig, BaseAutoModelClass
|
| 167 |
+
|
| 168 |
+
>>> # Download model and configuration from huggingface.co and cache.
|
| 169 |
+
>>> model = BaseAutoModelClass.from_pretrained("checkpoint_placeholder")
|
| 170 |
+
|
| 171 |
+
>>> # Update configuration during loading
|
| 172 |
+
>>> model = BaseAutoModelClass.from_pretrained("checkpoint_placeholder", output_attentions=True)
|
| 173 |
+
>>> model.config.output_attentions
|
| 174 |
+
True
|
| 175 |
+
```
|
| 176 |
+
"""
|
| 177 |
+
|
| 178 |
+
|
| 179 |
+
def _get_model_class(config, model_mapping):
|
| 180 |
+
supported_models = model_mapping[type(config)]
|
| 181 |
+
if not isinstance(supported_models, (list, tuple)):
|
| 182 |
+
return supported_models
|
| 183 |
+
|
| 184 |
+
name_to_model = {model.__name__: model for model in supported_models}
|
| 185 |
+
architectures = getattr(config, "architectures", [])
|
| 186 |
+
for arch in architectures:
|
| 187 |
+
if arch in name_to_model:
|
| 188 |
+
return name_to_model[arch]
|
| 189 |
+
|
| 190 |
+
# If not architecture is set in the config or match the supported models, the first element of the tuple is the
|
| 191 |
+
# defaults.
|
| 192 |
+
return supported_models[0]
|
| 193 |
+
|
| 194 |
+
|
| 195 |
+
class _BaseAutoModelClass:
|
| 196 |
+
# Base class for auto models.
|
| 197 |
+
_model_mapping = None
|
| 198 |
+
|
| 199 |
+
def __init__(self, *args, **kwargs) -> None:
|
| 200 |
+
raise OSError(
|
| 201 |
+
f"{self.__class__.__name__} is designed to be instantiated "
|
| 202 |
+
f"using the `{self.__class__.__name__}.from_pretrained(pretrained_model_name_or_path)` or "
|
| 203 |
+
f"`{self.__class__.__name__}.from_config(config)` methods."
|
| 204 |
+
)
|
| 205 |
+
|
| 206 |
+
@classmethod
|
| 207 |
+
def from_config(cls, config, **kwargs):
|
| 208 |
+
trust_remote_code = kwargs.pop("trust_remote_code", None)
|
| 209 |
+
has_remote_code = hasattr(config, "auto_map") and cls.__name__ in config.auto_map
|
| 210 |
+
has_local_code = type(config) in cls._model_mapping
|
| 211 |
+
explicit_local_code = has_local_code and not _get_model_class(
|
| 212 |
+
config, cls._model_mapping
|
| 213 |
+
).__module__.startswith("transformers.")
|
| 214 |
+
if has_remote_code:
|
| 215 |
+
class_ref = config.auto_map[cls.__name__]
|
| 216 |
+
if "--" in class_ref:
|
| 217 |
+
upstream_repo = class_ref.split("--")[0]
|
| 218 |
+
else:
|
| 219 |
+
upstream_repo = None
|
| 220 |
+
trust_remote_code = resolve_trust_remote_code(
|
| 221 |
+
trust_remote_code, config._name_or_path, has_local_code, has_remote_code, upstream_repo=upstream_repo
|
| 222 |
+
)
|
| 223 |
+
|
| 224 |
+
if has_remote_code and trust_remote_code and not explicit_local_code:
|
| 225 |
+
if "--" in class_ref:
|
| 226 |
+
repo_id, class_ref = class_ref.split("--")
|
| 227 |
+
else:
|
| 228 |
+
repo_id = config.name_or_path
|
| 229 |
+
model_class = get_class_from_dynamic_module(class_ref, repo_id, **kwargs)
|
| 230 |
+
# This block handles the case where the user is loading a model with `trust_remote_code=True`
|
| 231 |
+
# but a library model exists with the same name. We don't want to override the autoclass
|
| 232 |
+
# mappings in this case, or all future loads of that model will be the remote code model.
|
| 233 |
+
if not has_local_code:
|
| 234 |
+
cls.register(config.__class__, model_class, exist_ok=True)
|
| 235 |
+
model_class.register_for_auto_class(auto_class=cls)
|
| 236 |
+
_ = kwargs.pop("code_revision", None)
|
| 237 |
+
model_class = add_generation_mixin_to_remote_model(model_class)
|
| 238 |
+
return model_class._from_config(config, **kwargs)
|
| 239 |
+
elif has_local_code:
|
| 240 |
+
model_class = _get_model_class(config, cls._model_mapping)
|
| 241 |
+
if model_class.config_class == config.sub_configs.get("text_config", None):
|
| 242 |
+
# TODO: Validate that copying the parent quantization config to the text sub-config preserves
|
| 243 |
+
# modules_to_not_convert and skip-module matching when composite-model module prefixes differ.
|
| 244 |
+
parent_config = config
|
| 245 |
+
config = config.get_text_config()
|
| 246 |
+
# Check both `quantization_config` being present and also not null,
|
| 247 |
+
# as a `config.json` can have `"quantization_config": null` in it
|
| 248 |
+
parent_quant = getattr(parent_config, "quantization_config", None)
|
| 249 |
+
if parent_quant is not None:
|
| 250 |
+
config.quantization_config = parent_quant
|
| 251 |
+
return model_class._from_config(config, **kwargs)
|
| 252 |
+
|
| 253 |
+
raise ValueError(
|
| 254 |
+
f"Unrecognized configuration class {config.__class__} for this kind of AutoModel: {cls.__name__}.\n"
|
| 255 |
+
f"Model type should be one of {', '.join(c.__name__ for c in cls._model_mapping)}."
|
| 256 |
+
)
|
| 257 |
+
|
| 258 |
+
@classmethod
|
| 259 |
+
def _prepare_config_for_auto_class(cls, config: PreTrainedConfig) -> PreTrainedConfig:
|
| 260 |
+
"""Additional autoclass-specific config post-loading manipulation. May be overridden in subclasses."""
|
| 261 |
+
return config
|
| 262 |
+
|
| 263 |
+
@classmethod
|
| 264 |
+
def from_pretrained(cls, pretrained_model_name_or_path: str | os.PathLike[str], *model_args, **kwargs):
|
| 265 |
+
config = kwargs.pop("config", None)
|
| 266 |
+
trust_remote_code = kwargs.get("trust_remote_code")
|
| 267 |
+
kwargs["_from_auto"] = True
|
| 268 |
+
hub_kwargs_names = [
|
| 269 |
+
"cache_dir",
|
| 270 |
+
"force_download",
|
| 271 |
+
"local_files_only",
|
| 272 |
+
"proxies",
|
| 273 |
+
"revision",
|
| 274 |
+
"subfolder",
|
| 275 |
+
"token",
|
| 276 |
+
]
|
| 277 |
+
hub_kwargs = {name: kwargs.pop(name) for name in hub_kwargs_names if name in kwargs}
|
| 278 |
+
code_revision = kwargs.pop("code_revision", None)
|
| 279 |
+
commit_hash = kwargs.pop("_commit_hash", None)
|
| 280 |
+
adapter_kwargs = kwargs.pop("adapter_kwargs", None)
|
| 281 |
+
|
| 282 |
+
token = hub_kwargs.pop("token", None)
|
| 283 |
+
|
| 284 |
+
if token is not None:
|
| 285 |
+
hub_kwargs["token"] = token
|
| 286 |
+
|
| 287 |
+
if commit_hash is None:
|
| 288 |
+
if not isinstance(config, PreTrainedConfig):
|
| 289 |
+
# We make a call to the config file first (which may be absent) to get the commit hash as soon as possible
|
| 290 |
+
resolved_config_file = cached_file(
|
| 291 |
+
pretrained_model_name_or_path,
|
| 292 |
+
CONFIG_NAME,
|
| 293 |
+
_raise_exceptions_for_gated_repo=False,
|
| 294 |
+
_raise_exceptions_for_missing_entries=False,
|
| 295 |
+
_raise_exceptions_for_connection_errors=False,
|
| 296 |
+
**hub_kwargs,
|
| 297 |
+
)
|
| 298 |
+
commit_hash = extract_commit_hash(resolved_config_file, commit_hash)
|
| 299 |
+
else:
|
| 300 |
+
commit_hash = getattr(config, "_commit_hash", None)
|
| 301 |
+
|
| 302 |
+
if is_peft_available():
|
| 303 |
+
if adapter_kwargs is None:
|
| 304 |
+
adapter_kwargs = {}
|
| 305 |
+
adapter_kwargs = adapter_kwargs.copy() # avoid mutating original
|
| 306 |
+
if token is not None:
|
| 307 |
+
adapter_kwargs["token"] = token
|
| 308 |
+
|
| 309 |
+
maybe_adapter_path = find_adapter_config_file(
|
| 310 |
+
pretrained_model_name_or_path, _commit_hash=commit_hash, **adapter_kwargs
|
| 311 |
+
)
|
| 312 |
+
|
| 313 |
+
if maybe_adapter_path is not None:
|
| 314 |
+
with open(maybe_adapter_path, "r", encoding="utf-8") as f:
|
| 315 |
+
adapter_config = json.load(f)
|
| 316 |
+
|
| 317 |
+
adapter_kwargs["_adapter_model_path"] = pretrained_model_name_or_path
|
| 318 |
+
# Only override the model name/path if the current value doesn't point to a
|
| 319 |
+
# complete model with an embedded adapter so that local models with embedded
|
| 320 |
+
# adapters will load from the local base model rather than pull the base
|
| 321 |
+
# model named in the adapter's config from the hub.
|
| 322 |
+
if not os.path.exists(pretrained_model_name_or_path) or not os.path.exists(
|
| 323 |
+
os.path.join(pretrained_model_name_or_path, CONFIG_NAME)
|
| 324 |
+
):
|
| 325 |
+
pretrained_model_name_or_path = adapter_config["base_model_name_or_path"]
|
| 326 |
+
|
| 327 |
+
if not isinstance(config, PreTrainedConfig):
|
| 328 |
+
kwargs_orig = copy.deepcopy(kwargs)
|
| 329 |
+
# ensure not to pollute the config object with dtype="auto" - since it's
|
| 330 |
+
# meaningless in the context of the config object - torch.dtype values are acceptable
|
| 331 |
+
if kwargs.get("torch_dtype") == "auto":
|
| 332 |
+
_ = kwargs.pop("torch_dtype")
|
| 333 |
+
if kwargs.get("dtype") == "auto":
|
| 334 |
+
_ = kwargs.pop("dtype")
|
| 335 |
+
# to not overwrite the quantization_config if config has a quantization_config
|
| 336 |
+
if kwargs.get("quantization_config") is not None:
|
| 337 |
+
_ = kwargs.pop("quantization_config")
|
| 338 |
+
|
| 339 |
+
config, kwargs = AutoConfig.from_pretrained(
|
| 340 |
+
pretrained_model_name_or_path,
|
| 341 |
+
return_unused_kwargs=True,
|
| 342 |
+
code_revision=code_revision,
|
| 343 |
+
_commit_hash=commit_hash,
|
| 344 |
+
**hub_kwargs,
|
| 345 |
+
**kwargs,
|
| 346 |
+
)
|
| 347 |
+
|
| 348 |
+
# if torch_dtype=auto was passed here, ensure to pass it on
|
| 349 |
+
if kwargs_orig.get("torch_dtype", None) == "auto":
|
| 350 |
+
kwargs["torch_dtype"] = "auto"
|
| 351 |
+
if kwargs_orig.get("dtype", None) == "auto":
|
| 352 |
+
kwargs["dtype"] = "auto"
|
| 353 |
+
if kwargs_orig.get("quantization_config", None) is not None:
|
| 354 |
+
kwargs["quantization_config"] = kwargs_orig["quantization_config"]
|
| 355 |
+
|
| 356 |
+
has_remote_code = hasattr(config, "auto_map") and cls.__name__ in config.auto_map
|
| 357 |
+
has_local_code = type(config) in cls._model_mapping
|
| 358 |
+
explicit_local_code = has_local_code and not _get_model_class(
|
| 359 |
+
config, cls._model_mapping
|
| 360 |
+
).__module__.startswith("transformers.")
|
| 361 |
+
upstream_repo = None
|
| 362 |
+
if has_remote_code:
|
| 363 |
+
class_ref = config.auto_map[cls.__name__]
|
| 364 |
+
if "--" in class_ref:
|
| 365 |
+
upstream_repo = class_ref.split("--")[0]
|
| 366 |
+
trust_remote_code = resolve_trust_remote_code(
|
| 367 |
+
trust_remote_code,
|
| 368 |
+
pretrained_model_name_or_path,
|
| 369 |
+
has_local_code,
|
| 370 |
+
has_remote_code,
|
| 371 |
+
upstream_repo=upstream_repo,
|
| 372 |
+
)
|
| 373 |
+
kwargs["trust_remote_code"] = trust_remote_code
|
| 374 |
+
|
| 375 |
+
# Set the adapter kwargs
|
| 376 |
+
kwargs["adapter_kwargs"] = adapter_kwargs
|
| 377 |
+
|
| 378 |
+
if has_remote_code and trust_remote_code and not explicit_local_code:
|
| 379 |
+
model_class = get_class_from_dynamic_module(
|
| 380 |
+
class_ref, pretrained_model_name_or_path, code_revision=code_revision, **hub_kwargs, **kwargs
|
| 381 |
+
)
|
| 382 |
+
_ = hub_kwargs.pop("code_revision", None)
|
| 383 |
+
# This block handles the case where the user is loading a model with `trust_remote_code=True`
|
| 384 |
+
# but a library model exists with the same name. We don't want to override the autoclass
|
| 385 |
+
# mappings in this case, or all future loads of that model will be the remote code model.
|
| 386 |
+
if not has_local_code:
|
| 387 |
+
cls.register(config.__class__, model_class, exist_ok=True)
|
| 388 |
+
model_class.register_for_auto_class(auto_class=cls)
|
| 389 |
+
model_class = add_generation_mixin_to_remote_model(model_class)
|
| 390 |
+
return model_class.from_pretrained(
|
| 391 |
+
pretrained_model_name_or_path, *model_args, config=config, **hub_kwargs, **kwargs
|
| 392 |
+
)
|
| 393 |
+
elif has_local_code:
|
| 394 |
+
model_class = _get_model_class(config, cls._model_mapping)
|
| 395 |
+
if model_class.config_class == config.sub_configs.get("text_config", None):
|
| 396 |
+
# TODO: Validate that copying the parent quantization config to the text sub-config preserves
|
| 397 |
+
# modules_to_not_convert and skip-module matching when composite-model module prefixes differ.
|
| 398 |
+
parent_config = config
|
| 399 |
+
config = config.get_text_config()
|
| 400 |
+
# Check both `quantization_config` being present and also not null,
|
| 401 |
+
# as a `config.json` can have `"quantization_config": null` in it
|
| 402 |
+
parent_quant = getattr(parent_config, "quantization_config", None)
|
| 403 |
+
if parent_quant is not None:
|
| 404 |
+
config.quantization_config = parent_quant
|
| 405 |
+
return model_class.from_pretrained(
|
| 406 |
+
pretrained_model_name_or_path, *model_args, config=config, **hub_kwargs, **kwargs
|
| 407 |
+
)
|
| 408 |
+
raise ValueError(
|
| 409 |
+
f"Unrecognized configuration class {config.__class__} for this kind of AutoModel: {cls.__name__}.\n"
|
| 410 |
+
f"Model type should be one of {', '.join(c.__name__ for c in cls._model_mapping)}."
|
| 411 |
+
)
|
| 412 |
+
|
| 413 |
+
@classmethod
|
| 414 |
+
def register(cls, config_class, model_class, exist_ok=False) -> None:
|
| 415 |
+
"""
|
| 416 |
+
Register a new model for this class.
|
| 417 |
+
|
| 418 |
+
Args:
|
| 419 |
+
config_class ([`PreTrainedConfig`]):
|
| 420 |
+
The configuration corresponding to the model to register.
|
| 421 |
+
model_class ([`PreTrainedModel`]):
|
| 422 |
+
The model to register.
|
| 423 |
+
"""
|
| 424 |
+
if hasattr(model_class, "config_class") and model_class.config_class.__name__ != config_class.__name__:
|
| 425 |
+
raise ValueError(
|
| 426 |
+
"The model class you are passing has a `config_class` attribute that is not consistent with the "
|
| 427 |
+
f"config class you passed (model has {model_class.config_class} and you passed {config_class}. Fix "
|
| 428 |
+
"one of those so they match!"
|
| 429 |
+
)
|
| 430 |
+
cls._model_mapping.register(config_class, model_class, exist_ok=exist_ok)
|
| 431 |
+
|
| 432 |
+
|
| 433 |
+
class _BaseAutoBackboneClass(_BaseAutoModelClass):
|
| 434 |
+
# Base class for auto backbone models.
|
| 435 |
+
_model_mapping = None
|
| 436 |
+
|
| 437 |
+
@classmethod
|
| 438 |
+
def _load_timm_backbone_from_pretrained(cls, pretrained_model_name_or_path, *model_args, **kwargs):
|
| 439 |
+
requires_backends(cls, ["vision", "timm"])
|
| 440 |
+
from ...models.timm_backbone import TimmBackboneConfig
|
| 441 |
+
|
| 442 |
+
config = kwargs.pop("config", TimmBackboneConfig())
|
| 443 |
+
|
| 444 |
+
if kwargs.get("out_features") is not None:
|
| 445 |
+
raise ValueError("Cannot specify `out_features` for timm backbones")
|
| 446 |
+
|
| 447 |
+
if kwargs.get("output_loading_info", False):
|
| 448 |
+
raise ValueError("Cannot specify `output_loading_info=True` when loading from timm")
|
| 449 |
+
|
| 450 |
+
num_channels = kwargs.pop("num_channels", config.num_channels)
|
| 451 |
+
features_only = kwargs.pop("features_only", config.features_only)
|
| 452 |
+
out_indices = kwargs.pop("out_indices", config.out_indices)
|
| 453 |
+
config = TimmBackboneConfig(
|
| 454 |
+
backbone=pretrained_model_name_or_path,
|
| 455 |
+
num_channels=num_channels,
|
| 456 |
+
features_only=features_only,
|
| 457 |
+
out_indices=out_indices,
|
| 458 |
+
)
|
| 459 |
+
# Always load a pretrained model when `from_pretrained` is called
|
| 460 |
+
kwargs.pop("use_pretrained_backbone", None)
|
| 461 |
+
return super().from_config(config, pretrained=True, **kwargs)
|
| 462 |
+
|
| 463 |
+
@classmethod
|
| 464 |
+
def from_pretrained(cls, pretrained_model_name_or_path, *model_args, **kwargs):
|
| 465 |
+
kwargs.pop("use_timm_backbone", None)
|
| 466 |
+
if not repo_exists(pretrained_model_name_or_path):
|
| 467 |
+
return cls._load_timm_backbone_from_pretrained(pretrained_model_name_or_path, *model_args, **kwargs)
|
| 468 |
+
|
| 469 |
+
return super().from_pretrained(pretrained_model_name_or_path, *model_args, **kwargs)
|
| 470 |
+
|
| 471 |
+
|
| 472 |
+
def insert_head_doc(docstring, head_doc: str = ""):
|
| 473 |
+
if len(head_doc) > 0:
|
| 474 |
+
return docstring.replace(
|
| 475 |
+
"one of the model classes of the library ",
|
| 476 |
+
f"one of the model classes of the library (with a {head_doc} head) ",
|
| 477 |
+
)
|
| 478 |
+
return docstring.replace(
|
| 479 |
+
"one of the model classes of the library ", "one of the base model classes of the library "
|
| 480 |
+
)
|
| 481 |
+
|
| 482 |
+
|
| 483 |
+
def auto_class_update(cls, checkpoint_for_example: str = "google-bert/bert-base-cased", head_doc: str = ""):
|
| 484 |
+
# Create a new class with the right name from the base class
|
| 485 |
+
model_mapping = cls._model_mapping
|
| 486 |
+
name = cls.__name__
|
| 487 |
+
class_docstring = insert_head_doc(CLASS_DOCSTRING, head_doc=head_doc)
|
| 488 |
+
cls.__doc__ = class_docstring.replace("BaseAutoModelClass", name)
|
| 489 |
+
|
| 490 |
+
# Now we need to copy and re-register `from_config` and `from_pretrained` as class methods otherwise we can't
|
| 491 |
+
# have a specific docstrings for them.
|
| 492 |
+
from_config = copy_func(_BaseAutoModelClass.from_config)
|
| 493 |
+
from_config_docstring = insert_head_doc(FROM_CONFIG_DOCSTRING, head_doc=head_doc)
|
| 494 |
+
from_config_docstring = from_config_docstring.replace("BaseAutoModelClass", name)
|
| 495 |
+
from_config_docstring = from_config_docstring.replace("checkpoint_placeholder", checkpoint_for_example)
|
| 496 |
+
from_config.__doc__ = from_config_docstring
|
| 497 |
+
from_config = replace_list_option_in_docstrings(model_mapping._model_mapping, use_model_types=False)(from_config)
|
| 498 |
+
cls.from_config = classmethod(from_config)
|
| 499 |
+
|
| 500 |
+
from_pretrained_docstring = FROM_PRETRAINED_TORCH_DOCSTRING
|
| 501 |
+
from_pretrained = copy_func(_BaseAutoModelClass.from_pretrained)
|
| 502 |
+
from_pretrained_docstring = insert_head_doc(from_pretrained_docstring, head_doc=head_doc)
|
| 503 |
+
from_pretrained_docstring = from_pretrained_docstring.replace("BaseAutoModelClass", name)
|
| 504 |
+
from_pretrained_docstring = from_pretrained_docstring.replace("checkpoint_placeholder", checkpoint_for_example)
|
| 505 |
+
shortcut = checkpoint_for_example.split("/")[-1].split("-")[0]
|
| 506 |
+
from_pretrained_docstring = from_pretrained_docstring.replace("shortcut_placeholder", shortcut)
|
| 507 |
+
from_pretrained.__doc__ = from_pretrained_docstring
|
| 508 |
+
from_pretrained = replace_list_option_in_docstrings(model_mapping._model_mapping)(from_pretrained)
|
| 509 |
+
cls.from_pretrained = classmethod(from_pretrained)
|
| 510 |
+
return cls
|
| 511 |
+
|
| 512 |
+
|
| 513 |
+
def get_values(model_mapping):
|
| 514 |
+
result = []
|
| 515 |
+
for model in model_mapping.values():
|
| 516 |
+
if isinstance(model, (list, tuple)):
|
| 517 |
+
result += list(model)
|
| 518 |
+
else:
|
| 519 |
+
result.append(model)
|
| 520 |
+
|
| 521 |
+
return result
|
| 522 |
+
|
| 523 |
+
|
| 524 |
+
def getattribute_from_module(module, attr):
|
| 525 |
+
if attr is None:
|
| 526 |
+
return None
|
| 527 |
+
if isinstance(attr, tuple):
|
| 528 |
+
return tuple(getattribute_from_module(module, a) for a in attr)
|
| 529 |
+
if isinstance(attr, dict):
|
| 530 |
+
return {k: getattribute_from_module(module, v) for k, v in attr.items()}
|
| 531 |
+
if hasattr(module, attr):
|
| 532 |
+
return getattr(module, attr)
|
| 533 |
+
# Some of the mappings have entries model_type -> object of another model type. In that case we try to grab the
|
| 534 |
+
# object at the top level.
|
| 535 |
+
transformers_module = importlib.import_module("transformers")
|
| 536 |
+
|
| 537 |
+
if module != transformers_module:
|
| 538 |
+
try:
|
| 539 |
+
return getattribute_from_module(transformers_module, attr)
|
| 540 |
+
except ValueError:
|
| 541 |
+
raise ValueError(f"Could not find {attr} neither in {module} nor in {transformers_module}!")
|
| 542 |
+
else:
|
| 543 |
+
raise ValueError(f"Could not find {attr} in {transformers_module}!")
|
| 544 |
+
|
| 545 |
+
|
| 546 |
+
def add_generation_mixin_to_remote_model(model_class):
|
| 547 |
+
"""
|
| 548 |
+
Adds `GenerationMixin` to the inheritance of `model_class`, if `model_class` is a PyTorch model.
|
| 549 |
+
|
| 550 |
+
This function is used for backwards compatibility purposes: in v4.45, we've started a deprecation cycle to make
|
| 551 |
+
`PreTrainedModel` stop inheriting from `GenerationMixin`. Without this function, older models dynamically loaded
|
| 552 |
+
from the Hub may not have the `generate` method after we remove the inheritance.
|
| 553 |
+
"""
|
| 554 |
+
# 1. If it is not a PT model (i.e. doesn't inherit Module), do nothing
|
| 555 |
+
if "torch.nn.modules.module.Module" not in str(model_class.__mro__):
|
| 556 |
+
return model_class
|
| 557 |
+
|
| 558 |
+
# 2. If it already **directly** inherits from GenerationMixin, do nothing
|
| 559 |
+
if "GenerationMixin" in str(model_class.__bases__):
|
| 560 |
+
return model_class
|
| 561 |
+
|
| 562 |
+
# 3. Prior to v4.45, we could detect whether a model was `generate`-compatible if it had its own `generate` and/or
|
| 563 |
+
# `prepare_inputs_for_generation` method.
|
| 564 |
+
has_custom_generate_in_class = hasattr(model_class, "generate") and "GenerationMixin" not in str(
|
| 565 |
+
getattr(model_class, "generate")
|
| 566 |
+
)
|
| 567 |
+
has_custom_prepare_inputs = hasattr(model_class, "prepare_inputs_for_generation") and "GenerationMixin" not in str(
|
| 568 |
+
getattr(model_class, "prepare_inputs_for_generation")
|
| 569 |
+
)
|
| 570 |
+
if has_custom_generate_in_class or has_custom_prepare_inputs:
|
| 571 |
+
model_class_with_generation_mixin = type(
|
| 572 |
+
model_class.__name__, (model_class, GenerationMixin), {**model_class.__dict__}
|
| 573 |
+
)
|
| 574 |
+
return model_class_with_generation_mixin
|
| 575 |
+
return model_class
|
| 576 |
+
|
| 577 |
+
|
| 578 |
+
class _LazyAutoMapping(OrderedDict[type[PreTrainedConfig], _LazyAutoMappingValue]):
|
| 579 |
+
"""
|
| 580 |
+
A mapping config to object (model or tokenizer for instance) that will load keys and values when it is accessed.
|
| 581 |
+
|
| 582 |
+
Args:
|
| 583 |
+
- config_mapping: The map model type to config class
|
| 584 |
+
- model_mapping: The map model type to model (or tokenizer) class
|
| 585 |
+
"""
|
| 586 |
+
|
| 587 |
+
def __init__(self, config_mapping, model_mapping) -> None:
|
| 588 |
+
self._config_mapping = config_mapping
|
| 589 |
+
self._reverse_config_mapping = {v: k for k, v in config_mapping.items()}
|
| 590 |
+
self._model_mapping = model_mapping
|
| 591 |
+
self._model_mapping._model_mapping = self
|
| 592 |
+
self._extra_content = {}
|
| 593 |
+
self._modules = {}
|
| 594 |
+
|
| 595 |
+
def __len__(self) -> int:
|
| 596 |
+
common_keys = set(self._config_mapping.keys()).intersection(self._model_mapping.keys())
|
| 597 |
+
return len(common_keys) + len(self._extra_content)
|
| 598 |
+
|
| 599 |
+
def __getitem__(self, key: type[PreTrainedConfig]) -> _LazyAutoMappingValue:
|
| 600 |
+
if key in self._extra_content:
|
| 601 |
+
return self._extra_content[key]
|
| 602 |
+
model_type = self._reverse_config_mapping[key.__name__]
|
| 603 |
+
if model_type in self._model_mapping:
|
| 604 |
+
model_name = self._model_mapping[model_type]
|
| 605 |
+
return self._load_attr_from_module(model_type, model_name)
|
| 606 |
+
|
| 607 |
+
# Maybe there was several model types associated with this config.
|
| 608 |
+
model_types = [k for k, v in self._config_mapping.items() if v == key.__name__]
|
| 609 |
+
for mtype in model_types:
|
| 610 |
+
if mtype in self._model_mapping:
|
| 611 |
+
model_name = self._model_mapping[mtype]
|
| 612 |
+
return self._load_attr_from_module(mtype, model_name)
|
| 613 |
+
raise KeyError(key)
|
| 614 |
+
|
| 615 |
+
def _load_attr_from_module(self, model_type, attr):
|
| 616 |
+
module_name = model_type_to_module_name(model_type)
|
| 617 |
+
if module_name not in self._modules:
|
| 618 |
+
self._modules[module_name] = importlib.import_module(f".{module_name}", "transformers.models")
|
| 619 |
+
return getattribute_from_module(self._modules[module_name], attr)
|
| 620 |
+
|
| 621 |
+
def keys(self) -> list[type[PreTrainedConfig]]:
|
| 622 |
+
mapping_keys = [
|
| 623 |
+
self._load_attr_from_module(key, name)
|
| 624 |
+
for key, name in self._config_mapping.items()
|
| 625 |
+
if key in self._model_mapping
|
| 626 |
+
]
|
| 627 |
+
return mapping_keys + list(self._extra_content.keys())
|
| 628 |
+
|
| 629 |
+
def get(self, key: type[PreTrainedConfig], default: _T) -> _LazyAutoMappingValue | _T:
|
| 630 |
+
try:
|
| 631 |
+
return self.__getitem__(key)
|
| 632 |
+
except KeyError:
|
| 633 |
+
return default
|
| 634 |
+
|
| 635 |
+
def __bool__(self) -> bool:
|
| 636 |
+
return bool(self.keys())
|
| 637 |
+
|
| 638 |
+
def values(self) -> list[_LazyAutoMappingValue]:
|
| 639 |
+
mapping_values = [
|
| 640 |
+
self._load_attr_from_module(key, name)
|
| 641 |
+
for key, name in self._model_mapping.items()
|
| 642 |
+
if key in self._config_mapping
|
| 643 |
+
]
|
| 644 |
+
return mapping_values + list(self._extra_content.values())
|
| 645 |
+
|
| 646 |
+
def items(self) -> list[tuple[type[PreTrainedConfig], _LazyAutoMappingValue]]:
|
| 647 |
+
mapping_items = [
|
| 648 |
+
(
|
| 649 |
+
self._load_attr_from_module(key, self._config_mapping[key]),
|
| 650 |
+
self._load_attr_from_module(key, self._model_mapping[key]),
|
| 651 |
+
)
|
| 652 |
+
for key in self._model_mapping
|
| 653 |
+
if key in self._config_mapping
|
| 654 |
+
]
|
| 655 |
+
return mapping_items + list(self._extra_content.items())
|
| 656 |
+
|
| 657 |
+
def __iter__(self) -> Iterator[type[PreTrainedConfig]]:
|
| 658 |
+
return iter(self.keys())
|
| 659 |
+
|
| 660 |
+
def __contains__(self, item: type) -> bool:
|
| 661 |
+
if item in self._extra_content:
|
| 662 |
+
return True
|
| 663 |
+
if not hasattr(item, "__name__") or item.__name__ not in self._reverse_config_mapping:
|
| 664 |
+
return False
|
| 665 |
+
model_type = self._reverse_config_mapping[item.__name__]
|
| 666 |
+
return model_type in self._model_mapping
|
| 667 |
+
|
| 668 |
+
def register(self, key: type[PreTrainedConfig], value: _LazyAutoMappingValue, exist_ok=False) -> None:
|
| 669 |
+
"""
|
| 670 |
+
Register a new model in this mapping.
|
| 671 |
+
"""
|
| 672 |
+
if hasattr(key, "__name__") and key.__name__ in self._reverse_config_mapping:
|
| 673 |
+
model_type = self._reverse_config_mapping[key.__name__]
|
| 674 |
+
if model_type in self._model_mapping and not exist_ok:
|
| 675 |
+
raise ValueError(f"'{key}' is already used by a Transformers model.")
|
| 676 |
+
|
| 677 |
+
self._extra_content[key] = value
|
| 678 |
+
|
| 679 |
+
|
| 680 |
+
__all__ = ["get_values"]
|
LTA_openwebtext_dualt/mini_owt_logdirichlet/.venv_qwen35_uv/lib/python3.12/site-packages/transformers/models/auto/auto_mappings.py
ADDED
|
@@ -0,0 +1,1008 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# 🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨
|
| 2 |
+
# This file was automatically generated from existing config files and their `model_type`s. Do NOT edit this file
|
| 3 |
+
# manually as any edits will be overwritten by auto-generation of the file. If any change should be done,
|
| 4 |
+
# please add the correct `cls.model_type` in your config class and run `python utils/check_auto.py --fix_and_overwrite`.
|
| 5 |
+
# 🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨
|
| 6 |
+
# Copyright 2026 The HuggingFace Inc. team.
|
| 7 |
+
#
|
| 8 |
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
| 9 |
+
# you may not use this file except in compliance with the License.
|
| 10 |
+
# You may obtain a copy of the License at
|
| 11 |
+
#
|
| 12 |
+
# http://www.apache.org/licenses/LICENSE-2.0
|
| 13 |
+
#
|
| 14 |
+
# Unless required by applicable law or agreed to in writing, software
|
| 15 |
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
| 16 |
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
| 17 |
+
# See the License for the specific language governing permissions and
|
| 18 |
+
# limitations under the License.
|
| 19 |
+
|
| 20 |
+
|
| 21 |
+
from collections import OrderedDict
|
| 22 |
+
|
| 23 |
+
|
| 24 |
+
CONFIG_MAPPING_NAMES = OrderedDict(
|
| 25 |
+
[
|
| 26 |
+
("afmoe", "AfmoeConfig"),
|
| 27 |
+
("aimv2", "Aimv2Config"),
|
| 28 |
+
("aimv2_text_model", "Aimv2TextConfig"),
|
| 29 |
+
("aimv2_vision_model", "Aimv2VisionConfig"),
|
| 30 |
+
("albert", "AlbertConfig"),
|
| 31 |
+
("align", "AlignConfig"),
|
| 32 |
+
("align_text_model", "AlignTextConfig"),
|
| 33 |
+
("align_vision_model", "AlignVisionConfig"),
|
| 34 |
+
("altclip", "AltCLIPConfig"),
|
| 35 |
+
("altclip_text_model", "AltCLIPTextConfig"),
|
| 36 |
+
("altclip_vision_model", "AltCLIPVisionConfig"),
|
| 37 |
+
("apertus", "ApertusConfig"),
|
| 38 |
+
("arcee", "ArceeConfig"),
|
| 39 |
+
("aria", "AriaConfig"),
|
| 40 |
+
("aria_text", "AriaTextConfig"),
|
| 41 |
+
("audio-spectrogram-transformer", "ASTConfig"),
|
| 42 |
+
("audioflamingo3", "AudioFlamingo3Config"),
|
| 43 |
+
("audioflamingo3_encoder", "AudioFlamingo3EncoderConfig"),
|
| 44 |
+
("autoformer", "AutoformerConfig"),
|
| 45 |
+
("aya_vision", "AyaVisionConfig"),
|
| 46 |
+
("bamba", "BambaConfig"),
|
| 47 |
+
("bark", "BarkConfig"),
|
| 48 |
+
("bart", "BartConfig"),
|
| 49 |
+
("beit", "BeitConfig"),
|
| 50 |
+
("bert", "BertConfig"),
|
| 51 |
+
("bert-generation", "BertGenerationConfig"),
|
| 52 |
+
("big_bird", "BigBirdConfig"),
|
| 53 |
+
("bigbird_pegasus", "BigBirdPegasusConfig"),
|
| 54 |
+
("biogpt", "BioGptConfig"),
|
| 55 |
+
("bit", "BitConfig"),
|
| 56 |
+
("bitnet", "BitNetConfig"),
|
| 57 |
+
("blenderbot", "BlenderbotConfig"),
|
| 58 |
+
("blenderbot-small", "BlenderbotSmallConfig"),
|
| 59 |
+
("blip", "BlipConfig"),
|
| 60 |
+
("blip-2", "Blip2Config"),
|
| 61 |
+
("blip_2_qformer", "Blip2QFormerConfig"),
|
| 62 |
+
("blip_2_vision_model", "Blip2VisionConfig"),
|
| 63 |
+
("blip_text_model", "BlipTextConfig"),
|
| 64 |
+
("blip_vision_model", "BlipVisionConfig"),
|
| 65 |
+
("bloom", "BloomConfig"),
|
| 66 |
+
("blt", "BltConfig"),
|
| 67 |
+
("blt_global_transformer", "BltGlobalTransformerConfig"),
|
| 68 |
+
("blt_local_decoder", "BltLocalDecoderConfig"),
|
| 69 |
+
("blt_local_encoder", "BltLocalEncoderConfig"),
|
| 70 |
+
("blt_patcher", "BltPatcherConfig"),
|
| 71 |
+
("bridgetower", "BridgeTowerConfig"),
|
| 72 |
+
("bridgetower_text_model", "BridgeTowerTextConfig"),
|
| 73 |
+
("bridgetower_vision_model", "BridgeTowerVisionConfig"),
|
| 74 |
+
("bros", "BrosConfig"),
|
| 75 |
+
("camembert", "CamembertConfig"),
|
| 76 |
+
("canine", "CanineConfig"),
|
| 77 |
+
("chameleon", "ChameleonConfig"),
|
| 78 |
+
("chameleon_vqgan", "ChameleonVQVAEConfig"),
|
| 79 |
+
("chinese_clip", "ChineseCLIPConfig"),
|
| 80 |
+
("chinese_clip_text_model", "ChineseCLIPTextConfig"),
|
| 81 |
+
("chinese_clip_vision_model", "ChineseCLIPVisionConfig"),
|
| 82 |
+
("chmv2", "CHMv2Config"),
|
| 83 |
+
("clap", "ClapConfig"),
|
| 84 |
+
("clap_audio_model", "ClapAudioConfig"),
|
| 85 |
+
("clap_text_model", "ClapTextConfig"),
|
| 86 |
+
("clip", "CLIPConfig"),
|
| 87 |
+
("clip_text_model", "CLIPTextConfig"),
|
| 88 |
+
("clip_vision_model", "CLIPVisionConfig"),
|
| 89 |
+
("clipseg", "CLIPSegConfig"),
|
| 90 |
+
("clipseg_text_model", "CLIPSegTextConfig"),
|
| 91 |
+
("clipseg_vision_model", "CLIPSegVisionConfig"),
|
| 92 |
+
("clvp", "ClvpConfig"),
|
| 93 |
+
("clvp_decoder", "ClvpDecoderConfig"),
|
| 94 |
+
("clvp_encoder", "ClvpEncoderConfig"),
|
| 95 |
+
("codegen", "CodeGenConfig"),
|
| 96 |
+
("cohere", "CohereConfig"),
|
| 97 |
+
("cohere2", "Cohere2Config"),
|
| 98 |
+
("cohere2_moe", "Cohere2MoeConfig"),
|
| 99 |
+
("cohere2_vision", "Cohere2VisionConfig"),
|
| 100 |
+
("cohere_asr", "CohereAsrConfig"),
|
| 101 |
+
("colmodernvbert", "ColModernVBertConfig"),
|
| 102 |
+
("colpali", "ColPaliConfig"),
|
| 103 |
+
("colqwen2", "ColQwen2Config"),
|
| 104 |
+
("conditional_detr", "ConditionalDetrConfig"),
|
| 105 |
+
("convbert", "ConvBertConfig"),
|
| 106 |
+
("convnext", "ConvNextConfig"),
|
| 107 |
+
("convnextv2", "ConvNextV2Config"),
|
| 108 |
+
("cpmant", "CpmAntConfig"),
|
| 109 |
+
("csm", "CsmConfig"),
|
| 110 |
+
("csm_depth_decoder_model", "CsmDepthDecoderConfig"),
|
| 111 |
+
("ctrl", "CTRLConfig"),
|
| 112 |
+
("cvt", "CvtConfig"),
|
| 113 |
+
("cwm", "CwmConfig"),
|
| 114 |
+
("d_fine", "DFineConfig"),
|
| 115 |
+
("dab-detr", "DabDetrConfig"),
|
| 116 |
+
("dac", "DacConfig"),
|
| 117 |
+
("data2vec-audio", "Data2VecAudioConfig"),
|
| 118 |
+
("data2vec-text", "Data2VecTextConfig"),
|
| 119 |
+
("data2vec-vision", "Data2VecVisionConfig"),
|
| 120 |
+
("dbrx", "DbrxConfig"),
|
| 121 |
+
("deberta", "DebertaConfig"),
|
| 122 |
+
("deberta-v2", "DebertaV2Config"),
|
| 123 |
+
("decision_transformer", "DecisionTransformerConfig"),
|
| 124 |
+
("deepseek_v2", "DeepseekV2Config"),
|
| 125 |
+
("deepseek_v3", "DeepseekV3Config"),
|
| 126 |
+
("deepseek_v4", "DeepseekV4Config"),
|
| 127 |
+
("deepseek_vl", "DeepseekVLConfig"),
|
| 128 |
+
("deepseek_vl_hybrid", "DeepseekVLHybridConfig"),
|
| 129 |
+
("deformable_detr", "DeformableDetrConfig"),
|
| 130 |
+
("deimv2", "Deimv2Config"),
|
| 131 |
+
("deit", "DeiTConfig"),
|
| 132 |
+
("depth_anything", "DepthAnythingConfig"),
|
| 133 |
+
("depth_pro", "DepthProConfig"),
|
| 134 |
+
("detr", "DetrConfig"),
|
| 135 |
+
("dia", "DiaConfig"),
|
| 136 |
+
("dia_decoder", "DiaDecoderConfig"),
|
| 137 |
+
("dia_encoder", "DiaEncoderConfig"),
|
| 138 |
+
("diffllama", "DiffLlamaConfig"),
|
| 139 |
+
("dinat", "DinatConfig"),
|
| 140 |
+
("dinov2", "Dinov2Config"),
|
| 141 |
+
("dinov2_with_registers", "Dinov2WithRegistersConfig"),
|
| 142 |
+
("dinov3_convnext", "DINOv3ConvNextConfig"),
|
| 143 |
+
("dinov3_vit", "DINOv3ViTConfig"),
|
| 144 |
+
("distilbert", "DistilBertConfig"),
|
| 145 |
+
("doge", "DogeConfig"),
|
| 146 |
+
("donut-swin", "DonutSwinConfig"),
|
| 147 |
+
("dots1", "Dots1Config"),
|
| 148 |
+
("dpr", "DPRConfig"),
|
| 149 |
+
("dpt", "DPTConfig"),
|
| 150 |
+
("edgetam", "EdgeTamConfig"),
|
| 151 |
+
("edgetam_video", "EdgeTamVideoConfig"),
|
| 152 |
+
("edgetam_vision_model", "EdgeTamVisionConfig"),
|
| 153 |
+
("efficientloftr", "EfficientLoFTRConfig"),
|
| 154 |
+
("efficientnet", "EfficientNetConfig"),
|
| 155 |
+
("electra", "ElectraConfig"),
|
| 156 |
+
("emu3", "Emu3Config"),
|
| 157 |
+
("emu3_text_model", "Emu3TextConfig"),
|
| 158 |
+
("emu3_vqgan", "Emu3VQVAEConfig"),
|
| 159 |
+
("encodec", "EncodecConfig"),
|
| 160 |
+
("encoder-decoder", "EncoderDecoderConfig"),
|
| 161 |
+
("eomt", "EomtConfig"),
|
| 162 |
+
("eomt_dinov3", "EomtDinov3Config"),
|
| 163 |
+
("ernie", "ErnieConfig"),
|
| 164 |
+
("ernie4_5", "Ernie4_5Config"),
|
| 165 |
+
("ernie4_5_moe", "Ernie4_5_MoeConfig"),
|
| 166 |
+
("ernie4_5_vl_moe", "Ernie4_5_VLMoeConfig"),
|
| 167 |
+
("ernie4_5_vl_moe_text", "Ernie4_5_VLMoeTextConfig"),
|
| 168 |
+
("ernie4_5_vl_moe_vision", "Ernie4_5_VLMoeVisionConfig"),
|
| 169 |
+
("esm", "EsmConfig"),
|
| 170 |
+
("eurobert", "EuroBertConfig"),
|
| 171 |
+
("evolla", "EvollaConfig"),
|
| 172 |
+
("exaone4", "Exaone4Config"),
|
| 173 |
+
("exaone4_5", "Exaone4_5_Config"),
|
| 174 |
+
("exaone4_5_vision", "Exaone4_5_VisionConfig"),
|
| 175 |
+
("exaone_moe", "ExaoneMoeConfig"),
|
| 176 |
+
("falcon", "FalconConfig"),
|
| 177 |
+
("falcon_h1", "FalconH1Config"),
|
| 178 |
+
("falcon_mamba", "FalconMambaConfig"),
|
| 179 |
+
("fast_vlm", "FastVlmConfig"),
|
| 180 |
+
("fastspeech2_conformer", "FastSpeech2ConformerConfig"),
|
| 181 |
+
("fastspeech2_conformer_hifigan", "FastSpeech2ConformerHifiGanConfig"),
|
| 182 |
+
("fastspeech2_conformer_with_hifigan", "FastSpeech2ConformerWithHifiGanConfig"),
|
| 183 |
+
("flaubert", "FlaubertConfig"),
|
| 184 |
+
("flava", "FlavaConfig"),
|
| 185 |
+
("flava_image_model", "FlavaImageConfig"),
|
| 186 |
+
("flava_multimodal_model", "FlavaMultimodalConfig"),
|
| 187 |
+
("flava_text_model", "FlavaTextConfig"),
|
| 188 |
+
("flex_olmo", "FlexOlmoConfig"),
|
| 189 |
+
("florence2", "Florence2Config"),
|
| 190 |
+
("florence_vision", "Florence2VisionConfig"),
|
| 191 |
+
("fnet", "FNetConfig"),
|
| 192 |
+
("focalnet", "FocalNetConfig"),
|
| 193 |
+
("fsmt", "FSMTConfig"),
|
| 194 |
+
("funnel", "FunnelConfig"),
|
| 195 |
+
("fuyu", "FuyuConfig"),
|
| 196 |
+
("gemma", "GemmaConfig"),
|
| 197 |
+
("gemma2", "Gemma2Config"),
|
| 198 |
+
("gemma3", "Gemma3Config"),
|
| 199 |
+
("gemma3_text", "Gemma3TextConfig"),
|
| 200 |
+
("gemma3n", "Gemma3nConfig"),
|
| 201 |
+
("gemma3n_audio", "Gemma3nAudioConfig"),
|
| 202 |
+
("gemma3n_text", "Gemma3nTextConfig"),
|
| 203 |
+
("gemma3n_vision", "Gemma3nVisionConfig"),
|
| 204 |
+
("gemma4", "Gemma4Config"),
|
| 205 |
+
("gemma4_assistant", "Gemma4AssistantConfig"),
|
| 206 |
+
("gemma4_audio", "Gemma4AudioConfig"),
|
| 207 |
+
("gemma4_text", "Gemma4TextConfig"),
|
| 208 |
+
("gemma4_vision", "Gemma4VisionConfig"),
|
| 209 |
+
("git", "GitConfig"),
|
| 210 |
+
("git_vision_model", "GitVisionConfig"),
|
| 211 |
+
("glm", "GlmConfig"),
|
| 212 |
+
("glm4", "Glm4Config"),
|
| 213 |
+
("glm46v", "Glm46VConfig"),
|
| 214 |
+
("glm4_moe", "Glm4MoeConfig"),
|
| 215 |
+
("glm4_moe_lite", "Glm4MoeLiteConfig"),
|
| 216 |
+
("glm4v", "Glm4vConfig"),
|
| 217 |
+
("glm4v_moe", "Glm4vMoeConfig"),
|
| 218 |
+
("glm4v_moe_text", "Glm4vMoeTextConfig"),
|
| 219 |
+
("glm4v_moe_vision", "Glm4vMoeVisionConfig"),
|
| 220 |
+
("glm4v_text", "Glm4vTextConfig"),
|
| 221 |
+
("glm4v_vision", "Glm4vVisionConfig"),
|
| 222 |
+
("glm_image", "GlmImageConfig"),
|
| 223 |
+
("glm_image_text", "GlmImageTextConfig"),
|
| 224 |
+
("glm_image_vision", "GlmImageVisionConfig"),
|
| 225 |
+
("glm_image_vqmodel", "GlmImageVQVAEConfig"),
|
| 226 |
+
("glm_moe_dsa", "GlmMoeDsaConfig"),
|
| 227 |
+
("glm_ocr", "GlmOcrConfig"),
|
| 228 |
+
("glm_ocr_text", "GlmOcrTextConfig"),
|
| 229 |
+
("glm_ocr_vision", "GlmOcrVisionConfig"),
|
| 230 |
+
("glmasr", "GlmAsrConfig"),
|
| 231 |
+
("glmasr_encoder", "GlmAsrEncoderConfig"),
|
| 232 |
+
("glpn", "GLPNConfig"),
|
| 233 |
+
("got_ocr2", "GotOcr2Config"),
|
| 234 |
+
("gpt2", "GPT2Config"),
|
| 235 |
+
("gpt_bigcode", "GPTBigCodeConfig"),
|
| 236 |
+
("gpt_neo", "GPTNeoConfig"),
|
| 237 |
+
("gpt_neox", "GPTNeoXConfig"),
|
| 238 |
+
("gpt_neox_japanese", "GPTNeoXJapaneseConfig"),
|
| 239 |
+
("gpt_oss", "GptOssConfig"),
|
| 240 |
+
("gptj", "GPTJConfig"),
|
| 241 |
+
("granite", "GraniteConfig"),
|
| 242 |
+
("granite4_vision", "Granite4VisionConfig"),
|
| 243 |
+
("granite4_vision_text", "Granite4VisionTextConfig"),
|
| 244 |
+
("granite_speech", "GraniteSpeechConfig"),
|
| 245 |
+
("granite_speech_encoder", "GraniteSpeechEncoderConfig"),
|
| 246 |
+
("granite_speech_plus", "GraniteSpeechPlusConfig"),
|
| 247 |
+
("granite_speech_plus_encoder", "GraniteSpeechPlusEncoderConfig"),
|
| 248 |
+
("granitemoe", "GraniteMoeConfig"),
|
| 249 |
+
("granitemoehybrid", "GraniteMoeHybridConfig"),
|
| 250 |
+
("granitemoeshared", "GraniteMoeSharedConfig"),
|
| 251 |
+
("grounding-dino", "GroundingDinoConfig"),
|
| 252 |
+
("groupvit", "GroupViTConfig"),
|
| 253 |
+
("groupvit_text_model", "GroupViTTextConfig"),
|
| 254 |
+
("groupvit_vision_model", "GroupViTVisionConfig"),
|
| 255 |
+
("helium", "HeliumConfig"),
|
| 256 |
+
("hgnet_v2", "HGNetV2Config"),
|
| 257 |
+
("hiera", "HieraConfig"),
|
| 258 |
+
("higgs_audio_v2", "HiggsAudioV2Config"),
|
| 259 |
+
("higgs_audio_v2_tokenizer", "HiggsAudioV2TokenizerConfig"),
|
| 260 |
+
("hrm_text", "HrmTextConfig"),
|
| 261 |
+
("hubert", "HubertConfig"),
|
| 262 |
+
("hunyuan_v1_dense", "HunYuanDenseV1Config"),
|
| 263 |
+
("hunyuan_v1_moe", "HunYuanMoEV1Config"),
|
| 264 |
+
("hy_v3", "HYV3Config"),
|
| 265 |
+
("hyperclovax", "HyperCLOVAXConfig"),
|
| 266 |
+
("ibert", "IBertConfig"),
|
| 267 |
+
("idefics", "IdeficsConfig"),
|
| 268 |
+
("idefics2", "Idefics2Config"),
|
| 269 |
+
("idefics2_perceiver", "Idefics2PerceiverConfig"),
|
| 270 |
+
("idefics2_vision", "Idefics2VisionConfig"),
|
| 271 |
+
("idefics3", "Idefics3Config"),
|
| 272 |
+
("idefics3_vision", "Idefics3VisionConfig"),
|
| 273 |
+
("idefics_perciever", "IdeficsPerceiverConfig"),
|
| 274 |
+
("idefics_vision", "IdeficsVisionConfig"),
|
| 275 |
+
("ijepa", "IJepaConfig"),
|
| 276 |
+
("imagegpt", "ImageGPTConfig"),
|
| 277 |
+
("informer", "InformerConfig"),
|
| 278 |
+
("instructblip", "InstructBlipConfig"),
|
| 279 |
+
("instructblip_qformer", "InstructBlipQFormerConfig"),
|
| 280 |
+
("instructblip_vision_model", "InstructBlipVisionConfig"),
|
| 281 |
+
("instructblipvideo", "InstructBlipVideoConfig"),
|
| 282 |
+
("instructblipvideo_qformer", "InstructBlipVideoQFormerConfig"),
|
| 283 |
+
("instructblipvideo_vision_model", "InstructBlipVideoVisionConfig"),
|
| 284 |
+
("internvl", "InternVLConfig"),
|
| 285 |
+
("internvl_vision", "InternVLVisionConfig"),
|
| 286 |
+
("jais2", "Jais2Config"),
|
| 287 |
+
("jamba", "JambaConfig"),
|
| 288 |
+
("janus", "JanusConfig"),
|
| 289 |
+
("janus_vision_model", "JanusVisionConfig"),
|
| 290 |
+
("janus_vqgan", "JanusVQVAEConfig"),
|
| 291 |
+
("jetmoe", "JetMoeConfig"),
|
| 292 |
+
("jina_embeddings_v3", "JinaEmbeddingsV3Config"),
|
| 293 |
+
("kosmos-2", "Kosmos2Config"),
|
| 294 |
+
("kosmos-2.5", "Kosmos2_5Config"),
|
| 295 |
+
("kosmos_2_5_text_model", "Kosmos2_5TextConfig"),
|
| 296 |
+
("kosmos_2_5_vision_model", "Kosmos2_5VisionConfig"),
|
| 297 |
+
("kosmos_2_text_model", "Kosmos2TextConfig"),
|
| 298 |
+
("kosmos_2_vision_model", "Kosmos2VisionConfig"),
|
| 299 |
+
("kyutai_speech_to_text", "KyutaiSpeechToTextConfig"),
|
| 300 |
+
("laguna", "LagunaConfig"),
|
| 301 |
+
("lasr_ctc", "LasrCTCConfig"),
|
| 302 |
+
("lasr_encoder", "LasrEncoderConfig"),
|
| 303 |
+
("layoutlm", "LayoutLMConfig"),
|
| 304 |
+
("layoutlmv2", "LayoutLMv2Config"),
|
| 305 |
+
("layoutlmv3", "LayoutLMv3Config"),
|
| 306 |
+
("layoutxlm", "LayoutXLMConfig"),
|
| 307 |
+
("led", "LEDConfig"),
|
| 308 |
+
("levit", "LevitConfig"),
|
| 309 |
+
("lfm2", "Lfm2Config"),
|
| 310 |
+
("lfm2_moe", "Lfm2MoeConfig"),
|
| 311 |
+
("lfm2_vl", "Lfm2VlConfig"),
|
| 312 |
+
("lightglue", "LightGlueConfig"),
|
| 313 |
+
("lighton_ocr", "LightOnOcrConfig"),
|
| 314 |
+
("lilt", "LiltConfig"),
|
| 315 |
+
("llama", "LlamaConfig"),
|
| 316 |
+
("llama4", "Llama4Config"),
|
| 317 |
+
("llama4_text", "Llama4TextConfig"),
|
| 318 |
+
("llama4_vision_model", "Llama4VisionConfig"),
|
| 319 |
+
("llava", "LlavaConfig"),
|
| 320 |
+
("llava_next", "LlavaNextConfig"),
|
| 321 |
+
("llava_next_video", "LlavaNextVideoConfig"),
|
| 322 |
+
("llava_onevision", "LlavaOnevisionConfig"),
|
| 323 |
+
("longcat_flash", "LongcatFlashConfig"),
|
| 324 |
+
("longformer", "LongformerConfig"),
|
| 325 |
+
("longt5", "LongT5Config"),
|
| 326 |
+
("luke", "LukeConfig"),
|
| 327 |
+
("lw_detr", "LwDetrConfig"),
|
| 328 |
+
("lw_detr_vit", "LwDetrViTConfig"),
|
| 329 |
+
("lxmert", "LxmertConfig"),
|
| 330 |
+
("m2m_100", "M2M100Config"),
|
| 331 |
+
("mamba", "MambaConfig"),
|
| 332 |
+
("mamba2", "Mamba2Config"),
|
| 333 |
+
("marian", "MarianConfig"),
|
| 334 |
+
("markuplm", "MarkupLMConfig"),
|
| 335 |
+
("mask2former", "Mask2FormerConfig"),
|
| 336 |
+
("maskformer", "MaskFormerConfig"),
|
| 337 |
+
("maskformer-swin", "MaskFormerSwinConfig"),
|
| 338 |
+
("mbart", "MBartConfig"),
|
| 339 |
+
("megatron-bert", "MegatronBertConfig"),
|
| 340 |
+
("metaclip_2", "MetaClip2Config"),
|
| 341 |
+
("metaclip_2_text_model", "MetaClip2TextConfig"),
|
| 342 |
+
("metaclip_2_vision_model", "MetaClip2VisionConfig"),
|
| 343 |
+
("mgp-str", "MgpstrConfig"),
|
| 344 |
+
("mimi", "MimiConfig"),
|
| 345 |
+
("minicpmv4_6", "MiniCPMV4_6Config"),
|
| 346 |
+
("minicpmv4_6_vision", "MiniCPMV4_6VisionConfig"),
|
| 347 |
+
("minimax", "MiniMaxConfig"),
|
| 348 |
+
("minimax_m2", "MiniMaxM2Config"),
|
| 349 |
+
("ministral", "MinistralConfig"),
|
| 350 |
+
("ministral3", "Ministral3Config"),
|
| 351 |
+
("mistral", "MistralConfig"),
|
| 352 |
+
("mistral3", "Mistral3Config"),
|
| 353 |
+
("mistral4", "Mistral4Config"),
|
| 354 |
+
("mixtral", "MixtralConfig"),
|
| 355 |
+
("mlcd_vision_model", "MLCDVisionConfig"),
|
| 356 |
+
("mllama", "MllamaConfig"),
|
| 357 |
+
("mllama_text_model", "MllamaTextConfig"),
|
| 358 |
+
("mllama_vision_model", "MllamaVisionConfig"),
|
| 359 |
+
("mm-grounding-dino", "MMGroundingDinoConfig"),
|
| 360 |
+
("mobilebert", "MobileBertConfig"),
|
| 361 |
+
("mobilenet_v1", "MobileNetV1Config"),
|
| 362 |
+
("mobilenet_v2", "MobileNetV2Config"),
|
| 363 |
+
("mobilevit", "MobileViTConfig"),
|
| 364 |
+
("mobilevitv2", "MobileViTV2Config"),
|
| 365 |
+
("modernbert", "ModernBertConfig"),
|
| 366 |
+
("modernbert-decoder", "ModernBertDecoderConfig"),
|
| 367 |
+
("modernvbert", "ModernVBertConfig"),
|
| 368 |
+
("moonshine", "MoonshineConfig"),
|
| 369 |
+
("moonshine_streaming", "MoonshineStreamingConfig"),
|
| 370 |
+
("moonshine_streaming_encoder", "MoonshineStreamingEncoderConfig"),
|
| 371 |
+
("moshi", "MoshiConfig"),
|
| 372 |
+
("moshi_depth", "MoshiDepthConfig"),
|
| 373 |
+
("mpnet", "MPNetConfig"),
|
| 374 |
+
("mpt", "MptConfig"),
|
| 375 |
+
("mra", "MraConfig"),
|
| 376 |
+
("mt5", "MT5Config"),
|
| 377 |
+
("musicflamingo", "MusicFlamingoConfig"),
|
| 378 |
+
("musicgen", "MusicgenConfig"),
|
| 379 |
+
("musicgen_decoder", "MusicgenDecoderConfig"),
|
| 380 |
+
("musicgen_melody", "MusicgenMelodyConfig"),
|
| 381 |
+
("musicgen_melody_decoder", "MusicgenMelodyDecoderConfig"),
|
| 382 |
+
("mvp", "MvpConfig"),
|
| 383 |
+
("nanochat", "NanoChatConfig"),
|
| 384 |
+
("nemotron", "NemotronConfig"),
|
| 385 |
+
("nemotron_h", "NemotronHConfig"),
|
| 386 |
+
("nllb-moe", "NllbMoeConfig"),
|
| 387 |
+
("nomic_bert", "NomicBertConfig"),
|
| 388 |
+
("nougat", "NougatConfig"),
|
| 389 |
+
("nystromformer", "NystromformerConfig"),
|
| 390 |
+
("olmo", "OlmoConfig"),
|
| 391 |
+
("olmo2", "Olmo2Config"),
|
| 392 |
+
("olmo3", "Olmo3Config"),
|
| 393 |
+
("olmo_hybrid", "OlmoHybridConfig"),
|
| 394 |
+
("olmoe", "OlmoeConfig"),
|
| 395 |
+
("omdet-turbo", "OmDetTurboConfig"),
|
| 396 |
+
("oneformer", "OneFormerConfig"),
|
| 397 |
+
("openai-gpt", "OpenAIGPTConfig"),
|
| 398 |
+
("openai_privacy_filter", "OpenAIPrivacyFilterConfig"),
|
| 399 |
+
("opt", "OPTConfig"),
|
| 400 |
+
("ovis2", "Ovis2Config"),
|
| 401 |
+
("owlv2", "Owlv2Config"),
|
| 402 |
+
("owlv2_text_model", "Owlv2TextConfig"),
|
| 403 |
+
("owlv2_vision_model", "Owlv2VisionConfig"),
|
| 404 |
+
("owlvit", "OwlViTConfig"),
|
| 405 |
+
("owlvit_text_model", "OwlViTTextConfig"),
|
| 406 |
+
("owlvit_vision_model", "OwlViTVisionConfig"),
|
| 407 |
+
("paddleocr_vl", "PaddleOCRVLConfig"),
|
| 408 |
+
("paddleocr_vl_text", "PaddleOCRTextConfig"),
|
| 409 |
+
("paddleocr_vl_vision", "PaddleOCRVisionConfig"),
|
| 410 |
+
("paligemma", "PaliGemmaConfig"),
|
| 411 |
+
("parakeet_ctc", "ParakeetCTCConfig"),
|
| 412 |
+
("parakeet_encoder", "ParakeetEncoderConfig"),
|
| 413 |
+
("parakeet_tdt", "ParakeetTDTConfig"),
|
| 414 |
+
("patchtsmixer", "PatchTSMixerConfig"),
|
| 415 |
+
("patchtst", "PatchTSTConfig"),
|
| 416 |
+
("pe_audio", "PeAudioConfig"),
|
| 417 |
+
("pe_audio_encoder", "PeAudioEncoderConfig"),
|
| 418 |
+
("pe_audio_video", "PeAudioVideoConfig"),
|
| 419 |
+
("pe_audio_video_encoder", "PeAudioVideoEncoderConfig"),
|
| 420 |
+
("pe_video", "PeVideoConfig"),
|
| 421 |
+
("pe_video_encoder", "PeVideoEncoderConfig"),
|
| 422 |
+
("pegasus", "PegasusConfig"),
|
| 423 |
+
("pegasus_x", "PegasusXConfig"),
|
| 424 |
+
("perceiver", "PerceiverConfig"),
|
| 425 |
+
("perception_lm", "PerceptionLMConfig"),
|
| 426 |
+
("persimmon", "PersimmonConfig"),
|
| 427 |
+
("phi", "PhiConfig"),
|
| 428 |
+
("phi3", "Phi3Config"),
|
| 429 |
+
("phi4_multimodal", "Phi4MultimodalConfig"),
|
| 430 |
+
("phi4_multimodal_audio", "Phi4MultimodalAudioConfig"),
|
| 431 |
+
("phi4_multimodal_vision", "Phi4MultimodalVisionConfig"),
|
| 432 |
+
("phimoe", "PhimoeConfig"),
|
| 433 |
+
("pi0", "PI0Config"),
|
| 434 |
+
("pix2struct", "Pix2StructConfig"),
|
| 435 |
+
("pix2struct_text_model", "Pix2StructTextConfig"),
|
| 436 |
+
("pix2struct_vision_model", "Pix2StructVisionConfig"),
|
| 437 |
+
("pixio", "PixioConfig"),
|
| 438 |
+
("pixtral", "PixtralVisionConfig"),
|
| 439 |
+
("plbart", "PLBartConfig"),
|
| 440 |
+
("poolformer", "PoolFormerConfig"),
|
| 441 |
+
("pop2piano", "Pop2PianoConfig"),
|
| 442 |
+
("pp_chart2table", "PPChart2TableConfig"),
|
| 443 |
+
("pp_doclayout_v2", "PPDocLayoutV2Config"),
|
| 444 |
+
("pp_doclayout_v3", "PPDocLayoutV3Config"),
|
| 445 |
+
("pp_formulanet", "PPFormulaNetConfig"),
|
| 446 |
+
("pp_lcnet", "PPLCNetConfig"),
|
| 447 |
+
("pp_lcnet_v3", "PPLCNetV3Config"),
|
| 448 |
+
("pp_ocrv5_mobile_det", "PPOCRV5MobileDetConfig"),
|
| 449 |
+
("pp_ocrv5_mobile_rec", "PPOCRV5MobileRecConfig"),
|
| 450 |
+
("pp_ocrv5_server_det", "PPOCRV5ServerDetConfig"),
|
| 451 |
+
("pp_ocrv5_server_rec", "PPOCRV5ServerRecConfig"),
|
| 452 |
+
("prompt_depth_anything", "PromptDepthAnythingConfig"),
|
| 453 |
+
("prophetnet", "ProphetNetConfig"),
|
| 454 |
+
("pvt", "PvtConfig"),
|
| 455 |
+
("pvt_v2", "PvtV2Config"),
|
| 456 |
+
("qianfan_ocr", "QianfanOCRConfig"),
|
| 457 |
+
("qianfan_ocr_vision", "QianfanOCRVisionConfig"),
|
| 458 |
+
("qwen2", "Qwen2Config"),
|
| 459 |
+
("qwen2_5_omni", "Qwen2_5OmniConfig"),
|
| 460 |
+
("qwen2_5_omni_audio_encoder", "Qwen2_5OmniAudioEncoderConfig"),
|
| 461 |
+
("qwen2_5_omni_bigvgan", "Qwen2_5OmniBigVGANConfig"),
|
| 462 |
+
("qwen2_5_omni_dit", "Qwen2_5OmniDiTConfig"),
|
| 463 |
+
("qwen2_5_omni_talker", "Qwen2_5OmniTalkerConfig"),
|
| 464 |
+
("qwen2_5_omni_text", "Qwen2_5OmniTextConfig"),
|
| 465 |
+
("qwen2_5_omni_thinker", "Qwen2_5OmniThinkerConfig"),
|
| 466 |
+
("qwen2_5_omni_token2wav", "Qwen2_5OmniToken2WavConfig"),
|
| 467 |
+
("qwen2_5_omni_vision_encoder", "Qwen2_5OmniVisionEncoderConfig"),
|
| 468 |
+
("qwen2_5_vl", "Qwen2_5_VLConfig"),
|
| 469 |
+
("qwen2_5_vl_text", "Qwen2_5_VLTextConfig"),
|
| 470 |
+
("qwen2_5_vl_vision", "Qwen2_5_VLVisionConfig"),
|
| 471 |
+
("qwen2_audio", "Qwen2AudioConfig"),
|
| 472 |
+
("qwen2_audio_encoder", "Qwen2AudioEncoderConfig"),
|
| 473 |
+
("qwen2_moe", "Qwen2MoeConfig"),
|
| 474 |
+
("qwen2_vl", "Qwen2VLConfig"),
|
| 475 |
+
("qwen2_vl_text", "Qwen2VLTextConfig"),
|
| 476 |
+
("qwen2_vl_vision", "Qwen2VLVisionConfig"),
|
| 477 |
+
("qwen3", "Qwen3Config"),
|
| 478 |
+
("qwen3_5", "Qwen3_5Config"),
|
| 479 |
+
("qwen3_5_moe", "Qwen3_5MoeConfig"),
|
| 480 |
+
("qwen3_5_moe_text", "Qwen3_5MoeTextConfig"),
|
| 481 |
+
("qwen3_5_moe_vision", "Qwen3_5MoeVisionConfig"),
|
| 482 |
+
("qwen3_5_text", "Qwen3_5TextConfig"),
|
| 483 |
+
("qwen3_5_vision", "Qwen3_5VisionConfig"),
|
| 484 |
+
("qwen3_moe", "Qwen3MoeConfig"),
|
| 485 |
+
("qwen3_next", "Qwen3NextConfig"),
|
| 486 |
+
("qwen3_omni_moe", "Qwen3OmniMoeConfig"),
|
| 487 |
+
("qwen3_omni_moe_audio_encoder", "Qwen3OmniMoeAudioEncoderConfig"),
|
| 488 |
+
("qwen3_omni_moe_talker_code_predictor", "Qwen3OmniMoeTalkerCodePredictorConfig"),
|
| 489 |
+
("qwen3_omni_moe_talker_text", "Qwen3OmniMoeTalkerTextConfig"),
|
| 490 |
+
("qwen3_omni_moe_text", "Qwen3OmniMoeTextConfig"),
|
| 491 |
+
("qwen3_omni_moe_thinker", "Qwen3OmniMoeThinkerConfig"),
|
| 492 |
+
("qwen3_omni_moe_vision_encoder", "Qwen3OmniMoeVisionEncoderConfig"),
|
| 493 |
+
("qwen3_vl", "Qwen3VLConfig"),
|
| 494 |
+
("qwen3_vl_moe", "Qwen3VLMoeConfig"),
|
| 495 |
+
("qwen3_vl_moe_text", "Qwen3VLMoeTextConfig"),
|
| 496 |
+
("qwen3_vl_moe_vision", "Qwen3VLMoeVisionConfig"),
|
| 497 |
+
("qwen3_vl_text", "Qwen3VLTextConfig"),
|
| 498 |
+
("qwen3_vl_vision", "Qwen3VLVisionConfig"),
|
| 499 |
+
("rag", "RagConfig"),
|
| 500 |
+
("recurrent_gemma", "RecurrentGemmaConfig"),
|
| 501 |
+
("reformer", "ReformerConfig"),
|
| 502 |
+
("regnet", "RegNetConfig"),
|
| 503 |
+
("rembert", "RemBertConfig"),
|
| 504 |
+
("resnet", "ResNetConfig"),
|
| 505 |
+
("rf_detr", "RfDetrConfig"),
|
| 506 |
+
("rf_detr_dinov2", "RfDetrDinov2Config"),
|
| 507 |
+
("roberta", "RobertaConfig"),
|
| 508 |
+
("roberta-prelayernorm", "RobertaPreLayerNormConfig"),
|
| 509 |
+
("roc_bert", "RoCBertConfig"),
|
| 510 |
+
("roformer", "RoFormerConfig"),
|
| 511 |
+
("rt_detr", "RTDetrConfig"),
|
| 512 |
+
("rt_detr_resnet", "RTDetrResNetConfig"),
|
| 513 |
+
("rt_detr_v2", "RTDetrV2Config"),
|
| 514 |
+
("rwkv", "RwkvConfig"),
|
| 515 |
+
("sam", "SamConfig"),
|
| 516 |
+
("sam2", "Sam2Config"),
|
| 517 |
+
("sam2_hiera_det_model", "Sam2HieraDetConfig"),
|
| 518 |
+
("sam2_video", "Sam2VideoConfig"),
|
| 519 |
+
("sam2_vision_model", "Sam2VisionConfig"),
|
| 520 |
+
("sam3", "Sam3Config"),
|
| 521 |
+
("sam3_detr_decoder", "Sam3DETRDecoderConfig"),
|
| 522 |
+
("sam3_detr_encoder", "Sam3DETREncoderConfig"),
|
| 523 |
+
("sam3_geometry_encoder", "Sam3GeometryEncoderConfig"),
|
| 524 |
+
("sam3_lite_text", "Sam3LiteTextConfig"),
|
| 525 |
+
("sam3_lite_text_detr_decoder", "Sam3LiteTextDETRDecoderConfig"),
|
| 526 |
+
("sam3_lite_text_detr_encoder", "Sam3LiteTextDETREncoderConfig"),
|
| 527 |
+
("sam3_lite_text_geometry_encoder", "Sam3LiteTextGeometryEncoderConfig"),
|
| 528 |
+
("sam3_lite_text_mask_decoder", "Sam3LiteTextMaskDecoderConfig"),
|
| 529 |
+
("sam3_lite_text_text_model", "Sam3LiteTextTextConfig"),
|
| 530 |
+
("sam3_mask_decoder", "Sam3MaskDecoderConfig"),
|
| 531 |
+
("sam3_tracker", "Sam3TrackerConfig"),
|
| 532 |
+
("sam3_tracker_video", "Sam3TrackerVideoConfig"),
|
| 533 |
+
("sam3_video", "Sam3VideoConfig"),
|
| 534 |
+
("sam3_vision_model", "Sam3VisionConfig"),
|
| 535 |
+
("sam3_vit_model", "Sam3ViTConfig"),
|
| 536 |
+
("sam_hq", "SamHQConfig"),
|
| 537 |
+
("sam_hq_vision_model", "SamHQVisionConfig"),
|
| 538 |
+
("sam_vision_model", "SamVisionConfig"),
|
| 539 |
+
("seamless_m4t", "SeamlessM4TConfig"),
|
| 540 |
+
("seamless_m4t_v2", "SeamlessM4Tv2Config"),
|
| 541 |
+
("seed_oss", "SeedOssConfig"),
|
| 542 |
+
("segformer", "SegformerConfig"),
|
| 543 |
+
("seggpt", "SegGptConfig"),
|
| 544 |
+
("sew", "SEWConfig"),
|
| 545 |
+
("sew-d", "SEWDConfig"),
|
| 546 |
+
("shieldgemma2", "ShieldGemma2Config"),
|
| 547 |
+
("siglip", "SiglipConfig"),
|
| 548 |
+
("siglip2", "Siglip2Config"),
|
| 549 |
+
("siglip2_text_model", "Siglip2TextConfig"),
|
| 550 |
+
("siglip2_vision_model", "Siglip2VisionConfig"),
|
| 551 |
+
("siglip_text_model", "SiglipTextConfig"),
|
| 552 |
+
("siglip_vision_model", "SiglipVisionConfig"),
|
| 553 |
+
("slanet", "SLANetConfig"),
|
| 554 |
+
("slanext", "SLANeXtConfig"),
|
| 555 |
+
("smollm3", "SmolLM3Config"),
|
| 556 |
+
("smolvlm", "SmolVLMConfig"),
|
| 557 |
+
("smolvlm_vision", "SmolVLMVisionConfig"),
|
| 558 |
+
("solar_open", "SolarOpenConfig"),
|
| 559 |
+
("speech-encoder-decoder", "SpeechEncoderDecoderConfig"),
|
| 560 |
+
("speech_to_text", "Speech2TextConfig"),
|
| 561 |
+
("speecht5", "SpeechT5Config"),
|
| 562 |
+
("speecht5_hifigan", "SpeechT5HifiGanConfig"),
|
| 563 |
+
("splinter", "SplinterConfig"),
|
| 564 |
+
("squeezebert", "SqueezeBertConfig"),
|
| 565 |
+
("stablelm", "StableLmConfig"),
|
| 566 |
+
("starcoder2", "Starcoder2Config"),
|
| 567 |
+
("superglue", "SuperGlueConfig"),
|
| 568 |
+
("superpoint", "SuperPointConfig"),
|
| 569 |
+
("swiftformer", "SwiftFormerConfig"),
|
| 570 |
+
("swin", "SwinConfig"),
|
| 571 |
+
("swin2sr", "Swin2SRConfig"),
|
| 572 |
+
("swinv2", "Swinv2Config"),
|
| 573 |
+
("switch_transformers", "SwitchTransformersConfig"),
|
| 574 |
+
("t5", "T5Config"),
|
| 575 |
+
("t5_gemma_module", "T5GemmaModuleConfig"),
|
| 576 |
+
("t5gemma", "T5GemmaConfig"),
|
| 577 |
+
("t5gemma2", "T5Gemma2Config"),
|
| 578 |
+
("t5gemma2_decoder", "T5Gemma2DecoderConfig"),
|
| 579 |
+
("t5gemma2_encoder", "T5Gemma2EncoderConfig"),
|
| 580 |
+
("t5gemma2_text", "T5Gemma2TextConfig"),
|
| 581 |
+
("table-transformer", "TableTransformerConfig"),
|
| 582 |
+
("tapas", "TapasConfig"),
|
| 583 |
+
("textnet", "TextNetConfig"),
|
| 584 |
+
("time_series_transformer", "TimeSeriesTransformerConfig"),
|
| 585 |
+
("timesfm", "TimesFmConfig"),
|
| 586 |
+
("timesfm2_5", "TimesFm2_5Config"),
|
| 587 |
+
("timesformer", "TimesformerConfig"),
|
| 588 |
+
("timm_backbone", "TimmBackboneConfig"),
|
| 589 |
+
("timm_wrapper", "TimmWrapperConfig"),
|
| 590 |
+
("trocr", "TrOCRConfig"),
|
| 591 |
+
("tvp", "TvpConfig"),
|
| 592 |
+
("udop", "UdopConfig"),
|
| 593 |
+
("umt5", "UMT5Config"),
|
| 594 |
+
("unispeech", "UniSpeechConfig"),
|
| 595 |
+
("unispeech-sat", "UniSpeechSatConfig"),
|
| 596 |
+
("univnet", "UnivNetConfig"),
|
| 597 |
+
("upernet", "UperNetConfig"),
|
| 598 |
+
("uvdoc", "UVDocConfig"),
|
| 599 |
+
("uvdoc_backbone", "UVDocBackboneConfig"),
|
| 600 |
+
("vaultgemma", "VaultGemmaConfig"),
|
| 601 |
+
("vibevoice_acoustic_tokenizer", "VibeVoiceAcousticTokenizerConfig"),
|
| 602 |
+
("vibevoice_asr", "VibeVoiceAsrConfig"),
|
| 603 |
+
("video_llama_3", "VideoLlama3Config"),
|
| 604 |
+
("video_llama_3_vision", "VideoLlama3VisionConfig"),
|
| 605 |
+
("video_llava", "VideoLlavaConfig"),
|
| 606 |
+
("videomae", "VideoMAEConfig"),
|
| 607 |
+
("videomt", "VideomtConfig"),
|
| 608 |
+
("vilt", "ViltConfig"),
|
| 609 |
+
("vipllava", "VipLlavaConfig"),
|
| 610 |
+
("vision-encoder-decoder", "VisionEncoderDecoderConfig"),
|
| 611 |
+
("vision-text-dual-encoder", "VisionTextDualEncoderConfig"),
|
| 612 |
+
("visual_bert", "VisualBertConfig"),
|
| 613 |
+
("vit", "ViTConfig"),
|
| 614 |
+
("vit_mae", "ViTMAEConfig"),
|
| 615 |
+
("vit_msn", "ViTMSNConfig"),
|
| 616 |
+
("vitdet", "VitDetConfig"),
|
| 617 |
+
("vitmatte", "VitMatteConfig"),
|
| 618 |
+
("vitpose", "VitPoseConfig"),
|
| 619 |
+
("vitpose_backbone", "VitPoseBackboneConfig"),
|
| 620 |
+
("vits", "VitsConfig"),
|
| 621 |
+
("vivit", "VivitConfig"),
|
| 622 |
+
("vjepa2", "VJEPA2Config"),
|
| 623 |
+
("voxtral", "VoxtralConfig"),
|
| 624 |
+
("voxtral_encoder", "VoxtralEncoderConfig"),
|
| 625 |
+
("voxtral_realtime", "VoxtralRealtimeConfig"),
|
| 626 |
+
("voxtral_realtime_encoder", "VoxtralRealtimeEncoderConfig"),
|
| 627 |
+
("voxtral_realtime_text", "VoxtralRealtimeTextConfig"),
|
| 628 |
+
("wav2vec2", "Wav2Vec2Config"),
|
| 629 |
+
("wav2vec2-bert", "Wav2Vec2BertConfig"),
|
| 630 |
+
("wav2vec2-conformer", "Wav2Vec2ConformerConfig"),
|
| 631 |
+
("wavlm", "WavLMConfig"),
|
| 632 |
+
("whisper", "WhisperConfig"),
|
| 633 |
+
("xclip", "XCLIPConfig"),
|
| 634 |
+
("xclip_text_model", "XCLIPTextConfig"),
|
| 635 |
+
("xclip_vision_model", "XCLIPVisionConfig"),
|
| 636 |
+
("xcodec", "XcodecConfig"),
|
| 637 |
+
("xglm", "XGLMConfig"),
|
| 638 |
+
("xlm", "XLMConfig"),
|
| 639 |
+
("xlm-roberta", "XLMRobertaConfig"),
|
| 640 |
+
("xlm-roberta-xl", "XLMRobertaXLConfig"),
|
| 641 |
+
("xlnet", "XLNetConfig"),
|
| 642 |
+
("xlstm", "xLSTMConfig"),
|
| 643 |
+
("xmod", "XmodConfig"),
|
| 644 |
+
("yolos", "YolosConfig"),
|
| 645 |
+
("yoso", "YosoConfig"),
|
| 646 |
+
("youtu", "YoutuConfig"),
|
| 647 |
+
("zamba", "ZambaConfig"),
|
| 648 |
+
("zamba2", "Zamba2Config"),
|
| 649 |
+
("zoedepth", "ZoeDepthConfig"),
|
| 650 |
+
]
|
| 651 |
+
)
|
| 652 |
+
|
| 653 |
+
SPECIAL_MODEL_TYPE_TO_MODULE_NAME = OrderedDict(
|
| 654 |
+
[
|
| 655 |
+
("aimv2_text_model", "aimv2"),
|
| 656 |
+
("aimv2_vision_model", "aimv2"),
|
| 657 |
+
("align_text_model", "align"),
|
| 658 |
+
("align_vision_model", "align"),
|
| 659 |
+
("altclip_text_model", "altclip"),
|
| 660 |
+
("altclip_vision_model", "altclip"),
|
| 661 |
+
("aria_text", "aria"),
|
| 662 |
+
("audio-spectrogram-transformer", "audio_spectrogram_transformer"),
|
| 663 |
+
("audioflamingo3_encoder", "audioflamingo3"),
|
| 664 |
+
("bert-generation", "bert_generation"),
|
| 665 |
+
("blenderbot-small", "blenderbot_small"),
|
| 666 |
+
("blip-2", "blip_2"),
|
| 667 |
+
("blip_2_qformer", "blip_2"),
|
| 668 |
+
("blip_2_vision_model", "blip_2"),
|
| 669 |
+
("blip_text_model", "blip"),
|
| 670 |
+
("blip_vision_model", "blip"),
|
| 671 |
+
("blt_global_transformer", "blt"),
|
| 672 |
+
("blt_local_decoder", "blt"),
|
| 673 |
+
("blt_local_encoder", "blt"),
|
| 674 |
+
("blt_patcher", "blt"),
|
| 675 |
+
("bridgetower_text_model", "bridgetower"),
|
| 676 |
+
("bridgetower_vision_model", "bridgetower"),
|
| 677 |
+
("chameleon_vqgan", "chameleon"),
|
| 678 |
+
("chinese_clip_text_model", "chinese_clip"),
|
| 679 |
+
("chinese_clip_vision_model", "chinese_clip"),
|
| 680 |
+
("clap_audio_model", "clap"),
|
| 681 |
+
("clap_text_model", "clap"),
|
| 682 |
+
("clip_text_model", "clip"),
|
| 683 |
+
("clip_vision_model", "clip"),
|
| 684 |
+
("clipseg_text_model", "clipseg"),
|
| 685 |
+
("clipseg_vision_model", "clipseg"),
|
| 686 |
+
("clvp_decoder", "clvp"),
|
| 687 |
+
("clvp_encoder", "clvp"),
|
| 688 |
+
("csm_depth_decoder_model", "csm"),
|
| 689 |
+
("dab-detr", "dab_detr"),
|
| 690 |
+
("data2vec-audio", "data2vec"),
|
| 691 |
+
("data2vec-text", "data2vec"),
|
| 692 |
+
("data2vec-vision", "data2vec"),
|
| 693 |
+
("deberta-v2", "deberta_v2"),
|
| 694 |
+
("dia_decoder", "dia"),
|
| 695 |
+
("dia_encoder", "dia"),
|
| 696 |
+
("donut-swin", "donut"),
|
| 697 |
+
("edgetam_vision_model", "edgetam"),
|
| 698 |
+
("emu3_text_model", "emu3"),
|
| 699 |
+
("emu3_vqgan", "emu3"),
|
| 700 |
+
("encoder-decoder", "encoder_decoder"),
|
| 701 |
+
("ernie4_5_vl_moe_text", "ernie4_5_vl_moe"),
|
| 702 |
+
("ernie4_5_vl_moe_vision", "ernie4_5_vl_moe"),
|
| 703 |
+
("exaone4_5_vision", "exaone4_5"),
|
| 704 |
+
("fastspeech2_conformer_hifigan", "fastspeech2_conformer"),
|
| 705 |
+
("fastspeech2_conformer_with_hifigan", "fastspeech2_conformer"),
|
| 706 |
+
("flava_image_model", "flava"),
|
| 707 |
+
("flava_multimodal_model", "flava"),
|
| 708 |
+
("flava_text_model", "flava"),
|
| 709 |
+
("florence_vision", "florence2"),
|
| 710 |
+
("gemma3_text", "gemma3"),
|
| 711 |
+
("gemma3n_audio", "gemma3n"),
|
| 712 |
+
("gemma3n_text", "gemma3n"),
|
| 713 |
+
("gemma3n_vision", "gemma3n"),
|
| 714 |
+
("gemma4_audio", "gemma4"),
|
| 715 |
+
("gemma4_text", "gemma4"),
|
| 716 |
+
("gemma4_vision", "gemma4"),
|
| 717 |
+
("git_vision_model", "git"),
|
| 718 |
+
("glm4v_moe_text", "glm4v_moe"),
|
| 719 |
+
("glm4v_moe_vision", "glm4v_moe"),
|
| 720 |
+
("glm4v_text", "glm4v"),
|
| 721 |
+
("glm4v_vision", "glm4v"),
|
| 722 |
+
("glm_image_text", "glm_image"),
|
| 723 |
+
("glm_image_vision", "glm_image"),
|
| 724 |
+
("glm_image_vqmodel", "glm_image"),
|
| 725 |
+
("glm_ocr_text", "glm_ocr"),
|
| 726 |
+
("glm_ocr_vision", "glm_ocr"),
|
| 727 |
+
("glmasr_encoder", "glmasr"),
|
| 728 |
+
("granite4_vision_text", "granite4_vision"),
|
| 729 |
+
("granite_speech_encoder", "granite_speech"),
|
| 730 |
+
("granite_speech_plus_encoder", "granite_speech_plus"),
|
| 731 |
+
("grounding-dino", "grounding_dino"),
|
| 732 |
+
("groupvit_text_model", "groupvit"),
|
| 733 |
+
("groupvit_vision_model", "groupvit"),
|
| 734 |
+
("idefics2_perceiver", "idefics2"),
|
| 735 |
+
("idefics2_vision", "idefics2"),
|
| 736 |
+
("idefics3_vision", "idefics3"),
|
| 737 |
+
("idefics_perciever", "idefics"),
|
| 738 |
+
("idefics_vision", "idefics"),
|
| 739 |
+
("instructblip_qformer", "instructblip"),
|
| 740 |
+
("instructblip_vision_model", "instructblip"),
|
| 741 |
+
("instructblipvideo_qformer", "instructblipvideo"),
|
| 742 |
+
("instructblipvideo_vision_model", "instructblipvideo"),
|
| 743 |
+
("internvl_vision", "internvl"),
|
| 744 |
+
("janus_vision_model", "janus"),
|
| 745 |
+
("janus_vqgan", "janus"),
|
| 746 |
+
("kosmos-2", "kosmos2"),
|
| 747 |
+
("kosmos-2.5", "kosmos2_5"),
|
| 748 |
+
("kosmos_2_5_text_model", "kosmos2_5"),
|
| 749 |
+
("kosmos_2_5_vision_model", "kosmos2_5"),
|
| 750 |
+
("kosmos_2_text_model", "kosmos2"),
|
| 751 |
+
("kosmos_2_vision_model", "kosmos2"),
|
| 752 |
+
("lasr_ctc", "lasr"),
|
| 753 |
+
("lasr_encoder", "lasr"),
|
| 754 |
+
("llama4_text", "llama4"),
|
| 755 |
+
("llama4_vision_model", "llama4"),
|
| 756 |
+
("lw_detr_vit", "lw_detr"),
|
| 757 |
+
("maskformer-swin", "maskformer"),
|
| 758 |
+
("megatron-bert", "megatron_bert"),
|
| 759 |
+
("metaclip_2_text_model", "metaclip_2"),
|
| 760 |
+
("metaclip_2_vision_model", "metaclip_2"),
|
| 761 |
+
("mgp-str", "mgp_str"),
|
| 762 |
+
("minicpmv4_6_vision", "minicpmv4_6"),
|
| 763 |
+
("mlcd_vision_model", "mlcd"),
|
| 764 |
+
("mllama_text_model", "mllama"),
|
| 765 |
+
("mllama_vision_model", "mllama"),
|
| 766 |
+
("mm-grounding-dino", "mm_grounding_dino"),
|
| 767 |
+
("modernbert-decoder", "modernbert_decoder"),
|
| 768 |
+
("moonshine_streaming_encoder", "moonshine_streaming"),
|
| 769 |
+
("moshi_depth", "moshi"),
|
| 770 |
+
("musicgen_decoder", "musicgen"),
|
| 771 |
+
("musicgen_melody_decoder", "musicgen_melody"),
|
| 772 |
+
("nllb-moe", "nllb_moe"),
|
| 773 |
+
("omdet-turbo", "omdet_turbo"),
|
| 774 |
+
("openai-gpt", "openai"),
|
| 775 |
+
("owlv2_text_model", "owlv2"),
|
| 776 |
+
("owlv2_vision_model", "owlv2"),
|
| 777 |
+
("owlvit_text_model", "owlvit"),
|
| 778 |
+
("owlvit_vision_model", "owlvit"),
|
| 779 |
+
("paddleocr_vl_text", "paddleocr_vl"),
|
| 780 |
+
("paddleocr_vl_vision", "paddleocr_vl"),
|
| 781 |
+
("parakeet_ctc", "parakeet"),
|
| 782 |
+
("parakeet_encoder", "parakeet"),
|
| 783 |
+
("parakeet_tdt", "parakeet"),
|
| 784 |
+
("pe_audio_encoder", "pe_audio"),
|
| 785 |
+
("pe_audio_video_encoder", "pe_audio_video"),
|
| 786 |
+
("pe_video_encoder", "pe_video"),
|
| 787 |
+
("phi4_multimodal_audio", "phi4_multimodal"),
|
| 788 |
+
("phi4_multimodal_vision", "phi4_multimodal"),
|
| 789 |
+
("pix2struct_text_model", "pix2struct"),
|
| 790 |
+
("pix2struct_vision_model", "pix2struct"),
|
| 791 |
+
("qianfan_ocr_vision", "qianfan_ocr"),
|
| 792 |
+
("qwen2_5_omni_audio_encoder", "qwen2_5_omni"),
|
| 793 |
+
("qwen2_5_omni_bigvgan", "qwen2_5_omni"),
|
| 794 |
+
("qwen2_5_omni_dit", "qwen2_5_omni"),
|
| 795 |
+
("qwen2_5_omni_talker", "qwen2_5_omni"),
|
| 796 |
+
("qwen2_5_omni_text", "qwen2_5_omni"),
|
| 797 |
+
("qwen2_5_omni_thinker", "qwen2_5_omni"),
|
| 798 |
+
("qwen2_5_omni_token2wav", "qwen2_5_omni"),
|
| 799 |
+
("qwen2_5_omni_vision_encoder", "qwen2_5_omni"),
|
| 800 |
+
("qwen2_5_vl_text", "qwen2_5_vl"),
|
| 801 |
+
("qwen2_5_vl_vision", "qwen2_5_vl"),
|
| 802 |
+
("qwen2_audio_encoder", "qwen2_audio"),
|
| 803 |
+
("qwen2_vl_text", "qwen2_vl"),
|
| 804 |
+
("qwen2_vl_vision", "qwen2_vl"),
|
| 805 |
+
("qwen3_5_moe_text", "qwen3_5_moe"),
|
| 806 |
+
("qwen3_5_moe_vision", "qwen3_5_moe"),
|
| 807 |
+
("qwen3_5_text", "qwen3_5"),
|
| 808 |
+
("qwen3_5_vision", "qwen3_5"),
|
| 809 |
+
("qwen3_omni_moe_audio_encoder", "qwen3_omni_moe"),
|
| 810 |
+
("qwen3_omni_moe_talker_code_predictor", "qwen3_omni_moe"),
|
| 811 |
+
("qwen3_omni_moe_talker_text", "qwen3_omni_moe"),
|
| 812 |
+
("qwen3_omni_moe_text", "qwen3_omni_moe"),
|
| 813 |
+
("qwen3_omni_moe_thinker", "qwen3_omni_moe"),
|
| 814 |
+
("qwen3_omni_moe_vision_encoder", "qwen3_omni_moe"),
|
| 815 |
+
("qwen3_vl_moe_text", "qwen3_vl_moe"),
|
| 816 |
+
("qwen3_vl_moe_vision", "qwen3_vl_moe"),
|
| 817 |
+
("qwen3_vl_text", "qwen3_vl"),
|
| 818 |
+
("qwen3_vl_vision", "qwen3_vl"),
|
| 819 |
+
("rf_detr_dinov2", "rf_detr"),
|
| 820 |
+
("roberta-prelayernorm", "roberta_prelayernorm"),
|
| 821 |
+
("rt_detr_resnet", "rt_detr"),
|
| 822 |
+
("sam2_hiera_det_model", "sam2"),
|
| 823 |
+
("sam2_vision_model", "sam2"),
|
| 824 |
+
("sam3_detr_decoder", "sam3"),
|
| 825 |
+
("sam3_detr_encoder", "sam3"),
|
| 826 |
+
("sam3_geometry_encoder", "sam3"),
|
| 827 |
+
("sam3_lite_text_detr_decoder", "sam3_lite_text"),
|
| 828 |
+
("sam3_lite_text_detr_encoder", "sam3_lite_text"),
|
| 829 |
+
("sam3_lite_text_geometry_encoder", "sam3_lite_text"),
|
| 830 |
+
("sam3_lite_text_mask_decoder", "sam3_lite_text"),
|
| 831 |
+
("sam3_lite_text_text_model", "sam3_lite_text"),
|
| 832 |
+
("sam3_mask_decoder", "sam3"),
|
| 833 |
+
("sam3_vision_model", "sam3"),
|
| 834 |
+
("sam3_vit_model", "sam3"),
|
| 835 |
+
("sam_hq_vision_model", "sam_hq"),
|
| 836 |
+
("sam_vision_model", "sam"),
|
| 837 |
+
("sew-d", "sew_d"),
|
| 838 |
+
("siglip2_text_model", "siglip2"),
|
| 839 |
+
("siglip2_vision_model", "siglip2"),
|
| 840 |
+
("siglip_text_model", "siglip"),
|
| 841 |
+
("siglip_vision_model", "siglip"),
|
| 842 |
+
("smolvlm_vision", "smolvlm"),
|
| 843 |
+
("speech-encoder-decoder", "speech_encoder_decoder"),
|
| 844 |
+
("speecht5_hifigan", "speecht5"),
|
| 845 |
+
("t5_gemma_module", "t5gemma"),
|
| 846 |
+
("t5gemma2_decoder", "t5gemma2"),
|
| 847 |
+
("t5gemma2_encoder", "t5gemma2"),
|
| 848 |
+
("t5gemma2_text", "t5gemma2"),
|
| 849 |
+
("table-transformer", "table_transformer"),
|
| 850 |
+
("unispeech-sat", "unispeech_sat"),
|
| 851 |
+
("uvdoc_backbone", "uvdoc"),
|
| 852 |
+
("video_llama_3_vision", "video_llama_3"),
|
| 853 |
+
("vision-encoder-decoder", "vision_encoder_decoder"),
|
| 854 |
+
("vision-text-dual-encoder", "vision_text_dual_encoder"),
|
| 855 |
+
("voxtral_encoder", "voxtral"),
|
| 856 |
+
("voxtral_realtime_encoder", "voxtral_realtime"),
|
| 857 |
+
("voxtral_realtime_text", "voxtral_realtime"),
|
| 858 |
+
("wav2vec2-bert", "wav2vec2_bert"),
|
| 859 |
+
("wav2vec2-conformer", "wav2vec2_conformer"),
|
| 860 |
+
("xclip", "x_clip"),
|
| 861 |
+
("xclip_text_model", "x_clip"),
|
| 862 |
+
("xclip_vision_model", "x_clip"),
|
| 863 |
+
("xlm-roberta", "xlm_roberta"),
|
| 864 |
+
("xlm-roberta-xl", "xlm_roberta_xl"),
|
| 865 |
+
]
|
| 866 |
+
)
|
| 867 |
+
|
| 868 |
+
IMAGE_PROCESSOR_MAPPING_NAMES = OrderedDict(
|
| 869 |
+
[
|
| 870 |
+
("aria", {"pil": "AriaImageProcessorPil", "torchvision": "AriaImageProcessor"}),
|
| 871 |
+
("beit", {"pil": "BeitImageProcessorPil", "torchvision": "BeitImageProcessor"}),
|
| 872 |
+
("bit", {"pil": "BitImageProcessorPil", "torchvision": "BitImageProcessor"}),
|
| 873 |
+
("blip", {"pil": "BlipImageProcessorPil", "torchvision": "BlipImageProcessor"}),
|
| 874 |
+
("bridgetower", {"pil": "BridgeTowerImageProcessorPil", "torchvision": "BridgeTowerImageProcessor"}),
|
| 875 |
+
("chameleon", {"pil": "ChameleonImageProcessorPil", "torchvision": "ChameleonImageProcessor"}),
|
| 876 |
+
("chinese_clip", {"pil": "ChineseCLIPImageProcessorPil", "torchvision": "ChineseCLIPImageProcessor"}),
|
| 877 |
+
("chmv2", {"torchvision": "CHMv2ImageProcessor"}),
|
| 878 |
+
("clip", {"pil": "CLIPImageProcessorPil", "torchvision": "CLIPImageProcessor"}),
|
| 879 |
+
("cohere2_vision", {"torchvision": "Cohere2VisionImageProcessor"}),
|
| 880 |
+
(
|
| 881 |
+
"conditional_detr",
|
| 882 |
+
{"pil": "ConditionalDetrImageProcessorPil", "torchvision": "ConditionalDetrImageProcessor"},
|
| 883 |
+
),
|
| 884 |
+
("convnext", {"pil": "ConvNextImageProcessorPil", "torchvision": "ConvNextImageProcessor"}),
|
| 885 |
+
("deepseek_vl", {"pil": "DeepseekVLImageProcessorPil", "torchvision": "DeepseekVLImageProcessor"}),
|
| 886 |
+
(
|
| 887 |
+
"deepseek_vl_hybrid",
|
| 888 |
+
{"pil": "DeepseekVLHybridImageProcessorPil", "torchvision": "DeepseekVLHybridImageProcessor"},
|
| 889 |
+
),
|
| 890 |
+
("deformable_detr", {"pil": "DeformableDetrImageProcessorPil", "torchvision": "DeformableDetrImageProcessor"}),
|
| 891 |
+
("deit", {"pil": "DeiTImageProcessorPil", "torchvision": "DeiTImageProcessor"}),
|
| 892 |
+
("depth_pro", {"torchvision": "DepthProImageProcessor"}),
|
| 893 |
+
("detr", {"pil": "DetrImageProcessorPil", "torchvision": "DetrImageProcessor"}),
|
| 894 |
+
("dinov3_vit", {"torchvision": "DINOv3ViTImageProcessor"}),
|
| 895 |
+
("dpt", {"pil": "DPTImageProcessorPil", "torchvision": "DPTImageProcessor"}),
|
| 896 |
+
("efficientloftr", {"pil": "EfficientLoFTRImageProcessorPil", "torchvision": "EfficientLoFTRImageProcessor"}),
|
| 897 |
+
("efficientnet", {"pil": "EfficientNetImageProcessorPil", "torchvision": "EfficientNetImageProcessor"}),
|
| 898 |
+
("eomt", {"pil": "EomtImageProcessorPil", "torchvision": "EomtImageProcessor"}),
|
| 899 |
+
("ernie4_5_vl_moe", {"pil": "Ernie4_5_VLMoeImageProcessorPil", "torchvision": "Ernie4_5_VLMoeImageProcessor"}),
|
| 900 |
+
("flava", {"pil": "FlavaImageProcessorPil", "torchvision": "FlavaImageProcessor"}),
|
| 901 |
+
("fuyu", {"pil": "FuyuImageProcessorPil", "torchvision": "FuyuImageProcessor"}),
|
| 902 |
+
("gemma3", {"pil": "Gemma3ImageProcessorPil", "torchvision": "Gemma3ImageProcessor"}),
|
| 903 |
+
("gemma4", {"pil": "Gemma4ImageProcessorPil", "torchvision": "Gemma4ImageProcessor"}),
|
| 904 |
+
("glm46v", {"pil": "Glm46VImageProcessorPil", "torchvision": "Glm46VImageProcessor"}),
|
| 905 |
+
("glm4v", {"pil": "Glm4vImageProcessorPil", "torchvision": "Glm4vImageProcessor"}),
|
| 906 |
+
("glm_image", {"pil": "GlmImageImageProcessorPil", "torchvision": "GlmImageImageProcessor"}),
|
| 907 |
+
("glpn", {"pil": "GLPNImageProcessorPil", "torchvision": "GLPNImageProcessor"}),
|
| 908 |
+
("got_ocr2", {"pil": "GotOcr2ImageProcessorPil", "torchvision": "GotOcr2ImageProcessor"}),
|
| 909 |
+
("grounding-dino", {"pil": "GroundingDinoImageProcessorPil", "torchvision": "GroundingDinoImageProcessor"}),
|
| 910 |
+
("idefics", {"pil": "IdeficsImageProcessorPil", "torchvision": "IdeficsImageProcessor"}),
|
| 911 |
+
("idefics2", {"pil": "Idefics2ImageProcessorPil", "torchvision": "Idefics2ImageProcessor"}),
|
| 912 |
+
("idefics3", {"pil": "Idefics3ImageProcessorPil", "torchvision": "Idefics3ImageProcessor"}),
|
| 913 |
+
("imagegpt", {"pil": "ImageGPTImageProcessorPil", "torchvision": "ImageGPTImageProcessor"}),
|
| 914 |
+
("janus", {"pil": "JanusImageProcessorPil", "torchvision": "JanusImageProcessor"}),
|
| 915 |
+
("layoutlmv2", {"pil": "LayoutLMv2ImageProcessorPil", "torchvision": "LayoutLMv2ImageProcessor"}),
|
| 916 |
+
("layoutlmv3", {"pil": "LayoutLMv3ImageProcessorPil", "torchvision": "LayoutLMv3ImageProcessor"}),
|
| 917 |
+
("levit", {"pil": "LevitImageProcessorPil", "torchvision": "LevitImageProcessor"}),
|
| 918 |
+
("lfm2_vl", {"torchvision": "Lfm2VlImageProcessor"}),
|
| 919 |
+
("lightglue", {"pil": "LightGlueImageProcessorPil", "torchvision": "LightGlueImageProcessor"}),
|
| 920 |
+
("llama4", {"torchvision": "Llama4ImageProcessor"}),
|
| 921 |
+
("llava", {"pil": "LlavaImageProcessorPil", "torchvision": "LlavaImageProcessor"}),
|
| 922 |
+
("llava_next", {"pil": "LlavaNextImageProcessorPil", "torchvision": "LlavaNextImageProcessor"}),
|
| 923 |
+
("llava_onevision", {"pil": "LlavaOnevisionImageProcessorPil", "torchvision": "LlavaOnevisionImageProcessor"}),
|
| 924 |
+
("mask2former", {"pil": "Mask2FormerImageProcessorPil", "torchvision": "Mask2FormerImageProcessor"}),
|
| 925 |
+
("maskformer", {"pil": "MaskFormerImageProcessorPil", "torchvision": "MaskFormerImageProcessor"}),
|
| 926 |
+
("minicpmv4_6", {"pil": "MiniCPMV4_6ImageProcessorPil", "torchvision": "MiniCPMV4_6ImageProcessor"}),
|
| 927 |
+
("mllama", {"pil": "MllamaImageProcessorPil", "torchvision": "MllamaImageProcessor"}),
|
| 928 |
+
("mobilenet_v1", {"pil": "MobileNetV1ImageProcessorPil", "torchvision": "MobileNetV1ImageProcessor"}),
|
| 929 |
+
("mobilenet_v2", {"pil": "MobileNetV2ImageProcessorPil", "torchvision": "MobileNetV2ImageProcessor"}),
|
| 930 |
+
("mobilevit", {"pil": "MobileViTImageProcessorPil", "torchvision": "MobileViTImageProcessor"}),
|
| 931 |
+
("nougat", {"pil": "NougatImageProcessorPil", "torchvision": "NougatImageProcessor"}),
|
| 932 |
+
("oneformer", {"pil": "OneFormerImageProcessorPil", "torchvision": "OneFormerImageProcessor"}),
|
| 933 |
+
("ovis2", {"pil": "Ovis2ImageProcessorPil", "torchvision": "Ovis2ImageProcessor"}),
|
| 934 |
+
("owlv2", {"pil": "Owlv2ImageProcessorPil", "torchvision": "Owlv2ImageProcessor"}),
|
| 935 |
+
("owlvit", {"pil": "OwlViTImageProcessorPil", "torchvision": "OwlViTImageProcessor"}),
|
| 936 |
+
("paddleocr_vl", {"pil": "PaddleOCRVLImageProcessorPil", "torchvision": "PaddleOCRVLImageProcessor"}),
|
| 937 |
+
("perceiver", {"pil": "PerceiverImageProcessorPil", "torchvision": "PerceiverImageProcessor"}),
|
| 938 |
+
("perception_lm", {"torchvision": "PerceptionLMImageProcessor"}),
|
| 939 |
+
("phi4_multimodal", {"torchvision": "Phi4MultimodalImageProcessor"}),
|
| 940 |
+
("pi0", {"torchvision": "PI0ImageProcessor"}),
|
| 941 |
+
("pix2struct", {"pil": "Pix2StructImageProcessorPil", "torchvision": "Pix2StructImageProcessor"}),
|
| 942 |
+
("pixtral", {"pil": "PixtralImageProcessorPil", "torchvision": "PixtralImageProcessor"}),
|
| 943 |
+
("poolformer", {"pil": "PoolFormerImageProcessorPil", "torchvision": "PoolFormerImageProcessor"}),
|
| 944 |
+
("pp_chart2table", {"pil": "PPChart2TableImageProcessorPil", "torchvision": "PPChart2TableImageProcessor"}),
|
| 945 |
+
("pp_doclayout_v2", {"torchvision": "PPDocLayoutV2ImageProcessor"}),
|
| 946 |
+
("pp_doclayout_v3", {"torchvision": "PPDocLayoutV3ImageProcessor"}),
|
| 947 |
+
("pp_formulanet", {"torchvision": "PPFormulaNetImageProcessor"}),
|
| 948 |
+
("pp_lcnet", {"torchvision": "PPLCNetImageProcessor"}),
|
| 949 |
+
("pp_ocrv5_server_det", {"torchvision": "PPOCRV5ServerDetImageProcessor"}),
|
| 950 |
+
("pp_ocrv5_server_rec", {"torchvision": "PPOCRV5ServerRecImageProcessor"}),
|
| 951 |
+
(
|
| 952 |
+
"prompt_depth_anything",
|
| 953 |
+
{"pil": "PromptDepthAnythingImageProcessorPil", "torchvision": "PromptDepthAnythingImageProcessor"},
|
| 954 |
+
),
|
| 955 |
+
("pvt", {"pil": "PvtImageProcessorPil", "torchvision": "PvtImageProcessor"}),
|
| 956 |
+
("qwen2_vl", {"pil": "Qwen2VLImageProcessorPil", "torchvision": "Qwen2VLImageProcessor"}),
|
| 957 |
+
("rf_detr", {"torchvision": "RfDetrImageProcessor"}),
|
| 958 |
+
("rt_detr", {"pil": "RTDetrImageProcessorPil", "torchvision": "RTDetrImageProcessor"}),
|
| 959 |
+
("sam", {"pil": "SamImageProcessorPil", "torchvision": "SamImageProcessor"}),
|
| 960 |
+
("sam2", {"torchvision": "Sam2ImageProcessor"}),
|
| 961 |
+
("sam3", {"torchvision": "Sam3ImageProcessor"}),
|
| 962 |
+
("segformer", {"pil": "SegformerImageProcessorPil", "torchvision": "SegformerImageProcessor"}),
|
| 963 |
+
("seggpt", {"pil": "SegGptImageProcessorPil", "torchvision": "SegGptImageProcessor"}),
|
| 964 |
+
("siglip", {"pil": "SiglipImageProcessorPil", "torchvision": "SiglipImageProcessor"}),
|
| 965 |
+
("siglip2", {"pil": "Siglip2ImageProcessorPil", "torchvision": "Siglip2ImageProcessor"}),
|
| 966 |
+
("slanext", {"torchvision": "SLANeXtImageProcessor"}),
|
| 967 |
+
("smolvlm", {"pil": "SmolVLMImageProcessorPil", "torchvision": "SmolVLMImageProcessor"}),
|
| 968 |
+
("superglue", {"pil": "SuperGlueImageProcessorPil", "torchvision": "SuperGlueImageProcessor"}),
|
| 969 |
+
("superpoint", {"pil": "SuperPointImageProcessorPil", "torchvision": "SuperPointImageProcessor"}),
|
| 970 |
+
("swin2sr", {"pil": "Swin2SRImageProcessorPil", "torchvision": "Swin2SRImageProcessor"}),
|
| 971 |
+
("textnet", {"pil": "TextNetImageProcessorPil", "torchvision": "TextNetImageProcessor"}),
|
| 972 |
+
("tvp", {"pil": "TvpImageProcessorPil", "torchvision": "TvpImageProcessor"}),
|
| 973 |
+
("uvdoc", {"torchvision": "UVDocImageProcessor"}),
|
| 974 |
+
("video_llama_3", {"pil": "VideoLlama3ImageProcessorPil", "torchvision": "VideoLlama3ImageProcessor"}),
|
| 975 |
+
("videomae", {"pil": "VideoMAEImageProcessorPil", "torchvision": "VideoMAEImageProcessor"}),
|
| 976 |
+
("vilt", {"pil": "ViltImageProcessorPil", "torchvision": "ViltImageProcessor"}),
|
| 977 |
+
("vit", {"pil": "ViTImageProcessorPil", "torchvision": "ViTImageProcessor"}),
|
| 978 |
+
("vitmatte", {"pil": "VitMatteImageProcessorPil", "torchvision": "VitMatteImageProcessor"}),
|
| 979 |
+
("vitpose", {"pil": "VitPoseImageProcessorPil", "torchvision": "VitPoseImageProcessor"}),
|
| 980 |
+
("yolos", {"pil": "YolosImageProcessorPil", "torchvision": "YolosImageProcessor"}),
|
| 981 |
+
("zoedepth", {"pil": "ZoeDepthImageProcessorPil", "torchvision": "ZoeDepthImageProcessor"}),
|
| 982 |
+
]
|
| 983 |
+
)
|
| 984 |
+
|
| 985 |
+
VIDEO_PROCESSOR_MAPPING_NAMES = OrderedDict(
|
| 986 |
+
[
|
| 987 |
+
("ernie4_5_vl_moe", "Ernie4_5_VLMoeVideoProcessor"),
|
| 988 |
+
("gemma4", "Gemma4VideoProcessor"),
|
| 989 |
+
("glm46v", "Glm46VVideoProcessor"),
|
| 990 |
+
("glm4v", "Glm4vVideoProcessor"),
|
| 991 |
+
("instructblipvideo", "InstructBlipVideoVideoProcessor"),
|
| 992 |
+
("internvl", "InternVLVideoProcessor"),
|
| 993 |
+
("llava_next_video", "LlavaNextVideoVideoProcessor"),
|
| 994 |
+
("llava_onevision", "LlavaOnevisionVideoProcessor"),
|
| 995 |
+
("minicpmv4_6", "MiniCPMV4_6VideoProcessor"),
|
| 996 |
+
("pe_video", "PeVideoVideoProcessor"),
|
| 997 |
+
("perception_lm", "PerceptionLMVideoProcessor"),
|
| 998 |
+
("qwen2_vl", "Qwen2VLVideoProcessor"),
|
| 999 |
+
("qwen3_vl", "Qwen3VLVideoProcessor"),
|
| 1000 |
+
("sam2_video", "Sam2VideoVideoProcessor"),
|
| 1001 |
+
("smolvlm", "SmolVLMVideoProcessor"),
|
| 1002 |
+
("video_llama_3", "VideoLlama3VideoProcessor"),
|
| 1003 |
+
("video_llava", "VideoLlavaVideoProcessor"),
|
| 1004 |
+
("videomae", "VideoMAEVideoProcessor"),
|
| 1005 |
+
("videomt", "VideomtVideoProcessor"),
|
| 1006 |
+
("vjepa2", "VJEPA2VideoProcessor"),
|
| 1007 |
+
]
|
| 1008 |
+
)
|
LTA_openwebtext_dualt/mini_owt_logdirichlet/.venv_qwen35_uv/lib/python3.12/site-packages/transformers/models/auto/feature_extraction_auto.py
ADDED
|
@@ -0,0 +1,388 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# Copyright 2021 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 |
+
"""AutoFeatureExtractor class."""
|
| 15 |
+
|
| 16 |
+
import importlib
|
| 17 |
+
import os
|
| 18 |
+
from collections import OrderedDict
|
| 19 |
+
|
| 20 |
+
# Build the list of all feature extractors
|
| 21 |
+
from ...configuration_utils import PreTrainedConfig
|
| 22 |
+
from ...dynamic_module_utils import get_class_from_dynamic_module, resolve_trust_remote_code
|
| 23 |
+
from ...feature_extraction_utils import FeatureExtractionMixin
|
| 24 |
+
from ...utils import CONFIG_NAME, FEATURE_EXTRACTOR_NAME, PROCESSOR_NAME, cached_file, logging, safe_load_json_file
|
| 25 |
+
from .auto_factory import _LazyAutoMapping
|
| 26 |
+
from .configuration_auto import (
|
| 27 |
+
CONFIG_MAPPING_NAMES,
|
| 28 |
+
AutoConfig,
|
| 29 |
+
model_type_to_module_name,
|
| 30 |
+
replace_list_option_in_docstrings,
|
| 31 |
+
)
|
| 32 |
+
|
| 33 |
+
|
| 34 |
+
logger = logging.get_logger(__name__)
|
| 35 |
+
|
| 36 |
+
FEATURE_EXTRACTOR_MAPPING_NAMES = OrderedDict(
|
| 37 |
+
[
|
| 38 |
+
("audio-spectrogram-transformer", "ASTFeatureExtractor"),
|
| 39 |
+
("audioflamingo3", "WhisperFeatureExtractor"),
|
| 40 |
+
("clap", "ClapFeatureExtractor"),
|
| 41 |
+
("clvp", "ClvpFeatureExtractor"),
|
| 42 |
+
("cohere_asr", "CohereAsrFeatureExtractor"),
|
| 43 |
+
("csm", "EncodecFeatureExtractor"),
|
| 44 |
+
("dac", "DacFeatureExtractor"),
|
| 45 |
+
("data2vec-audio", "Wav2Vec2FeatureExtractor"),
|
| 46 |
+
("dia", "DiaFeatureExtractor"),
|
| 47 |
+
("encodec", "EncodecFeatureExtractor"),
|
| 48 |
+
("gemma3n", "Gemma3nAudioFeatureExtractor"),
|
| 49 |
+
("gemma4", "Gemma4AudioFeatureExtractor"),
|
| 50 |
+
("glmasr", "WhisperFeatureExtractor"),
|
| 51 |
+
("granite_speech", "GraniteSpeechFeatureExtractor"),
|
| 52 |
+
("granite_speech_plus", "GraniteSpeechFeatureExtractor"),
|
| 53 |
+
("higgs_audio_v2_tokenizer", "DacFeatureExtractor"),
|
| 54 |
+
("hubert", "Wav2Vec2FeatureExtractor"),
|
| 55 |
+
("kyutai_speech_to_text", "KyutaiSpeechToTextFeatureExtractor"),
|
| 56 |
+
("lasr_ctc", "LasrFeatureExtractor"),
|
| 57 |
+
("lasr_encoder", "LasrFeatureExtractor"),
|
| 58 |
+
("markuplm", "MarkupLMFeatureExtractor"),
|
| 59 |
+
("mimi", "EncodecFeatureExtractor"),
|
| 60 |
+
("moonshine", "Wav2Vec2FeatureExtractor"),
|
| 61 |
+
("moshi", "EncodecFeatureExtractor"),
|
| 62 |
+
("musicgen", "EncodecFeatureExtractor"),
|
| 63 |
+
("musicgen_melody", "MusicgenMelodyFeatureExtractor"),
|
| 64 |
+
("parakeet_ctc", "ParakeetFeatureExtractor"),
|
| 65 |
+
("parakeet_encoder", "ParakeetFeatureExtractor"),
|
| 66 |
+
("parakeet_tdt", "ParakeetFeatureExtractor"),
|
| 67 |
+
("pe_audio", "PeAudioFeatureExtractor"),
|
| 68 |
+
("pe_audio_video", "PeAudioFeatureExtractor"),
|
| 69 |
+
("phi4_multimodal", "Phi4MultimodalFeatureExtractor"),
|
| 70 |
+
("pop2piano", "Pop2PianoFeatureExtractor"),
|
| 71 |
+
("qwen2_5_omni", "WhisperFeatureExtractor"),
|
| 72 |
+
("qwen2_audio", "WhisperFeatureExtractor"),
|
| 73 |
+
("qwen3_omni_moe", "WhisperFeatureExtractor"),
|
| 74 |
+
("seamless_m4t", "SeamlessM4TFeatureExtractor"),
|
| 75 |
+
("seamless_m4t_v2", "SeamlessM4TFeatureExtractor"),
|
| 76 |
+
("sew", "Wav2Vec2FeatureExtractor"),
|
| 77 |
+
("sew-d", "Wav2Vec2FeatureExtractor"),
|
| 78 |
+
("speech_to_text", "Speech2TextFeatureExtractor"),
|
| 79 |
+
("speecht5", "SpeechT5FeatureExtractor"),
|
| 80 |
+
("unispeech", "Wav2Vec2FeatureExtractor"),
|
| 81 |
+
("unispeech-sat", "Wav2Vec2FeatureExtractor"),
|
| 82 |
+
("univnet", "UnivNetFeatureExtractor"),
|
| 83 |
+
("vibevoice_acoustic_tokenizer", "VibeVoiceAcousticTokenizerFeatureExtractor"),
|
| 84 |
+
("vibevoice_asr", "VibeVoiceAcousticTokenizerFeatureExtractor"),
|
| 85 |
+
("voxtral", "WhisperFeatureExtractor"),
|
| 86 |
+
("voxtral_realtime", "VoxtralRealtimeFeatureExtractor"),
|
| 87 |
+
("wav2vec2", "Wav2Vec2FeatureExtractor"),
|
| 88 |
+
("wav2vec2-bert", "Wav2Vec2FeatureExtractor"),
|
| 89 |
+
("wav2vec2-conformer", "Wav2Vec2FeatureExtractor"),
|
| 90 |
+
("wavlm", "Wav2Vec2FeatureExtractor"),
|
| 91 |
+
("whisper", "WhisperFeatureExtractor"),
|
| 92 |
+
("xcodec", "DacFeatureExtractor"),
|
| 93 |
+
]
|
| 94 |
+
)
|
| 95 |
+
|
| 96 |
+
FEATURE_EXTRACTOR_MAPPING = _LazyAutoMapping(CONFIG_MAPPING_NAMES, FEATURE_EXTRACTOR_MAPPING_NAMES)
|
| 97 |
+
|
| 98 |
+
|
| 99 |
+
def feature_extractor_class_from_name(class_name: str):
|
| 100 |
+
for module_name, extractors in FEATURE_EXTRACTOR_MAPPING_NAMES.items():
|
| 101 |
+
if class_name in extractors:
|
| 102 |
+
module_name = model_type_to_module_name(module_name)
|
| 103 |
+
|
| 104 |
+
module = importlib.import_module(f".{module_name}", "transformers.models")
|
| 105 |
+
try:
|
| 106 |
+
return getattr(module, class_name)
|
| 107 |
+
except AttributeError:
|
| 108 |
+
continue
|
| 109 |
+
|
| 110 |
+
for extractor in FEATURE_EXTRACTOR_MAPPING._extra_content.values():
|
| 111 |
+
if getattr(extractor, "__name__", None) == class_name:
|
| 112 |
+
return extractor
|
| 113 |
+
|
| 114 |
+
# We did not find the class, but maybe it's because a dep is missing. In that case, the class will be in the main
|
| 115 |
+
# init and we return the proper dummy to get an appropriate error message.
|
| 116 |
+
main_module = importlib.import_module("transformers")
|
| 117 |
+
if hasattr(main_module, class_name):
|
| 118 |
+
return getattr(main_module, class_name)
|
| 119 |
+
|
| 120 |
+
return None
|
| 121 |
+
|
| 122 |
+
|
| 123 |
+
def get_feature_extractor_config(
|
| 124 |
+
pretrained_model_name_or_path: str | os.PathLike,
|
| 125 |
+
cache_dir: str | os.PathLike | None = None,
|
| 126 |
+
force_download: bool = False,
|
| 127 |
+
proxies: dict[str, str] | None = None,
|
| 128 |
+
token: bool | str | None = None,
|
| 129 |
+
revision: str | None = None,
|
| 130 |
+
local_files_only: bool = False,
|
| 131 |
+
**kwargs,
|
| 132 |
+
):
|
| 133 |
+
"""
|
| 134 |
+
Loads the feature extractor configuration from a pretrained model feature extractor configuration.
|
| 135 |
+
|
| 136 |
+
Args:
|
| 137 |
+
pretrained_model_name_or_path (`str` or `os.PathLike`):
|
| 138 |
+
This can be either:
|
| 139 |
+
|
| 140 |
+
- a string, the *model id* of a pretrained model configuration hosted inside a model repo on
|
| 141 |
+
huggingface.co.
|
| 142 |
+
- a path to a *directory* containing a configuration file saved using the
|
| 143 |
+
[`~FeatureExtractionMixin.save_pretrained`] method, e.g., `./my_model_directory/`.
|
| 144 |
+
|
| 145 |
+
cache_dir (`str` or `os.PathLike`, *optional*):
|
| 146 |
+
Path to a directory in which a downloaded pretrained model configuration should be cached if the standard
|
| 147 |
+
cache should not be used.
|
| 148 |
+
force_download (`bool`, *optional*, defaults to `False`):
|
| 149 |
+
Whether or not to force to (re-)download the configuration files and override the cached versions if they
|
| 150 |
+
exist.
|
| 151 |
+
proxies (`dict[str, str]`, *optional*):
|
| 152 |
+
A dictionary of proxy servers to use by protocol or endpoint, e.g., `{'http': 'foo.bar:3128',
|
| 153 |
+
'http://hostname': 'foo.bar:4012'}.` The proxies are used on each request.
|
| 154 |
+
token (`str` or *bool*, *optional*):
|
| 155 |
+
The token to use as HTTP bearer authorization for remote files. If `True`, will use the token generated
|
| 156 |
+
when running `hf auth login` (stored in `~/.huggingface`).
|
| 157 |
+
revision (`str`, *optional*, defaults to `"main"`):
|
| 158 |
+
The specific model version to use. It can be a branch name, a tag name, or a commit id, since we use a
|
| 159 |
+
git-based system for storing models and other artifacts on huggingface.co, so `revision` can be any
|
| 160 |
+
identifier allowed by git.
|
| 161 |
+
local_files_only (`bool`, *optional*, defaults to `False`):
|
| 162 |
+
If `True`, will only try to load the feature extractor configuration from local files.
|
| 163 |
+
|
| 164 |
+
<Tip>
|
| 165 |
+
|
| 166 |
+
Passing `token=True` is required when you want to use a private model.
|
| 167 |
+
|
| 168 |
+
</Tip>
|
| 169 |
+
|
| 170 |
+
Returns:
|
| 171 |
+
`Dict`: The configuration of the feature extractor.
|
| 172 |
+
|
| 173 |
+
Examples:
|
| 174 |
+
|
| 175 |
+
```python
|
| 176 |
+
# Download configuration from huggingface.co and cache.
|
| 177 |
+
feature_extractor_config = get_feature_extractor_config("facebook/wav2vec2-base-960h")
|
| 178 |
+
# This model does not have a feature extractor config so the result will be an empty dict.
|
| 179 |
+
feature_extractor_config = get_feature_extractor_config("FacebookAI/xlm-roberta-base")
|
| 180 |
+
|
| 181 |
+
# Save a pretrained feature extractor locally and you can reload its config
|
| 182 |
+
from transformers import AutoFeatureExtractor
|
| 183 |
+
|
| 184 |
+
feature_extractor = AutoFeatureExtractor.from_pretrained("facebook/wav2vec2-base-960h")
|
| 185 |
+
feature_extractor.save_pretrained("feature-extractor-test")
|
| 186 |
+
feature_extractor_config = get_feature_extractor_config("feature-extractor-test")
|
| 187 |
+
```"""
|
| 188 |
+
# Load with a priority given to the nested processor config, if available in repo
|
| 189 |
+
resolved_processor_file = cached_file(
|
| 190 |
+
pretrained_model_name_or_path,
|
| 191 |
+
filename=PROCESSOR_NAME,
|
| 192 |
+
cache_dir=cache_dir,
|
| 193 |
+
force_download=force_download,
|
| 194 |
+
proxies=proxies,
|
| 195 |
+
token=token,
|
| 196 |
+
revision=revision,
|
| 197 |
+
local_files_only=local_files_only,
|
| 198 |
+
_raise_exceptions_for_gated_repo=False,
|
| 199 |
+
_raise_exceptions_for_missing_entries=False,
|
| 200 |
+
)
|
| 201 |
+
resolved_feature_extractor_file = cached_file(
|
| 202 |
+
pretrained_model_name_or_path,
|
| 203 |
+
filename=FEATURE_EXTRACTOR_NAME,
|
| 204 |
+
cache_dir=cache_dir,
|
| 205 |
+
force_download=force_download,
|
| 206 |
+
proxies=proxies,
|
| 207 |
+
token=token,
|
| 208 |
+
revision=revision,
|
| 209 |
+
local_files_only=local_files_only,
|
| 210 |
+
_raise_exceptions_for_gated_repo=False,
|
| 211 |
+
_raise_exceptions_for_missing_entries=False,
|
| 212 |
+
)
|
| 213 |
+
|
| 214 |
+
# An empty list if none of the possible files is found in the repo
|
| 215 |
+
if not resolved_feature_extractor_file and not resolved_processor_file:
|
| 216 |
+
logger.info("Could not locate the feature extractor configuration file.")
|
| 217 |
+
return {}
|
| 218 |
+
|
| 219 |
+
# Load feature_extractor dict. Priority goes as (nested config if found -> feature extractor config)
|
| 220 |
+
# We are downloading both configs because almost all models have a `processor_config.json` but
|
| 221 |
+
# not all of these are nested. We need to check if it was saved recently as nested or if it is legacy style
|
| 222 |
+
feature_extractor_dict = {}
|
| 223 |
+
if resolved_processor_file is not None:
|
| 224 |
+
processor_dict = safe_load_json_file(resolved_processor_file)
|
| 225 |
+
if "feature_extractor" in processor_dict:
|
| 226 |
+
feature_extractor_dict = processor_dict["feature_extractor"]
|
| 227 |
+
|
| 228 |
+
if resolved_feature_extractor_file is not None and feature_extractor_dict is None:
|
| 229 |
+
feature_extractor_dict = safe_load_json_file(resolved_feature_extractor_file)
|
| 230 |
+
return feature_extractor_dict
|
| 231 |
+
|
| 232 |
+
|
| 233 |
+
class AutoFeatureExtractor:
|
| 234 |
+
r"""
|
| 235 |
+
This is a generic feature extractor class that will be instantiated as one of the feature extractor classes of the
|
| 236 |
+
library when created with the [`AutoFeatureExtractor.from_pretrained`] class method.
|
| 237 |
+
|
| 238 |
+
This class cannot be instantiated directly using `__init__()` (throws an error).
|
| 239 |
+
"""
|
| 240 |
+
|
| 241 |
+
def __init__(self):
|
| 242 |
+
raise OSError(
|
| 243 |
+
"AutoFeatureExtractor is designed to be instantiated "
|
| 244 |
+
"using the `AutoFeatureExtractor.from_pretrained(pretrained_model_name_or_path)` method."
|
| 245 |
+
)
|
| 246 |
+
|
| 247 |
+
@classmethod
|
| 248 |
+
@replace_list_option_in_docstrings(FEATURE_EXTRACTOR_MAPPING_NAMES)
|
| 249 |
+
def from_pretrained(cls, pretrained_model_name_or_path, **kwargs):
|
| 250 |
+
r"""
|
| 251 |
+
Instantiate one of the feature extractor classes of the library from a pretrained model vocabulary.
|
| 252 |
+
|
| 253 |
+
The feature extractor class to instantiate is selected based on the `model_type` property of the config object
|
| 254 |
+
(either passed as an argument or loaded from `pretrained_model_name_or_path` if possible), or when it's
|
| 255 |
+
missing, by falling back to using pattern matching on `pretrained_model_name_or_path`:
|
| 256 |
+
|
| 257 |
+
List options
|
| 258 |
+
|
| 259 |
+
Params:
|
| 260 |
+
pretrained_model_name_or_path (`str` or `os.PathLike`):
|
| 261 |
+
This can be either:
|
| 262 |
+
|
| 263 |
+
- a string, the *model id* of a pretrained feature_extractor hosted inside a model repo on
|
| 264 |
+
huggingface.co.
|
| 265 |
+
- a path to a *directory* containing a feature extractor file saved using the
|
| 266 |
+
[`~feature_extraction_utils.FeatureExtractionMixin.save_pretrained`] method, e.g.,
|
| 267 |
+
`./my_model_directory/`.
|
| 268 |
+
- a path to a saved feature extractor JSON *file*, e.g.,
|
| 269 |
+
`./my_model_directory/preprocessor_config.json`.
|
| 270 |
+
cache_dir (`str` or `os.PathLike`, *optional*):
|
| 271 |
+
Path to a directory in which a downloaded pretrained model feature extractor should be cached if the
|
| 272 |
+
standard cache should not be used.
|
| 273 |
+
force_download (`bool`, *optional*, defaults to `False`):
|
| 274 |
+
Whether or not to force to (re-)download the feature extractor files and override the cached versions
|
| 275 |
+
if they exist.
|
| 276 |
+
proxies (`dict[str, str]`, *optional*):
|
| 277 |
+
A dictionary of proxy servers to use by protocol or endpoint, e.g., `{'http': 'foo.bar:3128',
|
| 278 |
+
'http://hostname': 'foo.bar:4012'}.` The proxies are used on each request.
|
| 279 |
+
token (`str` or *bool*, *optional*):
|
| 280 |
+
The token to use as HTTP bearer authorization for remote files. If `True`, will use the token generated
|
| 281 |
+
when running `hf auth login` (stored in `~/.huggingface`).
|
| 282 |
+
revision (`str`, *optional*, defaults to `"main"`):
|
| 283 |
+
The specific model version to use. It can be a branch name, a tag name, or a commit id, since we use a
|
| 284 |
+
git-based system for storing models and other artifacts on huggingface.co, so `revision` can be any
|
| 285 |
+
identifier allowed by git.
|
| 286 |
+
return_unused_kwargs (`bool`, *optional*, defaults to `False`):
|
| 287 |
+
If `False`, then this function returns just the final feature extractor object. If `True`, then this
|
| 288 |
+
functions returns a `Tuple(feature_extractor, unused_kwargs)` where *unused_kwargs* is a dictionary
|
| 289 |
+
consisting of the key/value pairs whose keys are not feature extractor attributes: i.e., the part of
|
| 290 |
+
`kwargs` which has not been used to update `feature_extractor` and is otherwise ignored.
|
| 291 |
+
trust_remote_code (`bool`, *optional*, defaults to `False`):
|
| 292 |
+
Whether or not to allow for custom models defined on the Hub in their own modeling files. This option
|
| 293 |
+
should only be set to `True` for repositories you trust and in which you have read the code, as it will
|
| 294 |
+
execute code present on the Hub on your local machine.
|
| 295 |
+
kwargs (`dict[str, Any]`, *optional*):
|
| 296 |
+
The values in kwargs of any keys which are feature extractor attributes will be used to override the
|
| 297 |
+
loaded values. Behavior concerning key/value pairs whose keys are *not* feature extractor attributes is
|
| 298 |
+
controlled by the `return_unused_kwargs` keyword parameter.
|
| 299 |
+
|
| 300 |
+
<Tip>
|
| 301 |
+
|
| 302 |
+
Passing `token=True` is required when you want to use a private model.
|
| 303 |
+
|
| 304 |
+
</Tip>
|
| 305 |
+
|
| 306 |
+
Examples:
|
| 307 |
+
|
| 308 |
+
```python
|
| 309 |
+
>>> from transformers import AutoFeatureExtractor
|
| 310 |
+
|
| 311 |
+
>>> # Download feature extractor from huggingface.co and cache.
|
| 312 |
+
>>> feature_extractor = AutoFeatureExtractor.from_pretrained("facebook/wav2vec2-base-960h")
|
| 313 |
+
|
| 314 |
+
>>> # If feature extractor files are in a directory (e.g. feature extractor was saved using *save_pretrained('./test/saved_model/')*)
|
| 315 |
+
>>> # feature_extractor = AutoFeatureExtractor.from_pretrained("./test/saved_model/")
|
| 316 |
+
```"""
|
| 317 |
+
config = kwargs.pop("config", None)
|
| 318 |
+
trust_remote_code = kwargs.pop("trust_remote_code", None)
|
| 319 |
+
kwargs["_from_auto"] = True
|
| 320 |
+
|
| 321 |
+
config_dict, _ = FeatureExtractionMixin.get_feature_extractor_dict(pretrained_model_name_or_path, **kwargs)
|
| 322 |
+
feature_extractor_class = config_dict.get("feature_extractor_type", None)
|
| 323 |
+
feature_extractor_auto_map = None
|
| 324 |
+
if "AutoFeatureExtractor" in config_dict.get("auto_map", {}):
|
| 325 |
+
feature_extractor_auto_map = config_dict["auto_map"]["AutoFeatureExtractor"]
|
| 326 |
+
|
| 327 |
+
# If we don't find the feature extractor class in the feature extractor config, let's try the model config.
|
| 328 |
+
if feature_extractor_class is None and feature_extractor_auto_map is None:
|
| 329 |
+
if not isinstance(config, PreTrainedConfig):
|
| 330 |
+
config = AutoConfig.from_pretrained(
|
| 331 |
+
pretrained_model_name_or_path, trust_remote_code=trust_remote_code, **kwargs
|
| 332 |
+
)
|
| 333 |
+
# It could be in `config.feature_extractor_type``
|
| 334 |
+
feature_extractor_class = getattr(config, "feature_extractor_type", None)
|
| 335 |
+
if hasattr(config, "auto_map") and "AutoFeatureExtractor" in config.auto_map:
|
| 336 |
+
feature_extractor_auto_map = config.auto_map["AutoFeatureExtractor"]
|
| 337 |
+
|
| 338 |
+
if feature_extractor_class is not None:
|
| 339 |
+
feature_extractor_class = feature_extractor_class_from_name(feature_extractor_class)
|
| 340 |
+
|
| 341 |
+
has_remote_code = feature_extractor_auto_map is not None
|
| 342 |
+
has_local_code = feature_extractor_class is not None or type(config) in FEATURE_EXTRACTOR_MAPPING
|
| 343 |
+
explicit_local_code = has_local_code and not (
|
| 344 |
+
feature_extractor_class or FEATURE_EXTRACTOR_MAPPING[type(config)]
|
| 345 |
+
).__module__.startswith("transformers.")
|
| 346 |
+
if has_remote_code:
|
| 347 |
+
if "--" in feature_extractor_auto_map:
|
| 348 |
+
upstream_repo = feature_extractor_auto_map.split("--")[0]
|
| 349 |
+
else:
|
| 350 |
+
upstream_repo = None
|
| 351 |
+
trust_remote_code = resolve_trust_remote_code(
|
| 352 |
+
trust_remote_code, pretrained_model_name_or_path, has_local_code, has_remote_code, upstream_repo
|
| 353 |
+
)
|
| 354 |
+
|
| 355 |
+
if has_remote_code and trust_remote_code and not explicit_local_code:
|
| 356 |
+
feature_extractor_class = get_class_from_dynamic_module(
|
| 357 |
+
feature_extractor_auto_map, pretrained_model_name_or_path, **kwargs
|
| 358 |
+
)
|
| 359 |
+
_ = kwargs.pop("code_revision", None)
|
| 360 |
+
feature_extractor_class.register_for_auto_class()
|
| 361 |
+
return feature_extractor_class.from_pretrained(pretrained_model_name_or_path, **kwargs)
|
| 362 |
+
elif feature_extractor_class is not None:
|
| 363 |
+
return feature_extractor_class.from_pretrained(pretrained_model_name_or_path, **kwargs)
|
| 364 |
+
# Last try: we use the FEATURE_EXTRACTOR_MAPPING.
|
| 365 |
+
elif type(config) in FEATURE_EXTRACTOR_MAPPING:
|
| 366 |
+
feature_extractor_class = FEATURE_EXTRACTOR_MAPPING[type(config)]
|
| 367 |
+
return feature_extractor_class.from_pretrained(pretrained_model_name_or_path, **kwargs)
|
| 368 |
+
|
| 369 |
+
raise ValueError(
|
| 370 |
+
f"Unrecognized feature extractor in {pretrained_model_name_or_path}. Should have a "
|
| 371 |
+
f"`feature_extractor_type` key in its {FEATURE_EXTRACTOR_NAME} of {CONFIG_NAME}, or one of the following "
|
| 372 |
+
f"`model_type` keys in its {CONFIG_NAME}: {', '.join(c for c in FEATURE_EXTRACTOR_MAPPING_NAMES)}"
|
| 373 |
+
)
|
| 374 |
+
|
| 375 |
+
@staticmethod
|
| 376 |
+
def register(config_class, feature_extractor_class, exist_ok=False):
|
| 377 |
+
"""
|
| 378 |
+
Register a new feature extractor for this class.
|
| 379 |
+
|
| 380 |
+
Args:
|
| 381 |
+
config_class ([`PreTrainedConfig`]):
|
| 382 |
+
The configuration corresponding to the model to register.
|
| 383 |
+
feature_extractor_class ([`FeatureExtractorMixin`]): The feature extractor to register.
|
| 384 |
+
"""
|
| 385 |
+
FEATURE_EXTRACTOR_MAPPING.register(config_class, feature_extractor_class, exist_ok=exist_ok)
|
| 386 |
+
|
| 387 |
+
|
| 388 |
+
__all__ = ["FEAT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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# Copyright 2022 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 |
+
"""AutoImageProcessor class."""
|
| 15 |
+
|
| 16 |
+
import importlib
|
| 17 |
+
import os
|
| 18 |
+
from collections import OrderedDict
|
| 19 |
+
from typing import TYPE_CHECKING
|
| 20 |
+
|
| 21 |
+
# Build the list of all image processors
|
| 22 |
+
from ...configuration_utils import PreTrainedConfig
|
| 23 |
+
from ...dynamic_module_utils import get_class_from_dynamic_module, resolve_trust_remote_code
|
| 24 |
+
from ...image_processing_utils import ImageProcessingMixin
|
| 25 |
+
from ...utils import (
|
| 26 |
+
CONFIG_NAME,
|
| 27 |
+
IMAGE_PROCESSOR_NAME,
|
| 28 |
+
PROCESSOR_NAME,
|
| 29 |
+
cached_file,
|
| 30 |
+
is_timm_config_dict,
|
| 31 |
+
is_timm_local_checkpoint,
|
| 32 |
+
is_torchvision_available,
|
| 33 |
+
logging,
|
| 34 |
+
safe_load_json_file,
|
| 35 |
+
)
|
| 36 |
+
from ...utils.import_utils import requires
|
| 37 |
+
from .auto_factory import _LazyAutoMapping
|
| 38 |
+
from .auto_mappings import IMAGE_PROCESSOR_MAPPING_NAMES
|
| 39 |
+
from .configuration_auto import (
|
| 40 |
+
CONFIG_MAPPING_NAMES,
|
| 41 |
+
AutoConfig,
|
| 42 |
+
model_type_to_module_name,
|
| 43 |
+
replace_list_option_in_docstrings,
|
| 44 |
+
)
|
| 45 |
+
|
| 46 |
+
|
| 47 |
+
logger = logging.get_logger(__name__)
|
| 48 |
+
|
| 49 |
+
# These image processors use Lanczos interpolation, which is not supported by fast image processors.
|
| 50 |
+
# To avoid important differences in outputs, we default to using the PIL backend for these processors.
|
| 51 |
+
DEFAULT_TO_PIL_BACKEND_IMAGE_PROCESSORS = [
|
| 52 |
+
"ChameleonImageProcessor",
|
| 53 |
+
"FlavaImageProcessor",
|
| 54 |
+
"Idefics3ImageProcessor",
|
| 55 |
+
"SmolVLMImageProcessor",
|
| 56 |
+
]
|
| 57 |
+
|
| 58 |
+
|
| 59 |
+
if TYPE_CHECKING:
|
| 60 |
+
# This significantly improves completion suggestion performance when
|
| 61 |
+
# the transformers package is used with Microsoft's Pylance language server.
|
| 62 |
+
IMAGE_PROCESSOR_MAPPING_NAMES: OrderedDict[str, dict[str, str | None]] = OrderedDict()
|
| 63 |
+
else:
|
| 64 |
+
# Merge non-standard mapping names with auto-inferred `IMAGE_PROCESSOR_MAPPING_NAMES`
|
| 65 |
+
MISSING_IMAGE_PROCESSOR_MAPPING_NAMES = OrderedDict(
|
| 66 |
+
[
|
| 67 |
+
("aimv2", {"torchvision": "CLIPImageProcessor", "pil": "CLIPImageProcessorPil"}),
|
| 68 |
+
("aimv2_vision_model", {"torchvision": "CLIPImageProcessor", "pil": "CLIPImageProcessorPil"}),
|
| 69 |
+
("align", {"torchvision": "EfficientNetImageProcessor", "pil": "EfficientNetImageProcessorPil"}),
|
| 70 |
+
("altclip", {"torchvision": "CLIPImageProcessor", "pil": "CLIPImageProcessorPil"}),
|
| 71 |
+
("aya_vision", {"torchvision": "GotOcr2ImageProcessor", "pil": "GotOcr2ImageProcessorPil"}),
|
| 72 |
+
("blip-2", {"torchvision": "BlipImageProcessor", "pil": "BlipImageProcessorPil"}),
|
| 73 |
+
("clipseg", {"torchvision": "ViTImageProcessor", "pil": "ViTImageProcessorPil"}),
|
| 74 |
+
("colpali", {"torchvision": "SiglipImageProcessor", "pil": "SiglipImageProcessorPil"}),
|
| 75 |
+
("colqwen2", {"torchvision": "Qwen2VLImageProcessor", "pil": "Qwen2VLImageProcessorPil"}),
|
| 76 |
+
("convnextv2", {"torchvision": "ConvNextImageProcessor", "pil": "ConvNextImageProcessorPil"}),
|
| 77 |
+
("cvt", {"torchvision": "ConvNextImageProcessor", "pil": "ConvNextImageProcessorPil"}),
|
| 78 |
+
("data2vec-vision", {"torchvision": "BeitImageProcessor", "pil": "BeitImageProcessorPil"}),
|
| 79 |
+
("deimv2", {"torchvision": "RTDetrImageProcessor", "pil": "RTDetrImageProcessorPil"}),
|
| 80 |
+
("depth_anything", {"torchvision": "DPTImageProcessor", "pil": "DPTImageProcessorPil"}),
|
| 81 |
+
("dinat", {"torchvision": "ViTImageProcessor", "pil": "ViTImageProcessorPil"}),
|
| 82 |
+
("dinov2", {"torchvision": "BitImageProcessor", "pil": "BitImageProcessorPil"}),
|
| 83 |
+
("donut-swin", {"torchvision": "DonutImageProcessor", "pil": "DonutImageProcessorPil"}),
|
| 84 |
+
("edgetam", {"torchvision": "Sam2ImageProcessor"}),
|
| 85 |
+
("emu3", {"pil": "Emu3ImageProcessor"}),
|
| 86 |
+
("eomt_dinov3", {"torchvision": "EomtImageProcessor", "pil": "EomtImageProcessorPil"}),
|
| 87 |
+
("exaone4_5", {"torchvision": "Qwen2VLImageProcessor", "pil": "Qwen2VLImageProcessorPil"}),
|
| 88 |
+
("florence2", {"torchvision": "CLIPImageProcessor", "pil": "CLIPImageProcessorPil"}),
|
| 89 |
+
("focalnet", {"torchvision": "BitImageProcessor", "pil": "BitImageProcessorPil"}),
|
| 90 |
+
("gemma3n", {"torchvision": "SiglipImageProcessor", "pil": "SiglipImageProcessorPil"}),
|
| 91 |
+
("git", {"torchvision": "CLIPImageProcessor", "pil": "CLIPImageProcessorPil"}),
|
| 92 |
+
("granite4_vision", {"torchvision": "LlavaNextImageProcessor", "pil": "LlavaNextImageProcessorPil"}),
|
| 93 |
+
("groupvit", {"torchvision": "CLIPImageProcessor", "pil": "CLIPImageProcessorPil"}),
|
| 94 |
+
("hiera", {"torchvision": "BitImageProcessor", "pil": "BitImageProcessorPil"}),
|
| 95 |
+
("ijepa", {"torchvision": "ViTImageProcessor", "pil": "ViTImageProcessorPil"}),
|
| 96 |
+
("instructblip", {"torchvision": "BlipImageProcessor", "pil": "BlipImageProcessorPil"}),
|
| 97 |
+
("internvl", {"torchvision": "GotOcr2ImageProcessor", "pil": "GotOcr2ImageProcessorPil"}),
|
| 98 |
+
("kosmos-2", {"torchvision": "CLIPImageProcessor", "pil": "CLIPImageProcessorPil"}),
|
| 99 |
+
("kosmos-2.5", {"torchvision": "Kosmos2_5ImageProcessor", "pil": "Kosmos2_5ImageProcessorPil"}),
|
| 100 |
+
("layoutxlm", {"torchvision": "LayoutLMv2ImageProcessor", "pil": "LayoutLMv2ImageProcessorPil"}),
|
| 101 |
+
("lighton_ocr", {"torchvision": "PixtralImageProcessor", "pil": "PixtralImageProcessorPil"}),
|
| 102 |
+
("llava_next_video", {"torchvision": "LlavaNextImageProcessor", "pil": "LlavaNextImageProcessorPil"}),
|
| 103 |
+
("lw_detr", {"torchvision": "DeformableDetrImageProcessor", "pil": "DeformableDetrImageProcessorPil"}),
|
| 104 |
+
("metaclip_2", {"torchvision": "CLIPImageProcessor", "pil": "CLIPImageProcessorPil"}),
|
| 105 |
+
("mgp-str", {"torchvision": "ViTImageProcessor", "pil": "ViTImageProcessorPil"}),
|
| 106 |
+
("mistral3", {"torchvision": "PixtralImageProcessor", "pil": "PixtralImageProcessorPil"}),
|
| 107 |
+
("mlcd", {"torchvision": "CLIPImageProcessor", "pil": "CLIPImageProcessorPil"}),
|
| 108 |
+
(
|
| 109 |
+
"mm-grounding-dino",
|
| 110 |
+
{
|
| 111 |
+
"torchvision": "GroundingDinoImageProcessor",
|
| 112 |
+
"pil": "GroundingDinoImageProcessorPil",
|
| 113 |
+
},
|
| 114 |
+
),
|
| 115 |
+
("mobilevitv2", {"torchvision": "MobileViTImageProcessor", "pil": "MobileViTImageProcessorPil"}),
|
| 116 |
+
("omdet-turbo", {"torchvision": "DetrImageProcessor", "pil": "DetrImageProcessorPil"}),
|
| 117 |
+
("paligemma", {"torchvision": "SiglipImageProcessor", "pil": "SiglipImageProcessorPil"}),
|
| 118 |
+
("pixio", {"torchvision": "BitImageProcessor", "pil": "BitImageProcessorPil"}),
|
| 119 |
+
("pp_ocrv5_mobile_det", {"torchvision": "PPOCRV5ServerDetImageProcessor"}),
|
| 120 |
+
("pp_ocrv5_mobile_rec", {"torchvision": "PPOCRV5ServerRecImageProcessor"}),
|
| 121 |
+
("pvt_v2", {"torchvision": "PvtImageProcessor", "pil": "PvtImageProcessorPil"}),
|
| 122 |
+
("qianfan_ocr", {"torchvision": "GotOcr2ImageProcessor", "pil": "GotOcr2ImageProcessorPil"}),
|
| 123 |
+
("qwen2_5_omni", {"torchvision": "Qwen2VLImageProcessor", "pil": "Qwen2VLImageProcessorPil"}),
|
| 124 |
+
("qwen2_5_vl", {"torchvision": "Qwen2VLImageProcessor", "pil": "Qwen2VLImageProcessorPil"}),
|
| 125 |
+
("qwen3_5", {"torchvision": "Qwen2VLImageProcessor", "pil": "Qwen2VLImageProcessorPil"}),
|
| 126 |
+
("qwen3_5_moe", {"torchvision": "Qwen2VLImageProcessor", "pil": "Qwen2VLImageProcessorPil"}),
|
| 127 |
+
("qwen3_omni_moe", {"torchvision": "Qwen2VLImageProcessor", "pil": "Qwen2VLImageProcessorPil"}),
|
| 128 |
+
("qwen3_vl", {"torchvision": "Qwen2VLImageProcessor", "pil": "Qwen2VLImageProcessorPil"}),
|
| 129 |
+
("regnet", {"torchvision": "ConvNextImageProcessor", "pil": "ConvNextImageProcessorPil"}),
|
| 130 |
+
("resnet", {"torchvision": "ConvNextImageProcessor", "pil": "ConvNextImageProcessorPil"}),
|
| 131 |
+
("sam2_video", {"torchvision": "Sam2ImageProcessor"}),
|
| 132 |
+
("sam3_lite_text", {"torchvision": "Sam3ImageProcessor"}),
|
| 133 |
+
("sam3_tracker", {"torchvision": "Sam3ImageProcessor"}),
|
| 134 |
+
("sam3_tracker_video", {"torchvision": "Sam3ImageProcessor"}),
|
| 135 |
+
("sam3_video", {"torchvision": "Sam3ImageProcessor"}),
|
| 136 |
+
("sam_hq", {"torchvision": "SamImageProcessor", "pil": "SamImageProcessorPil"}),
|
| 137 |
+
("shieldgemma2", {"torchvision": "Gemma3ImageProcessor", "pil": "Gemma3ImageProcessorPil"}),
|
| 138 |
+
("slanet", {"torchvision": "SLANeXtImageProcessor"}),
|
| 139 |
+
("swiftformer", {"torchvision": "ViTImageProcessor", "pil": "ViTImageProcessorPil"}),
|
| 140 |
+
("swin", {"torchvision": "ViTImageProcessor", "pil": "ViTImageProcessorPil"}),
|
| 141 |
+
("swinv2", {"torchvision": "ViTImageProcessor", "pil": "ViTImageProcessorPil"}),
|
| 142 |
+
("t5gemma2", {"torchvision": "Gemma3ImageProcessor", "pil": "Gemma3ImageProcessorPil"}),
|
| 143 |
+
("t5gemma2_encoder", {"torchvision": "Gemma3ImageProcessor", "pil": "Gemma3ImageProcessorPil"}),
|
| 144 |
+
("table-transformer", {"torchvision": "DetrImageProcessor", "pil": "DetrImageProcessorPil"}),
|
| 145 |
+
("timesformer", {"pil": "VideoMAEImageProcessorPil", "torchvision": "VideoMAEImageProcessor"}),
|
| 146 |
+
("timm_wrapper", {"pil": "TimmWrapperImageProcessor"}),
|
| 147 |
+
("trocr", {"torchvision": "ViTImageProcessor", "pil": "ViTImageProcessorPil"}),
|
| 148 |
+
("udop", {"torchvision": "LayoutLMv3ImageProcessor", "pil": "LayoutLMv3ImageProcessorPil"}),
|
| 149 |
+
("upernet", {"torchvision": "SegformerImageProcessor", "pil": "SegformerImageProcessorPil"}),
|
| 150 |
+
("video_llava", {"pil": "VideoLlavaImageProcessor"}),
|
| 151 |
+
("vipllava", {"torchvision": "CLIPImageProcessor", "pil": "CLIPImageProcessorPil"}),
|
| 152 |
+
("vit_mae", {"torchvision": "ViTImageProcessor", "pil": "ViTImageProcessorPil"}),
|
| 153 |
+
("vit_msn", {"torchvision": "ViTImageProcessor", "pil": "ViTImageProcessorPil"}),
|
| 154 |
+
("vivit", {"torchvision": "VivitImageProcessor"}),
|
| 155 |
+
("xclip", {"torchvision": "CLIPImageProcessor", "pil": "CLIPImageProcessorPil"}),
|
| 156 |
+
]
|
| 157 |
+
)
|
| 158 |
+
|
| 159 |
+
IMAGE_PROCESSOR_MAPPING_NAMES.update(MISSING_IMAGE_PROCESSOR_MAPPING_NAMES)
|
| 160 |
+
|
| 161 |
+
IMAGE_PROCESSOR_MAPPING = _LazyAutoMapping(CONFIG_MAPPING_NAMES, IMAGE_PROCESSOR_MAPPING_NAMES)
|
| 162 |
+
|
| 163 |
+
|
| 164 |
+
def get_image_processor_class_from_name(class_name: str):
|
| 165 |
+
"""Resolve an image processor class name to its class. Handles both base names (e.g. CLIPImageProcessor)
|
| 166 |
+
and PIL backend names (e.g. CLIPImageProcessorPil). No recursion needed since names are direct."""
|
| 167 |
+
if class_name == "BaseImageProcessorFast":
|
| 168 |
+
# kept for backward compatibility - return TorchvisionBackend
|
| 169 |
+
from ...image_processing_backends import TorchvisionBackend
|
| 170 |
+
|
| 171 |
+
return TorchvisionBackend
|
| 172 |
+
|
| 173 |
+
# First, check registered extra content (user-registered classes)
|
| 174 |
+
for mapping in IMAGE_PROCESSOR_MAPPING._extra_content.values():
|
| 175 |
+
for extractor_class in mapping.values():
|
| 176 |
+
if isinstance(extractor_class, type) and getattr(extractor_class, "__name__", None) == class_name:
|
| 177 |
+
return extractor_class
|
| 178 |
+
|
| 179 |
+
# Check the mapping names - class names are either base (torchvision) or base+Pil (pil)
|
| 180 |
+
for model_type, extractors_dict in IMAGE_PROCESSOR_MAPPING_NAMES.items():
|
| 181 |
+
if class_name in extractors_dict.values():
|
| 182 |
+
module_name = model_type_to_module_name(model_type)
|
| 183 |
+
module = importlib.import_module(f".{module_name}", "transformers.models")
|
| 184 |
+
try:
|
| 185 |
+
return getattr(module, class_name)
|
| 186 |
+
except AttributeError:
|
| 187 |
+
continue
|
| 188 |
+
|
| 189 |
+
# Fallback: class may be in main init (e.g. when dep is missing, returns dummy)
|
| 190 |
+
main_module = importlib.import_module("transformers")
|
| 191 |
+
if hasattr(main_module, class_name):
|
| 192 |
+
return getattr(main_module, class_name)
|
| 193 |
+
|
| 194 |
+
return None
|
| 195 |
+
|
| 196 |
+
|
| 197 |
+
def get_image_processor_config(
|
| 198 |
+
pretrained_model_name_or_path: str | os.PathLike,
|
| 199 |
+
cache_dir: str | os.PathLike | None = None,
|
| 200 |
+
force_download: bool = False,
|
| 201 |
+
proxies: dict[str, str] | None = None,
|
| 202 |
+
token: bool | str | None = None,
|
| 203 |
+
revision: str | None = None,
|
| 204 |
+
local_files_only: bool = False,
|
| 205 |
+
**kwargs,
|
| 206 |
+
):
|
| 207 |
+
"""
|
| 208 |
+
Loads the image processor configuration from a pretrained model image processor configuration.
|
| 209 |
+
|
| 210 |
+
Args:
|
| 211 |
+
pretrained_model_name_or_path (`str` or `os.PathLike`):
|
| 212 |
+
This can be either:
|
| 213 |
+
|
| 214 |
+
- a string, the *model id* of a pretrained model configuration hosted inside a model repo on
|
| 215 |
+
huggingface.co.
|
| 216 |
+
- a path to a *directory* containing a configuration file saved using the
|
| 217 |
+
[`~ProcessorMixin.save_pretrained`] method, e.g., `./my_model_directory/`.
|
| 218 |
+
|
| 219 |
+
cache_dir (`str` or `os.PathLike`, *optional*):
|
| 220 |
+
Path to a directory in which a downloaded pretrained model configuration should be cached if the standard
|
| 221 |
+
cache should not be used.
|
| 222 |
+
force_download (`bool`, *optional*, defaults to `False`):
|
| 223 |
+
Whether or not to force to (re-)download the configuration files and override the cached versions if they
|
| 224 |
+
exist.
|
| 225 |
+
proxies (`dict[str, str]`, *optional*):
|
| 226 |
+
A dictionary of proxy servers to use by protocol or endpoint, e.g., `{'http': 'foo.bar:3128',
|
| 227 |
+
'http://hostname': 'foo.bar:4012'}.` The proxies are used on each request.
|
| 228 |
+
token (`str` or *bool*, *optional*):
|
| 229 |
+
The token to use as HTTP bearer authorization for remote files. If `True`, will use the token generated
|
| 230 |
+
when running `hf auth login` (stored in `~/.huggingface`).
|
| 231 |
+
revision (`str`, *optional*, defaults to `"main"`):
|
| 232 |
+
The specific model version to use. It can be a branch name, a tag name, or a commit id, since we use a
|
| 233 |
+
git-based system for storing models and other artifacts on huggingface.co, so `revision` can be any
|
| 234 |
+
identifier allowed by git.
|
| 235 |
+
local_files_only (`bool`, *optional*, defaults to `False`):
|
| 236 |
+
If `True`, will only try to load the image processor configuration from local files.
|
| 237 |
+
|
| 238 |
+
<Tip>
|
| 239 |
+
|
| 240 |
+
Passing `token=True` is required when you want to use a private model.
|
| 241 |
+
|
| 242 |
+
</Tip>
|
| 243 |
+
|
| 244 |
+
Returns:
|
| 245 |
+
`Dict`: The configuration of the image processor.
|
| 246 |
+
|
| 247 |
+
Examples:
|
| 248 |
+
|
| 249 |
+
```python
|
| 250 |
+
# Download configuration from huggingface.co and cache.
|
| 251 |
+
image_processor_config = get_image_processor_config("google-bert/bert-base-uncased")
|
| 252 |
+
# This model does not have a image processor config so the result will be an empty dict.
|
| 253 |
+
image_processor_config = get_image_processor_config("FacebookAI/xlm-roberta-base")
|
| 254 |
+
|
| 255 |
+
# Save a pretrained image processor locally and you can reload its config
|
| 256 |
+
from transformers import AutoImageProcessor
|
| 257 |
+
|
| 258 |
+
image_processor = AutoImageProcessor.from_pretrained("google/vit-base-patch16-224-in21k")
|
| 259 |
+
image_processor.save_pretrained("image-processor-test")
|
| 260 |
+
image_processor_config = get_image_processor_config("image-processor-test")
|
| 261 |
+
```"""
|
| 262 |
+
# Load with a priority given to the nested processor config, if available in repo
|
| 263 |
+
resolved_processor_file = cached_file(
|
| 264 |
+
pretrained_model_name_or_path,
|
| 265 |
+
filename=PROCESSOR_NAME,
|
| 266 |
+
cache_dir=cache_dir,
|
| 267 |
+
force_download=force_download,
|
| 268 |
+
proxies=proxies,
|
| 269 |
+
token=token,
|
| 270 |
+
revision=revision,
|
| 271 |
+
local_files_only=local_files_only,
|
| 272 |
+
_raise_exceptions_for_gated_repo=False,
|
| 273 |
+
_raise_exceptions_for_missing_entries=False,
|
| 274 |
+
)
|
| 275 |
+
resolved_image_processor_file = cached_file(
|
| 276 |
+
pretrained_model_name_or_path,
|
| 277 |
+
filename=IMAGE_PROCESSOR_NAME,
|
| 278 |
+
cache_dir=cache_dir,
|
| 279 |
+
force_download=force_download,
|
| 280 |
+
proxies=proxies,
|
| 281 |
+
token=token,
|
| 282 |
+
revision=revision,
|
| 283 |
+
local_files_only=local_files_only,
|
| 284 |
+
_raise_exceptions_for_gated_repo=False,
|
| 285 |
+
_raise_exceptions_for_missing_entries=False,
|
| 286 |
+
)
|
| 287 |
+
|
| 288 |
+
# An empty list if none of the possible files is found in the repo
|
| 289 |
+
if not resolved_image_processor_file and not resolved_processor_file:
|
| 290 |
+
logger.info("Could not locate the image processor configuration file.")
|
| 291 |
+
return {}
|
| 292 |
+
|
| 293 |
+
# Load image_processor dict. Priority goes as (nested config if found -> image processor config)
|
| 294 |
+
# We are downloading both configs because almost all models have a `processor_config.json` but
|
| 295 |
+
# not all of these are nested. We need to check if it was saved recently as nested or if it is legacy style
|
| 296 |
+
image_processor_dict = {}
|
| 297 |
+
if resolved_processor_file is not None:
|
| 298 |
+
processor_dict = safe_load_json_file(resolved_processor_file)
|
| 299 |
+
if "image_processor" in processor_dict:
|
| 300 |
+
image_processor_dict = processor_dict["image_processor"]
|
| 301 |
+
|
| 302 |
+
if resolved_image_processor_file is not None and image_processor_dict is None:
|
| 303 |
+
image_processor_dict = safe_load_json_file(resolved_image_processor_file)
|
| 304 |
+
|
| 305 |
+
return image_processor_dict
|
| 306 |
+
|
| 307 |
+
|
| 308 |
+
def _resolve_backend(backend: str | None, use_fast: bool | None, base_class_name: str | None) -> str:
|
| 309 |
+
"""Resolve raw backend inputs to a concrete backend name ('torchvision' or 'pil').
|
| 310 |
+
|
| 311 |
+
Handles, in order:
|
| 312 |
+
- Deprecated ``use_fast`` flag: warns and converts to an explicit backend string when no
|
| 313 |
+
explicit backend is given.
|
| 314 |
+
- Explicit backend string: returned as-is.
|
| 315 |
+
- None resolution: forces 'pil' for processors in DEFAULT_TO_PIL_BACKEND_IMAGE_PROCESSORS
|
| 316 |
+
(Lanczos interpolation, unsupported by torchvision); otherwise picks 'torchvision' when
|
| 317 |
+
available, falling back to 'pil'.
|
| 318 |
+
"""
|
| 319 |
+
if use_fast is not None:
|
| 320 |
+
logger.warning_once(
|
| 321 |
+
"The `use_fast` parameter is deprecated and will be removed in a future version. "
|
| 322 |
+
'Use `backend="torchvision"` instead of `use_fast=True`, or `backend="pil"` instead of `use_fast=False`.'
|
| 323 |
+
)
|
| 324 |
+
if backend is None:
|
| 325 |
+
backend = "torchvision" if use_fast else "pil"
|
| 326 |
+
|
| 327 |
+
if backend is None:
|
| 328 |
+
if base_class_name in DEFAULT_TO_PIL_BACKEND_IMAGE_PROCESSORS:
|
| 329 |
+
return "pil"
|
| 330 |
+
return "torchvision" if is_torchvision_available() else "pil"
|
| 331 |
+
|
| 332 |
+
return backend
|
| 333 |
+
|
| 334 |
+
|
| 335 |
+
def _load_class_with_fallback(mapping, backend):
|
| 336 |
+
"""
|
| 337 |
+
Load an image processor class from a backend-to-class mapping, with fallback.
|
| 338 |
+
|
| 339 |
+
Tries the requested backend first, then the opposite standard backend,
|
| 340 |
+
then any remaining backends. Works with both string class names and resolved class objects.
|
| 341 |
+
|
| 342 |
+
Unavailable backends are detected via DummyObject: classes whose required libraries are missing
|
| 343 |
+
are represented as DummyObject subclasses (is_dummy=True). When the torchvision backend is
|
| 344 |
+
missing but a PIL variant exists, _LazyModule transparently returns the PIL class with its own
|
| 345 |
+
warning, so _load_class_with_fallback naturally receives a usable class without extra gating.
|
| 346 |
+
|
| 347 |
+
Args:
|
| 348 |
+
mapping: dict mapping backend names (str) to class names (str) or class objects (type).
|
| 349 |
+
backend: the preferred backend name (e.g. "torchvision", "pil").
|
| 350 |
+
|
| 351 |
+
Returns:
|
| 352 |
+
The loaded class, or None if no class could be loaded.
|
| 353 |
+
"""
|
| 354 |
+
backends_to_try = [backend] + [k for k in mapping if k != backend]
|
| 355 |
+
|
| 356 |
+
for b in backends_to_try:
|
| 357 |
+
value = mapping.get(b)
|
| 358 |
+
if value is None:
|
| 359 |
+
continue
|
| 360 |
+
|
| 361 |
+
# Value can be a class object (from resolved mapping) or a string class name
|
| 362 |
+
if isinstance(value, type):
|
| 363 |
+
processor_class = value
|
| 364 |
+
else:
|
| 365 |
+
processor_class = get_image_processor_class_from_name(value)
|
| 366 |
+
|
| 367 |
+
if processor_class is None or getattr(processor_class, "is_dummy", False):
|
| 368 |
+
continue
|
| 369 |
+
|
| 370 |
+
if b != backend:
|
| 371 |
+
logger.warning_once(f"Requested {backend} backend is not available. Falling back to {b} backend.")
|
| 372 |
+
return processor_class
|
| 373 |
+
|
| 374 |
+
return None
|
| 375 |
+
|
| 376 |
+
|
| 377 |
+
def _find_mapping_for_image_processor(base_class_name: str) -> dict | None:
|
| 378 |
+
"""
|
| 379 |
+
Find the backend->class mapping that contains base_class_name in its values.
|
| 380 |
+
Returns the mapping dict (including any custom registered backends) or None.
|
| 381 |
+
"""
|
| 382 |
+
|
| 383 |
+
def _value_matches(val, name: str) -> bool:
|
| 384 |
+
if val is None:
|
| 385 |
+
return False
|
| 386 |
+
if isinstance(val, str):
|
| 387 |
+
return val == name
|
| 388 |
+
if isinstance(val, type):
|
| 389 |
+
return getattr(val, "__name__", None) == name
|
| 390 |
+
return False
|
| 391 |
+
|
| 392 |
+
for mapping_dict in IMAGE_PROCESSOR_MAPPING_NAMES.values():
|
| 393 |
+
if any(_value_matches(v, base_class_name) for v in mapping_dict.values()):
|
| 394 |
+
return mapping_dict
|
| 395 |
+
|
| 396 |
+
for content in IMAGE_PROCESSOR_MAPPING._extra_content.values():
|
| 397 |
+
if any(_value_matches(v, base_class_name) for v in content.values()):
|
| 398 |
+
return content
|
| 399 |
+
|
| 400 |
+
return None
|
| 401 |
+
|
| 402 |
+
|
| 403 |
+
def _load_backend_class(base_class_name, backend, is_legacy_fast=False):
|
| 404 |
+
"""
|
| 405 |
+
Load image processor class for a given backend. Uses the mapping from
|
| 406 |
+
IMAGE_PROCESSOR_MAPPING when base_class_name is found in its values (so config
|
| 407 |
+
overrides and custom backends are respected). Falls back to base+Pil convention
|
| 408 |
+
for remote code / unknown processors.
|
| 409 |
+
"""
|
| 410 |
+
mapping = _find_mapping_for_image_processor(base_class_name)
|
| 411 |
+
if mapping is None:
|
| 412 |
+
mapping = {
|
| 413 |
+
"torchvision": base_class_name,
|
| 414 |
+
"pil": base_class_name + "Pil",
|
| 415 |
+
}
|
| 416 |
+
processor_class = _load_class_with_fallback(mapping, backend)
|
| 417 |
+
|
| 418 |
+
# For legacy Fast classes, try the original Fast class name as last resort
|
| 419 |
+
if processor_class is None and is_legacy_fast:
|
| 420 |
+
processor_class = get_image_processor_class_from_name(base_class_name + "Fast")
|
| 421 |
+
|
| 422 |
+
return processor_class
|
| 423 |
+
|
| 424 |
+
|
| 425 |
+
def _resolve_auto_map_class_ref(auto_map, backend):
|
| 426 |
+
"""Extract the class reference string from an auto_map entry based on backend preference.
|
| 427 |
+
|
| 428 |
+
Returns:
|
| 429 |
+
A string that may be:
|
| 430 |
+
- A simple class name (e.g. `"MyImageProcessor"`)
|
| 431 |
+
- A Hub reference in the form `upstream_repo--path/to/file.py::ClassName`, where the part before
|
| 432 |
+
`--` is the upstream repo ID (used for trust_remote_code resolution).
|
| 433 |
+
"""
|
| 434 |
+
if isinstance(auto_map, dict):
|
| 435 |
+
return auto_map.get(backend) or next(iter(auto_map.values()))
|
| 436 |
+
if isinstance(auto_map, (list, tuple)):
|
| 437 |
+
if backend == "torchvision" and len(auto_map) > 1 and auto_map[1] is not None:
|
| 438 |
+
return auto_map[1]
|
| 439 |
+
return auto_map[0]
|
| 440 |
+
# Single string (legacy)
|
| 441 |
+
return auto_map
|
| 442 |
+
|
| 443 |
+
|
| 444 |
+
@requires(backends=("vision",))
|
| 445 |
+
class AutoImageProcessor:
|
| 446 |
+
r"""
|
| 447 |
+
This is a generic image processor class that will be instantiated as one of the image processor classes of the
|
| 448 |
+
library when created with the [`AutoImageProcessor.from_pretrained`] class method.
|
| 449 |
+
|
| 450 |
+
This class cannot be instantiated directly using `__init__()` (throws an error).
|
| 451 |
+
"""
|
| 452 |
+
|
| 453 |
+
def __init__(self):
|
| 454 |
+
raise OSError(
|
| 455 |
+
"AutoImageProcessor is designed to be instantiated "
|
| 456 |
+
"using the `AutoImageProcessor.from_pretrained(pretrained_model_name_or_path)` method."
|
| 457 |
+
)
|
| 458 |
+
|
| 459 |
+
@classmethod
|
| 460 |
+
@replace_list_option_in_docstrings(IMAGE_PROCESSOR_MAPPING_NAMES)
|
| 461 |
+
def from_pretrained(cls, pretrained_model_name_or_path, *inputs, **kwargs):
|
| 462 |
+
r"""
|
| 463 |
+
Instantiate one of the image processor classes of the library from a pretrained model vocabulary.
|
| 464 |
+
|
| 465 |
+
The image processor class to instantiate is selected based on the `model_type` property of the config object
|
| 466 |
+
(either passed as an argument or loaded from `pretrained_model_name_or_path` if possible), or when it's
|
| 467 |
+
missing, by falling back to using pattern matching on `pretrained_model_name_or_path`:
|
| 468 |
+
|
| 469 |
+
List options
|
| 470 |
+
|
| 471 |
+
Params:
|
| 472 |
+
pretrained_model_name_or_path (`str` or `os.PathLike`):
|
| 473 |
+
This can be either:
|
| 474 |
+
|
| 475 |
+
- a string, the *model id* of a pretrained image_processor hosted inside a model repo on
|
| 476 |
+
huggingface.co.
|
| 477 |
+
- a path to a *directory* containing a image processor file saved using the
|
| 478 |
+
[`~image_processing_utils.ImageProcessingMixin.save_pretrained`] method, e.g.,
|
| 479 |
+
`./my_model_directory/`.
|
| 480 |
+
- a path to a saved image processor JSON *file*, e.g.,
|
| 481 |
+
`./my_model_directory/preprocessor_config.json`.
|
| 482 |
+
cache_dir (`str` or `os.PathLike`, *optional*):
|
| 483 |
+
Path to a directory in which a downloaded pretrained model image processor should be cached if the
|
| 484 |
+
standard cache should not be used.
|
| 485 |
+
force_download (`bool`, *optional*, defaults to `False`):
|
| 486 |
+
Whether or not to force to (re-)download the image processor files and override the cached versions if
|
| 487 |
+
they exist.
|
| 488 |
+
proxies (`dict[str, str]`, *optional*):
|
| 489 |
+
A dictionary of proxy servers to use by protocol or endpoint, e.g., `{'http': 'foo.bar:3128',
|
| 490 |
+
'http://hostname': 'foo.bar:4012'}.` The proxies are used on each request.
|
| 491 |
+
token (`str` or *bool*, *optional*):
|
| 492 |
+
The token to use as HTTP bearer authorization for remote files. If `True`, will use the token generated
|
| 493 |
+
when running `hf auth login` (stored in `~/.huggingface`).
|
| 494 |
+
revision (`str`, *optional*, defaults to `"main"`):
|
| 495 |
+
The specific model version to use. It can be a branch name, a tag name, or a commit id, since we use a
|
| 496 |
+
git-based system for storing models and other artifacts on huggingface.co, so `revision` can be any
|
| 497 |
+
identifier allowed by git.
|
| 498 |
+
use_fast (`bool`, *optional*, defaults to `False`):
|
| 499 |
+
**Deprecated**: Use `backend="torchvision"` instead. This parameter is kept for backward compatibility.
|
| 500 |
+
Use a fast torchvision-based image processor if it is supported for a given model.
|
| 501 |
+
If a fast image processor is not available for a given model, a normal numpy-based image processor
|
| 502 |
+
is returned instead.
|
| 503 |
+
backend (`str`, *optional*, defaults to `None`):
|
| 504 |
+
The backend to use for image processing. Can be:
|
| 505 |
+
- `None`: Automatically select the best available backend (torchvision if available, otherwise pil)
|
| 506 |
+
- `"torchvision"`: Use Torchvision backend (GPU-accelerated, faster)
|
| 507 |
+
- `"pil"`: Use PIL backend (portable, CPU-only)
|
| 508 |
+
- Any custom backend name registered via `register()` method
|
| 509 |
+
return_unused_kwargs (`bool`, *optional*, defaults to `False`):
|
| 510 |
+
If `False`, then this function returns just the final image processor object. If `True`, then this
|
| 511 |
+
functions returns a `Tuple(image_processor, unused_kwargs)` where *unused_kwargs* is a dictionary
|
| 512 |
+
consisting of the key/value pairs whose keys are not image processor attributes: i.e., the part of
|
| 513 |
+
`kwargs` which has not been used to update `image_processor` and is otherwise ignored.
|
| 514 |
+
trust_remote_code (`bool`, *optional*, defaults to `False`):
|
| 515 |
+
Whether or not to allow for custom models defined on the Hub in their own modeling files. This option
|
| 516 |
+
should only be set to `True` for repositories you trust and in which you have read the code, as it will
|
| 517 |
+
execute code present on the Hub on your local machine.
|
| 518 |
+
image_processor_filename (`str`, *optional*, defaults to `"config.json"`):
|
| 519 |
+
The name of the file in the model directory to use for the image processor config.
|
| 520 |
+
kwargs (`dict[str, Any]`, *optional*):
|
| 521 |
+
The values in kwargs of any keys which are image processor attributes will be used to override the
|
| 522 |
+
loaded values. Behavior concerning key/value pairs whose keys are *not* image processor attributes is
|
| 523 |
+
controlled by the `return_unused_kwargs` keyword parameter.
|
| 524 |
+
|
| 525 |
+
<Tip>
|
| 526 |
+
|
| 527 |
+
Passing `token=True` is required when you want to use a private model.
|
| 528 |
+
|
| 529 |
+
</Tip>
|
| 530 |
+
|
| 531 |
+
Examples:
|
| 532 |
+
|
| 533 |
+
```python
|
| 534 |
+
>>> from transformers import AutoImageProcessor
|
| 535 |
+
|
| 536 |
+
>>> # Download image processor from huggingface.co and cache.
|
| 537 |
+
>>> image_processor = AutoImageProcessor.from_pretrained("google/vit-base-patch16-224-in21k")
|
| 538 |
+
|
| 539 |
+
>>> # If image processor files are in a directory (e.g. image processor was saved using *save_pretrained('./test/saved_model/')*)
|
| 540 |
+
>>> # image_processor = AutoImageProcessor.from_pretrained("./test/saved_model/")
|
| 541 |
+
```"""
|
| 542 |
+
config = kwargs.pop("config", None)
|
| 543 |
+
use_fast = kwargs.pop("use_fast", None)
|
| 544 |
+
backend_kwarg = kwargs.pop("backend", None)
|
| 545 |
+
trust_remote_code = kwargs.pop("trust_remote_code", None)
|
| 546 |
+
kwargs["_from_auto"] = True
|
| 547 |
+
|
| 548 |
+
# Resolve the image processor config filename
|
| 549 |
+
if "image_processor_filename" in kwargs:
|
| 550 |
+
image_processor_filename = kwargs.pop("image_processor_filename")
|
| 551 |
+
elif is_timm_local_checkpoint(pretrained_model_name_or_path):
|
| 552 |
+
image_processor_filename = CONFIG_NAME
|
| 553 |
+
else:
|
| 554 |
+
image_processor_filename = IMAGE_PROCESSOR_NAME
|
| 555 |
+
|
| 556 |
+
# Load the image processor config
|
| 557 |
+
|
| 558 |
+
try:
|
| 559 |
+
config_dict, _ = ImageProcessingMixin.get_image_processor_dict(
|
| 560 |
+
pretrained_model_name_or_path, image_processor_filename=image_processor_filename, **kwargs
|
| 561 |
+
)
|
| 562 |
+
except Exception as initial_exception:
|
| 563 |
+
# Fallback for Hub TimmWrapper checkpoints (image processing in config.json, not preprocessor_config.json)
|
| 564 |
+
try:
|
| 565 |
+
config_dict, _ = ImageProcessingMixin.get_image_processor_dict(
|
| 566 |
+
pretrained_model_name_or_path, image_processor_filename=CONFIG_NAME, **kwargs
|
| 567 |
+
)
|
| 568 |
+
except Exception:
|
| 569 |
+
raise initial_exception
|
| 570 |
+
|
| 571 |
+
if not is_timm_config_dict(config_dict):
|
| 572 |
+
raise initial_exception
|
| 573 |
+
|
| 574 |
+
image_processor_type = config_dict.get("image_processor_type", None)
|
| 575 |
+
image_processor_auto_map = None
|
| 576 |
+
if "AutoImageProcessor" in config_dict.get("auto_map", {}):
|
| 577 |
+
image_processor_auto_map = config_dict["auto_map"]["AutoImageProcessor"]
|
| 578 |
+
|
| 579 |
+
# Backward compat: infer from feature extractor config
|
| 580 |
+
if image_processor_type is None and image_processor_auto_map is None:
|
| 581 |
+
feature_extractor_class = config_dict.pop("feature_extractor_type", None)
|
| 582 |
+
if feature_extractor_class is not None:
|
| 583 |
+
image_processor_type = feature_extractor_class.replace("FeatureExtractor", "ImageProcessor")
|
| 584 |
+
if "AutoFeatureExtractor" in config_dict.get("auto_map", {}):
|
| 585 |
+
feature_extractor_auto_map = config_dict["auto_map"]["AutoFeatureExtractor"]
|
| 586 |
+
image_processor_auto_map = feature_extractor_auto_map.replace("FeatureExtractor", "ImageProcessor")
|
| 587 |
+
|
| 588 |
+
# If not in image processor config, try the model config (override image_processor_auto_map if trust_remote_code is False)
|
| 589 |
+
if image_processor_type is None and (image_processor_auto_map is None or trust_remote_code is False):
|
| 590 |
+
if not isinstance(config, PreTrainedConfig):
|
| 591 |
+
config = AutoConfig.from_pretrained(
|
| 592 |
+
pretrained_model_name_or_path,
|
| 593 |
+
trust_remote_code=trust_remote_code,
|
| 594 |
+
**kwargs,
|
| 595 |
+
)
|
| 596 |
+
image_processor_type = getattr(config, "image_processor_type", None)
|
| 597 |
+
if hasattr(config, "auto_map") and "AutoImageProcessor" in config.auto_map:
|
| 598 |
+
image_processor_auto_map = config.auto_map["AutoImageProcessor"]
|
| 599 |
+
|
| 600 |
+
# Derive base_class_name from image_processor_type
|
| 601 |
+
is_legacy_fast = False
|
| 602 |
+
base_class_name = None
|
| 603 |
+
if image_processor_type is not None:
|
| 604 |
+
is_legacy_fast = image_processor_type.endswith("Fast")
|
| 605 |
+
base_class_name = image_processor_type[:-4] if is_legacy_fast else image_processor_type
|
| 606 |
+
|
| 607 |
+
backend = _resolve_backend(backend_kwarg, use_fast, base_class_name)
|
| 608 |
+
|
| 609 |
+
image_processor_class = None
|
| 610 |
+
if base_class_name is not None:
|
| 611 |
+
image_processor_class = _load_backend_class(base_class_name, backend, is_legacy_fast)
|
| 612 |
+
|
| 613 |
+
# Handle remote code
|
| 614 |
+
has_remote_code = image_processor_auto_map is not None
|
| 615 |
+
has_local_code = image_processor_class is not None or type(config) in IMAGE_PROCESSOR_MAPPING
|
| 616 |
+
explicit_local_code = has_local_code and not (
|
| 617 |
+
image_processor_class or _load_class_with_fallback(IMAGE_PROCESSOR_MAPPING[type(config)], backend)
|
| 618 |
+
).__module__.startswith("transformers.")
|
| 619 |
+
if has_remote_code:
|
| 620 |
+
class_ref = _resolve_auto_map_class_ref(image_processor_auto_map, backend)
|
| 621 |
+
upstream_repo = class_ref.split("--")[0] if "--" in class_ref else None
|
| 622 |
+
trust_remote_code = resolve_trust_remote_code(
|
| 623 |
+
trust_remote_code, pretrained_model_name_or_path, has_local_code, has_remote_code, upstream_repo
|
| 624 |
+
)
|
| 625 |
+
|
| 626 |
+
if has_remote_code and trust_remote_code and not explicit_local_code:
|
| 627 |
+
image_processor_class = get_class_from_dynamic_module(class_ref, pretrained_model_name_or_path, **kwargs)
|
| 628 |
+
_ = kwargs.pop("code_revision", None)
|
| 629 |
+
image_processor_class.register_for_auto_class()
|
| 630 |
+
return image_processor_class.from_pretrained(pretrained_model_name_or_path, *inputs, **kwargs)
|
| 631 |
+
elif image_processor_class is not None:
|
| 632 |
+
return image_processor_class.from_pretrained(pretrained_model_name_or_path, *inputs, **kwargs)
|
| 633 |
+
# Last try: we use the IMAGE_PROCESSOR_MAPPING.
|
| 634 |
+
elif type(config) in IMAGE_PROCESSOR_MAPPING:
|
| 635 |
+
image_processor_mapping = IMAGE_PROCESSOR_MAPPING[type(config)]
|
| 636 |
+
image_processor_class = _load_class_with_fallback(image_processor_mapping, backend)
|
| 637 |
+
|
| 638 |
+
if image_processor_class is not None:
|
| 639 |
+
return image_processor_class.from_pretrained(pretrained_model_name_or_path, *inputs, **kwargs)
|
| 640 |
+
|
| 641 |
+
available = [k for k, v in image_processor_mapping.items() if v is not None]
|
| 642 |
+
raise ValueError(f"Could not find image processor class. Available backends: {', '.join(available)}")
|
| 643 |
+
raise ValueError(
|
| 644 |
+
f"Unrecognized image processor in {pretrained_model_name_or_path}. Should have a "
|
| 645 |
+
f"`image_processor_type` key in its {IMAGE_PROCESSOR_NAME} of {CONFIG_NAME}, or one of the following "
|
| 646 |
+
f"`model_type` keys in its {CONFIG_NAME}: {', '.join(c for c in IMAGE_PROCESSOR_MAPPING_NAMES)}"
|
| 647 |
+
)
|
| 648 |
+
|
| 649 |
+
@staticmethod
|
| 650 |
+
def register(
|
| 651 |
+
config_class,
|
| 652 |
+
slow_image_processor_class: type | None = None,
|
| 653 |
+
fast_image_processor_class: type | None = None,
|
| 654 |
+
image_processor_classes: dict[str, type] | None = None,
|
| 655 |
+
exist_ok: bool = False,
|
| 656 |
+
):
|
| 657 |
+
"""
|
| 658 |
+
Register a new image processor for this class.
|
| 659 |
+
|
| 660 |
+
Args:
|
| 661 |
+
config_class ([`PreTrainedConfig`]):
|
| 662 |
+
The configuration corresponding to the model to register.
|
| 663 |
+
slow_image_processor_class (`type`, *optional*):
|
| 664 |
+
The PIL backend image processor class (deprecated, use `image_processor_classes={"pil": ...}`).
|
| 665 |
+
fast_image_processor_class (`type`, *optional*):
|
| 666 |
+
The Torchvision backend image processor class (deprecated, use `image_processor_classes={"torchvision": ...}`).
|
| 667 |
+
image_processor_classes (`dict[str, type]`, *optional*):
|
| 668 |
+
Dictionary mapping backend names to image processor classes. Allows registering custom backends.
|
| 669 |
+
Example: `{"pil": MyPilProcessor, "torchvision": MyTorchvisionProcessor, "custom": MyCustomProcessor}`
|
| 670 |
+
exist_ok (`bool`, *optional*, defaults to `False`):
|
| 671 |
+
If `True`, allow overwriting existing registrations.
|
| 672 |
+
"""
|
| 673 |
+
# Handle backward compatibility: convert old parameters to new format
|
| 674 |
+
if image_processor_classes is None:
|
| 675 |
+
image_processor_classes = {}
|
| 676 |
+
if slow_image_processor_class is not None:
|
| 677 |
+
image_processor_classes["pil"] = slow_image_processor_class
|
| 678 |
+
if fast_image_processor_class is not None:
|
| 679 |
+
image_processor_classes["torchvision"] = fast_image_processor_class
|
| 680 |
+
|
| 681 |
+
if not image_processor_classes:
|
| 682 |
+
raise ValueError(
|
| 683 |
+
"You need to specify at least one image processor class. "
|
| 684 |
+
"Use `image_processor_classes={'backend_name': ProcessorClass}` or the deprecated "
|
| 685 |
+
"`slow_image_processor_class`/`fast_image_processor_class` parameters."
|
| 686 |
+
)
|
| 687 |
+
|
| 688 |
+
# Avoid resetting existing processors if we are passing partial updates
|
| 689 |
+
if config_class in IMAGE_PROCESSOR_MAPPING._extra_content:
|
| 690 |
+
existing_mapping = IMAGE_PROCESSOR_MAPPING[config_class]
|
| 691 |
+
existing_mapping.update(image_processor_classes)
|
| 692 |
+
image_processor_classes = existing_mapping
|
| 693 |
+
|
| 694 |
+
# Validate that all classes are proper image processor classes
|
| 695 |
+
from ...image_processing_utils import BaseImageProcessor
|
| 696 |
+
|
| 697 |
+
for backend_key, processor_class in image_processor_classes.items():
|
| 698 |
+
if processor_class is not None and not issubclass(processor_class, BaseImageProcessor):
|
| 699 |
+
raise ValueError(
|
| 700 |
+
f"Image processor class for backend '{backend_key}' must inherit from `BaseImageProcessor`. "
|
| 701 |
+
f"Got: {processor_class}"
|
| 702 |
+
)
|
| 703 |
+
IMAGE_PROCESSOR_MAPPING.register(config_class, image_processor_classes, exist_ok=exist_ok)
|
| 704 |
+
|
| 705 |
+
|
| 706 |
+
__all__ = ["IMAGE_PROCESSOR_MAPPING", "AutoImageProcessor"]
|
LTA_openwebtext_dualt/mini_owt_logdirichlet/.venv_qwen35_uv/lib/python3.12/site-packages/transformers/models/auto/modeling_auto.py
ADDED
|
The diff for this file is too large to render.
See raw diff
|
|
|
LTA_openwebtext_dualt/mini_owt_logdirichlet/.venv_qwen35_uv/lib/python3.12/site-packages/transformers/models/auto/processing_auto.py
ADDED
|
@@ -0,0 +1,474 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# Copyright 2021 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 |
+
"""AutoProcessor class."""
|
| 15 |
+
|
| 16 |
+
import importlib
|
| 17 |
+
import json
|
| 18 |
+
from collections import OrderedDict
|
| 19 |
+
from typing import TYPE_CHECKING
|
| 20 |
+
|
| 21 |
+
# Build the list of all feature extractors
|
| 22 |
+
from ...configuration_utils import PreTrainedConfig
|
| 23 |
+
from ...dynamic_module_utils import get_class_from_dynamic_module, resolve_trust_remote_code
|
| 24 |
+
from ...feature_extraction_utils import FeatureExtractionMixin
|
| 25 |
+
from ...image_processing_utils import ImageProcessingMixin
|
| 26 |
+
from ...processing_utils import ProcessorMixin
|
| 27 |
+
from ...tokenization_python import TOKENIZER_CONFIG_FILE
|
| 28 |
+
from ...utils import FEATURE_EXTRACTOR_NAME, PROCESSOR_NAME, VIDEO_PROCESSOR_NAME, cached_file, logging
|
| 29 |
+
from ...video_processing_utils import BaseVideoProcessor
|
| 30 |
+
from .auto_factory import _LazyAutoMapping
|
| 31 |
+
from .configuration_auto import (
|
| 32 |
+
CONFIG_MAPPING_NAMES,
|
| 33 |
+
AutoConfig,
|
| 34 |
+
model_type_to_module_name,
|
| 35 |
+
replace_list_option_in_docstrings,
|
| 36 |
+
)
|
| 37 |
+
from .feature_extraction_auto import AutoFeatureExtractor
|
| 38 |
+
from .image_processing_auto import AutoImageProcessor
|
| 39 |
+
from .tokenization_auto import AutoTokenizer
|
| 40 |
+
from .video_processing_auto import AutoVideoProcessor
|
| 41 |
+
|
| 42 |
+
|
| 43 |
+
logger = logging.get_logger(__name__)
|
| 44 |
+
if TYPE_CHECKING:
|
| 45 |
+
# This significantly improves completion suggestion performance when
|
| 46 |
+
# the transformers package is used with Microsoft's Pylance language server.
|
| 47 |
+
PROCESSOR_MAPPING_NAMES: OrderedDict[str, str | None] = OrderedDict()
|
| 48 |
+
else:
|
| 49 |
+
PROCESSOR_MAPPING_NAMES = OrderedDict(
|
| 50 |
+
[
|
| 51 |
+
("aimv2", "CLIPProcessor"),
|
| 52 |
+
("align", "AlignProcessor"),
|
| 53 |
+
("altclip", "AltCLIPProcessor"),
|
| 54 |
+
("aria", "AriaProcessor"),
|
| 55 |
+
("audioflamingo3", "AudioFlamingo3Processor"),
|
| 56 |
+
("aya_vision", "AyaVisionProcessor"),
|
| 57 |
+
("bark", "BarkProcessor"),
|
| 58 |
+
("blip", "BlipProcessor"),
|
| 59 |
+
("blip-2", "Blip2Processor"),
|
| 60 |
+
("bridgetower", "BridgeTowerProcessor"),
|
| 61 |
+
("chameleon", "ChameleonProcessor"),
|
| 62 |
+
("chinese_clip", "ChineseCLIPProcessor"),
|
| 63 |
+
("clap", "ClapProcessor"),
|
| 64 |
+
("clip", "CLIPProcessor"),
|
| 65 |
+
("clipseg", "CLIPSegProcessor"),
|
| 66 |
+
("clvp", "ClvpProcessor"),
|
| 67 |
+
("cohere2_vision", "Cohere2VisionProcessor"),
|
| 68 |
+
("cohere_asr", "CohereAsrProcessor"),
|
| 69 |
+
("colmodernvbert", "ColModernVBertProcessor"),
|
| 70 |
+
("colpali", "ColPaliProcessor"),
|
| 71 |
+
("colqwen2", "ColQwen2Processor"),
|
| 72 |
+
("deepseek_vl", "DeepseekVLProcessor"),
|
| 73 |
+
("deepseek_vl_hybrid", "DeepseekVLHybridProcessor"),
|
| 74 |
+
("dia", "DiaProcessor"),
|
| 75 |
+
("edgetam", "Sam2Processor"),
|
| 76 |
+
("emu3", "Emu3Processor"),
|
| 77 |
+
("ernie4_5_vl_moe", "Ernie4_5_VLMoeProcessor"),
|
| 78 |
+
("evolla", "EvollaProcessor"),
|
| 79 |
+
("exaone4_5", "Exaone4_5_Processor"),
|
| 80 |
+
("flava", "FlavaProcessor"),
|
| 81 |
+
("florence2", "Florence2Processor"),
|
| 82 |
+
("fuyu", "FuyuProcessor"),
|
| 83 |
+
("gemma3", "Gemma3Processor"),
|
| 84 |
+
("gemma3n", "Gemma3nProcessor"),
|
| 85 |
+
("gemma4", "Gemma4Processor"),
|
| 86 |
+
("git", "GitProcessor"),
|
| 87 |
+
("glm46v", "Glm46VProcessor"),
|
| 88 |
+
("glm4v", "Glm4vProcessor"),
|
| 89 |
+
("glm4v_moe", "Glm4vProcessor"),
|
| 90 |
+
("glm_image", "Glm4vProcessor"),
|
| 91 |
+
("glmasr", "GlmAsrProcessor"),
|
| 92 |
+
("got_ocr2", "GotOcr2Processor"),
|
| 93 |
+
("granite4_vision", "Granite4VisionProcessor"),
|
| 94 |
+
("granite_speech", "GraniteSpeechProcessor"),
|
| 95 |
+
("granite_speech_plus", "GraniteSpeechProcessor"),
|
| 96 |
+
("grounding-dino", "GroundingDinoProcessor"),
|
| 97 |
+
("groupvit", "CLIPProcessor"),
|
| 98 |
+
("higgs_audio_v2", "HiggsAudioV2Processor"),
|
| 99 |
+
("hubert", "Wav2Vec2Processor"),
|
| 100 |
+
("idefics", "IdeficsProcessor"),
|
| 101 |
+
("idefics2", "Idefics2Processor"),
|
| 102 |
+
("idefics3", "Idefics3Processor"),
|
| 103 |
+
("instructblip", "InstructBlipProcessor"),
|
| 104 |
+
("instructblipvideo", "InstructBlipVideoProcessor"),
|
| 105 |
+
("internvl", "InternVLProcessor"),
|
| 106 |
+
("janus", "JanusProcessor"),
|
| 107 |
+
("kosmos-2", "Kosmos2Processor"),
|
| 108 |
+
("kosmos-2.5", "Kosmos2_5Processor"),
|
| 109 |
+
("kyutai_speech_to_text", "KyutaiSpeechToTextProcessor"),
|
| 110 |
+
("lasr_ctc", "LasrProcessor"),
|
| 111 |
+
("lasr_encoder", "LasrProcessor"),
|
| 112 |
+
("layoutlmv2", "LayoutLMv2Processor"),
|
| 113 |
+
("layoutlmv3", "LayoutLMv3Processor"),
|
| 114 |
+
("layoutxlm", "LayoutXLMProcessor"),
|
| 115 |
+
("lfm2_vl", "Lfm2VlProcessor"),
|
| 116 |
+
("lighton_ocr", "LightOnOcrProcessor"),
|
| 117 |
+
("llama4", "Llama4Processor"),
|
| 118 |
+
("llava", "LlavaProcessor"),
|
| 119 |
+
("llava_next", "LlavaNextProcessor"),
|
| 120 |
+
("llava_next_video", "LlavaNextVideoProcessor"),
|
| 121 |
+
("llava_onevision", "LlavaOnevisionProcessor"),
|
| 122 |
+
("markuplm", "MarkupLMProcessor"),
|
| 123 |
+
("metaclip_2", "CLIPProcessor"),
|
| 124 |
+
("mgp-str", "MgpstrProcessor"),
|
| 125 |
+
("minicpmv4_6", "MiniCPMV4_6Processor"),
|
| 126 |
+
("mistral3", "PixtralProcessor"),
|
| 127 |
+
("mllama", "MllamaProcessor"),
|
| 128 |
+
("mm-grounding-dino", "GroundingDinoProcessor"),
|
| 129 |
+
("modernvbert", "Idefics3Processor"),
|
| 130 |
+
("moonshine", "Wav2Vec2Processor"),
|
| 131 |
+
("moonshine_streaming", "MoonshineStreamingProcessor"),
|
| 132 |
+
("musicflamingo", "MusicFlamingoProcessor"),
|
| 133 |
+
("omdet-turbo", "OmDetTurboProcessor"),
|
| 134 |
+
("oneformer", "OneFormerProcessor"),
|
| 135 |
+
("ovis2", "Ovis2Processor"),
|
| 136 |
+
("owlv2", "Owlv2Processor"),
|
| 137 |
+
("owlvit", "OwlViTProcessor"),
|
| 138 |
+
("paddleocr_vl", "PaddleOCRVLProcessor"),
|
| 139 |
+
("paligemma", "PaliGemmaProcessor"),
|
| 140 |
+
("parakeet_ctc", "ParakeetProcessor"),
|
| 141 |
+
("parakeet_tdt", "ParakeetProcessor"),
|
| 142 |
+
("perception_lm", "PerceptionLMProcessor"),
|
| 143 |
+
("phi4_multimodal", "Phi4MultimodalProcessor"),
|
| 144 |
+
("pi0", "PI0Processor"),
|
| 145 |
+
("pix2struct", "Pix2StructProcessor"),
|
| 146 |
+
("pixtral", "PixtralProcessor"),
|
| 147 |
+
("pop2piano", "Pop2PianoProcessor"),
|
| 148 |
+
("pp_chart2table", "PPChart2TableProcessor"),
|
| 149 |
+
("pp_formulanet", "PPFormulaNetProcessor"),
|
| 150 |
+
("qianfan_ocr", "QianfanOCRProcessor"),
|
| 151 |
+
("qwen2_5_omni", "Qwen2_5OmniProcessor"),
|
| 152 |
+
("qwen2_5_vl", "Qwen2_5_VLProcessor"),
|
| 153 |
+
("qwen2_audio", "Qwen2AudioProcessor"),
|
| 154 |
+
("qwen2_vl", "Qwen2VLProcessor"),
|
| 155 |
+
("qwen3_5", "Qwen3VLProcessor"),
|
| 156 |
+
("qwen3_5_moe", "Qwen3VLProcessor"),
|
| 157 |
+
("qwen3_omni_moe", "Qwen3OmniMoeProcessor"),
|
| 158 |
+
("qwen3_vl", "Qwen3VLProcessor"),
|
| 159 |
+
("qwen3_vl_moe", "Qwen3VLProcessor"),
|
| 160 |
+
("sam", "SamProcessor"),
|
| 161 |
+
("sam2", "Sam2Processor"),
|
| 162 |
+
("sam3", "Sam3Processor"),
|
| 163 |
+
("sam3_lite_text", "Sam3Processor"),
|
| 164 |
+
("sam_hq", "SamHQProcessor"),
|
| 165 |
+
("seamless_m4t", "SeamlessM4TProcessor"),
|
| 166 |
+
("sew", "Wav2Vec2Processor"),
|
| 167 |
+
("sew-d", "Wav2Vec2Processor"),
|
| 168 |
+
("shieldgemma2", "ShieldGemma2Processor"),
|
| 169 |
+
("siglip", "SiglipProcessor"),
|
| 170 |
+
("siglip2", "Siglip2Processor"),
|
| 171 |
+
("smolvlm", "SmolVLMProcessor"),
|
| 172 |
+
("speech_to_text", "Speech2TextProcessor"),
|
| 173 |
+
("speecht5", "SpeechT5Processor"),
|
| 174 |
+
("t5gemma2", "Gemma3Processor"),
|
| 175 |
+
("t5gemma2_encoder", "Gemma3Processor"),
|
| 176 |
+
("trocr", "TrOCRProcessor"),
|
| 177 |
+
("tvp", "TvpProcessor"),
|
| 178 |
+
("udop", "UdopProcessor"),
|
| 179 |
+
("unispeech", "Wav2Vec2Processor"),
|
| 180 |
+
("unispeech-sat", "Wav2Vec2Processor"),
|
| 181 |
+
("vibevoice_asr", "VibeVoiceAsrProcessor"),
|
| 182 |
+
("video_llava", "VideoLlavaProcessor"),
|
| 183 |
+
("vilt", "ViltProcessor"),
|
| 184 |
+
("vipllava", "LlavaProcessor"),
|
| 185 |
+
("vision-text-dual-encoder", "VisionTextDualEncoderProcessor"),
|
| 186 |
+
("voxtral", "VoxtralProcessor"),
|
| 187 |
+
("voxtral_realtime", "VoxtralRealtimeProcessor"),
|
| 188 |
+
("wav2vec2", "Wav2Vec2Processor"),
|
| 189 |
+
("wav2vec2-bert", "Wav2Vec2Processor"),
|
| 190 |
+
("wav2vec2-conformer", "Wav2Vec2Processor"),
|
| 191 |
+
("wavlm", "Wav2Vec2Processor"),
|
| 192 |
+
("whisper", "WhisperProcessor"),
|
| 193 |
+
("xclip", "XCLIPProcessor"),
|
| 194 |
+
]
|
| 195 |
+
)
|
| 196 |
+
|
| 197 |
+
PROCESSOR_MAPPING = _LazyAutoMapping(CONFIG_MAPPING_NAMES, PROCESSOR_MAPPING_NAMES)
|
| 198 |
+
|
| 199 |
+
|
| 200 |
+
def processor_class_from_name(class_name: str):
|
| 201 |
+
for module_name, processors in PROCESSOR_MAPPING_NAMES.items():
|
| 202 |
+
if class_name in processors:
|
| 203 |
+
module_name = model_type_to_module_name(module_name)
|
| 204 |
+
|
| 205 |
+
module = importlib.import_module(f".{module_name}", "transformers.models")
|
| 206 |
+
try:
|
| 207 |
+
return getattr(module, class_name)
|
| 208 |
+
except AttributeError:
|
| 209 |
+
continue
|
| 210 |
+
|
| 211 |
+
for processor in PROCESSOR_MAPPING._extra_content.values():
|
| 212 |
+
if getattr(processor, "__name__", None) == class_name:
|
| 213 |
+
return processor
|
| 214 |
+
|
| 215 |
+
# We did not find the class, but maybe it's because a dep is missing. In that case, the class will be in the main
|
| 216 |
+
# init and we return the proper dummy to get an appropriate error message.
|
| 217 |
+
main_module = importlib.import_module("transformers")
|
| 218 |
+
if hasattr(main_module, class_name):
|
| 219 |
+
return getattr(main_module, class_name)
|
| 220 |
+
|
| 221 |
+
return None
|
| 222 |
+
|
| 223 |
+
|
| 224 |
+
class AutoProcessor:
|
| 225 |
+
r"""
|
| 226 |
+
This is a generic processor class that will be instantiated as one of the processor classes of the library when
|
| 227 |
+
created with the [`AutoProcessor.from_pretrained`] class method.
|
| 228 |
+
|
| 229 |
+
This class cannot be instantiated directly using `__init__()` (throws an error).
|
| 230 |
+
"""
|
| 231 |
+
|
| 232 |
+
def __init__(self):
|
| 233 |
+
raise OSError(
|
| 234 |
+
"AutoProcessor is designed to be instantiated "
|
| 235 |
+
"using the `AutoProcessor.from_pretrained(pretrained_model_name_or_path)` method."
|
| 236 |
+
)
|
| 237 |
+
|
| 238 |
+
@classmethod
|
| 239 |
+
@replace_list_option_in_docstrings(PROCESSOR_MAPPING_NAMES)
|
| 240 |
+
def from_pretrained(cls, pretrained_model_name_or_path, **kwargs):
|
| 241 |
+
r"""
|
| 242 |
+
Instantiate one of the processor classes of the library from a pretrained model vocabulary.
|
| 243 |
+
|
| 244 |
+
The processor class to instantiate is selected based on the `model_type` property of the config object (either
|
| 245 |
+
passed as an argument or loaded from `pretrained_model_name_or_path` if possible):
|
| 246 |
+
|
| 247 |
+
List options
|
| 248 |
+
|
| 249 |
+
Params:
|
| 250 |
+
pretrained_model_name_or_path (`str` or `os.PathLike`):
|
| 251 |
+
This can be either:
|
| 252 |
+
|
| 253 |
+
- a string, the *model id* of a pretrained feature_extractor hosted inside a model repo on
|
| 254 |
+
huggingface.co.
|
| 255 |
+
- a path to a *directory* containing a processor files saved using the `save_pretrained()` method,
|
| 256 |
+
e.g., `./my_model_directory/`.
|
| 257 |
+
cache_dir (`str` or `os.PathLike`, *optional*):
|
| 258 |
+
Path to a directory in which a downloaded pretrained model feature extractor should be cached if the
|
| 259 |
+
standard cache should not be used.
|
| 260 |
+
force_download (`bool`, *optional*, defaults to `False`):
|
| 261 |
+
Whether or not to force to (re-)download the feature extractor files and override the cached versions
|
| 262 |
+
if they exist.
|
| 263 |
+
proxies (`dict[str, str]`, *optional*):
|
| 264 |
+
A dictionary of proxy servers to use by protocol or endpoint, e.g., `{'http': 'foo.bar:3128',
|
| 265 |
+
'http://hostname': 'foo.bar:4012'}.` The proxies are used on each request.
|
| 266 |
+
token (`str` or *bool*, *optional*):
|
| 267 |
+
The token to use as HTTP bearer authorization for remote files. If `True`, will use the token generated
|
| 268 |
+
when running `hf auth login` (stored in `~/.huggingface`).
|
| 269 |
+
revision (`str`, *optional*, defaults to `"main"`):
|
| 270 |
+
The specific model version to use. It can be a branch name, a tag name, or a commit id, since we use a
|
| 271 |
+
git-based system for storing models and other artifacts on huggingface.co, so `revision` can be any
|
| 272 |
+
identifier allowed by git.
|
| 273 |
+
return_unused_kwargs (`bool`, *optional*, defaults to `False`):
|
| 274 |
+
If `False`, then this function returns just the final feature extractor object. If `True`, then this
|
| 275 |
+
functions returns a `Tuple(feature_extractor, unused_kwargs)` where *unused_kwargs* is a dictionary
|
| 276 |
+
consisting of the key/value pairs whose keys are not feature extractor attributes: i.e., the part of
|
| 277 |
+
`kwargs` which has not been used to update `feature_extractor` and is otherwise ignored.
|
| 278 |
+
trust_remote_code (`bool`, *optional*, defaults to `False`):
|
| 279 |
+
Whether or not to allow for custom models defined on the Hub in their own modeling files. This option
|
| 280 |
+
should only be set to `True` for repositories you trust and in which you have read the code, as it will
|
| 281 |
+
execute code present on the Hub on your local machine.
|
| 282 |
+
kwargs (`dict[str, Any]`, *optional*):
|
| 283 |
+
The values in kwargs of any keys which are feature extractor attributes will be used to override the
|
| 284 |
+
loaded values. Behavior concerning key/value pairs whose keys are *not* feature extractor attributes is
|
| 285 |
+
controlled by the `return_unused_kwargs` keyword parameter.
|
| 286 |
+
|
| 287 |
+
<Tip>
|
| 288 |
+
|
| 289 |
+
Passing `token=True` is required when you want to use a private model.
|
| 290 |
+
|
| 291 |
+
</Tip>
|
| 292 |
+
|
| 293 |
+
Examples:
|
| 294 |
+
|
| 295 |
+
```python
|
| 296 |
+
>>> from transformers import AutoProcessor
|
| 297 |
+
|
| 298 |
+
>>> # Download processor from huggingface.co and cache.
|
| 299 |
+
>>> processor = AutoProcessor.from_pretrained("facebook/wav2vec2-base-960h")
|
| 300 |
+
|
| 301 |
+
>>> # If processor files are in a directory (e.g. processor was saved using *save_pretrained('./test/saved_model/')*)
|
| 302 |
+
>>> # processor = AutoProcessor.from_pretrained("./test/saved_model/")
|
| 303 |
+
```"""
|
| 304 |
+
config = kwargs.pop("config", None)
|
| 305 |
+
trust_remote_code = kwargs.pop("trust_remote_code", None)
|
| 306 |
+
kwargs["_from_auto"] = True
|
| 307 |
+
|
| 308 |
+
processor_class = None
|
| 309 |
+
processor_auto_map = None
|
| 310 |
+
|
| 311 |
+
# First, let's see if we have a processor or preprocessor config.
|
| 312 |
+
# Filter the kwargs for `cached_file`.
|
| 313 |
+
_hub_valid_kwargs = (
|
| 314 |
+
"cache_dir",
|
| 315 |
+
"force_download",
|
| 316 |
+
"proxies",
|
| 317 |
+
"token",
|
| 318 |
+
"revision",
|
| 319 |
+
"local_files_only",
|
| 320 |
+
"subfolder",
|
| 321 |
+
"repo_type",
|
| 322 |
+
"user_agent",
|
| 323 |
+
)
|
| 324 |
+
cached_file_kwargs = {key: kwargs[key] for key in _hub_valid_kwargs if key in kwargs}
|
| 325 |
+
# We don't want to raise
|
| 326 |
+
cached_file_kwargs.update(
|
| 327 |
+
{
|
| 328 |
+
"_raise_exceptions_for_gated_repo": False,
|
| 329 |
+
"_raise_exceptions_for_missing_entries": False,
|
| 330 |
+
"_raise_exceptions_for_connection_errors": False,
|
| 331 |
+
}
|
| 332 |
+
)
|
| 333 |
+
|
| 334 |
+
# Let's start by checking whether the processor class is saved in a processor config
|
| 335 |
+
processor_config_file = cached_file(pretrained_model_name_or_path, PROCESSOR_NAME, **cached_file_kwargs)
|
| 336 |
+
if processor_config_file is not None:
|
| 337 |
+
config_dict, _ = ProcessorMixin.get_processor_dict(pretrained_model_name_or_path, **kwargs)
|
| 338 |
+
processor_class = config_dict.get("processor_class")
|
| 339 |
+
if "AutoProcessor" in config_dict.get("auto_map", {}):
|
| 340 |
+
processor_auto_map = config_dict["auto_map"]["AutoProcessor"]
|
| 341 |
+
|
| 342 |
+
if processor_class is None:
|
| 343 |
+
# If not found, let's check whether the processor class is saved in an image processor config
|
| 344 |
+
preprocessor_config_file = cached_file(
|
| 345 |
+
pretrained_model_name_or_path, FEATURE_EXTRACTOR_NAME, **cached_file_kwargs
|
| 346 |
+
)
|
| 347 |
+
if preprocessor_config_file is not None:
|
| 348 |
+
config_dict, _ = ImageProcessingMixin.get_image_processor_dict(pretrained_model_name_or_path, **kwargs)
|
| 349 |
+
processor_class = config_dict.get("processor_class", None)
|
| 350 |
+
if "AutoProcessor" in config_dict.get("auto_map", {}):
|
| 351 |
+
processor_auto_map = config_dict["auto_map"]["AutoProcessor"]
|
| 352 |
+
|
| 353 |
+
# Saved as video processor
|
| 354 |
+
if preprocessor_config_file is None:
|
| 355 |
+
preprocessor_config_file = cached_file(
|
| 356 |
+
pretrained_model_name_or_path, VIDEO_PROCESSOR_NAME, **cached_file_kwargs
|
| 357 |
+
)
|
| 358 |
+
if preprocessor_config_file is not None:
|
| 359 |
+
config_dict, _ = BaseVideoProcessor.get_video_processor_dict(
|
| 360 |
+
pretrained_model_name_or_path, **kwargs
|
| 361 |
+
)
|
| 362 |
+
processor_class = config_dict.get("processor_class", None)
|
| 363 |
+
if "AutoProcessor" in config_dict.get("auto_map", {}):
|
| 364 |
+
processor_auto_map = config_dict["auto_map"]["AutoProcessor"]
|
| 365 |
+
# Saved as feature extractor
|
| 366 |
+
if preprocessor_config_file is None:
|
| 367 |
+
preprocessor_config_file = cached_file(
|
| 368 |
+
pretrained_model_name_or_path, FEATURE_EXTRACTOR_NAME, **cached_file_kwargs
|
| 369 |
+
)
|
| 370 |
+
if preprocessor_config_file is not None and processor_class is None:
|
| 371 |
+
config_dict, _ = FeatureExtractionMixin.get_feature_extractor_dict(
|
| 372 |
+
pretrained_model_name_or_path, **kwargs
|
| 373 |
+
)
|
| 374 |
+
processor_class = config_dict.get("processor_class", None)
|
| 375 |
+
if "AutoProcessor" in config_dict.get("auto_map", {}):
|
| 376 |
+
processor_auto_map = config_dict["auto_map"]["AutoProcessor"]
|
| 377 |
+
|
| 378 |
+
if processor_class is None:
|
| 379 |
+
# Next, let's check whether the processor class is saved in a tokenizer
|
| 380 |
+
tokenizer_config_file = cached_file(
|
| 381 |
+
pretrained_model_name_or_path, TOKENIZER_CONFIG_FILE, **cached_file_kwargs
|
| 382 |
+
)
|
| 383 |
+
if tokenizer_config_file is not None:
|
| 384 |
+
with open(tokenizer_config_file, encoding="utf-8") as reader:
|
| 385 |
+
config_dict = json.load(reader)
|
| 386 |
+
|
| 387 |
+
processor_class = config_dict.get("processor_class", None)
|
| 388 |
+
if "AutoProcessor" in config_dict.get("auto_map", {}):
|
| 389 |
+
processor_auto_map = config_dict["auto_map"]["AutoProcessor"]
|
| 390 |
+
|
| 391 |
+
if processor_class is None:
|
| 392 |
+
# Last resort: try loading the model config to get processor_class.
|
| 393 |
+
# This handles cases where processor info is only in config.json (not in any
|
| 394 |
+
# preprocessor/tokenizer config files). AutoConfig.from_pretrained may raise
|
| 395 |
+
# ValueError if the model_type is unrecognized or the config is invalid -
|
| 396 |
+
# we catch and ignore this to allow fallback to AutoTokenizer/AutoImageProcessor.
|
| 397 |
+
try:
|
| 398 |
+
if not isinstance(config, PreTrainedConfig):
|
| 399 |
+
config = AutoConfig.from_pretrained(
|
| 400 |
+
pretrained_model_name_or_path, trust_remote_code=trust_remote_code, **kwargs
|
| 401 |
+
)
|
| 402 |
+
|
| 403 |
+
processor_class = getattr(config, "processor_class", None)
|
| 404 |
+
if hasattr(config, "auto_map") and "AutoProcessor" in config.auto_map:
|
| 405 |
+
processor_auto_map = config.auto_map["AutoProcessor"]
|
| 406 |
+
except ValueError:
|
| 407 |
+
# Config loading failed (unrecognized model_type, invalid config, etc.)
|
| 408 |
+
# Continue to fallback logic below (AutoTokenizer, AutoImageProcessor, etc.)
|
| 409 |
+
pass
|
| 410 |
+
|
| 411 |
+
if processor_class is not None:
|
| 412 |
+
processor_class = processor_class_from_name(processor_class)
|
| 413 |
+
|
| 414 |
+
has_remote_code = processor_auto_map is not None
|
| 415 |
+
has_local_code = processor_class is not None or type(config) in PROCESSOR_MAPPING
|
| 416 |
+
explicit_local_code = has_local_code and not (
|
| 417 |
+
processor_class or PROCESSOR_MAPPING[type(config)]
|
| 418 |
+
).__module__.startswith("transformers.")
|
| 419 |
+
if has_remote_code:
|
| 420 |
+
if "--" in processor_auto_map:
|
| 421 |
+
upstream_repo = processor_auto_map.split("--")[0]
|
| 422 |
+
else:
|
| 423 |
+
upstream_repo = None
|
| 424 |
+
trust_remote_code = resolve_trust_remote_code(
|
| 425 |
+
trust_remote_code, pretrained_model_name_or_path, has_local_code, has_remote_code, upstream_repo
|
| 426 |
+
)
|
| 427 |
+
|
| 428 |
+
if has_remote_code and trust_remote_code and not explicit_local_code:
|
| 429 |
+
processor_class = get_class_from_dynamic_module(
|
| 430 |
+
processor_auto_map, pretrained_model_name_or_path, **kwargs
|
| 431 |
+
)
|
| 432 |
+
_ = kwargs.pop("code_revision", None)
|
| 433 |
+
processor_class.register_for_auto_class()
|
| 434 |
+
return processor_class.from_pretrained(
|
| 435 |
+
pretrained_model_name_or_path, trust_remote_code=trust_remote_code, **kwargs
|
| 436 |
+
)
|
| 437 |
+
elif processor_class is not None:
|
| 438 |
+
return processor_class.from_pretrained(
|
| 439 |
+
pretrained_model_name_or_path, trust_remote_code=trust_remote_code, **kwargs
|
| 440 |
+
)
|
| 441 |
+
# Last try: we use the PROCESSOR_MAPPING.
|
| 442 |
+
elif type(config) in PROCESSOR_MAPPING:
|
| 443 |
+
return PROCESSOR_MAPPING[type(config)].from_pretrained(pretrained_model_name_or_path, **kwargs)
|
| 444 |
+
|
| 445 |
+
# At this stage, there doesn't seem to be a `Processor` class available for this model.
|
| 446 |
+
# Let's try the commonly available classes
|
| 447 |
+
for klass in (AutoTokenizer, AutoImageProcessor, AutoVideoProcessor, AutoFeatureExtractor):
|
| 448 |
+
try:
|
| 449 |
+
return klass.from_pretrained(
|
| 450 |
+
pretrained_model_name_or_path, trust_remote_code=trust_remote_code, **kwargs
|
| 451 |
+
)
|
| 452 |
+
except Exception:
|
| 453 |
+
continue
|
| 454 |
+
|
| 455 |
+
raise ValueError(
|
| 456 |
+
f"Unrecognized processing class in {pretrained_model_name_or_path}. Can't instantiate a processor, a "
|
| 457 |
+
"tokenizer, an image processor, a video processor or a feature extractor for this model. "
|
| 458 |
+
"Make sure the repository contains the files of at least one of those processing classes."
|
| 459 |
+
)
|
| 460 |
+
|
| 461 |
+
@staticmethod
|
| 462 |
+
def register(config_class, processor_class, exist_ok=False):
|
| 463 |
+
"""
|
| 464 |
+
Register a new processor for this class.
|
| 465 |
+
|
| 466 |
+
Args:
|
| 467 |
+
config_class ([`PreTrainedConfig`]):
|
| 468 |
+
The configuration corresponding to the model to register.
|
| 469 |
+
processor_class ([`ProcessorMixin`]): The processor to register.
|
| 470 |
+
"""
|
| 471 |
+
PROCESSOR_MAPPING.register(config_class, processor_class, exist_ok=exist_ok)
|
| 472 |
+
|
| 473 |
+
|
| 474 |
+
__all__ = ["PROCESSOR_MAPPING", "AutoProcessor"]
|
LTA_openwebtext_dualt/mini_owt_logdirichlet/.venv_qwen35_uv/lib/python3.12/site-packages/transformers/models/auto/tokenization_auto.py
ADDED
|
@@ -0,0 +1,893 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# Copyright 2018 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 |
+
"""Auto Tokenizer class."""
|
| 15 |
+
|
| 16 |
+
import importlib
|
| 17 |
+
import json
|
| 18 |
+
import os
|
| 19 |
+
import sys
|
| 20 |
+
from collections import OrderedDict
|
| 21 |
+
from typing import Any
|
| 22 |
+
|
| 23 |
+
from transformers.utils.import_utils import is_mistral_common_available
|
| 24 |
+
|
| 25 |
+
from ...configuration_utils import PreTrainedConfig
|
| 26 |
+
from ...dynamic_module_utils import get_class_from_dynamic_module, resolve_trust_remote_code
|
| 27 |
+
from ...modeling_gguf_pytorch_utils import load_gguf_checkpoint
|
| 28 |
+
from ...tokenization_utils_base import TOKENIZER_CONFIG_FILE
|
| 29 |
+
from ...utils import (
|
| 30 |
+
extract_commit_hash,
|
| 31 |
+
is_g2p_en_available,
|
| 32 |
+
is_sentencepiece_available,
|
| 33 |
+
is_tokenizers_available,
|
| 34 |
+
logging,
|
| 35 |
+
)
|
| 36 |
+
from ...utils.hub import cached_file
|
| 37 |
+
from ..encoder_decoder import EncoderDecoderConfig
|
| 38 |
+
from .auto_factory import _LazyAutoMapping
|
| 39 |
+
from .configuration_auto import (
|
| 40 |
+
CONFIG_MAPPING_NAMES,
|
| 41 |
+
AutoConfig,
|
| 42 |
+
config_class_to_model_type,
|
| 43 |
+
model_type_to_module_name,
|
| 44 |
+
replace_list_option_in_docstrings,
|
| 45 |
+
)
|
| 46 |
+
|
| 47 |
+
|
| 48 |
+
if is_tokenizers_available():
|
| 49 |
+
from ...tokenization_utils_tokenizers import TokenizersBackend
|
| 50 |
+
else:
|
| 51 |
+
TokenizersBackend = None
|
| 52 |
+
|
| 53 |
+
if is_sentencepiece_available():
|
| 54 |
+
from ...tokenization_utils_sentencepiece import SentencePieceBackend
|
| 55 |
+
else:
|
| 56 |
+
SentencePieceBackend = None
|
| 57 |
+
|
| 58 |
+
logger = logging.get_logger(__name__)
|
| 59 |
+
|
| 60 |
+
# V5: Simplified mapping - single tokenizer class per model type (always prefer tokenizers-based)
|
| 61 |
+
REGISTERED_TOKENIZER_CLASSES: dict[str, type[Any]] = {}
|
| 62 |
+
REGISTERED_FAST_ALIASES: dict[str, type[Any]] = {}
|
| 63 |
+
|
| 64 |
+
TOKENIZER_MAPPING_NAMES = OrderedDict[str, str | None](
|
| 65 |
+
[
|
| 66 |
+
("aimv2", "CLIPTokenizer" if is_tokenizers_available() else None),
|
| 67 |
+
("albert", "AlbertTokenizer" if is_tokenizers_available() else None),
|
| 68 |
+
("align", "BertTokenizer" if is_tokenizers_available() else None),
|
| 69 |
+
("audioflamingo3", "Qwen2Tokenizer" if is_tokenizers_available() else None),
|
| 70 |
+
("aya_vision", "CohereTokenizer" if is_tokenizers_available() else None),
|
| 71 |
+
("bark", "BertTokenizer" if is_tokenizers_available() else None),
|
| 72 |
+
("bart", "RobertaTokenizer" if is_tokenizers_available() else None),
|
| 73 |
+
("barthez", "BarthezTokenizer" if is_tokenizers_available() else None),
|
| 74 |
+
("bartpho", "BartphoTokenizer"),
|
| 75 |
+
("bert", "BertTokenizer" if is_tokenizers_available() else None),
|
| 76 |
+
("bert-generation", "BertGenerationTokenizer" if is_sentencepiece_available() else None),
|
| 77 |
+
("bert-japanese", "BertJapaneseTokenizer"),
|
| 78 |
+
("bertweet", "BertweetTokenizer"),
|
| 79 |
+
("big_bird", "BigBirdTokenizer" if is_tokenizers_available() else None),
|
| 80 |
+
("bigbird_pegasus", "PegasusTokenizer" if is_tokenizers_available() else None),
|
| 81 |
+
("biogpt", "BioGptTokenizer"),
|
| 82 |
+
("blenderbot", "BlenderbotTokenizer" if is_tokenizers_available() else None),
|
| 83 |
+
("blenderbot-small", "BlenderbotSmallTokenizer"),
|
| 84 |
+
("blip", "BertTokenizer" if is_tokenizers_available() else None),
|
| 85 |
+
("blip-2", "GPT2Tokenizer" if is_tokenizers_available() else None),
|
| 86 |
+
("bridgetower", "RobertaTokenizer"),
|
| 87 |
+
("bros", "BertTokenizer" if is_tokenizers_available() else None),
|
| 88 |
+
("byt5", "ByT5Tokenizer"),
|
| 89 |
+
("camembert", "CamembertTokenizer" if is_tokenizers_available() else None),
|
| 90 |
+
("canine", "CanineTokenizer"),
|
| 91 |
+
("chinese_clip", "BertTokenizer" if is_tokenizers_available() else None),
|
| 92 |
+
("clap", "RobertaTokenizer"),
|
| 93 |
+
("clip", "CLIPTokenizer" if is_tokenizers_available() else None),
|
| 94 |
+
("clipseg", "CLIPTokenizer" if is_tokenizers_available() else None),
|
| 95 |
+
("clvp", "ClvpTokenizer"),
|
| 96 |
+
("code_llama", "CodeLlamaTokenizer" if is_tokenizers_available() else None),
|
| 97 |
+
("codegen", "GPT2Tokenizer" if is_tokenizers_available() else None),
|
| 98 |
+
("cohere", "CohereTokenizer" if is_tokenizers_available() else None),
|
| 99 |
+
("cohere2", "CohereTokenizer" if is_tokenizers_available() else None),
|
| 100 |
+
("colqwen2", "Qwen2Tokenizer" if is_tokenizers_available() else None),
|
| 101 |
+
("convbert", "BertTokenizer" if is_tokenizers_available() else None),
|
| 102 |
+
("cpm", "CpmTokenizer" if is_tokenizers_available() else None),
|
| 103 |
+
("cpmant", "CpmAntTokenizer"),
|
| 104 |
+
("ctrl", "CTRLTokenizer"),
|
| 105 |
+
("data2vec-audio", "Wav2Vec2CTCTokenizer"),
|
| 106 |
+
("data2vec-text", "RobertaTokenizer"),
|
| 107 |
+
("dbrx", "GPT2Tokenizer" if is_tokenizers_available() else None),
|
| 108 |
+
("deberta", "DebertaTokenizer" if is_tokenizers_available() else None),
|
| 109 |
+
("deberta-v2", "DebertaV2Tokenizer" if is_tokenizers_available() else None),
|
| 110 |
+
("dia", "DiaTokenizer"),
|
| 111 |
+
("distilbert", "BertTokenizer" if is_tokenizers_available() else None),
|
| 112 |
+
("dpr", "DPRQuestionEncoderTokenizer" if is_tokenizers_available() else None),
|
| 113 |
+
("electra", "BertTokenizer" if is_tokenizers_available() else None),
|
| 114 |
+
("emu3", "GPT2Tokenizer" if is_tokenizers_available() else None),
|
| 115 |
+
("ernie", "BertTokenizer" if is_tokenizers_available() else None),
|
| 116 |
+
("esm", "EsmTokenizer"),
|
| 117 |
+
("falcon_mamba", "GPTNeoXTokenizer" if is_tokenizers_available() else None),
|
| 118 |
+
("fastspeech2_conformer", "FastSpeech2ConformerTokenizer" if is_g2p_en_available() else None),
|
| 119 |
+
("flaubert", "FlaubertTokenizer"),
|
| 120 |
+
("flava", "BertTokenizer" if is_tokenizers_available() else None),
|
| 121 |
+
("flex_olmo", "GPT2Tokenizer" if is_tokenizers_available() else None),
|
| 122 |
+
("florence2", "BartTokenizer" if is_tokenizers_available() else None),
|
| 123 |
+
("fnet", "FNetTokenizer" if is_tokenizers_available() else None),
|
| 124 |
+
("fsmt", "FSMTTokenizer"),
|
| 125 |
+
("funnel", "FunnelTokenizer" if is_tokenizers_available() else None),
|
| 126 |
+
("gemma", "GemmaTokenizer" if is_tokenizers_available() else None),
|
| 127 |
+
("gemma2", "GemmaTokenizer" if is_tokenizers_available() else None),
|
| 128 |
+
("gemma3", "GemmaTokenizer" if is_tokenizers_available() else None),
|
| 129 |
+
("gemma3_text", "GemmaTokenizer" if is_tokenizers_available() else None),
|
| 130 |
+
("gemma3n", "GemmaTokenizer" if is_tokenizers_available() else None),
|
| 131 |
+
("gemma3n_text", "GemmaTokenizer" if is_tokenizers_available() else None),
|
| 132 |
+
("git", "BertTokenizer" if is_tokenizers_available() else None),
|
| 133 |
+
("glm", "TokenizersBackend" if is_tokenizers_available() else None),
|
| 134 |
+
("glm4", "TokenizersBackend" if is_tokenizers_available() else None),
|
| 135 |
+
("glm4_moe", "TokenizersBackend" if is_tokenizers_available() else None),
|
| 136 |
+
("glm4_moe_lite", "TokenizersBackend" if is_tokenizers_available() else None),
|
| 137 |
+
("glm4v", "TokenizersBackend" if is_tokenizers_available() else None),
|
| 138 |
+
("glm4v_moe", "TokenizersBackend" if is_tokenizers_available() else None),
|
| 139 |
+
("glm_image", "TokenizersBackend" if is_tokenizers_available() else None),
|
| 140 |
+
("glmasr", "TokenizersBackend" if is_tokenizers_available() else None),
|
| 141 |
+
("got_ocr2", "TokenizersBackend" if is_tokenizers_available() else None),
|
| 142 |
+
("gpt-sw3", "GPTSw3Tokenizer" if is_sentencepiece_available() else None),
|
| 143 |
+
("gpt2", "GPT2Tokenizer" if is_tokenizers_available() else None),
|
| 144 |
+
("gpt_bigcode", "GPT2Tokenizer" if is_tokenizers_available() else None),
|
| 145 |
+
("gpt_neo", "GPT2Tokenizer" if is_tokenizers_available() else None),
|
| 146 |
+
("gpt_neox", "GPTNeoXTokenizer" if is_tokenizers_available() else None),
|
| 147 |
+
("gpt_neox_japanese", "GPTNeoXJapaneseTokenizer"),
|
| 148 |
+
("gptj", "GPT2Tokenizer" if is_tokenizers_available() else None),
|
| 149 |
+
("granite", "TokenizersBackend" if is_tokenizers_available() else None),
|
| 150 |
+
("granitemoe", "TokenizersBackend" if is_tokenizers_available() else None),
|
| 151 |
+
("granitemoehybrid", "TokenizersBackend" if is_tokenizers_available() else None),
|
| 152 |
+
("granitemoeshared", "TokenizersBackend" if is_tokenizers_available() else None),
|
| 153 |
+
("grounding-dino", "BertTokenizer" if is_tokenizers_available() else None),
|
| 154 |
+
("groupvit", "CLIPTokenizer" if is_tokenizers_available() else None),
|
| 155 |
+
("herbert", "HerbertTokenizer" if is_tokenizers_available() else None),
|
| 156 |
+
("hubert", "Wav2Vec2CTCTokenizer"),
|
| 157 |
+
("ibert", "RobertaTokenizer"),
|
| 158 |
+
("idefics", "LlamaTokenizer" if is_tokenizers_available() else None),
|
| 159 |
+
("idefics2", "LlamaTokenizer" if is_tokenizers_available() else None),
|
| 160 |
+
("instructblip", "GPT2Tokenizer" if is_tokenizers_available() else None),
|
| 161 |
+
("instructblipvideo", "GPT2Tokenizer" if is_tokenizers_available() else None),
|
| 162 |
+
("internvl", "Qwen2Tokenizer" if is_tokenizers_available() else None),
|
| 163 |
+
("jais2", "GPT2Tokenizer" if is_tokenizers_available() else None),
|
| 164 |
+
("jina_embeddings_v3", "XLMRobertaTokenizer" if is_tokenizers_available() else None),
|
| 165 |
+
("kosmos-2", "XLMRobertaTokenizer" if is_tokenizers_available() else None),
|
| 166 |
+
("lasr_ctc", "LasrTokenizer" if is_tokenizers_available() else None),
|
| 167 |
+
("lasr_encoder", "LasrTokenizer" if is_tokenizers_available() else None),
|
| 168 |
+
("layoutlm", "BertTokenizer" if is_tokenizers_available() else None),
|
| 169 |
+
("layoutlmv2", "LayoutLMv2Tokenizer" if is_tokenizers_available() else None),
|
| 170 |
+
("layoutlmv3", "LayoutLMv3Tokenizer" if is_tokenizers_available() else None),
|
| 171 |
+
("layoutxlm", "LayoutXLMTokenizer" if is_tokenizers_available() else None),
|
| 172 |
+
("led", "LEDTokenizer" if is_tokenizers_available() else None),
|
| 173 |
+
("lighton_ocr", "Qwen2TokenizerFast" if is_tokenizers_available() else None),
|
| 174 |
+
("lilt", "RobertaTokenizer" if is_tokenizers_available() else None),
|
| 175 |
+
("longformer", "RobertaTokenizer" if is_tokenizers_available() else None),
|
| 176 |
+
("luke", "LukeTokenizer"),
|
| 177 |
+
("lxmert", "LxmertTokenizer" if is_tokenizers_available() else None),
|
| 178 |
+
("m2m_100", "M2M100Tokenizer" if is_sentencepiece_available() else None),
|
| 179 |
+
("mamba", "GPTNeoXTokenizer" if is_tokenizers_available() else None),
|
| 180 |
+
("mamba2", "GPTNeoXTokenizer" if is_tokenizers_available() else None),
|
| 181 |
+
("marian", "MarianTokenizer" if is_sentencepiece_available() else None),
|
| 182 |
+
("markuplm", "MarkupLMTokenizer" if is_tokenizers_available() else None),
|
| 183 |
+
("mbart", "MBartTokenizer" if is_tokenizers_available() else None),
|
| 184 |
+
("mbart50", "MBart50Tokenizer" if is_tokenizers_available() else None),
|
| 185 |
+
("mega", "RobertaTokenizer"),
|
| 186 |
+
("megatron-bert", "BertTokenizer" if is_tokenizers_available() else None),
|
| 187 |
+
("metaclip_2", "XLMRobertaTokenizer" if is_tokenizers_available() else None),
|
| 188 |
+
("mgp-str", "MgpstrTokenizer"),
|
| 189 |
+
("minicpmv4_6", "TokenizersBackend" if is_tokenizers_available() else None),
|
| 190 |
+
(
|
| 191 |
+
"ministral",
|
| 192 |
+
"MistralCommonBackend"
|
| 193 |
+
if is_mistral_common_available()
|
| 194 |
+
else ("TokenizersBackend" if is_tokenizers_available() else None),
|
| 195 |
+
),
|
| 196 |
+
(
|
| 197 |
+
"ministral3",
|
| 198 |
+
"MistralCommonBackend"
|
| 199 |
+
if is_mistral_common_available()
|
| 200 |
+
else ("TokenizersBackend" if is_tokenizers_available() else None),
|
| 201 |
+
),
|
| 202 |
+
(
|
| 203 |
+
"mistral",
|
| 204 |
+
"MistralCommonBackend"
|
| 205 |
+
if is_mistral_common_available()
|
| 206 |
+
else ("TokenizersBackend" if is_tokenizers_available() else None),
|
| 207 |
+
),
|
| 208 |
+
(
|
| 209 |
+
"mistral3",
|
| 210 |
+
"MistralCommonBackend"
|
| 211 |
+
if is_mistral_common_available()
|
| 212 |
+
else ("TokenizersBackend" if is_tokenizers_available() else None),
|
| 213 |
+
),
|
| 214 |
+
(
|
| 215 |
+
"mixtral",
|
| 216 |
+
"MistralCommonBackend"
|
| 217 |
+
if is_mistral_common_available()
|
| 218 |
+
else ("TokenizersBackend" if is_tokenizers_available() else None),
|
| 219 |
+
),
|
| 220 |
+
("mluke", "MLukeTokenizer" if is_sentencepiece_available() else None),
|
| 221 |
+
("mm-grounding-dino", "BertTokenizer" if is_tokenizers_available() else None),
|
| 222 |
+
("mobilebert", "MobileBertTokenizer" if is_tokenizers_available() else None),
|
| 223 |
+
("mpnet", "MPNetTokenizer" if is_tokenizers_available() else None),
|
| 224 |
+
("mpt", "GPTNeoXTokenizer" if is_tokenizers_available() else None),
|
| 225 |
+
("mra", "RobertaTokenizer"),
|
| 226 |
+
("mt5", "T5Tokenizer" if is_tokenizers_available() else None),
|
| 227 |
+
("musicgen", "T5Tokenizer" if is_tokenizers_available() else None),
|
| 228 |
+
("musicgen_melody", "T5Tokenizer" if is_tokenizers_available() else None),
|
| 229 |
+
("mvp", "MvpTokenizer" if is_tokenizers_available() else None),
|
| 230 |
+
("myt5", "MyT5Tokenizer"),
|
| 231 |
+
("nezha", "BertTokenizer" if is_tokenizers_available() else None),
|
| 232 |
+
("nllb", "NllbTokenizer" if is_tokenizers_available() else None),
|
| 233 |
+
("nllb-moe", "NllbTokenizer" if is_tokenizers_available() else None),
|
| 234 |
+
("nomic_bert", "BertTokenizer" if is_tokenizers_available() else None),
|
| 235 |
+
("nougat", "NougatTokenizer" if is_tokenizers_available() else None),
|
| 236 |
+
("nystromformer", "AlbertTokenizer" if is_tokenizers_available() else None),
|
| 237 |
+
("olmo", "GPTNeoXTokenizer" if is_tokenizers_available() else None),
|
| 238 |
+
("olmo2", "GPTNeoXTokenizer" if is_tokenizers_available() else None),
|
| 239 |
+
("olmo3", "TokenizersBackend" if is_tokenizers_available() else None),
|
| 240 |
+
("olmo_hybrid", "TokenizersBackend" if is_tokenizers_available() else None),
|
| 241 |
+
("olmoe", "GPTNeoXTokenizer" if is_tokenizers_available() else None),
|
| 242 |
+
("omdet-turbo", "CLIPTokenizer" if is_tokenizers_available() else None),
|
| 243 |
+
("oneformer", "CLIPTokenizer" if is_tokenizers_available() else None),
|
| 244 |
+
("openai-gpt", "OpenAIGPTTokenizer" if is_tokenizers_available() else None),
|
| 245 |
+
("opt", "GPT2Tokenizer" if is_tokenizers_available() else None),
|
| 246 |
+
("ovis2", "Qwen2Tokenizer" if is_tokenizers_available() else None),
|
| 247 |
+
("owlv2", "CLIPTokenizer" if is_tokenizers_available() else None),
|
| 248 |
+
("owlvit", "CLIPTokenizer" if is_tokenizers_available() else None),
|
| 249 |
+
("parakeet_ctc", "ParakeetTokenizer" if is_tokenizers_available() else None),
|
| 250 |
+
("parakeet_tdt", "ParakeetTokenizer" if is_tokenizers_available() else None),
|
| 251 |
+
("pegasus", "PegasusTokenizer" if is_tokenizers_available() else None),
|
| 252 |
+
("pegasus_x", "PegasusTokenizer" if is_tokenizers_available() else None),
|
| 253 |
+
("perceiver", "PerceiverTokenizer"),
|
| 254 |
+
("phi", "GPT2Tokenizer" if is_tokenizers_available() else None),
|
| 255 |
+
("phobert", "PhobertTokenizer"),
|
| 256 |
+
("pix2struct", "T5Tokenizer" if is_tokenizers_available() else None),
|
| 257 |
+
(
|
| 258 |
+
"pixtral",
|
| 259 |
+
"MistralCommonBackend"
|
| 260 |
+
if is_mistral_common_available()
|
| 261 |
+
else ("TokenizersBackend" if is_tokenizers_available() else None),
|
| 262 |
+
),
|
| 263 |
+
("plbart", "PLBartTokenizer" if is_tokenizers_available() else None),
|
| 264 |
+
("pp_formulanet", "NougatTokenizer" if is_tokenizers_available() else None),
|
| 265 |
+
("prophetnet", "ProphetNetTokenizer"),
|
| 266 |
+
("qdqbert", "BertTokenizer" if is_tokenizers_available() else None),
|
| 267 |
+
("qianfan_ocr", "Qwen2Tokenizer" if is_tokenizers_available() else None),
|
| 268 |
+
("qwen2", "Qwen2Tokenizer" if is_tokenizers_available() else None),
|
| 269 |
+
("qwen2_5_omni", "Qwen2Tokenizer" if is_tokenizers_available() else None),
|
| 270 |
+
("qwen2_5_vl", "Qwen2Tokenizer" if is_tokenizers_available() else None),
|
| 271 |
+
("qwen2_audio", "Qwen2Tokenizer" if is_tokenizers_available() else None),
|
| 272 |
+
("qwen2_moe", "Qwen2Tokenizer" if is_tokenizers_available() else None),
|
| 273 |
+
("qwen2_vl", "Qwen2Tokenizer" if is_tokenizers_available() else None),
|
| 274 |
+
("qwen3", "Qwen2Tokenizer" if is_tokenizers_available() else None),
|
| 275 |
+
("qwen3_5", "Qwen3_5Tokenizer" if is_tokenizers_available() else None),
|
| 276 |
+
("qwen3_5_moe", "Qwen3_5Tokenizer" if is_tokenizers_available() else None),
|
| 277 |
+
("qwen3_moe", "Qwen2Tokenizer" if is_tokenizers_available() else None),
|
| 278 |
+
("qwen3_next", "Qwen2Tokenizer" if is_tokenizers_available() else None),
|
| 279 |
+
("qwen3_omni_moe", "Qwen2Tokenizer" if is_tokenizers_available() else None),
|
| 280 |
+
("qwen3_vl", "Qwen2Tokenizer" if is_tokenizers_available() else None),
|
| 281 |
+
("qwen3_vl_moe", "Qwen2Tokenizer" if is_tokenizers_available() else None),
|
| 282 |
+
("rag", "RagTokenizer"),
|
| 283 |
+
("realm", "BertTokenizer" if is_tokenizers_available() else None),
|
| 284 |
+
("recurrent_gemma", "GemmaTokenizer" if is_tokenizers_available() else None),
|
| 285 |
+
("reformer", "ReformerTokenizer" if is_tokenizers_available() else None),
|
| 286 |
+
("rembert", "RemBertTokenizer" if is_tokenizers_available() else None),
|
| 287 |
+
("retribert", "BertTokenizer" if is_tokenizers_available() else None),
|
| 288 |
+
("roberta", "RobertaTokenizer"),
|
| 289 |
+
("roberta-prelayernorm", "RobertaTokenizer"),
|
| 290 |
+
("roc_bert", "RoCBertTokenizer"),
|
| 291 |
+
("roformer", "RoFormerTokenizer" if is_tokenizers_available() else None),
|
| 292 |
+
("rwkv", "GPTNeoXTokenizer" if is_tokenizers_available() else None),
|
| 293 |
+
("sam3", "CLIPTokenizer" if is_tokenizers_available() else None),
|
| 294 |
+
("sam3_video", "CLIPTokenizer" if is_tokenizers_available() else None),
|
| 295 |
+
("seamless_m4t", "SeamlessM4TTokenizer" if is_tokenizers_available() else None),
|
| 296 |
+
("seamless_m4t_v2", "SeamlessM4TTokenizer" if is_tokenizers_available() else None),
|
| 297 |
+
("shieldgemma2", "GemmaTokenizer" if is_tokenizers_available() else None),
|
| 298 |
+
("siglip", "SiglipTokenizer" if is_sentencepiece_available() else None),
|
| 299 |
+
("siglip2", "Siglip2Tokenizer" if is_tokenizers_available() else None),
|
| 300 |
+
("speech_to_text", "Speech2TextTokenizer" if is_sentencepiece_available() else None),
|
| 301 |
+
("speecht5", "SpeechT5Tokenizer" if is_sentencepiece_available() else None),
|
| 302 |
+
("splinter", "SplinterTokenizer"),
|
| 303 |
+
("squeezebert", "BertTokenizer" if is_tokenizers_available() else None),
|
| 304 |
+
("stablelm", "GPTNeoXTokenizer" if is_tokenizers_available() else None),
|
| 305 |
+
("starcoder2", "GPT2Tokenizer" if is_tokenizers_available() else None),
|
| 306 |
+
("switch_transformers", "T5Tokenizer" if is_tokenizers_available() else None),
|
| 307 |
+
("t5", "T5Tokenizer" if is_tokenizers_available() else None),
|
| 308 |
+
("t5gemma", "GemmaTokenizer" if is_tokenizers_available() else None),
|
| 309 |
+
("tapas", "TapasTokenizer"),
|
| 310 |
+
("trocr", "XLMRobertaTokenizer" if is_tokenizers_available() else None),
|
| 311 |
+
("tvp", "BertTokenizer" if is_tokenizers_available() else None),
|
| 312 |
+
("udop", "UdopTokenizer" if is_tokenizers_available() else None),
|
| 313 |
+
("umt5", "T5Tokenizer" if is_tokenizers_available() else None),
|
| 314 |
+
("unispeech", "Wav2Vec2CTCTokenizer"),
|
| 315 |
+
("unispeech-sat", "Wav2Vec2CTCTokenizer"),
|
| 316 |
+
("vilt", "BertTokenizer" if is_tokenizers_available() else None),
|
| 317 |
+
("visual_bert", "BertTokenizer" if is_tokenizers_available() else None),
|
| 318 |
+
("vits", "VitsTokenizer"),
|
| 319 |
+
(
|
| 320 |
+
"voxtral",
|
| 321 |
+
"MistralCommonBackend"
|
| 322 |
+
if is_mistral_common_available()
|
| 323 |
+
else ("TokenizersBackend" if is_tokenizers_available() else None),
|
| 324 |
+
),
|
| 325 |
+
(
|
| 326 |
+
"voxtral_realtime",
|
| 327 |
+
"MistralCommonBackend"
|
| 328 |
+
if is_mistral_common_available()
|
| 329 |
+
else ("TokenizersBackend" if is_tokenizers_available() else None),
|
| 330 |
+
),
|
| 331 |
+
("wav2vec2", "Wav2Vec2CTCTokenizer"),
|
| 332 |
+
("wav2vec2-bert", "Wav2Vec2CTCTokenizer"),
|
| 333 |
+
("wav2vec2-conformer", "Wav2Vec2CTCTokenizer"),
|
| 334 |
+
("wav2vec2_phoneme", "Wav2Vec2PhonemeCTCTokenizer"),
|
| 335 |
+
("whisper", "WhisperTokenizer" if is_tokenizers_available() else None),
|
| 336 |
+
("xclip", "CLIPTokenizer" if is_tokenizers_available() else None),
|
| 337 |
+
("xglm", "XGLMTokenizer" if is_tokenizers_available() else None),
|
| 338 |
+
("xlm", "XLMTokenizer"),
|
| 339 |
+
("xlm-roberta", "XLMRobertaTokenizer" if is_tokenizers_available() else None),
|
| 340 |
+
("xlm-roberta-xl", "XLMRobertaTokenizer" if is_tokenizers_available() else None),
|
| 341 |
+
("xlnet", "XLNetTokenizer" if is_tokenizers_available() else None),
|
| 342 |
+
("xlstm", "GPTNeoXTokenizer" if is_tokenizers_available() else None),
|
| 343 |
+
("xmod", "XLMRobertaTokenizer" if is_tokenizers_available() else None),
|
| 344 |
+
("yoso", "AlbertTokenizer" if is_tokenizers_available() else None),
|
| 345 |
+
]
|
| 346 |
+
)
|
| 347 |
+
|
| 348 |
+
# Models with incorrect tokenizer_class in their Hub tokenizer_config.json files.
|
| 349 |
+
# These models will be forced to use TokenizersBackend.
|
| 350 |
+
MODELS_WITH_INCORRECT_HUB_TOKENIZER_CLASS: set[str] = {
|
| 351 |
+
"arctic",
|
| 352 |
+
"chameleon",
|
| 353 |
+
"chatlm",
|
| 354 |
+
"deepseek_v2",
|
| 355 |
+
"deepseek_v3",
|
| 356 |
+
"deepseek_v4",
|
| 357 |
+
"deepseek_vl",
|
| 358 |
+
"deepseek_vl_hybrid",
|
| 359 |
+
"deepseek_vl_v2",
|
| 360 |
+
"deepseek_ocr",
|
| 361 |
+
"deepseek_ocr2",
|
| 362 |
+
"fuyu",
|
| 363 |
+
"h2ovl_chat",
|
| 364 |
+
"hyperclovax_vlm",
|
| 365 |
+
"internlm2",
|
| 366 |
+
"internvl_chat",
|
| 367 |
+
"jamba",
|
| 368 |
+
"janus",
|
| 369 |
+
"llava",
|
| 370 |
+
"llava_next",
|
| 371 |
+
"minicpmv",
|
| 372 |
+
"minimax_m2",
|
| 373 |
+
"modernbert",
|
| 374 |
+
"molmo",
|
| 375 |
+
"molmo2",
|
| 376 |
+
"nemotron",
|
| 377 |
+
"nvfp4",
|
| 378 |
+
"opencua",
|
| 379 |
+
"openvla",
|
| 380 |
+
"phi3",
|
| 381 |
+
"phi3_v",
|
| 382 |
+
"phimoe",
|
| 383 |
+
"qwen2",
|
| 384 |
+
"step3p5",
|
| 385 |
+
"step3_vl",
|
| 386 |
+
"vipllava",
|
| 387 |
+
"cohere_asr",
|
| 388 |
+
}
|
| 389 |
+
|
| 390 |
+
for model_type in MODELS_WITH_INCORRECT_HUB_TOKENIZER_CLASS:
|
| 391 |
+
if model_type not in TOKENIZER_MAPPING_NAMES:
|
| 392 |
+
TOKENIZER_MAPPING_NAMES[model_type] = "TokenizersBackend" if is_tokenizers_available() else None
|
| 393 |
+
|
| 394 |
+
TOKENIZER_MAPPING = _LazyAutoMapping(CONFIG_MAPPING_NAMES, TOKENIZER_MAPPING_NAMES)
|
| 395 |
+
|
| 396 |
+
CONFIG_TO_TYPE = {v: k for k, v in CONFIG_MAPPING_NAMES.items()}
|
| 397 |
+
|
| 398 |
+
|
| 399 |
+
def load_vocab(vocab_file):
|
| 400 |
+
"""Loads a vocabulary file into a dictionary."""
|
| 401 |
+
with open(vocab_file, "r", encoding="utf-8") as reader:
|
| 402 |
+
return json.load(reader)
|
| 403 |
+
|
| 404 |
+
|
| 405 |
+
def load_merges(merges_file):
|
| 406 |
+
"""Loads a merges file into a list."""
|
| 407 |
+
merges = []
|
| 408 |
+
with open(merges_file, "r", encoding="utf-8") as reader:
|
| 409 |
+
for line in reader:
|
| 410 |
+
line = line.strip()
|
| 411 |
+
if line and not line.startswith("#"):
|
| 412 |
+
merges.append(tuple(line.split()))
|
| 413 |
+
return merges
|
| 414 |
+
|
| 415 |
+
|
| 416 |
+
def tokenizer_class_from_name(class_name: str) -> type[Any] | None:
|
| 417 |
+
# Bloom tokenizer classes were removed but should map to the fast backend for BC
|
| 418 |
+
if class_name in {"BloomTokenizer", "BloomTokenizerFast"}:
|
| 419 |
+
return TokenizersBackend
|
| 420 |
+
|
| 421 |
+
if class_name in REGISTERED_FAST_ALIASES:
|
| 422 |
+
return REGISTERED_FAST_ALIASES[class_name]
|
| 423 |
+
|
| 424 |
+
if class_name in REGISTERED_TOKENIZER_CLASSES:
|
| 425 |
+
return REGISTERED_TOKENIZER_CLASSES[class_name]
|
| 426 |
+
|
| 427 |
+
if class_name == "TokenizersBackend":
|
| 428 |
+
return TokenizersBackend
|
| 429 |
+
|
| 430 |
+
# V5: TOKENIZER_MAPPING_NAMES now maps to single strings, not tuples
|
| 431 |
+
for module_name, tokenizer_class in TOKENIZER_MAPPING_NAMES.items():
|
| 432 |
+
if tokenizer_class == class_name:
|
| 433 |
+
module_name = model_type_to_module_name(module_name)
|
| 434 |
+
if (
|
| 435 |
+
module_name in ["mistral", "mistral3", "mixtral", "ministral", "ministral3", "pixtral", "voxtral"]
|
| 436 |
+
and class_name == "MistralCommonBackend"
|
| 437 |
+
):
|
| 438 |
+
module = importlib.import_module(".tokenization_mistral_common", "transformers")
|
| 439 |
+
else:
|
| 440 |
+
module = importlib.import_module(f".{module_name}", "transformers.models")
|
| 441 |
+
try:
|
| 442 |
+
result = getattr(module, class_name)
|
| 443 |
+
# BC v5: expose XxxFast alias and tokenization_*_fast submodule for pre-v5 remote code.
|
| 444 |
+
if (submod := getattr(result, "__module__", None)) and submod in sys.modules:
|
| 445 |
+
base_mod = sys.modules[submod]
|
| 446 |
+
setattr(base_mod, result.__name__ + "Fast", result)
|
| 447 |
+
sys.modules.setdefault(submod + "_fast", base_mod)
|
| 448 |
+
return result
|
| 449 |
+
except AttributeError:
|
| 450 |
+
continue
|
| 451 |
+
|
| 452 |
+
for tokenizer in TOKENIZER_MAPPING._extra_content.values():
|
| 453 |
+
if getattr(tokenizer, "__name__", None) == class_name:
|
| 454 |
+
return tokenizer
|
| 455 |
+
|
| 456 |
+
# We did not find the class, but maybe it's because a dep is missing. In that case, the class will be in the main
|
| 457 |
+
# We did not find the class, but maybe it's because a dep is missing. In that case, the class will be in the main
|
| 458 |
+
# init and we return the proper dummy to get an appropriate error message.
|
| 459 |
+
main_module = importlib.import_module("transformers")
|
| 460 |
+
if hasattr(main_module, class_name):
|
| 461 |
+
return getattr(main_module, class_name)
|
| 462 |
+
|
| 463 |
+
# BC v5: If a XxxFast class is not found, retry without 'Fast' for tokenizers saved pre-v5.
|
| 464 |
+
if class_name.endswith("Fast"):
|
| 465 |
+
return tokenizer_class_from_name(class_name[:-4])
|
| 466 |
+
|
| 467 |
+
return None
|
| 468 |
+
|
| 469 |
+
|
| 470 |
+
def get_tokenizer_config(
|
| 471 |
+
pretrained_model_name_or_path: str | os.PathLike[str],
|
| 472 |
+
cache_dir: str | os.PathLike[str] | None = None,
|
| 473 |
+
force_download: bool = False,
|
| 474 |
+
proxies: dict[str, str] | None = None,
|
| 475 |
+
token: bool | str | None = None,
|
| 476 |
+
revision: str | None = None,
|
| 477 |
+
local_files_only: bool = False,
|
| 478 |
+
subfolder: str = "",
|
| 479 |
+
**kwargs,
|
| 480 |
+
) -> dict[str, Any]:
|
| 481 |
+
"""
|
| 482 |
+
Loads the tokenizer configuration from a pretrained model tokenizer configuration.
|
| 483 |
+
|
| 484 |
+
Args:
|
| 485 |
+
pretrained_model_name_or_path (`str` or `os.PathLike`):
|
| 486 |
+
This can be either:
|
| 487 |
+
|
| 488 |
+
- a string, the *model id* of a pretrained model configuration hosted inside a model repo on
|
| 489 |
+
huggingface.co.
|
| 490 |
+
- a path to a *directory* containing a configuration file saved using the
|
| 491 |
+
[`~PreTrainedTokenizer.save_pretrained`] method, e.g., `./my_model_directory/`.
|
| 492 |
+
|
| 493 |
+
cache_dir (`str` or `os.PathLike`, *optional*):
|
| 494 |
+
Path to a directory in which a downloaded pretrained model configuration should be cached if the standard
|
| 495 |
+
cache should not be used.
|
| 496 |
+
force_download (`bool`, *optional*, defaults to `False`):
|
| 497 |
+
Whether or not to force to (re-)download the configuration files and override the cached versions if they
|
| 498 |
+
exist.
|
| 499 |
+
proxies (`dict[str, str]`, *optional*):
|
| 500 |
+
A dictionary of proxy servers to use by protocol or endpoint, e.g., `{'http': 'foo.bar:3128',
|
| 501 |
+
'http://hostname': 'foo.bar:4012'}.` The proxies are used on each request.
|
| 502 |
+
token (`str` or *bool*, *optional*):
|
| 503 |
+
The token to use as HTTP bearer authorization for remote files. If `True`, will use the token generated
|
| 504 |
+
when running `hf auth login` (stored in `~/.huggingface`).
|
| 505 |
+
revision (`str`, *optional*, defaults to `"main"`):
|
| 506 |
+
The specific model version to use. It can be a branch name, a tag name, or a commit id, since we use a
|
| 507 |
+
git-based system for storing models and other artifacts on huggingface.co, so `revision` can be any
|
| 508 |
+
identifier allowed by git.
|
| 509 |
+
local_files_only (`bool`, *optional*, defaults to `False`):
|
| 510 |
+
If `True`, will only try to load the tokenizer configuration from local files.
|
| 511 |
+
subfolder (`str`, *optional*, defaults to `""`):
|
| 512 |
+
In case the tokenizer config is located inside a subfolder of the model repo on huggingface.co, you can
|
| 513 |
+
specify the folder name here.
|
| 514 |
+
|
| 515 |
+
<Tip>
|
| 516 |
+
|
| 517 |
+
Passing `token=True` is required when you want to use a private model.
|
| 518 |
+
|
| 519 |
+
</Tip>
|
| 520 |
+
|
| 521 |
+
Returns:
|
| 522 |
+
`dict`: The configuration of the tokenizer.
|
| 523 |
+
|
| 524 |
+
Examples:
|
| 525 |
+
|
| 526 |
+
```python
|
| 527 |
+
# Download configuration from huggingface.co and cache.
|
| 528 |
+
tokenizer_config = get_tokenizer_config("google-bert/bert-base-uncased")
|
| 529 |
+
# This model does not have a tokenizer config so the result will be an empty dict.
|
| 530 |
+
tokenizer_config = get_tokenizer_config("FacebookAI/xlm-roberta-base")
|
| 531 |
+
|
| 532 |
+
# Save a pretrained tokenizer locally and you can reload its config
|
| 533 |
+
from transformers import AutoTokenizer
|
| 534 |
+
|
| 535 |
+
tokenizer = AutoTokenizer.from_pretrained("google-bert/bert-base-cased")
|
| 536 |
+
tokenizer.save_pretrained("tokenizer-test")
|
| 537 |
+
tokenizer_config = get_tokenizer_config("tokenizer-test")
|
| 538 |
+
```"""
|
| 539 |
+
commit_hash = kwargs.get("_commit_hash")
|
| 540 |
+
resolved_config_file = cached_file(
|
| 541 |
+
pretrained_model_name_or_path,
|
| 542 |
+
TOKENIZER_CONFIG_FILE,
|
| 543 |
+
cache_dir=cache_dir,
|
| 544 |
+
force_download=force_download,
|
| 545 |
+
proxies=proxies,
|
| 546 |
+
token=token,
|
| 547 |
+
revision=revision,
|
| 548 |
+
local_files_only=local_files_only,
|
| 549 |
+
subfolder=subfolder,
|
| 550 |
+
_raise_exceptions_for_gated_repo=False,
|
| 551 |
+
_raise_exceptions_for_missing_entries=False,
|
| 552 |
+
_raise_exceptions_for_connection_errors=False,
|
| 553 |
+
_commit_hash=commit_hash,
|
| 554 |
+
)
|
| 555 |
+
if resolved_config_file is None:
|
| 556 |
+
logger.info("Could not locate the tokenizer configuration file, will try to use the model config instead.")
|
| 557 |
+
return {}
|
| 558 |
+
commit_hash = extract_commit_hash(resolved_config_file, commit_hash)
|
| 559 |
+
|
| 560 |
+
with open(resolved_config_file, encoding="utf-8") as reader:
|
| 561 |
+
result = json.load(reader)
|
| 562 |
+
result["_commit_hash"] = commit_hash
|
| 563 |
+
return result
|
| 564 |
+
|
| 565 |
+
|
| 566 |
+
class AutoTokenizer:
|
| 567 |
+
r"""
|
| 568 |
+
This is a generic tokenizer class that will be instantiated as one of the tokenizer classes of the library when
|
| 569 |
+
created with the [`AutoTokenizer.from_pretrained`] class method.
|
| 570 |
+
|
| 571 |
+
This class cannot be instantiated directly using `__init__()` (throws an error).
|
| 572 |
+
"""
|
| 573 |
+
|
| 574 |
+
def __init__(self):
|
| 575 |
+
raise OSError(
|
| 576 |
+
"AutoTokenizer is designed to be instantiated "
|
| 577 |
+
"using the `AutoTokenizer.from_pretrained(pretrained_model_name_or_path)` method."
|
| 578 |
+
)
|
| 579 |
+
|
| 580 |
+
@classmethod
|
| 581 |
+
@replace_list_option_in_docstrings(TOKENIZER_MAPPING_NAMES)
|
| 582 |
+
def from_pretrained(
|
| 583 |
+
cls, pretrained_model_name_or_path, *inputs, **kwargs
|
| 584 |
+
) -> TokenizersBackend | SentencePieceBackend:
|
| 585 |
+
r"""
|
| 586 |
+
Instantiate one of the tokenizer classes of the library from a pretrained model vocabulary.
|
| 587 |
+
|
| 588 |
+
The tokenizer class to instantiate is selected based on the `model_type` property of the config object (either
|
| 589 |
+
passed as an argument or loaded from `pretrained_model_name_or_path` if possible), or when it's missing, by
|
| 590 |
+
falling back to using pattern matching on `pretrained_model_name_or_path`:
|
| 591 |
+
|
| 592 |
+
List options
|
| 593 |
+
|
| 594 |
+
Params:
|
| 595 |
+
pretrained_model_name_or_path (`str` or `os.PathLike`):
|
| 596 |
+
Can be either:
|
| 597 |
+
|
| 598 |
+
- A string, the *model id* of a predefined tokenizer hosted inside a model repo on huggingface.co.
|
| 599 |
+
- A path to a *directory* containing vocabulary files required by the tokenizer, for instance saved
|
| 600 |
+
using the [`~PreTrainedTokenizer.save_pretrained`] method, e.g., `./my_model_directory/`.
|
| 601 |
+
- a path to a single saved vocabulary file if and only if the tokenizer only requires a
|
| 602 |
+
single vocabulary file (like Bert or XLNet), e.g.: `./my_model_directory/vocab.txt`. (Not
|
| 603 |
+
applicable to all derived classes)
|
| 604 |
+
inputs (additional positional arguments, *optional*):
|
| 605 |
+
Will be passed along to the Tokenizer `__init__()` method.
|
| 606 |
+
config ([`PreTrainedConfig`], *optional*)
|
| 607 |
+
The configuration object used to determine the tokenizer class to instantiate.
|
| 608 |
+
cache_dir (`str` or `os.PathLike`, *optional*):
|
| 609 |
+
Path to a directory in which a downloaded pretrained model configuration should be cached if the
|
| 610 |
+
standard cache should not be used.
|
| 611 |
+
force_download (`bool`, *optional*, defaults to `False`):
|
| 612 |
+
Whether or not to force the (re-)download the model weights and configuration files and override the
|
| 613 |
+
cached versions if they exist.
|
| 614 |
+
proxies (`dict[str, str]`, *optional*):
|
| 615 |
+
A dictionary of proxy servers to use by protocol or endpoint, e.g., `{'http': 'foo.bar:3128',
|
| 616 |
+
'http://hostname': 'foo.bar:4012'}`. The proxies are used on each request.
|
| 617 |
+
revision (`str`, *optional*, defaults to `"main"`):
|
| 618 |
+
The specific model version to use. It can be a branch name, a tag name, or a commit id, since we use a
|
| 619 |
+
git-based system for storing models and other artifacts on huggingface.co, so `revision` can be any
|
| 620 |
+
identifier allowed by git.
|
| 621 |
+
subfolder (`str`, *optional*):
|
| 622 |
+
In case the relevant files are located inside a subfolder of the model repo on huggingface.co (e.g. for
|
| 623 |
+
facebook/rag-token-base), specify it here.
|
| 624 |
+
tokenizer_type (`str`, *optional*):
|
| 625 |
+
Tokenizer type to be loaded.
|
| 626 |
+
backend (`str`, *optional*, defaults to `"tokenizers"`):
|
| 627 |
+
Backend to use for tokenization. Valid options are:
|
| 628 |
+
- `"tokenizers"`: Use the HuggingFace tokenizers library backend (default)
|
| 629 |
+
- `"sentencepiece"`: Use the SentencePiece backend
|
| 630 |
+
trust_remote_code (`bool`, *optional*, defaults to `False`):
|
| 631 |
+
Whether or not to allow for custom models defined on the Hub in their own modeling files. This option
|
| 632 |
+
should only be set to `True` for repositories you trust and in which you have read the code, as it will
|
| 633 |
+
execute code present on the Hub on your local machine.
|
| 634 |
+
kwargs (additional keyword arguments, *optional*):
|
| 635 |
+
Will be passed to the Tokenizer `__init__()` method. Can be used to set special tokens like
|
| 636 |
+
`bos_token`, `eos_token`, `unk_token`, `sep_token`, `pad_token`, `cls_token`, `mask_token`,
|
| 637 |
+
`additional_special_tokens`. See parameters in the `__init__()` for more details.
|
| 638 |
+
|
| 639 |
+
Examples:
|
| 640 |
+
|
| 641 |
+
```python
|
| 642 |
+
>>> from transformers import AutoTokenizer
|
| 643 |
+
|
| 644 |
+
>>> # Download vocabulary from huggingface.co and cache.
|
| 645 |
+
>>> tokenizer = AutoTokenizer.from_pretrained("google-bert/bert-base-uncased")
|
| 646 |
+
|
| 647 |
+
>>> # Download vocabulary from huggingface.co (user-uploaded) and cache.
|
| 648 |
+
>>> tokenizer = AutoTokenizer.from_pretrained("dbmdz/bert-base-german-cased")
|
| 649 |
+
|
| 650 |
+
>>> # If vocabulary files are in a directory (e.g. tokenizer was saved using *save_pretrained('./test/saved_model/')*)
|
| 651 |
+
>>> # tokenizer = AutoTokenizer.from_pretrained("./test/bert_saved_model/")
|
| 652 |
+
|
| 653 |
+
>>> # Download vocabulary from huggingface.co and define model-specific arguments
|
| 654 |
+
>>> tokenizer = AutoTokenizer.from_pretrained("FacebookAI/roberta-base", add_prefix_space=True)
|
| 655 |
+
|
| 656 |
+
>>> # Explicitly use the tokenizers backend
|
| 657 |
+
>>> tokenizer = AutoTokenizer.from_pretrained("hf-internal-testing/llama-tokenizer", backend="tokenizers")
|
| 658 |
+
|
| 659 |
+
>>> # Explicitly use the sentencepiece backend
|
| 660 |
+
>>> tokenizer = AutoTokenizer.from_pretrained("hf-internal-testing/llama-tokenizer", backend="sentencepiece")
|
| 661 |
+
```"""
|
| 662 |
+
config = kwargs.pop("config", None)
|
| 663 |
+
kwargs["_from_auto"] = True
|
| 664 |
+
|
| 665 |
+
# V5: Always use fast tokenizers, ignore use_fast parameter
|
| 666 |
+
_ = kwargs.pop("use_fast", None)
|
| 667 |
+
tokenizer_type = kwargs.pop("tokenizer_type", None)
|
| 668 |
+
trust_remote_code = kwargs.pop("trust_remote_code", None)
|
| 669 |
+
gguf_file = kwargs.get("gguf_file")
|
| 670 |
+
|
| 671 |
+
# First, let's see whether the tokenizer_type is passed so that we can leverage it
|
| 672 |
+
if tokenizer_type is not None:
|
| 673 |
+
tokenizer_class_name = TOKENIZER_MAPPING_NAMES.get(tokenizer_type, None)
|
| 674 |
+
|
| 675 |
+
if tokenizer_class_name is None:
|
| 676 |
+
raise ValueError(
|
| 677 |
+
f"Passed `tokenizer_type` {tokenizer_type} does not exist. `tokenizer_type` should be one of "
|
| 678 |
+
f"{', '.join(c for c in TOKENIZER_MAPPING_NAMES)}."
|
| 679 |
+
)
|
| 680 |
+
|
| 681 |
+
tokenizer_class = tokenizer_class_from_name(tokenizer_class_name)
|
| 682 |
+
|
| 683 |
+
if tokenizer_class is None:
|
| 684 |
+
raise ValueError(f"Tokenizer class {tokenizer_class_name} is not currently imported.")
|
| 685 |
+
|
| 686 |
+
return tokenizer_class.from_pretrained(pretrained_model_name_or_path, *inputs, **kwargs)
|
| 687 |
+
|
| 688 |
+
if gguf_file:
|
| 689 |
+
gguf_path = cached_file(pretrained_model_name_or_path, gguf_file, **kwargs)
|
| 690 |
+
config_dict = load_gguf_checkpoint(gguf_path, return_tensors=False)["config"]
|
| 691 |
+
config = AutoConfig.for_model(**config_dict)
|
| 692 |
+
elif config is None:
|
| 693 |
+
try:
|
| 694 |
+
config = AutoConfig.from_pretrained(
|
| 695 |
+
pretrained_model_name_or_path, trust_remote_code=trust_remote_code, **kwargs
|
| 696 |
+
)
|
| 697 |
+
except (ValueError, OSError):
|
| 698 |
+
config = PreTrainedConfig.from_pretrained(pretrained_model_name_or_path, **kwargs)
|
| 699 |
+
|
| 700 |
+
config_model_type = config.model_type
|
| 701 |
+
|
| 702 |
+
# Next, let's try to use the tokenizer_config file to get the tokenizer class.
|
| 703 |
+
tokenizer_config = get_tokenizer_config(pretrained_model_name_or_path, **kwargs)
|
| 704 |
+
tokenizer_config_class = tokenizer_config.get("tokenizer_class", None)
|
| 705 |
+
|
| 706 |
+
# Check for auto_map early to handle dynamic tokenizers properly
|
| 707 |
+
tokenizer_auto_map = None
|
| 708 |
+
if "auto_map" in tokenizer_config:
|
| 709 |
+
if isinstance(tokenizer_config["auto_map"], (tuple, list)):
|
| 710 |
+
# Legacy format for dynamic tokenizers
|
| 711 |
+
tokenizer_auto_map = tokenizer_config["auto_map"]
|
| 712 |
+
else:
|
| 713 |
+
tokenizer_auto_map = tokenizer_config["auto_map"].get("AutoTokenizer", None)
|
| 714 |
+
|
| 715 |
+
# if there is a config, we can check that the tokenizer class != than model class.
|
| 716 |
+
# Use the config class if it's a specialized tokenizer, otherwise fall back to TokenizersBackend.
|
| 717 |
+
if (
|
| 718 |
+
tokenizer_auto_map is None
|
| 719 |
+
and tokenizer_config_class is not None
|
| 720 |
+
and config_model_type is not None
|
| 721 |
+
and config_model_type != ""
|
| 722 |
+
and TOKENIZER_MAPPING_NAMES.get(config_model_type) is not None
|
| 723 |
+
and (TOKENIZER_MAPPING_NAMES.get(config_model_type).removesuffix("Fast"))
|
| 724 |
+
!= (tokenizer_config_class.removesuffix("Fast"))
|
| 725 |
+
):
|
| 726 |
+
registered_class_name = TOKENIZER_MAPPING_NAMES.get(config_model_type).removesuffix("Fast")
|
| 727 |
+
if registered_class_name not in ("TokenizersBackend", "PythonBackend", "PreTrainedTokenizerFast"):
|
| 728 |
+
# If the hub class is known incorrect for this model type, use the registered class; otherwise trust the hub.
|
| 729 |
+
class_name = (
|
| 730 |
+
registered_class_name
|
| 731 |
+
if config_model_type in MODELS_WITH_INCORRECT_HUB_TOKENIZER_CLASS
|
| 732 |
+
else tokenizer_config_class
|
| 733 |
+
)
|
| 734 |
+
tokenizer_class = tokenizer_class_from_name(class_name)
|
| 735 |
+
if tokenizer_class is not None and tokenizer_class.__name__ not in (
|
| 736 |
+
"TokenizersBackend",
|
| 737 |
+
"PythonBackend",
|
| 738 |
+
"PreTrainedTokenizerFast",
|
| 739 |
+
):
|
| 740 |
+
return tokenizer_class.from_pretrained(pretrained_model_name_or_path, *inputs, **kwargs)
|
| 741 |
+
|
| 742 |
+
if TokenizersBackend is not None:
|
| 743 |
+
return TokenizersBackend.from_pretrained(pretrained_model_name_or_path, *inputs, **kwargs)
|
| 744 |
+
|
| 745 |
+
raise ValueError(
|
| 746 |
+
f"Tokenizer class '{tokenizer_config_class}' specified in the tokenizer config was not found. "
|
| 747 |
+
f"The tokenizer may need to be converted or re-saved."
|
| 748 |
+
)
|
| 749 |
+
|
| 750 |
+
if "_commit_hash" in tokenizer_config:
|
| 751 |
+
kwargs["_commit_hash"] = tokenizer_config["_commit_hash"]
|
| 752 |
+
|
| 753 |
+
if tokenizer_config_class and tokenizer_config_class.endswith("Fast"):
|
| 754 |
+
tokenizer_config_class = tokenizer_config_class[:-4]
|
| 755 |
+
|
| 756 |
+
has_remote_code = tokenizer_auto_map is not None
|
| 757 |
+
has_local_code = type(config) in TOKENIZER_MAPPING or (
|
| 758 |
+
tokenizer_config_class is not None
|
| 759 |
+
and (
|
| 760 |
+
tokenizer_class_from_name(tokenizer_config_class) is not None
|
| 761 |
+
or tokenizer_class_from_name(tokenizer_config_class + "Fast") is not None
|
| 762 |
+
)
|
| 763 |
+
)
|
| 764 |
+
explicit_local_code = (
|
| 765 |
+
has_local_code
|
| 766 |
+
and type(config) not in TOKENIZER_MAPPING
|
| 767 |
+
and (
|
| 768 |
+
tokenizer_config_class is not None
|
| 769 |
+
and not (
|
| 770 |
+
tokenizer_class_from_name(tokenizer_config_class)
|
| 771 |
+
or tokenizer_class_from_name(tokenizer_config_class + "Fast")
|
| 772 |
+
).__module__.startswith("transformers.")
|
| 773 |
+
)
|
| 774 |
+
)
|
| 775 |
+
# V5: Skip remote tokenizer for custom models with incorrect hub tokenizer class
|
| 776 |
+
if has_remote_code and config_model_type in MODELS_WITH_INCORRECT_HUB_TOKENIZER_CLASS:
|
| 777 |
+
has_remote_code = False
|
| 778 |
+
tokenizer_auto_map = None
|
| 779 |
+
|
| 780 |
+
if has_remote_code:
|
| 781 |
+
# V5: Always prefer fast tokenizer (index 1), fallback to slow (index 0)
|
| 782 |
+
if tokenizer_auto_map[1] is not None:
|
| 783 |
+
class_ref = tokenizer_auto_map[1]
|
| 784 |
+
else:
|
| 785 |
+
class_ref = tokenizer_auto_map[0]
|
| 786 |
+
if "--" in class_ref:
|
| 787 |
+
upstream_repo = class_ref.split("--")[0]
|
| 788 |
+
else:
|
| 789 |
+
upstream_repo = None
|
| 790 |
+
trust_remote_code = resolve_trust_remote_code(
|
| 791 |
+
trust_remote_code, pretrained_model_name_or_path, has_local_code, has_remote_code, upstream_repo
|
| 792 |
+
)
|
| 793 |
+
|
| 794 |
+
if has_remote_code and trust_remote_code and not explicit_local_code:
|
| 795 |
+
# BC v5: register *Fast aliases before remote code loads.
|
| 796 |
+
if tokenizer_config_class:
|
| 797 |
+
tokenizer_class_from_name(tokenizer_config_class.removesuffix("Fast"))
|
| 798 |
+
tokenizer_class = get_class_from_dynamic_module(class_ref, pretrained_model_name_or_path, **kwargs)
|
| 799 |
+
_ = kwargs.pop("code_revision", None)
|
| 800 |
+
tokenizer_class.register_for_auto_class()
|
| 801 |
+
return tokenizer_class.from_pretrained(
|
| 802 |
+
pretrained_model_name_or_path, *inputs, trust_remote_code=trust_remote_code, **kwargs
|
| 803 |
+
)
|
| 804 |
+
elif tokenizer_config_class is not None:
|
| 805 |
+
tokenizer_class_candidate = tokenizer_config_class
|
| 806 |
+
tokenizer_class = tokenizer_class_from_name(tokenizer_class_candidate)
|
| 807 |
+
if tokenizer_class is None and not tokenizer_class_candidate.endswith("Fast"):
|
| 808 |
+
tokenizer_class = tokenizer_class_from_name(tokenizer_class_candidate + "Fast")
|
| 809 |
+
if tokenizer_class is not None and tokenizer_class.__name__ == "PythonBackend":
|
| 810 |
+
tokenizer_class = TokenizersBackend
|
| 811 |
+
# Fallback to TokenizersBackend if the class wasn't found
|
| 812 |
+
if tokenizer_class is None:
|
| 813 |
+
tokenizer_class = TokenizersBackend
|
| 814 |
+
|
| 815 |
+
return tokenizer_class.from_pretrained(pretrained_model_name_or_path, *inputs, **kwargs)
|
| 816 |
+
elif getattr(config, "tokenizer_class", None):
|
| 817 |
+
_class = config.tokenizer_class
|
| 818 |
+
if "PreTrainedTokenizerFast" not in _class and _class.endswith("Fast"):
|
| 819 |
+
_class = _class[:-4]
|
| 820 |
+
tokenizer_class = tokenizer_class_from_name(_class)
|
| 821 |
+
return tokenizer_class.from_pretrained(pretrained_model_name_or_path, *inputs, **kwargs)
|
| 822 |
+
|
| 823 |
+
# Otherwise we have to be creative.
|
| 824 |
+
# if model is an encoder decoder, the encoder tokenizer class is used by default
|
| 825 |
+
if isinstance(config, EncoderDecoderConfig):
|
| 826 |
+
if type(config.decoder) is not type(config.encoder):
|
| 827 |
+
logger.warning(
|
| 828 |
+
f"The encoder model config class: {config.encoder.__class__} is different from the decoder model "
|
| 829 |
+
f"config class: {config.decoder.__class__}. It is not recommended to use the "
|
| 830 |
+
"`AutoTokenizer.from_pretrained()` method in this case. Please use the encoder and decoder "
|
| 831 |
+
"specific tokenizer classes."
|
| 832 |
+
)
|
| 833 |
+
config = config.encoder
|
| 834 |
+
|
| 835 |
+
model_type = config_class_to_model_type(type(config).__name__) or getattr(config, "model_type", None)
|
| 836 |
+
if model_type is not None:
|
| 837 |
+
tokenizer_class = TOKENIZER_MAPPING.get(type(config), TokenizersBackend)
|
| 838 |
+
if tokenizer_class is not None:
|
| 839 |
+
return tokenizer_class.from_pretrained(pretrained_model_name_or_path, *inputs, **kwargs)
|
| 840 |
+
|
| 841 |
+
# Fallback: try tokenizer_class from tokenizer_config.json
|
| 842 |
+
tokenizer_config_class = tokenizer_config.get("tokenizer_class", None)
|
| 843 |
+
if tokenizer_config_class is not None:
|
| 844 |
+
if tokenizer_config_class != "TokenizersBackend" and tokenizer_config_class.endswith("Fast"):
|
| 845 |
+
tokenizer_config_class = tokenizer_config_class[:-4]
|
| 846 |
+
tokenizer_class = tokenizer_class_from_name(tokenizer_config_class)
|
| 847 |
+
if tokenizer_class is None and not tokenizer_config_class.endswith("Fast"):
|
| 848 |
+
tokenizer_class = tokenizer_class_from_name(tokenizer_config_class + "Fast")
|
| 849 |
+
if tokenizer_class is not None and tokenizer_class.__name__ == "PythonBackend":
|
| 850 |
+
tokenizer_class = TokenizersBackend
|
| 851 |
+
if tokenizer_class is None:
|
| 852 |
+
tokenizer_class = TokenizersBackend
|
| 853 |
+
return tokenizer_class.from_pretrained(pretrained_model_name_or_path, *inputs, **kwargs)
|
| 854 |
+
|
| 855 |
+
raise ValueError(
|
| 856 |
+
f"Unrecognized configuration class {config.__class__} to build an AutoTokenizer.\n"
|
| 857 |
+
f"Model type should be one of {', '.join(c.__name__ for c in TOKENIZER_MAPPING)}."
|
| 858 |
+
)
|
| 859 |
+
|
| 860 |
+
@staticmethod
|
| 861 |
+
def register(
|
| 862 |
+
config_class, tokenizer_class=None, slow_tokenizer_class=None, fast_tokenizer_class=None, exist_ok=False
|
| 863 |
+
):
|
| 864 |
+
"""
|
| 865 |
+
Register a new tokenizer in this mapping.
|
| 866 |
+
|
| 867 |
+
Args:
|
| 868 |
+
config_class ([`PreTrainedConfig`]):
|
| 869 |
+
The configuration corresponding to the model to register.
|
| 870 |
+
tokenizer_class: The tokenizer class to register (V5 - preferred parameter).
|
| 871 |
+
slow_tokenizer_class: (Deprecated) The slow tokenizer to register.
|
| 872 |
+
fast_tokenizer_class: (Deprecated) The fast tokenizer to register.
|
| 873 |
+
"""
|
| 874 |
+
if tokenizer_class is None:
|
| 875 |
+
# Legacy: prefer fast over slow
|
| 876 |
+
if fast_tokenizer_class is not None:
|
| 877 |
+
tokenizer_class = fast_tokenizer_class
|
| 878 |
+
elif slow_tokenizer_class is not None:
|
| 879 |
+
tokenizer_class = slow_tokenizer_class
|
| 880 |
+
else:
|
| 881 |
+
raise ValueError("You need to pass a `tokenizer_class`")
|
| 882 |
+
|
| 883 |
+
for candidate in (slow_tokenizer_class, fast_tokenizer_class, tokenizer_class):
|
| 884 |
+
if candidate is not None:
|
| 885 |
+
REGISTERED_TOKENIZER_CLASSES[candidate.__name__] = candidate
|
| 886 |
+
|
| 887 |
+
if slow_tokenizer_class is not None and fast_tokenizer_class is not None:
|
| 888 |
+
REGISTERED_FAST_ALIASES[slow_tokenizer_class.__name__] = fast_tokenizer_class
|
| 889 |
+
|
| 890 |
+
TOKENIZER_MAPPING.register(config_class, tokenizer_class, exist_ok=exist_ok)
|
| 891 |
+
|
| 892 |
+
|
| 893 |
+
__all__ = ["TOKENIZER_MAPPING", "AutoTokenizer"]
|
LTA_openwebtext_dualt/mini_owt_logdirichlet/.venv_qwen35_uv/lib/python3.12/site-packages/transformers/models/auto/video_processing_auto.py
ADDED
|
@@ -0,0 +1,408 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# Copyright 2025 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 |
+
"""AutoVideoProcessor class."""
|
| 15 |
+
|
| 16 |
+
import importlib
|
| 17 |
+
import os
|
| 18 |
+
from collections import OrderedDict
|
| 19 |
+
from typing import TYPE_CHECKING
|
| 20 |
+
|
| 21 |
+
# Build the list of all video processors
|
| 22 |
+
from ...configuration_utils import PreTrainedConfig
|
| 23 |
+
from ...dynamic_module_utils import get_class_from_dynamic_module, resolve_trust_remote_code
|
| 24 |
+
from ...utils import (
|
| 25 |
+
CONFIG_NAME,
|
| 26 |
+
IMAGE_PROCESSOR_NAME,
|
| 27 |
+
PROCESSOR_NAME,
|
| 28 |
+
VIDEO_PROCESSOR_NAME,
|
| 29 |
+
cached_file,
|
| 30 |
+
is_torchvision_available,
|
| 31 |
+
logging,
|
| 32 |
+
safe_load_json_file,
|
| 33 |
+
)
|
| 34 |
+
from ...utils.import_utils import requires
|
| 35 |
+
from ...video_processing_utils import BaseVideoProcessor
|
| 36 |
+
from .auto_factory import _LazyAutoMapping
|
| 37 |
+
from .auto_mappings import VIDEO_PROCESSOR_MAPPING_NAMES
|
| 38 |
+
from .configuration_auto import (
|
| 39 |
+
CONFIG_MAPPING_NAMES,
|
| 40 |
+
AutoConfig,
|
| 41 |
+
model_type_to_module_name,
|
| 42 |
+
replace_list_option_in_docstrings,
|
| 43 |
+
)
|
| 44 |
+
|
| 45 |
+
|
| 46 |
+
logger = logging.get_logger(__name__)
|
| 47 |
+
|
| 48 |
+
|
| 49 |
+
if TYPE_CHECKING:
|
| 50 |
+
# This significantly improves completion suggestion performance when
|
| 51 |
+
# the transformers package is used with Microsoft's Pylance language server.
|
| 52 |
+
VIDEO_PROCESSOR_MAPPING_NAMES: OrderedDict[str, tuple[str | None, str | None]] = OrderedDict()
|
| 53 |
+
else:
|
| 54 |
+
# Merge non-standard mapping names with auto-inferred `VIDEO_PROCESSOR_MAPPING_NAMES`
|
| 55 |
+
MISSING_VIDEO_PROCESSOR_MAPPING_NAMES = OrderedDict(
|
| 56 |
+
[
|
| 57 |
+
("exaone4_5", "Qwen2VLVideoProcessor"),
|
| 58 |
+
("instructblip", "InstructBlipVideoVideoProcessor"),
|
| 59 |
+
("pe_audio_video", "PeVideoVideoProcessor"),
|
| 60 |
+
("qwen2_5_omni", "Qwen2VLVideoProcessor"),
|
| 61 |
+
("qwen2_5_vl", "Qwen2VLVideoProcessor"),
|
| 62 |
+
("qwen3_5", "Qwen3VLVideoProcessor"),
|
| 63 |
+
("qwen3_5_moe", "Qwen3VLVideoProcessor"),
|
| 64 |
+
("qwen3_omni_moe", "Qwen2VLVideoProcessor"),
|
| 65 |
+
("qwen3_vl_moe", "Qwen3VLVideoProcessor"),
|
| 66 |
+
]
|
| 67 |
+
)
|
| 68 |
+
VIDEO_PROCESSOR_MAPPING_NAMES.update(MISSING_VIDEO_PROCESSOR_MAPPING_NAMES)
|
| 69 |
+
|
| 70 |
+
for model_type, video_processors in VIDEO_PROCESSOR_MAPPING_NAMES.items():
|
| 71 |
+
fast_video_processor_class = video_processors
|
| 72 |
+
|
| 73 |
+
# If the torchvision is not available, we set it to None
|
| 74 |
+
if not is_torchvision_available():
|
| 75 |
+
fast_video_processor_class = None
|
| 76 |
+
|
| 77 |
+
VIDEO_PROCESSOR_MAPPING_NAMES[model_type] = fast_video_processor_class
|
| 78 |
+
|
| 79 |
+
VIDEO_PROCESSOR_MAPPING = _LazyAutoMapping(CONFIG_MAPPING_NAMES, VIDEO_PROCESSOR_MAPPING_NAMES)
|
| 80 |
+
|
| 81 |
+
|
| 82 |
+
def video_processor_class_from_name(class_name: str):
|
| 83 |
+
for module_name, extractor in VIDEO_PROCESSOR_MAPPING_NAMES.items():
|
| 84 |
+
if class_name == extractor:
|
| 85 |
+
module_name = model_type_to_module_name(module_name)
|
| 86 |
+
|
| 87 |
+
module = importlib.import_module(f".{module_name}", "transformers.models")
|
| 88 |
+
try:
|
| 89 |
+
return getattr(module, class_name)
|
| 90 |
+
except AttributeError:
|
| 91 |
+
continue
|
| 92 |
+
|
| 93 |
+
for extractor in VIDEO_PROCESSOR_MAPPING._extra_content.values():
|
| 94 |
+
if getattr(extractor, "__name__", None) == class_name:
|
| 95 |
+
return extractor
|
| 96 |
+
|
| 97 |
+
# We did not find the class, but maybe it's because a dep is missing. In that case, the class will be in the main
|
| 98 |
+
# init and we return the proper dummy to get an appropriate error message.
|
| 99 |
+
main_module = importlib.import_module("transformers")
|
| 100 |
+
if hasattr(main_module, class_name):
|
| 101 |
+
return getattr(main_module, class_name)
|
| 102 |
+
|
| 103 |
+
return None
|
| 104 |
+
|
| 105 |
+
|
| 106 |
+
def get_video_processor_config(
|
| 107 |
+
pretrained_model_name_or_path: str | os.PathLike,
|
| 108 |
+
cache_dir: str | os.PathLike | None = None,
|
| 109 |
+
force_download: bool = False,
|
| 110 |
+
proxies: dict[str, str] | None = None,
|
| 111 |
+
token: bool | str | None = None,
|
| 112 |
+
revision: str | None = None,
|
| 113 |
+
local_files_only: bool = False,
|
| 114 |
+
**kwargs,
|
| 115 |
+
):
|
| 116 |
+
"""
|
| 117 |
+
Loads the video processor configuration from a pretrained model video processor configuration.
|
| 118 |
+
|
| 119 |
+
Args:
|
| 120 |
+
pretrained_model_name_or_path (`str` or `os.PathLike`):
|
| 121 |
+
This can be either:
|
| 122 |
+
|
| 123 |
+
- a string, the *model id* of a pretrained model configuration hosted inside a model repo on
|
| 124 |
+
huggingface.co.
|
| 125 |
+
- a path to a *directory* containing a configuration file saved using the
|
| 126 |
+
[`~BaseVideoProcessor.save_pretrained`] method, e.g., `./my_model_directory/`.
|
| 127 |
+
|
| 128 |
+
cache_dir (`str` or `os.PathLike`, *optional*):
|
| 129 |
+
Path to a directory in which a downloaded pretrained model configuration should be cached if the standard
|
| 130 |
+
cache should not be used.
|
| 131 |
+
force_download (`bool`, *optional*, defaults to `False`):
|
| 132 |
+
Whether or not to force to (re-)download the configuration files and override the cached versions if they
|
| 133 |
+
exist.
|
| 134 |
+
proxies (`dict[str, str]`, *optional*):
|
| 135 |
+
A dictionary of proxy servers to use by protocol or endpoint, e.g., `{'http': 'foo.bar:3128',
|
| 136 |
+
'http://hostname': 'foo.bar:4012'}.` The proxies are used on each request.
|
| 137 |
+
token (`str` or *bool*, *optional*):
|
| 138 |
+
The token to use as HTTP bearer authorization for remote files. If `True`, will use the token generated
|
| 139 |
+
when running `hf auth login` (stored in `~/.huggingface`).
|
| 140 |
+
revision (`str`, *optional*, defaults to `"main"`):
|
| 141 |
+
The specific model version to use. It can be a branch name, a tag name, or a commit id, since we use a
|
| 142 |
+
git-based system for storing models and other artifacts on huggingface.co, so `revision` can be any
|
| 143 |
+
identifier allowed by git.
|
| 144 |
+
local_files_only (`bool`, *optional*, defaults to `False`):
|
| 145 |
+
If `True`, will only try to load the video processor configuration from local files.
|
| 146 |
+
|
| 147 |
+
<Tip>
|
| 148 |
+
|
| 149 |
+
Passing `token=True` is required when you want to use a private model.
|
| 150 |
+
|
| 151 |
+
</Tip>
|
| 152 |
+
|
| 153 |
+
Returns:
|
| 154 |
+
`Dict`: The configuration of the video processor.
|
| 155 |
+
|
| 156 |
+
Examples:
|
| 157 |
+
|
| 158 |
+
```python
|
| 159 |
+
# Download configuration from huggingface.co and cache.
|
| 160 |
+
video_processor_config = get_video_processor_config("llava-hf/llava-onevision-qwen2-0.5b-ov-hf")
|
| 161 |
+
# This model does not have a video processor config so the result will be an empty dict.
|
| 162 |
+
video_processor_config = get_video_processor_config("FacebookAI/xlm-roberta-base")
|
| 163 |
+
|
| 164 |
+
# Save a pretrained video processor locally and you can reload its config
|
| 165 |
+
from transformers import AutoVideoProcessor
|
| 166 |
+
|
| 167 |
+
video_processor = AutoVideoProcessor.from_pretrained("llava-hf/llava-onevision-qwen2-0.5b-ov-hf")
|
| 168 |
+
video_processor.save_pretrained("video-processor-test")
|
| 169 |
+
video_processor = get_video_processor_config("video-processor-test")
|
| 170 |
+
```"""
|
| 171 |
+
# Load with a priority given to the nested processor config, if available in repo
|
| 172 |
+
resolved_processor_file = cached_file(
|
| 173 |
+
pretrained_model_name_or_path,
|
| 174 |
+
filename=PROCESSOR_NAME,
|
| 175 |
+
cache_dir=cache_dir,
|
| 176 |
+
force_download=force_download,
|
| 177 |
+
proxies=proxies,
|
| 178 |
+
token=token,
|
| 179 |
+
revision=revision,
|
| 180 |
+
local_files_only=local_files_only,
|
| 181 |
+
_raise_exceptions_for_gated_repo=False,
|
| 182 |
+
_raise_exceptions_for_missing_entries=False,
|
| 183 |
+
)
|
| 184 |
+
resolved_video_processor_files = [
|
| 185 |
+
resolved_file
|
| 186 |
+
for filename in [VIDEO_PROCESSOR_NAME, IMAGE_PROCESSOR_NAME]
|
| 187 |
+
if (
|
| 188 |
+
resolved_file := cached_file(
|
| 189 |
+
pretrained_model_name_or_path,
|
| 190 |
+
filename=filename,
|
| 191 |
+
cache_dir=cache_dir,
|
| 192 |
+
force_download=force_download,
|
| 193 |
+
proxies=proxies,
|
| 194 |
+
token=token,
|
| 195 |
+
revision=revision,
|
| 196 |
+
local_files_only=local_files_only,
|
| 197 |
+
_raise_exceptions_for_gated_repo=False,
|
| 198 |
+
_raise_exceptions_for_missing_entries=False,
|
| 199 |
+
_raise_exceptions_for_connection_errors=False,
|
| 200 |
+
)
|
| 201 |
+
)
|
| 202 |
+
is not None
|
| 203 |
+
]
|
| 204 |
+
resolved_video_processor_file = resolved_video_processor_files[0] if resolved_video_processor_files else None
|
| 205 |
+
|
| 206 |
+
# An empty list if none of the possible files is found in the repo
|
| 207 |
+
if not resolved_video_processor_file and not resolved_processor_file:
|
| 208 |
+
logger.info("Could not locate the video processor configuration file.")
|
| 209 |
+
return {}
|
| 210 |
+
|
| 211 |
+
# Load video_processor dict. Priority goes as (nested config if found -> video processor config -> image processor config)
|
| 212 |
+
# We are downloading both configs because almost all models have a `processor_config.json` but
|
| 213 |
+
# not all of these are nested. We need to check if it was saved recebtly as nested or if it is legacy style
|
| 214 |
+
video_processor_dict = {}
|
| 215 |
+
if resolved_processor_file is not None:
|
| 216 |
+
processor_dict = safe_load_json_file(resolved_processor_file)
|
| 217 |
+
if "video_processor" in processor_dict:
|
| 218 |
+
video_processor_dict = processor_dict["video_processor"]
|
| 219 |
+
|
| 220 |
+
if resolved_video_processor_file is not None and video_processor_dict is None:
|
| 221 |
+
video_processor_dict = safe_load_json_file(resolved_video_processor_file)
|
| 222 |
+
|
| 223 |
+
return video_processor_dict
|
| 224 |
+
|
| 225 |
+
|
| 226 |
+
@requires(backends=("vision", "torchvision"))
|
| 227 |
+
class AutoVideoProcessor:
|
| 228 |
+
r"""
|
| 229 |
+
This is a generic video processor class that will be instantiated as one of the video processor classes of the
|
| 230 |
+
library when created with the [`AutoVideoProcessor.from_pretrained`] class method.
|
| 231 |
+
|
| 232 |
+
This class cannot be instantiated directly using `__init__()` (throws an error).
|
| 233 |
+
"""
|
| 234 |
+
|
| 235 |
+
def __init__(self):
|
| 236 |
+
raise OSError(
|
| 237 |
+
"AutoVideoProcessor is designed to be instantiated "
|
| 238 |
+
"using the `AutoVideoProcessor.from_pretrained(pretrained_model_name_or_path)` method."
|
| 239 |
+
)
|
| 240 |
+
|
| 241 |
+
@classmethod
|
| 242 |
+
@replace_list_option_in_docstrings(VIDEO_PROCESSOR_MAPPING_NAMES)
|
| 243 |
+
def from_pretrained(cls, pretrained_model_name_or_path, *inputs, **kwargs):
|
| 244 |
+
r"""
|
| 245 |
+
Instantiate one of the video processor classes of the library from a pretrained model vocabulary.
|
| 246 |
+
|
| 247 |
+
The video processor class to instantiate is selected based on the `model_type` property of the config object
|
| 248 |
+
(either passed as an argument or loaded from `pretrained_model_name_or_path` if possible), or when it's
|
| 249 |
+
missing, by falling back to using pattern matching on `pretrained_model_name_or_path`:
|
| 250 |
+
|
| 251 |
+
List options
|
| 252 |
+
|
| 253 |
+
Params:
|
| 254 |
+
pretrained_model_name_or_path (`str` or `os.PathLike`):
|
| 255 |
+
This can be either:
|
| 256 |
+
|
| 257 |
+
- a string, the *model id* of a pretrained video_processor hosted inside a model repo on
|
| 258 |
+
huggingface.co.
|
| 259 |
+
- a path to a *directory* containing a video processor file saved using the
|
| 260 |
+
[`~video_processing_utils.BaseVideoProcessor.save_pretrained`] method, e.g.,
|
| 261 |
+
`./my_model_directory/`.
|
| 262 |
+
- a path to a saved video processor JSON *file*, e.g.,
|
| 263 |
+
`./my_model_directory/preprocessor_config.json`.
|
| 264 |
+
cache_dir (`str` or `os.PathLike`, *optional*):
|
| 265 |
+
Path to a directory in which a downloaded pretrained model video processor should be cached if the
|
| 266 |
+
standard cache should not be used.
|
| 267 |
+
force_download (`bool`, *optional*, defaults to `False`):
|
| 268 |
+
Whether or not to force to (re-)download the video processor files and override the cached versions if
|
| 269 |
+
they exist.
|
| 270 |
+
proxies (`dict[str, str]`, *optional*):
|
| 271 |
+
A dictionary of proxy servers to use by protocol or endpoint, e.g., `{'http': 'foo.bar:3128',
|
| 272 |
+
'http://hostname': 'foo.bar:4012'}.` The proxies are used on each request.
|
| 273 |
+
token (`str` or *bool*, *optional*):
|
| 274 |
+
The token to use as HTTP bearer authorization for remote files. If `True`, will use the token generated
|
| 275 |
+
when running `hf auth login` (stored in `~/.huggingface`).
|
| 276 |
+
revision (`str`, *optional*, defaults to `"main"`):
|
| 277 |
+
The specific model version to use. It can be a branch name, a tag name, or a commit id, since we use a
|
| 278 |
+
git-based system for storing models and other artifacts on huggingface.co, so `revision` can be any
|
| 279 |
+
identifier allowed by git.
|
| 280 |
+
return_unused_kwargs (`bool`, *optional*, defaults to `False`):
|
| 281 |
+
If `False`, then this function returns just the final video processor object. If `True`, then this
|
| 282 |
+
functions returns a `Tuple(video_processor, unused_kwargs)` where *unused_kwargs* is a dictionary
|
| 283 |
+
consisting of the key/value pairs whose keys are not video processor attributes: i.e., the part of
|
| 284 |
+
`kwargs` which has not been used to update `video_processor` and is otherwise ignored.
|
| 285 |
+
trust_remote_code (`bool`, *optional*, defaults to `False`):
|
| 286 |
+
Whether or not to allow for custom models defined on the Hub in their own modeling files. This option
|
| 287 |
+
should only be set to `True` for repositories you trust and in which you have read the code, as it will
|
| 288 |
+
execute code present on the Hub on your local machine.
|
| 289 |
+
kwargs (`dict[str, Any]`, *optional*):
|
| 290 |
+
The values in kwargs of any keys which are video processor attributes will be used to override the
|
| 291 |
+
loaded values. Behavior concerning key/value pairs whose keys are *not* video processor attributes is
|
| 292 |
+
controlled by the `return_unused_kwargs` keyword parameter.
|
| 293 |
+
|
| 294 |
+
<Tip>
|
| 295 |
+
|
| 296 |
+
Passing `token=True` is required when you want to use a private model.
|
| 297 |
+
|
| 298 |
+
</Tip>
|
| 299 |
+
|
| 300 |
+
Examples:
|
| 301 |
+
|
| 302 |
+
```python
|
| 303 |
+
>>> from transformers import AutoVideoProcessor
|
| 304 |
+
|
| 305 |
+
>>> # Download video processor from huggingface.co and cache.
|
| 306 |
+
>>> video_processor = AutoVideoProcessor.from_pretrained("llava-hf/llava-onevision-qwen2-0.5b-ov-hf")
|
| 307 |
+
|
| 308 |
+
>>> # If video processor files are in a directory (e.g. video processor was saved using *save_pretrained('./test/saved_model/')*)
|
| 309 |
+
>>> # video_processor = AutoVideoProcessor.from_pretrained("./test/saved_model/")
|
| 310 |
+
```"""
|
| 311 |
+
config = kwargs.pop("config", None)
|
| 312 |
+
trust_remote_code = kwargs.pop("trust_remote_code", None)
|
| 313 |
+
kwargs["_from_auto"] = True
|
| 314 |
+
|
| 315 |
+
config_dict, _ = BaseVideoProcessor.get_video_processor_dict(pretrained_model_name_or_path, **kwargs)
|
| 316 |
+
video_processor_class = config_dict.get("video_processor_type", None)
|
| 317 |
+
video_processor_auto_map = None
|
| 318 |
+
if "AutoVideoProcessor" in config_dict.get("auto_map", {}):
|
| 319 |
+
video_processor_auto_map = config_dict["auto_map"]["AutoVideoProcessor"]
|
| 320 |
+
|
| 321 |
+
# If we still don't have the video processor class, check if we're loading from a previous image processor config
|
| 322 |
+
# and if so, infer the video processor class from there.
|
| 323 |
+
if video_processor_class is None and video_processor_auto_map is None:
|
| 324 |
+
image_processor_class = config_dict.pop("image_processor_type", None)
|
| 325 |
+
if image_processor_class is not None:
|
| 326 |
+
video_processor_class_inferred = image_processor_class.replace("ImageProcessor", "VideoProcessor")
|
| 327 |
+
|
| 328 |
+
# Some models have different image processors, e.g. InternVL uses GotOCRImageProcessor
|
| 329 |
+
# We cannot use GotOCRVideoProcessor when falling back for BC and should try to infer from config later on
|
| 330 |
+
if video_processor_class_from_name(video_processor_class_inferred) is not None:
|
| 331 |
+
video_processor_class = video_processor_class_inferred
|
| 332 |
+
if "AutoImageProcessor" in config_dict.get("auto_map", {}):
|
| 333 |
+
image_processor_auto_map = config_dict["auto_map"]["AutoImageProcessor"]
|
| 334 |
+
video_processor_auto_map = image_processor_auto_map.replace("ImageProcessor", "VideoProcessor")
|
| 335 |
+
|
| 336 |
+
# If we don't find the video processor class in the video processor config, let's try the model config.
|
| 337 |
+
if video_processor_class is None and video_processor_auto_map is None:
|
| 338 |
+
if not isinstance(config, PreTrainedConfig):
|
| 339 |
+
config = AutoConfig.from_pretrained(
|
| 340 |
+
pretrained_model_name_or_path, trust_remote_code=trust_remote_code, **kwargs
|
| 341 |
+
)
|
| 342 |
+
# It could be in `config.video_processor_type``
|
| 343 |
+
video_processor_class = getattr(config, "video_processor_type", None)
|
| 344 |
+
if hasattr(config, "auto_map") and "AutoVideoProcessor" in config.auto_map:
|
| 345 |
+
video_processor_auto_map = config.auto_map["AutoVideoProcessor"]
|
| 346 |
+
|
| 347 |
+
if video_processor_class is not None:
|
| 348 |
+
video_processor_class = video_processor_class_from_name(video_processor_class)
|
| 349 |
+
|
| 350 |
+
has_remote_code = video_processor_auto_map is not None
|
| 351 |
+
has_local_code = video_processor_class is not None or type(config) in VIDEO_PROCESSOR_MAPPING
|
| 352 |
+
explicit_local_code = has_local_code and not (
|
| 353 |
+
video_processor_class or VIDEO_PROCESSOR_MAPPING[type(config)]
|
| 354 |
+
).__module__.startswith("transformers.")
|
| 355 |
+
if has_remote_code:
|
| 356 |
+
if "--" in video_processor_auto_map:
|
| 357 |
+
upstream_repo = video_processor_auto_map.split("--")[0]
|
| 358 |
+
else:
|
| 359 |
+
upstream_repo = None
|
| 360 |
+
trust_remote_code = resolve_trust_remote_code(
|
| 361 |
+
trust_remote_code, pretrained_model_name_or_path, has_local_code, has_remote_code, upstream_repo
|
| 362 |
+
)
|
| 363 |
+
|
| 364 |
+
if has_remote_code and trust_remote_code and not explicit_local_code:
|
| 365 |
+
class_ref = video_processor_auto_map
|
| 366 |
+
video_processor_class = get_class_from_dynamic_module(class_ref, pretrained_model_name_or_path, **kwargs)
|
| 367 |
+
_ = kwargs.pop("code_revision", None)
|
| 368 |
+
video_processor_class.register_for_auto_class()
|
| 369 |
+
return video_processor_class.from_pretrained(pretrained_model_name_or_path, *inputs, **kwargs)
|
| 370 |
+
elif video_processor_class is not None:
|
| 371 |
+
return video_processor_class.from_pretrained(pretrained_model_name_or_path, *inputs, **kwargs)
|
| 372 |
+
# Last try: we use the VIDEO_PROCESSOR_MAPPING.
|
| 373 |
+
elif type(config) in VIDEO_PROCESSOR_MAPPING:
|
| 374 |
+
video_processor_class = VIDEO_PROCESSOR_MAPPING[type(config)]
|
| 375 |
+
if video_processor_class is not None:
|
| 376 |
+
return video_processor_class.from_pretrained(pretrained_model_name_or_path, *inputs, **kwargs)
|
| 377 |
+
|
| 378 |
+
# Raise a more informative error message if torchvision isn't found, otherwise just fallback to default
|
| 379 |
+
if not is_torchvision_available():
|
| 380 |
+
raise ValueError(
|
| 381 |
+
f"{pretrained_model_name_or_path} requires `torchvision` to be installed. Please install `torchvision` and try again."
|
| 382 |
+
)
|
| 383 |
+
|
| 384 |
+
raise ValueError(
|
| 385 |
+
f"Unrecognized video processor in {pretrained_model_name_or_path}. Should have a "
|
| 386 |
+
f"`video_processor_type` key in its {VIDEO_PROCESSOR_NAME} of {CONFIG_NAME}, or one of the following "
|
| 387 |
+
f"`model_type` keys in its {CONFIG_NAME}: {', '.join(c for c in VIDEO_PROCESSOR_MAPPING_NAMES)}"
|
| 388 |
+
)
|
| 389 |
+
|
| 390 |
+
@staticmethod
|
| 391 |
+
def register(
|
| 392 |
+
config_class,
|
| 393 |
+
video_processor_class,
|
| 394 |
+
exist_ok=False,
|
| 395 |
+
):
|
| 396 |
+
"""
|
| 397 |
+
Register a new video processor for this class.
|
| 398 |
+
|
| 399 |
+
Args:
|
| 400 |
+
config_class ([`PreTrainedConfig`]):
|
| 401 |
+
The configuration corresponding to the model to register.
|
| 402 |
+
video_processor_class ([`BaseVideoProcessor`]):
|
| 403 |
+
The video processor to register.
|
| 404 |
+
"""
|
| 405 |
+
VIDEO_PROCESSOR_MAPPING.register(config_class, video_processor_class, exist_ok=exist_ok)
|
| 406 |
+
|
| 407 |
+
|
| 408 |
+
__all__ = ["VIDEO_PROCESSOR_MAPPING", "AutoVideoProcessor"]
|
LTA_openwebtext_dualt/mini_owt_logdirichlet/.venv_qwen35_uv/lib/python3.12/site-packages/transformers/models/distilbert/tokenization_distilbert.py
ADDED
|
@@ -0,0 +1,42 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# Copyright 2018 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 |
+
"""Tokenization classes for DistilBERT."""
|
| 15 |
+
|
| 16 |
+
from ...models.bert.tokenization_bert import BertTokenizer
|
| 17 |
+
|
| 18 |
+
|
| 19 |
+
VOCAB_FILES_NAMES = {"vocab_file": "vocab.txt", "tokenizer_file": "tokenizer.json"}
|
| 20 |
+
|
| 21 |
+
|
| 22 |
+
class DistilBertTokenizer(BertTokenizer):
|
| 23 |
+
model_input_names = ["input_ids", "attention_mask"]
|
| 24 |
+
|
| 25 |
+
def __init__(self, *args, do_lower_case: bool = True, **kwargs):
|
| 26 |
+
"""
|
| 27 |
+
Construct a DistilBERT tokenizer (backed by HuggingFace's tokenizers library). Based on WordPiece.
|
| 28 |
+
|
| 29 |
+
This tokenizer inherits from [`BertTokenizer`] which contains most of the main methods. Users should refer to
|
| 30 |
+
this superclass for more information regarding those methods.
|
| 31 |
+
|
| 32 |
+
Args:
|
| 33 |
+
do_lower_case (`bool`, *optional*, defaults to `True`):
|
| 34 |
+
Whether or not to lowercase the input when tokenizing.
|
| 35 |
+
"""
|
| 36 |
+
super().__init__(*args, do_lower_case=do_lower_case, **kwargs)
|
| 37 |
+
|
| 38 |
+
|
| 39 |
+
# DistilBertTokenizerFast is an alias for DistilBertTokenizer (since BertTokenizer is already a fast tokenizer)
|
| 40 |
+
DistilBertTokenizerFast = DistilBertTokenizer
|
| 41 |
+
|
| 42 |
+
__all__ = ["DistilBertTokenizer", "DistilBertTokenizerFast"]
|
LTA_openwebtext_dualt/mini_owt_logdirichlet/.venv_qwen35_uv/lib/python3.12/site-packages/transformers/models/slanext/configuration_slanext.py
ADDED
|
@@ -0,0 +1,103 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# 🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨
|
| 2 |
+
# This file was automatically generated from src/transformers/models/slanext/modular_slanext.py.
|
| 3 |
+
# Do NOT edit this file manually as any edits will be overwritten by the generation of
|
| 4 |
+
# the file from the modular. If any change should be done, please apply the change to the
|
| 5 |
+
# modular_slanext.py file directly. One of our CI enforces this.
|
| 6 |
+
# 🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨
|
| 7 |
+
# Copyright 2026 The PaddlePaddle Team and The HuggingFace Inc. team. All rights reserved.
|
| 8 |
+
#
|
| 9 |
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
| 10 |
+
# you may not use this file except in compliance with the License.
|
| 11 |
+
# You may obtain a copy of the License at
|
| 12 |
+
#
|
| 13 |
+
# http://www.apache.org/licenses/LICENSE-2.0
|
| 14 |
+
#
|
| 15 |
+
# Unless required by applicable law or agreed to in writing, software
|
| 16 |
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
| 17 |
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
| 18 |
+
# See the License for the specific language governing permissions and
|
| 19 |
+
# limitations under the License.
|
| 20 |
+
|
| 21 |
+
|
| 22 |
+
from huggingface_hub.dataclasses import strict
|
| 23 |
+
|
| 24 |
+
from ...configuration_utils import PreTrainedConfig
|
| 25 |
+
from ...utils import auto_docstring
|
| 26 |
+
|
| 27 |
+
|
| 28 |
+
@auto_docstring(checkpoint="PaddlePaddle/SLANeXt_wired_safetensors")
|
| 29 |
+
@strict
|
| 30 |
+
class SLANeXtVisionConfig(PreTrainedConfig):
|
| 31 |
+
r"""
|
| 32 |
+
output_channels (`int`, *optional*, defaults to 256):
|
| 33 |
+
Dimensionality of the output channels in the Patch Encoder.
|
| 34 |
+
use_abs_pos (`bool`, *optional*, defaults to `True`):
|
| 35 |
+
Whether to use absolute position embedding.
|
| 36 |
+
use_rel_pos (`bool`, *optional*, defaults to `True`):
|
| 37 |
+
Whether to use relative position embedding.
|
| 38 |
+
window_size (`int`, *optional*, defaults to 14):
|
| 39 |
+
Window size for relative position.
|
| 40 |
+
global_attn_indexes (`list[int]`, *optional*, defaults to `[2, 5, 8, 11]`):
|
| 41 |
+
The indexes of the global attention layers.
|
| 42 |
+
mlp_dim (`int`, *optional*, defaults to 3072):
|
| 43 |
+
The dimensionality of the MLP layer in the Transformer encoder.
|
| 44 |
+
"""
|
| 45 |
+
|
| 46 |
+
base_config_key = "vision_config"
|
| 47 |
+
hidden_size: int = 768
|
| 48 |
+
output_channels: int = 256
|
| 49 |
+
num_hidden_layers: int = 12
|
| 50 |
+
num_attention_heads: int = 12
|
| 51 |
+
num_channels: int = 3
|
| 52 |
+
image_size: int = 512
|
| 53 |
+
patch_size: int | list[int] | tuple[int, int] = 16
|
| 54 |
+
hidden_act: str = "gelu"
|
| 55 |
+
layer_norm_eps: float = 1e-06
|
| 56 |
+
attention_dropout: float | int = 0.0
|
| 57 |
+
initializer_range: float = 1e-10
|
| 58 |
+
qkv_bias: bool = True
|
| 59 |
+
use_abs_pos: bool = True
|
| 60 |
+
use_rel_pos: bool = True
|
| 61 |
+
window_size: int = 14
|
| 62 |
+
global_attn_indexes: list[int] | tuple[int, ...] = (2, 5, 8, 11)
|
| 63 |
+
mlp_dim: int = 3072
|
| 64 |
+
|
| 65 |
+
|
| 66 |
+
@auto_docstring(checkpoint="PaddlePaddle/SLANeXt_wired_safetensors")
|
| 67 |
+
@strict
|
| 68 |
+
class SLANeXtConfig(PreTrainedConfig):
|
| 69 |
+
r"""
|
| 70 |
+
vision_config (`dict` or [`SLANeXtVisionConfig`], *optional*):
|
| 71 |
+
Configuration for the vision encoder. If `None`, a default [`SLANeXtVisionConfig`] is used.
|
| 72 |
+
post_conv_in_channels (`int`, *optional*, defaults to 256):
|
| 73 |
+
Number of input channels for the post-encoder convolution layer.
|
| 74 |
+
post_conv_out_channels (`int`, *optional*, defaults to 512):
|
| 75 |
+
Number of output channels for the post-encoder convolution layer.
|
| 76 |
+
out_channels (`int`, *optional*, defaults to 50):
|
| 77 |
+
Vocabulary size for the table structure token prediction head, i.e., the number of distinct structure
|
| 78 |
+
tokens the model can predict.
|
| 79 |
+
hidden_size (`int`, *optional*, defaults to 512):
|
| 80 |
+
Dimensionality of the hidden states in the attention GRU cell and the structure/location prediction heads.
|
| 81 |
+
max_text_length (`int`, *optional*, defaults to 500):
|
| 82 |
+
Maximum number of autoregressive decoding steps (tokens) for the structure and location decoder.
|
| 83 |
+
"""
|
| 84 |
+
|
| 85 |
+
model_type = "slanext"
|
| 86 |
+
sub_configs = {"vision_config": SLANeXtVisionConfig}
|
| 87 |
+
|
| 88 |
+
vision_config: dict | SLANeXtVisionConfig | None = None
|
| 89 |
+
post_conv_in_channels: int = 256
|
| 90 |
+
post_conv_out_channels: int = 512
|
| 91 |
+
out_channels: int = 50
|
| 92 |
+
hidden_size: int = 512
|
| 93 |
+
max_text_length: int = 500
|
| 94 |
+
|
| 95 |
+
def __post_init__(self, **kwargs):
|
| 96 |
+
if self.vision_config is None:
|
| 97 |
+
self.vision_config = SLANeXtVisionConfig()
|
| 98 |
+
elif isinstance(self.vision_config, dict):
|
| 99 |
+
self.vision_config = SLANeXtVisionConfig(**self.vision_config)
|
| 100 |
+
super().__post_init__(**kwargs)
|
| 101 |
+
|
| 102 |
+
|
| 103 |
+
__all__ = ["SLANeXtConfig"]
|
LTA_openwebtext_dualt/mini_owt_logdirichlet/.venv_qwen35_uv/lib/python3.12/site-packages/transformers/models/slanext/image_processing_slanext.py
ADDED
|
@@ -0,0 +1,257 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|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🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨
|
| 2 |
+
# This file was automatically generated from src/transformers/models/slanext/modular_slanext.py.
|
| 3 |
+
# Do NOT edit this file manually as any edits will be overwritten by the generation of
|
| 4 |
+
# the file from the modular. If any change should be done, please apply the change to the
|
| 5 |
+
# modular_slanext.py file directly. One of our CI enforces this.
|
| 6 |
+
# 🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨
|
| 7 |
+
# Copyright 2026 The PaddlePaddle Team and The HuggingFace Inc. team. All rights reserved.
|
| 8 |
+
#
|
| 9 |
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
| 10 |
+
# you may not use this file except in compliance with the License.
|
| 11 |
+
# You may obtain a copy of the License at
|
| 12 |
+
#
|
| 13 |
+
# http://www.apache.org/licenses/LICENSE-2.0
|
| 14 |
+
#
|
| 15 |
+
# Unless required by applicable law or agreed to in writing, software
|
| 16 |
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
| 17 |
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
| 18 |
+
# See the License for the specific language governing permissions and
|
| 19 |
+
# limitations under the License.
|
| 20 |
+
|
| 21 |
+
|
| 22 |
+
import torch
|
| 23 |
+
import torchvision.transforms.v2.functional as tvF
|
| 24 |
+
|
| 25 |
+
from ...image_processing_backends import TorchvisionBackend
|
| 26 |
+
from ...image_processing_utils import BatchFeature
|
| 27 |
+
from ...image_transforms import group_images_by_shape, reorder_images
|
| 28 |
+
from ...image_utils import IMAGENET_DEFAULT_MEAN, IMAGENET_DEFAULT_STD, SizeDict
|
| 29 |
+
from ...processing_utils import ImagesKwargs, Unpack
|
| 30 |
+
from ...utils import auto_docstring, is_torchdynamo_compiling, logging
|
| 31 |
+
from ...utils.generic import TensorType
|
| 32 |
+
from ...utils.import_utils import requires
|
| 33 |
+
|
| 34 |
+
|
| 35 |
+
logger = logging.get_logger(__name__)
|
| 36 |
+
|
| 37 |
+
|
| 38 |
+
@auto_docstring
|
| 39 |
+
@requires(backends=("torch",))
|
| 40 |
+
class SLANeXtImageProcessor(TorchvisionBackend):
|
| 41 |
+
resample = 2 # PILImageResampling.BILINEAR
|
| 42 |
+
image_mean = IMAGENET_DEFAULT_MEAN
|
| 43 |
+
image_std = IMAGENET_DEFAULT_STD
|
| 44 |
+
size = {"height": 512, "width": 512}
|
| 45 |
+
pad_size = {"height": 512, "width": 512}
|
| 46 |
+
do_convert_rgb = True
|
| 47 |
+
do_resize = True
|
| 48 |
+
do_rescale = True
|
| 49 |
+
do_normalize = True
|
| 50 |
+
do_pad = True
|
| 51 |
+
|
| 52 |
+
def _resize(
|
| 53 |
+
self,
|
| 54 |
+
image: "torch.Tensor",
|
| 55 |
+
size: SizeDict,
|
| 56 |
+
) -> "torch.Tensor":
|
| 57 |
+
batch_size, channels, height, width = image.shape
|
| 58 |
+
image = image.view(batch_size * channels, height, width)
|
| 59 |
+
|
| 60 |
+
device = image.device
|
| 61 |
+
|
| 62 |
+
scale = max(size.height, size.width) / max(height, width)
|
| 63 |
+
target_height = round(height * scale)
|
| 64 |
+
target_width = round(width * scale)
|
| 65 |
+
|
| 66 |
+
target_col = torch.arange(target_width, dtype=torch.float32, device=device)
|
| 67 |
+
src_col = (target_col + 0.5) * (float(width) / float(target_width)) - 0.5
|
| 68 |
+
src_col_floor = src_col.floor().to(torch.int32)
|
| 69 |
+
src_col_frac = src_col - src_col_floor.float()
|
| 70 |
+
# boundary handling
|
| 71 |
+
src_col_frac = torch.where(src_col_floor < 0, torch.zeros_like(src_col_frac), src_col_frac)
|
| 72 |
+
src_col_floor = torch.where(src_col_floor < 0, torch.zeros_like(src_col_floor), src_col_floor)
|
| 73 |
+
src_col_frac = torch.where(src_col_floor >= width - 1, torch.ones_like(src_col_frac), src_col_frac)
|
| 74 |
+
src_col_floor = torch.where(
|
| 75 |
+
src_col_floor >= width - 1, torch.full_like(src_col_floor, width - 2), src_col_floor
|
| 76 |
+
)
|
| 77 |
+
# fixed-point weights
|
| 78 |
+
weight_right = (src_col_frac * 2048 + 0.5).floor().to(torch.int32) # round-to-nearest
|
| 79 |
+
weight_left = 2048 - weight_right # (target_w,)
|
| 80 |
+
# --- row coordinate tables ---
|
| 81 |
+
target_row = torch.arange(target_height, dtype=torch.float32, device=device)
|
| 82 |
+
src_row = (target_row + 0.5) * (float(height) / float(target_height)) - 0.5
|
| 83 |
+
src_row_floor = src_row.floor().to(torch.int32)
|
| 84 |
+
src_row_frac = src_row - src_row_floor.float()
|
| 85 |
+
src_row_frac = torch.where(src_row_floor < 0, torch.zeros_like(src_row_frac), src_row_frac)
|
| 86 |
+
src_row_floor = torch.where(src_row_floor < 0, torch.zeros_like(src_row_floor), src_row_floor)
|
| 87 |
+
src_row_frac = torch.where(src_row_floor >= height - 1, torch.ones_like(src_row_frac), src_row_frac)
|
| 88 |
+
src_row_floor = torch.where(
|
| 89 |
+
src_row_floor >= height - 1, torch.full_like(src_row_floor, height - 2), src_row_floor
|
| 90 |
+
)
|
| 91 |
+
weight_bottom = (src_row_frac * 2048 + 0.5).floor().to(torch.int32)
|
| 92 |
+
weight_top = 2048 - weight_bottom # (target_h,)
|
| 93 |
+
|
| 94 |
+
image_uint8 = image.clamp(0, 255).to(torch.uint8) # (C, H, W)
|
| 95 |
+
image_int32 = image_uint8.to(torch.int32) # (C, H, W)
|
| 96 |
+
col_left = src_col_floor.long() # (target_w,)
|
| 97 |
+
col_right = (src_col_floor + 1).long() # (target_w,) safe: src_col_floor <= width-2
|
| 98 |
+
row_top = src_row_floor.long() # (target_h,)
|
| 99 |
+
row_bottom = (src_row_floor + 1).long() # (target_h,)
|
| 100 |
+
# gather 4 neighbours: (C, target_h, target_w)
|
| 101 |
+
pixel_top_left = image_int32[:, row_top[:, None], col_left[None, :]]
|
| 102 |
+
pixel_top_right = image_int32[:, row_top[:, None], col_right[None, :]]
|
| 103 |
+
pixel_bottom_left = image_int32[:, row_bottom[:, None], col_left[None, :]]
|
| 104 |
+
pixel_bottom_right = image_int32[:, row_bottom[:, None], col_right[None, :]]
|
| 105 |
+
# fixed-point bilinear: weights broadcast over (C, target_h, target_w)
|
| 106 |
+
weight_bottom_3d = weight_bottom.view(1, target_height, 1)
|
| 107 |
+
weight_top_3d = weight_top.view(1, target_height, 1)
|
| 108 |
+
weight_right_3d = weight_right.view(1, 1, target_width)
|
| 109 |
+
weight_left_3d = weight_left.view(1, 1, target_width)
|
| 110 |
+
interp = weight_top_3d * (
|
| 111 |
+
weight_left_3d * pixel_top_left + weight_right_3d * pixel_top_right
|
| 112 |
+
) + weight_bottom_3d * (weight_left_3d * pixel_bottom_left + weight_right_3d * pixel_bottom_right)
|
| 113 |
+
interp = (interp + (1 << 21)) >> 22
|
| 114 |
+
result = interp.clamp(0, 255).to(torch.uint8) # (B*C, target_h, target_w)
|
| 115 |
+
|
| 116 |
+
return result.view(batch_size, channels, target_height, target_width).to(dtype=image.dtype)
|
| 117 |
+
|
| 118 |
+
def _preprocess(
|
| 119 |
+
self,
|
| 120 |
+
images: list["torch.Tensor"],
|
| 121 |
+
do_resize: bool,
|
| 122 |
+
size: SizeDict,
|
| 123 |
+
resample: "tvF.InterpolationMode | int | None",
|
| 124 |
+
do_center_crop: bool,
|
| 125 |
+
crop_size: SizeDict,
|
| 126 |
+
do_rescale: bool,
|
| 127 |
+
rescale_factor: float,
|
| 128 |
+
do_normalize: bool,
|
| 129 |
+
image_mean: float | list[float] | None,
|
| 130 |
+
image_std: float | list[float] | None,
|
| 131 |
+
do_pad: bool | None,
|
| 132 |
+
pad_size: SizeDict | None,
|
| 133 |
+
disable_grouping: bool | None,
|
| 134 |
+
return_tensors: str | TensorType | None,
|
| 135 |
+
**kwargs,
|
| 136 |
+
) -> BatchFeature:
|
| 137 |
+
if resample is not None and not is_torchdynamo_compiling():
|
| 138 |
+
logger.warning_once("Resampling is not supported in SLANeXt")
|
| 139 |
+
|
| 140 |
+
# Group images by size for batched resizing
|
| 141 |
+
grouped_images, grouped_images_index = group_images_by_shape(images, disable_grouping=disable_grouping)
|
| 142 |
+
resized_images_grouped = {}
|
| 143 |
+
for shape, stacked_images in grouped_images.items():
|
| 144 |
+
if do_resize:
|
| 145 |
+
stacked_images = self._resize(image=stacked_images, size=size)
|
| 146 |
+
resized_images_grouped[shape] = stacked_images
|
| 147 |
+
resized_images = reorder_images(resized_images_grouped, grouped_images_index)
|
| 148 |
+
|
| 149 |
+
# Group images by size for further processing
|
| 150 |
+
# Needed in case do_resize is False, or resize returns images with different sizes
|
| 151 |
+
grouped_images, grouped_images_index = group_images_by_shape(resized_images, disable_grouping=disable_grouping)
|
| 152 |
+
processed_images_grouped = {}
|
| 153 |
+
for shape, stacked_images in grouped_images.items():
|
| 154 |
+
if do_center_crop:
|
| 155 |
+
stacked_images = self.center_crop(stacked_images, crop_size)
|
| 156 |
+
# Fused rescale and normalize
|
| 157 |
+
stacked_images = self.rescale_and_normalize(
|
| 158 |
+
stacked_images, do_rescale, rescale_factor, do_normalize, image_mean, image_std
|
| 159 |
+
)
|
| 160 |
+
processed_images_grouped[shape] = stacked_images
|
| 161 |
+
processed_images = reorder_images(processed_images_grouped, grouped_images_index)
|
| 162 |
+
|
| 163 |
+
if do_pad:
|
| 164 |
+
processed_images = self.pad(processed_images, pad_size=pad_size, disable_grouping=disable_grouping)
|
| 165 |
+
|
| 166 |
+
return BatchFeature(data={"pixel_values": processed_images}, tensor_type=return_tensors)
|
| 167 |
+
|
| 168 |
+
def __init__(self, **kwargs: Unpack[ImagesKwargs]):
|
| 169 |
+
super().__init__(**kwargs)
|
| 170 |
+
self.init_decoder()
|
| 171 |
+
|
| 172 |
+
def init_decoder(self):
|
| 173 |
+
"""
|
| 174 |
+
Initialize the decoder vocabulary for table structure recognition.
|
| 175 |
+
|
| 176 |
+
Builds a character dictionary mapping HTML table structure tokens (e.g., `<thead>`, `<tr>`, `<td>`, colspan/
|
| 177 |
+
rowspan attributes) to integer indices. The dictionary includes special `"sos"` (start-of-sequence) and
|
| 178 |
+
`"eos"` (end-of-sequence) tokens. Merged `<td></td>` tokens are used in place of standalone `<td>` tokens
|
| 179 |
+
when applicable.
|
| 180 |
+
"""
|
| 181 |
+
dict_character = [
|
| 182 |
+
"<thead>",
|
| 183 |
+
"</thead>",
|
| 184 |
+
"<tbody>",
|
| 185 |
+
"</tbody>",
|
| 186 |
+
"<tr>",
|
| 187 |
+
"</tr>",
|
| 188 |
+
"<td>",
|
| 189 |
+
"<td",
|
| 190 |
+
">",
|
| 191 |
+
"</td>",
|
| 192 |
+
]
|
| 193 |
+
dict_character += [f' colspan="{i + 2}"' for i in range(19)]
|
| 194 |
+
dict_character += [f' rowspan="{i + 2}"' for i in range(19)]
|
| 195 |
+
|
| 196 |
+
if "<td></td>" not in dict_character:
|
| 197 |
+
dict_character.append("<td></td>")
|
| 198 |
+
if "<td>" in dict_character:
|
| 199 |
+
dict_character.remove("<td>")
|
| 200 |
+
|
| 201 |
+
dict_character = ["sos"] + dict_character + ["eos"]
|
| 202 |
+
self.dict = {char: i for i, char in enumerate(dict_character)}
|
| 203 |
+
self.character = dict_character
|
| 204 |
+
self.td_token = ["<td>", "<td", "<td></td>"]
|
| 205 |
+
self.bos_id = self.dict["sos"]
|
| 206 |
+
self.eos_id = self.dict["eos"]
|
| 207 |
+
|
| 208 |
+
def post_process_table_recognition(self, outputs):
|
| 209 |
+
"""
|
| 210 |
+
Post-process the raw model outputs to decode the predicted table structure into an HTML token sequence.
|
| 211 |
+
|
| 212 |
+
Converts the model's predicted probability distributions over the structure vocabulary into a sequence of
|
| 213 |
+
HTML tokens representing the table structure. The decoded tokens are wrapped with `<html>`, `<body>`, and
|
| 214 |
+
`<table>` tags to form a complete HTML table structure.
|
| 215 |
+
|
| 216 |
+
Args:
|
| 217 |
+
outputs ([`SLANeXtForTableRecognitionOutput`]):
|
| 218 |
+
Raw outputs from the SLANeXt model. The `last_hidden_state` field contains the predicted probability
|
| 219 |
+
distributions over the structure vocabulary at each decoding step, with shape
|
| 220 |
+
`(batch_size, max_text_length, num_classes)`.
|
| 221 |
+
|
| 222 |
+
Returns:
|
| 223 |
+
`dict`: A dictionary containing:
|
| 224 |
+
- **structure** (`list[str]`): The predicted HTML table structure as a list of tokens, wrapped with
|
| 225 |
+
`<html>`, `<body>`, and `<table>` tags.
|
| 226 |
+
- **structure_score** (`float`): The mean confidence score across all predicted tokens.
|
| 227 |
+
"""
|
| 228 |
+
self.pred = outputs.last_hidden_state
|
| 229 |
+
structure_probs = self.pred[0:1]
|
| 230 |
+
ignored_tokens = [int(self.bos_id), int(self.eos_id)]
|
| 231 |
+
end_idx = int(self.eos_id)
|
| 232 |
+
|
| 233 |
+
structure_idx = structure_probs.argmax(dim=2)
|
| 234 |
+
structure_probs = structure_probs.max(dim=2).values
|
| 235 |
+
|
| 236 |
+
structure_str_list = []
|
| 237 |
+
batch_size = structure_idx.shape[0]
|
| 238 |
+
for batch_index in range(batch_size):
|
| 239 |
+
structure_list = []
|
| 240 |
+
score_list = []
|
| 241 |
+
for position in range(structure_idx.shape[1]):
|
| 242 |
+
char_idx = int(structure_idx[batch_index, position])
|
| 243 |
+
if position > 0 and char_idx == end_idx:
|
| 244 |
+
break
|
| 245 |
+
if char_idx in ignored_tokens:
|
| 246 |
+
continue
|
| 247 |
+
text = self.character[char_idx]
|
| 248 |
+
structure_list.append(text)
|
| 249 |
+
score_list.append(structure_probs[batch_index, position])
|
| 250 |
+
structure_str_list.append(structure_list)
|
| 251 |
+
structure_score = torch.stack(score_list).mean().item()
|
| 252 |
+
|
| 253 |
+
structure = ["<html>", "<body>", "<table>"] + structure_str_list[0] + ["</table>", "</body>", "</html>"]
|
| 254 |
+
return {"structure": structure, "structure_score": structure_score}
|
| 255 |
+
|
| 256 |
+
|
| 257 |
+
__all__ = ["SLANeXtImageProcessor"]
|
LTA_openwebtext_dualt/mini_owt_logdirichlet/.venv_qwen35_uv/lib/python3.12/site-packages/transformers/models/vitdet/__init__.py
ADDED
|
@@ -0,0 +1,27 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 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_vitdet import *
|
| 22 |
+
from .modeling_vitdet import *
|
| 23 |
+
else:
|
| 24 |
+
import sys
|
| 25 |
+
|
| 26 |
+
_file = globals()["__file__"]
|
| 27 |
+
sys.modules[__name__] = _LazyModule(__name__, _file, define_import_structure(_file), module_spec=__spec__)
|
LTA_openwebtext_dualt/mini_owt_logdirichlet/runs/owt_t5_elftokenized_full_len1024_C1_to_1024_pow1_d768_l12_h12_gbs512_8gpu_50ep_lr3e4_elfopt_t5embed_unfixed_stateprobadd_selfcond_ce_fast_20260531_230026/step_029000.pt
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:7d221009eecb873d733178e1f32b36540eaec5298c006106b419d001ba3c2360
|
| 3 |
+
size 515519058
|
LTA_openwebtext_dualt/mini_owt_logdirichlet/runs/owt_t5_elftokenized_full_len1024_C1_to_1024_pow1_d768_l12_h12_gbs512_8gpu_50ep_lr3e4_elfopt_t5embed_unfixed_stateprobadd_selfcond_ce_fast_20260531_230026/step_096000.pt
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:73153c0e7f00aeb1c680b93e767843b424adc5e5d89a0afe314684bc49a26e4f
|
| 3 |
+
size 515519058
|
LTA_openwebtext_dualt/mini_owt_logdirichlet/runs/owt_t5_elftokenized_full_len1024_C1_to_1024_pow1_d768_l12_h12_gbs512_8gpu_50ep_lr3e4_elfopt_t5embed_unfixed_stateprobadd_selfcond_ce_fast_20260531_230026/step_167000.pt
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:e67f128f4b00cc4ad62f759a90617390d55ab4a62de1ba5e334e9cced469dec0
|
| 3 |
+
size 515519058
|
LTA_openwebtext_dualt/mini_owt_logdirichlet/runs/owt_t5_elftokenized_full_len1024_C1_to_1024_pow1_d768_l12_h12_gbs512_8gpu_50ep_lr3e4_elfopt_t5embed_unfixed_stateprobadd_selfcond_ce_fast_20260531_230026/step_210000.pt
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:751cccbc439dfeeb636473d92259367833270066cfcff5038194db9989c796fc
|
| 3 |
+
size 515519058
|