mirror of
https://github.com/NVIDIA/TensorRT-LLM.git
synced 2026-01-14 06:27:45 +08:00
Co-authored-by: Kaiyu Xie <26294424+kaiyux@users.noreply.github.com> open source f8c0381a2bc50ee2739c3d8c2be481b31e5f00bd (#2736) Co-authored-by: Kaiyu Xie <26294424+kaiyux@users.noreply.github.com> Add note for blackwell (#2742) Update the docs to workaround the extra-index-url issue (#2744) update README.md (#2751) Fix github io pages (#2761) Update
39 lines
1.4 KiB
Python
39 lines
1.4 KiB
Python
# Adapt from
|
|
# https://github.com/vllm-project/vllm/blob/2e33fe419186c65a18da6668972d61d7bbc31564/vllm/multimodal/image.py
|
|
from typing import Any, cast
|
|
|
|
from transformers import AutoImageProcessor
|
|
from transformers.image_processing_utils import BaseImageProcessor
|
|
|
|
|
|
def get_hf_image_processor(
|
|
processor_name: str,
|
|
*args: Any,
|
|
trust_remote_code: bool = False,
|
|
**kwargs: Any,
|
|
):
|
|
"""Load an image processor for the given model name via HuggingFace."""
|
|
|
|
try:
|
|
processor = AutoImageProcessor.from_pretrained(
|
|
processor_name,
|
|
*args,
|
|
trust_remote_code=trust_remote_code,
|
|
**kwargs)
|
|
except ValueError as e:
|
|
# If the error pertains to the processor class not existing or not
|
|
# currently being imported, suggest using the --trust-remote-code flag.
|
|
# Unlike AutoTokenizer, AutoImageProcessor does not separate such errors
|
|
if not trust_remote_code:
|
|
err_msg = (
|
|
"Failed to load the image processor. If the image processor is "
|
|
"a custom processor not yet available in the HuggingFace "
|
|
"transformers library, consider setting "
|
|
"`trust_remote_code=True` in LLM or using the "
|
|
"`--trust-remote-code` flag in the CLI.")
|
|
raise RuntimeError(err_msg) from e
|
|
else:
|
|
raise e
|
|
|
|
return cast(BaseImageProcessor, processor)
|