> For the complete documentation index, see [llms.txt](https://docs.roboflow.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.roboflow.com/models/ja/supported-models/smolvlm2.md).

# SmolVLM2

SmolVLM2はHuggingFaceのコンパクトなビジョン・ランゲージモデルです。画像とテキストプロンプトを受け取り、テキスト応答を返します。

{% hint style="info" %}
SmolVLM2はServerless Cloud APIでは利用できません。aで実行してください [Dedicated Deployment](https://docs.roboflow.com/deployment/roboflow-cloud/dedicated-deployments) または [self-hosted Inference](https://docs.roboflow.com/deployment/self-hosted/self-hosted).
{% endhint %}

## SmolVLM2 API

{% stepper %}
{% step %}

### APIキーを取得する

Roboflow アカウントを作成し、 [Roboflow API 設定ページ](https://app.roboflow.com/settings/api) でキーを見つけ、シェルで利用できるようにします。

```bash
export ROBOFLOW_API_KEY="your-key-here"
```

{% endstep %}

{% step %}

### 依存関係をインストールする

以下をインストールします [Inference SDK](https://docs.roboflow.com/deployment/self-hosted/self-hosted):

```bash
pip install -U inference-sdk supervision
```

{% endstep %}

{% step %}

### モデルを実行する

設定する `api_url` 専用デプロイURLまたはローカル推論サーバーに対して。

```python
import os
import supervision as sv
from inference_sdk import InferenceHTTPClient, InferenceConfiguration

image = sv.load_image_from_url("https://media.roboflow.com/quickstart/dog.jpeg")

client = InferenceHTTPClient(
    api_url="https://your-deployment.roboflow.cloud",
    api_key=os.environ["ROBOFLOW_API_KEY"],
).configure(InferenceConfiguration(api_key_transport="header"))
result = client.infer_lmm(
    image,
    model_id="smolvlm2",
    prompt="この画像を簡単に説明してください。",
    max_new_tokens=64,
)
print(result["response"] )
```

{% endstep %}
{% endstepper %}

上記のコードは、モデルの応答をターミナルに出力します：

```
男性が犬を肩に乗せています。
```

<figure><img src="/files/240f842a980c044a24142bc421a7c2cb7108f650" alt=""><figcaption></figcaption></figure>

## SmolVLM2の推論速度

次で測定したレイテンシー [Roboflow Inference](https://docs.roboflow.com/deployment/self-hosted/self-hosted) 1 台の NVIDIA L4、バッチサイズ 1、固定プロンプトから greedy decoding でちょうど 128 トークンを生成した条件で測定。レイテンシは出力長に比例するため、他の長さの見積もりには tokens/sec を使用してください。

<table data-search="false"><thead><tr><th>別名</th><th>レイテンシ、128トークン（ms）</th><th>トークン/秒</th></tr></thead><tbody><tr><td><code>smolvlm2</code></td><td>3113</td><td>41</td></tr></tbody></table>

{% hint style="info" %}
設定する `api_url` をデプロイ先に合わせます:

* `http://localhost:9001` ローカルの [Inference](https://docs.roboflow.com/deployment/self-hosted/self-hosted) サーバー用。
* あなたの [Dedicated Deployment](https://docs.roboflow.com/deployment/roboflow-cloud/dedicated-deployments) プライベートエンドポイント用のURL。
  {% endhint %}

## セルフホストの推論でSmolVLM2を実行する

SmolVLM2は、次の [`inference`](https://docs.roboflow.com/deployment/self-hosted/self-hosted) VQA、文書OCR、文書VQA、オブジェクトカウント用のパッケージです。

{% stepper %}
{% step %}

### パッケージをインストールする

```bash
pip install "inference[transformers]"
```

使用する `inference-gpu[transformers]` GPUマシンでは。
{% endstep %}

{% step %}

### モデルを実行する

```python
from PIL import Image

from inference.models.smolvlm.smolvlm import SmolVLM

model = SmolVLM(api_key="YOUR_API_KEY")

image = Image.open("dog.jpeg")
result = model.predict(image, "How many dogs are in this image?")

print(result)
```

{% endstep %}
{% endstepper %}

### Workflowsの実行モード

次の環境で使用する場合： [Workflow](https://docs.roboflow.com/workflows)、SmolVLM2は2つのモードのいずれかで動作します:

* **ローカル実行**：モデルはInferenceサーバー上で実行されます（GPU推奨）。
* **リモート実行**：モデルは、次を介してリモートInferenceサーバー上でHTTP経由で呼び出されます： `infer_lmm()` クライアントメソッド。
