File size: 1,899 Bytes
ed21311
b236878
 
 
 
 
 
 
 
 
 
ed21311
 
b236878
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
---
tags:
- reasoning
- reasoning-vector
- weight-diff
- qwen2
- deepseek
license: apache-2.0
language:
- en
- ja
---

# Reasoning Vector

## 概要
**Reasoning Vector** は、ベースモデルとReasoningモデル間の重みの差分を抽出する手法により生成されたモデルです。
本モデルは、ChatVectorと同様の生成方法を採用しており、追加学習したベースモデルに対して推論能力(Reasoning)を追加するために使用されます。
単体では使用できません。

### モデル
- **Base Model**: [Qwen/Qwen2.5-32B](https://huggingface.co/Qwen/Qwen2.5-32B)
- **Reasoning Model**: [deepseek-ai/DeepSeek-R1-Distill-Qwen-32B](https://huggingface.co/deepseek-ai/DeepSeek-R1-Distill-Qwen-32B)

## 使用方法
以下は、ベースモデルに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-Qwen-32B")

# ベースモデルに差分を適用(実装に応じた適用方法を記載)
# 除外対象
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))
```