|
--- |
|
tags: |
|
- reasoning |
|
- reasoning-vector |
|
- weight-diff |
|
- llama |
|
- deepseek |
|
license: llama3.1 |
|
language: |
|
- en |
|
- ja |
|
--- |
|
|
|
# Reasoning Vector |
|
|
|
## 概要 |
|
**Reasoning Vector** は、ベースモデルとReasoningモデル間の重みの差分を抽出する手法により生成されたモデルです。 |
|
本モデルは、ChatVectorと同様の生成方法を採用しており、追加学習したベースモデルに対して推論能力(Reasoning)を追加するために使用されます。 |
|
単体では使用できません。 |
|
|
|
### モデル |
|
- **Base Model**: [meta-llama/Llama-3.1-8B](https://huggingface.co/meta-llama/Llama-3.1-8B) |
|
- **Reasoning Model**: [deepseek-ai/DeepSeek-R1-Distill-Llama-8B](https://huggingface.co/deepseek-ai/DeepSeek-R1-Distill-Llama-8B) |
|
|
|
## 使用方法 |
|
以下は、ベースモデルにReasoning Vectorを適用して推論モデルを生成する際の例です。 |
|
|
|
```python |
|
from transformers import AutoModelForCausalLM, AutoTokenizer |
|
|
|
# ベースモデルのロード |
|
base_model = AutoModelForCausalLM.from_pretrained("your-base-model") |
|
tokenizer = AutoTokenizer.from_pretrained("your-base-model") |
|
|
|
# Reasoning Vectorのロード(差分パラメータ) |
|
reasoning_vector = AutoModelForCausalLM.from_pretrained("HachiML/ReasoningVector-DeepSeek-R1-Distill-Llama-8B") |
|
|
|
# ベースモデルに差分を適用(実装に応じた適用方法を記載) |
|
# 除外対象 |
|
skip_layers = ["model.embed_tokens.weight", "model.norm.weight", "lm_head.weight"] |
|
for k, v in base_model.state_dict().items(): |
|
# layernormも除外 |
|
if (k in skip_layers) or ("layernorm" in k): |
|
continue |
|
new_v += reasoning_vector.state_dict()[k].to(v.device) |
|
v.copy_(new_v) |
|
|
|
# 推論の実行例 |
|
inputs = tokenizer("推論したいテキストを入力", return_tensors="pt") |
|
outputs = base_model.generate(**inputs) |
|
print(tokenizer.decode(outputs[0], skip_special_tokens=True)) |
|
``` |