11# SPDX-License-Identifier: Apache-2.0
22
33from functools import lru_cache
4- from typing import TYPE_CHECKING , Any , Union , cast
4+ from typing import TYPE_CHECKING , Any , Optional , Union , cast
55
66from transformers .processing_utils import ProcessorMixin
77from typing_extensions import TypeVar
@@ -54,6 +54,7 @@ def _merge_mm_kwargs(model_config: "ModelConfig", **kwargs):
5454def get_processor (
5555 processor_name : str ,
5656 * args : Any ,
57+ revision : Optional [str ] = None ,
5758 trust_remote_code : bool = False ,
5859 processor_cls : Union [type [_P ], tuple [type [_P ], ...]] = ProcessorMixin ,
5960 ** kwargs : Any ,
@@ -70,6 +71,7 @@ def get_processor(
7071 processor = processor_factory .from_pretrained (
7172 processor_name ,
7273 * args ,
74+ revision = revision ,
7375 trust_remote_code = trust_remote_code ,
7476 ** kwargs ,
7577 )
@@ -106,6 +108,7 @@ def cached_processor_from_config(
106108) -> _P :
107109 return cached_get_processor (
108110 model_config .model ,
111+ revision = model_config .revision ,
109112 trust_remote_code = model_config .trust_remote_code ,
110113 processor_cls = processor_cls , # type: ignore[arg-type]
111114 ** _merge_mm_kwargs (model_config , ** kwargs ),
@@ -115,6 +118,7 @@ def cached_processor_from_config(
115118def get_feature_extractor (
116119 processor_name : str ,
117120 * args : Any ,
121+ revision : Optional [str ] = None ,
118122 trust_remote_code : bool = False ,
119123 ** kwargs : Any ,
120124):
@@ -128,6 +132,7 @@ def get_feature_extractor(
128132 feature_extractor = AutoFeatureExtractor .from_pretrained (
129133 processor_name ,
130134 * args ,
135+ revision = revision ,
131136 trust_remote_code = trust_remote_code ,
132137 ** kwargs )
133138 except ValueError as e :
@@ -156,6 +161,7 @@ def cached_feature_extractor_from_config(
156161):
157162 return cached_get_feature_extractor (
158163 model_config .model ,
164+ revision = model_config .revision ,
159165 trust_remote_code = model_config .trust_remote_code ,
160166 ** _merge_mm_kwargs (model_config , ** kwargs ),
161167 )
@@ -164,6 +170,7 @@ def cached_feature_extractor_from_config(
164170def get_image_processor (
165171 processor_name : str ,
166172 * args : Any ,
173+ revision : Optional [str ] = None ,
167174 trust_remote_code : bool = False ,
168175 ** kwargs : Any ,
169176):
@@ -177,6 +184,7 @@ def get_image_processor(
177184 processor = AutoImageProcessor .from_pretrained (
178185 processor_name ,
179186 * args ,
187+ revision = revision ,
180188 trust_remote_code = trust_remote_code ,
181189 ** kwargs )
182190 except ValueError as e :
@@ -206,6 +214,7 @@ def cached_image_processor_from_config(
206214):
207215 return cached_get_image_processor (
208216 model_config .model ,
217+ revision = model_config .revision ,
209218 trust_remote_code = model_config .trust_remote_code ,
210219 ** _merge_mm_kwargs (model_config , ** kwargs ),
211220 )
0 commit comments