File size: 6,259 Bytes
24086a8
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
a5326f8
 
 
 
24086a8
a5326f8
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
---
language: ja
tags:
- japanese
- vision-language
- multimodal
license: apache-2.0
datasets:
- custom
model-index:
- name: LLaVA-JP-1.3B
  results: []
---

# Hibernates-JP-1.3b-Max

This is a Japanese vision-language model based on LLaVA architecture with 1.3B parameters.

## Model Details

- Model Type: Vision-Language Model
- Base Model: HibernatesGpt2 (1.3B parameters)
- Vision Encoder: ConvNeXt Large
- Training Data: Custom Japanese vision-language dataset
- Context Length: 1024 tokens
- Vision Resolution: 1280x1280
- License: Apache 2.0

## Usage

[Add usage instructions here]

## Training Details

- Vision Encoder: ConvNeXt Large
- Hidden Size: 2048
- Number of Attention Heads: 16
- Number of Layers: 24
- Vision Feature Selection: patch
- Vision Select Layer: -2
- Multimodal Projector Type: mlp2x_gelu

## Limitations

[Add model limitations here]

## Citation

[Add citation information if applicable]

# Hibernates-JP-1.3b-Max Model Card


Hibernates-JP-1.3b-Max は高解像度(1280x1280)に対応した日本語マルチモーダル言語モデルです。画像理解と自然な対話を組み合わせ、視覚的なコンテキストについて日本語で会話することができます。

## Updates in Latest Version

- 高解像度(1280x1280)での画像処理に対応
- 日本語での視覚言語理解を強化
- メモリ効率の改善とbfloat16による最適化
- 3段階の学習による精度向上
- 対話型の画像理解が可能

## 🌟 Key Features

- **高解像度対応**: 1280x1280の高解像度画像処理をサポート
- **日本語最適化**: 日本語での自然な対話と画像理解
- **効率的な処理**: bfloat16とGradient Checkpointingによる最適化
- **3段階学習**: 段階的な学習による高精度な視覚-言語理解
- **軽量モデル**: 約1.7Bパラメータでの効率的な処理

## Model Architecture

The model consists of:
- Vision Encoder: ConvNeXt Large (LAION-2B学習済み)
- Cross-Modal Projector: 2層MLPによる特徴量変換
- Language Model: LLM-JP 1.3B (日本語特化モデル)
- 総パラメータ数: 約1.7B



### 主な用途

- 🖼️ 画像説明生成
- 💬 画像に関する質問応答
- 🔍 視覚的詳細の分析
- 🗣️ マルチターン対話
- 📝 画像内容の要約

## 💻 Quick Start


### 基本的な使い方

```python
import requests
import torch
import transformers
from PIL import Image

from transformers.generation.streamers import TextStreamer
from llava.constants import DEFAULT_IMAGE_TOKEN, IMAGE_TOKEN_INDEX
from llava.conversation import conv_templates, SeparatorStyle
from llava.model.llava_gpt2 import LlavaGpt2ForCausalLM
from llava.train.dataset import tokenizer_image_token


if __name__ == "__main__":
    model_path = 'Hibernates/Hibernates-JP-1.3b-Max'
    device = "cuda" if torch.cuda.is_available() else "cpu"
    torch_dtype = torch.bfloat16 if device=="cuda" else torch.float32

    model = LlavaGpt2ForCausalLM.from_pretrained(
        model_path, 
        low_cpu_mem_usage=True,
        use_safetensors=True,
        torch_dtype=torch_dtype,
        device_map=device,
    )
    tokenizer = transformers.AutoTokenizer.from_pretrained(
        model_path,
        model_max_length=1532,
        padding_side="right",
        use_fast=False,
    )
    model.eval()

    conv_mode = "v1"
    conv = conv_templates[conv_mode].copy()

    # image pre-process
    image_url = "https://huggingface.co/rinna/bilingual-gpt-neox-4b-minigpt4/resolve/main/sample.jpg"
    image = Image.open(requests.get(image_url, stream=True).raw).convert('RGB')
    
    if device == "cuda":
        image_tensor = model.get_model().vision_tower.image_processor(image).unsqueeze(0).half().cuda().to(torch_dtype)
    else:
        image_tensor = model.get_model().vision_tower.image_processor(image).unsqueeze(0).to(torch_dtype)

    # create prompt
    # ユーザー: <image>\n{prompt}
    prompt = "猫の隣には何がありますか?"
    inp = DEFAULT_IMAGE_TOKEN + '\n' + prompt
    conv.append_message(conv.roles[0], inp)
    conv.append_message(conv.roles[1], None)
    prompt = conv.get_prompt()

    input_ids = tokenizer_image_token(
        prompt, 
        tokenizer, 
        IMAGE_TOKEN_INDEX, 
        return_tensors='pt'
    ).unsqueeze(0)
    if device == "cuda":
        input_ids = input_ids.to(device)

    input_ids = input_ids[:, :-1] # </sep>がinputの最後に入るので削除する
    stop_str = conv.sep if conv.sep_style != SeparatorStyle.TWO else conv.sep2
    keywords = [stop_str]
    streamer = TextStreamer(tokenizer, skip_prompt=True, timeout=20.0)

    # predict
    with torch.inference_mode():
        output_id = model.generate(
            inputs=input_ids,
            images=image_tensor,
            do_sample=False,
            temperature=1.0,
            top_p=1.0,
            max_new_tokens=256,
            streamer=streamer,
            use_cache=True,
        )
    """猫の隣にはノートパソコンがあります。"""

### 🔧 Advanced Usage

<details>
<summary>パラメータのカスタマイズ</summary>

```python
# 生成パラメータの調整
model.generate(
    temperature=0.8,  # 創造性の制御
    top_p=0.95,      # サンプリングの多様性
    max_new_tokens=1024  # 生成テキストの長さ
)
```
</details>

## Training dataset

### データセット構成

**Stage1 and Stage2 Pretrain**
- [LLaVA-Pretrain-JA](https://huggingface.co/datasets/turing-motors/LLaVA-Pretrain-JA)

**Stage3 Fine-tuning**
- [LLaVA-v1.5-Instruct-620K-JA](https://huggingface.co/datasets/turing-motors/LLaVA-v1.5-Instruct-620K-JA)

## 📊 System Requirements

- **GPU**: NVIDIA GPU with 12GB+ VRAM
- **RAM**: 16GB+
- **Storage**: 10GB for model weights
- **Python**: 3.8+

## Acknowledgement

本モデルは以下のプロジェクトの成果を活用しています:

- [ConvLLaVA](https://arxiv.org/abs/2405.15738)
- [LLM-jp](https://llm-jp.nii.ac.jp/)
- [Open CLIP](https://github.com/mlfoundations/open_clip)

## License

このプロジェクトは [Creative Commons Attribution-NonCommercial 4.0 International License](https://creativecommons.org/licenses/by-nc/4.0/) の下でライセンスされています。