File size: 2,928 Bytes
0751253
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
# トラブルシューティングガイド

## よくある問題と解決策

### 1. インストール関連

#### 問題: ONNX Runtime のインストールエラー
```bash
ERROR: Could not find a version that satisfies the requirement onnxruntime
```

**解決策:**
```bash
pip install --upgrade pip
pip install onnxruntime==1.16.3  # 特定バージョンを指定
```

### 2. 量子化関連

#### 問題: "indices element out of data bounds"
```
IndexError: indices element out of data bounds, idx=44914 must be within the inclusive range [-32001,32000]
```

**解決策:**
- キャリブレーションサンプル数を削減: `max_samples=20`
- テキストの長さを制限: `text[:100]`
- 語彙サイズの確認とトークナイザーの再設定

#### 問題: "Got invalid dimensions for input"
```
Invalid Input: Got invalid dimensions for input: input_ids Expected: 1
```

**解決策:**
- 元の非量子化ONNXモデルを使用
- decoder_with_pastモデルの場合は1トークンのみを入力
- モデル入力仕様の確認

### 3. メモリ関連

#### 問題: メモリ不足エラー
```
RuntimeError: CUDA out of memory
```

**解決策:**
```python
# バッチサイズを削減
batch_size = 1
# サンプル数を削減
max_samples = 10
# CPUを使用
providers = ['CPUExecutionProvider']
```

### 4. Hugging Face関連

#### 問題: データセット読み込みエラー
```
ConnectionError: Couldn't reach 'https://huggingface.co'
```

**解決策:**
```python
# オフラインモードを使用
from datasets import load_dataset
dataset = load_dataset("TFMC/imatrix-dataset-for-japanese-llm", 
                      split="train", download_mode="reuse_cache")
```

## デバッグのヒント

### 1. ログレベルの設定
```python
import logging
logging.basicConfig(level=logging.DEBUG)
```

### 2. モデル情報の確認
```python
import onnx
model = onnx.load("your_model.onnx")
print("Inputs:", [inp.name for inp in model.graph.input])
print("Outputs:", [out.name for out in model.graph.output])
```

### 3. トークナイザーの確認
```python
from transformers import MarianTokenizer
tokenizer = MarianTokenizer.from_pretrained("Helsinki-NLP/opus-mt-ja-en")
print("Vocab size:", len(tokenizer))
```

## パフォーマンス最適化

### 1. CPU最適化
```python
session_options = ort.SessionOptions()
session_options.intra_op_num_threads = 4
session_options.inter_op_num_threads = 1
session_options.execution_mode = ort.ExecutionMode.ORT_SEQUENTIAL
```

### 2. GPU使用(CUDAが利用可能な場合)
```python
providers = ['CUDAExecutionProvider', 'CPUExecutionProvider']
session = ort.InferenceSession(model_path, providers=providers)
```

## サポートリソース

- [ONNX Runtime Documentation](https://onnxruntime.ai/docs/)
- [Transformers Documentation](https://huggingface.co/docs/transformers/)
- [GitHub Issues](https://github.com/your-repo/issues)