Transformers documentation

MLCD

You are viewing main version, which requires installation from source. If you'd like regular pip install, checkout the latest stable version (v5.22.1).
Hugging Face's logo
Join the Hugging Face community

and get access to the augmented documentation experience

to get started

このモデルは2024年7月24日にHF papersで公開され、2025年4月15日にHugging Face Transformersに貢献されました。

MLCD

SDPA

概要

MLCDモデルは、unicomのDeepGlint-AIチームによってリリースされました。unicomは、LAION400MやCOYO700Mなどの大規模データセットを用いて、大規模マルチモーダル言語モデル向けの基盤となる視覚モデルの構築に注力しており、パフォーマンスの最適化のためにサンプルからクラスターへの対比学習を採用しています。MLCDモデルは、LLaVAなどのマルチモーダル視覚大規模言語モデルに主に使用されます。

🔥MLCD-ViT-bigG🔥 シリーズは、2D Rotary Position Embedding (RoPE2D) により強化された最先端の Vision Transformer モデルであり、文書理解および視覚的質問応答タスクにおいて優れたパフォーマンスを実現しています。DeepGlint AI によって開発されたこのモデルは、複雑な視覚言語インタラクションの処理において卓越した能力を示しています。

ヒント:

  • 基礎的なビジュアルモデルの評価には、公式のLLaVA-NeXTと公式の学習データセットLLaVA-NeXT-Dataを採用しました。

  • 言語モデルはQwen2.5-7Bです。

結果:

ビジョンタワーRoPE2DChartQADocVQAInfoVQAOCRBenchMMMU
CLIP (ViT-L-14-336px)×66.5275.2138.88525.0044.20
SigLIP (ViT-SO400M-384px)×69.2876.7141.38554.0046.78
DFN5B (ViT-H-14-378px)×64.3670.8738.59473.0048.00
MLCD (ViT-L-14-336px)×67.8476.4643.48531.0044.30
MLCD (ViT-bigG-14-336px)√71.0779.6344.38572.0046.78
MLCD (ViT-bigG-14-448px)√73.8083.3446.59582.0046.00

使用方法

import requests
from PIL import Image

from transformers import AutoProcessor, MLCDVisionModel


# Load model and processor
model = MLCDVisionModel.from_pretrained("DeepGlint-AI/mlcd-vit-bigG-patch14-448", device_map="auto")
processor = AutoProcessor.from_pretrained("DeepGlint-AI/mlcd-vit-bigG-patch14-448")

# Process single image
url = "http://images.cocodataset.org/val2017/000000039769.jpg"
image = Image.open(requests.get(url, stream=True).raw)
inputs = processor(images=image, return_tensors="pt").to(model.device)

# Generate outputs
with torch.no_grad():
    outputs = model(**inputs)

# Get visual features
features = outputs.last_hidden_state

print(f"Extracted features shape: {features.shape}")

MLCDVisionConfig

クラス transformers.MLCDVisionConfig

< >

( transformers_version: str | None = Nonearchitectures: list[str] | None = Noneoutput_hidden_states: bool | None = Falsereturn_dict: bool | None = Truedtype: str | torch.dtype | None = Nonechunk_size_feed_forward: int = 0is_encoder_decoder: bool = Falseid2label: dict[int, str] | dict[str, str] | None = Nonelabel2id: dict[str, int] | dict[str, str] | None = Noneproblem_type: Literal['regression', 'single_label_classification', 'multi_label_classification'] | None = Nonehidden_size: int = 1664intermediate_size: int = 8192num_hidden_layers: int = 48num_attention_heads: int = 16num_key_value_groups: int = 1num_channels: int = 3image_size: int | list[int] | tuple[int, int] = 336patch_size: int | list[int] | tuple[int, int] = 14hidden_act: str = 'gelu'layer_norm_eps: float = 1e-05attention_dropout: float | int = 0.0initializer_range: float = 0.02initializer_factor: float = 1.0rope_parameters: dict | None = None )

パラメータ

  • hidden_size (int、任意、デフォルトは 1664) — 隠れ表現の次元数です。
  • intermediate_size (int、任意、デフォルトは8192) — MLP 表現の次元数。
  • num_hidden_layers (int、任意、デフォルトは 48) — Transformer デコーダーの隠れ層の数。
  • num_attention_heads (int、任意、デフォルトは 16) — Transformer デコーダーの各アテンション層におけるアテンションヘッドの数。
  • num_key_value_groups (int、任意、デフォルトは 1) — Attention で使用される key-value グループの数です。
  • num_channels (int、任意、デフォルトは3) — 入力チャネル数。
  • image_size (Union[int, list[int], tuple[int, int]]、任意、デフォルトは 336) — 各画像のサイズ(解像度)です。
  • patch_size (Union[int, list[int], tuple[int, int]]、任意、デフォルトは14) — 各パッチのサイズ(解像度)です。
  • hidden_act (str、任意、デフォルトは gelu) — デコーダーで使用する非線形活性化関数(関数または文字列)。例えば、"gelu"、 "relu"、"silu" など。
  • layer_norm_eps (float、任意、デフォルトは 1e-05) — レイヤーノーマル層で使用する epsilon です。
  • attention_dropout (Union[float, int]、任意、デフォルトは 0.0) — アテンション確率のドロップアウト率です。
  • initializer_range (float、任意、デフォルトは 0.02) — すべての重み行列を初期化するための truncated_normal_initializer の標準偏差です。
  • initializer_factor (float、任意、デフォルトは 1.0) — すべての重み行列を初期化する際に用いる係数です(1 に保つ必要があります。初期化のテスト用に内部で使用されます)。
  • rope_parameters (dict, 任意) — RoPE 埋め込みの設定パラメータを含む辞書です。辞書には rope_theta の値が含まれており、より長い max_position_embeddings で RoPE を使用する場合、スケーリングに使用されるパラメータが任意で含まれます。

This is the configuration class to store the configuration of a MLCDVisionModel. It is used to instantiate a Mlcd model according to the specified arguments, defining the model architecture. Instantiating a configuration with the defaults will yield a similar configuration to that of the DeepGlint-AI/mlcd-vit-bigG-patch14-336

設定オブジェクトはPreTrainedConfigを継承し、モデルの出力を制御するために使用できます。詳細については、PreTrainedConfigのドキュメントを参照してください。

例:

>>> from transformers import MLCDVisionConfig, MLCDVisionModel

>>> # Initializing a MLCDVisionConfig with DeepGlint-AI/mlcd-vit-bigG-patch14-336 style configuration
>>> configuration = MLCDVisionConfig()

>>> # Initializing a MLCDVisionModel (with random weights) from the DeepGlint-AI/mlcd-vit-bigG-patch14-336 style configuration
>>> model = MLCDVisionModel(configuration)

>>> # Accessing the model configuration
>>> configuration = model.config

MLCDVisionModel

クラス transformers.MLCDVisionModel

< >

( config: MLCDVisionConfig )

パラメータ

  • config (MLCDVisionConfig) — モデルのパラメータをすべて含むモデル設定クラスです。設定ファイルで初期化しても、モデルに関連する重みは読み込まれず、設定のみが読み込まれます。モデルの重みをロードするには、from_pretrained() メソッドを参照してください。

ヘッドや投影が上に乗せられていないM_L_C_Dのビジョンモデル。

このモデルは PreTrainedModel を継承しています。すべてのモデルに実装されている汎用的なメソッド(ダウンロードや保存、入力埋め込みのリサイズ、ヘッドのプルーニングなど)については、スーパークラスのドキュメントを参照してください。

このモデルは、PyTorchのtorch.nn.Moduleのサブクラスでもあります。 通常のPyTorch Moduleとして使用し、一般的な使用方法や動作に関する詳細については、PyTorchのドキュメントを参照してください。

forward

< >

( pixel_values: typing.Optional[torch.FloatTensor] = None**kwargs: *<class 'transformers.utils.generic.TransformersKwargs'> ) → BaseModelOutputWithPooling or tuple(torch.FloatTensor)

パラメータ

  • pixel_values (torch.FloatTensor、形状 (batch_size, num_channels, image_size, image_size)、任意) — 入力画像に対応するテンソルです。ピクセル値は CLIPImageProcessor を使用して取得できます。詳細は CLIPImageProcessor.call() を参照してください(processor_class は画像の処理に CLIPImageProcessor を使用します)。

戻り値

BaseModelOutputWithPooling または tuple(torch.FloatTensor)

torch.FloatTensor のタプル(return_dict=False が渡された場合、または config.return_dict=False の場合)、または BaseModelOutputWithPooling。設定(MLCDVisionConfig)や入力に応じて、さまざまな要素で構成されます。

MLCDVisionModelのforwardメソッドは、__call__特殊メソッドをオーバーライドします。

この関数内でフォワードパスの手順を定義する必要がありますが、その後、この関数ではなくModuleインスタンスを呼び出すべきです。前者は前処理と後処理の実行を適切に処理するのに対し、後者はそれらを黙って無視するためです。

  • last_hidden_state (torch.FloatTensor、shape (batch_size, sequence_length, hidden_size)) — モデルの最終層の出力における隠れ状態のシーケンス。

  • pooler_output (torch.FloatTensor、shape (batch_size, hidden_size)) — 補助事前学習タスクに使用される層をさらに通して処理された後、シーケンスの最初のトークン(分類トークン)の最終層の隠れ状態。例えば、BERT 系のモデルでは、線形層と tanh 活性化関数を経て処理された後の分類トークンを返します。この線形層の重みは、事前学習中の次文予測(分類)目的から学習されます。

  • hidden_states (tuple(torch.FloatTensor)、optional、output_hidden_states=True が渡された場合または config.output_hidden_states=True の場合に返されます)— torch.FloatTensor のタプル(埋め込み層を持つモデルの場合、埋め込みの出力が 1 つ、各層の出力がそれぞれ 1 つずつ)で、形状は (batch_size, sequence_length, hidden_size) です。

    各層の出力におけるモデルのHidden-states、および任意の初期埋め込み出力。

  • attentions (tuple(torch.FloatTensor)、optional、output_attentions=True が渡された場合または config.output_attentions=True の場合に返されます)— torch.FloatTensor のタプル(各レイヤーごとに1つ)、形状は (batch_size, num_heads, sequence_length, sequence_length)。

    アテンションのsoftmax後のアテンション重み。自己アテンションヘッド内で加重平均を計算するために使用されます。

例:

>>> from huggingface_hub.utils import httpx
>>> from io import BytesIO
>>> from PIL import Image
>>> from transformers import AutoProcessor, MLCDVisionModel
>>> model = MLCDVisionModel.from_pretrained("DeepGlint-AI/mlcd-vit-bigG-patch14-448")
>>> processor = AutoProcessor.from_pretrained("DeepGlint-AI/mlcd-vit-bigG-patch14-448")

>>> url = "http://images.cocodataset.org/val2017/000000039769.jpg"
>>> with httpx.stream("GET", url) as response:
...     image = Image.open(BytesIO(response.read()))
>>> inputs = processor(images=image, return_tensors="pt")

>>> with torch.no_grad():
...     outputs = model(**inputs, output_attentions=True)

>>> features = outputs.last_hidden_state
>>> print(f"Extracted features shape: {features.shape}")
>>> print(f"Number of attention layers: {len(outputs.attentions)}")
>>> print(f"Attention shape: {outputs.attentions[0].shape}")
Update on GitHub