# vLLM デプロイと推論ガイド

### :computer:vLLM のインストール

NVIDIA GPU の場合、uv を使用して次を実行してください：

```bash
pip install --upgrade pip
pip install uv
uv pip install -U vllm --torch-backend=auto
```

AMD GPU の場合は、ナイトリービルドの Docker イメージを使用してください： `rocm/vllm-dev:nightly`

NVIDIA GPU 用のナイトリーブランチは、次を実行します：

{% code overflow="wrap" %}

```bash
pip install --upgrade pip
pip install uv
uv pip install -U vllm --torch-backend=auto --extra-index-url https://wheels.vllm.ai/nightly
```

{% endcode %}

詳細については [vLLM ドキュメント](https://docs.vllm.ai/en/stable/getting_started/installation) 詳細については

### :truck:vLLM モデルのデプロイ

ファインチューンを保存した後、単に次のようにできます：

```bash
vllm serve unsloth/gpt-oss-120b
```

### :fire\_engine:vLLM デプロイメントサーバーのフラグ、エンジン引数とオプション

使用する重要なサーバーフラグは次にあります [#vllm-deployment-server-flags-engine-arguments-and-options](#vllm-deployment-server-flags-engine-arguments-and-options "mention")

### 🦥vLLM での Unsloth ファインチューンのデプロイ

ファインチューニング後 [fine-tuning-llms-guide](https://unsloth.ai/docs/jp/meru/fine-tuning-llms-guide "mention") または当社のノートブックを使用して [unsloth-notebooks](https://unsloth.ai/docs/jp/meru/unsloth-notebooks "mention")、単一のワークフロー内で vLLM を通じてモデルを直接保存またはデプロイできます。例えばの Unsloth ファインチューニングスクリプトの例：

```python
from unsloth import FastLanguageModel
import torch
model, tokenizer = FastLanguageModel.from_pretrained(
    model_name = "unsloth/gpt-oss-20b",
    max_seq_length = 2048,
    load_in_4bit = True,
)
model = FastLanguageModel.get_peft_model(model)
```

**vLLM 用に 16 ビットで保存するには、次を使用します：**

{% code overflow="wrap" %}

```python
model.save_pretrained_merged("finetuned_model", tokenizer, save_method = "merged_16bit")
## または HuggingFace にアップロードするには：
model.push_to_hub_merged("hf/model", tokenizer, save_method = "merged_16bit", token = "")
```

{% endcode %}

**LoRA アダプタだけを保存するには**、いずれかを使用します：

```python
model.save_pretrained("finetuned_lora")
tokenizer.save_pretrained("finetuned_lora")
```

または当社の組み込み関数を使ってこれを行うだけでも良いです：

{% code overflow="wrap" %}

```python
model.save_pretrained_merged("finetuned_model", tokenizer, save_method = "lora")
## または HuggingFace にアップロードするには
model.push_to_hub_merged("hf/model", tokenizer, save_method = "lora", token = "")
```

{% endcode %}

HuggingFace でロードするために 4bit にマージするには、まず呼び出します `merged_4bit`。その後使用します `merged_4bit_forced` もし 4bit にマージすることを確信しているなら。4bit モデルをどう扱うか（例：DPO トレーニングや HuggingFace のオンライン推論エンジン等）を理解している場合を除き、私は強くお勧めしません。

{% code overflow="wrap" %}

```python
model.save_pretrained_merged("finetuned_model", tokenizer, save_method = "merged_4bit")
## HuggingFace にアップロードするには：
model.push_to_hub_merged("hf/model", tokenizer, save_method = "merged_4bit", token = "")
```

{% endcode %}

その後、別のターミナルで vLLM にファインチューンドモデルをロードするには：

```bash
vllm serve finetuned_model
```

上記が動作しない場合はフルパスを指定する必要があるかもしれません、例：

```bash
vllm serve /mnt/disks/daniel/finetuned_model
```

その他のコンテンツを参照：

### [vllm-engine-arguments](https://unsloth.ai/docs/jp/ji-ben/inference-and-deployment/vllm-guide/vllm-engine-arguments "mention")

### [lora-hot-swapping-guide](https://unsloth.ai/docs/jp/ji-ben/inference-and-deployment/vllm-guide/lora-hot-swapping-guide "mention")


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://unsloth.ai/docs/jp/ji-ben/inference-and-deployment/vllm-guide.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
