gyung commited on
Commit
72ef8e1
·
verified ·
1 Parent(s): cc5c06b

Update model card with corrected TB2-lite evaluation

Browse files
Files changed (1) hide show
  1. README.md +194 -24
README.md CHANGED
@@ -1,42 +1,212 @@
1
  ---
2
- license: apache-2.0
 
 
3
  library_name: transformers
4
- base_model: google/gemma-4-E4B
5
  tags:
6
- - gemma-4
7
- - terminal-agent
8
- - full-finetuning
9
  - tb2-lite
10
- - gemma4-native-template
11
  ---
12
 
13
  # LLM-OS-Models/gemma-4-E4B-Terminal-SFT-Native-Liquid-2Epoch
14
 
15
- ## Summary
 
 
16
 
17
  - Base model: `google/gemma-4-E4B`
18
- - Source dataset/cache: `/home/work/.data/gemma4_native_sft/datasets/google__gemma-4-E4B__liquid_raw_json_masked_8192`
19
- - Training format: Gemma 4 native chat template
20
- - Labels: assistant JSON command response only
21
- - Prompt/history labels are masked with `-100`
22
- - Previous assistant thinking blocks are stripped from history
23
 
24
- ## TB2-lite
25
 
26
- - Result: `pending`
 
 
 
 
 
27
 
28
- ## Notes
29
 
30
- - Source checkpoint: `/home/work/.data/gemma4_native_sft/models/google__gemma-4-E4B__terminal_sft_native_liquid_2epoch/checkpoint-2042`
31
- - Checkpoint step: `2042`
32
- - Trainer epoch: `2.0000`
33
- - TB2-lite score: pending GPU evaluation
34
- - Upload policy: checkpoint uploaded immediately after save; score card updates after evaluation.
35
 
36
- ## Loading
37
 
38
  ```python
39
- from transformers import AutoModelForCausalLM, AutoTokenizer
40
- tokenizer = AutoTokenizer.from_pretrained("LLM-OS-Models/gemma-4-E4B-Terminal-SFT-Native-Liquid-2Epoch")
41
- model = AutoModelForCausalLM.from_pretrained("LLM-OS-Models/gemma-4-E4B-Terminal-SFT-Native-Liquid-2Epoch", torch_dtype="auto")
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
42
  ```
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
  ---
2
+ language:
3
+ - en
4
+ - ko
5
  library_name: transformers
6
+ pipeline_tag: text-generation
7
  tags:
8
+ - terminal
9
+ - sft
10
+ - vllm
11
  - tb2-lite
12
+ base_model: google/gemma-4-E4B
13
  ---
14
 
15
  # LLM-OS-Models/gemma-4-E4B-Terminal-SFT-Native-Liquid-2Epoch
16
 
17
+ 터미널 작업 자동화를 위한 Terminal SFT 모델입니다. 입력된 작업/이전 터미널 상태를 보고 다음에 실행할 명령을 JSON 형태로 생성하는 용도로 학습했습니다.
18
+
19
+ ## 모델 요약
20
 
21
  - Base model: `google/gemma-4-E4B`
22
+ - Training setup: `2 epochs, Gemma native Liquid preprocessing`
23
+ - Evaluation snapshot: `2026-05-09 19:40:34 UTC`
24
+ - Evaluation result id: `gemma4_e4b_base_native_e2`
 
 
25
 
26
+ ## Quickstart
27
 
28
+ 설치와 로그인:
29
+
30
+ ```bash
31
+ pip install -U vllm transformers huggingface_hub
32
+ huggingface-cli login
33
+ ```
34
 
35
+ 관련 코드:
36
 
37
+ - GitHub: https://github.com/LLM-OS-Models/Terminal
38
+ - vLLM 평가 실행: `tb2_lite/scripts/replay_eval.py`
39
+ - chat template/fallback 생성: `tb2_lite/scripts/prompt_builder.py`
40
+ - JSON/command 채점: `tb2_lite/scripts/replay_metrics.py`
 
41
 
42
+ vLLM 직접 실행 예시. 평가 코드와 동일하게 chat template을 우선 사용하고, template이 없으면 ChatML/Gemma fallback을 사용합니다.
43
 
44
  ```python
45
+ from transformers import AutoTokenizer
46
+ from vllm import LLM, SamplingParams
47
+
48
+ model_id = "LLM-OS-Models/gemma-4-E4B-Terminal-SFT-Native-Liquid-2Epoch"
49
+ tp = 1
50
+
51
+ tokenizer = AutoTokenizer.from_pretrained(model_id, trust_remote_code=True)
52
+ llm = LLM(
53
+ model=model_id,
54
+ tokenizer=model_id,
55
+ trust_remote_code=True,
56
+ dtype="bfloat16",
57
+ tensor_parallel_size=tp,
58
+ max_model_len=49152,
59
+ gpu_memory_utilization=0.92,
60
+ )
61
+
62
+ messages = [
63
+ {"role": "system", "content": "You are a terminal automation assistant. Return JSON only."},
64
+ {"role": "user", "content": "Inspect the current directory and list Python files."},
65
+ ]
66
+
67
+ def render_chatml(messages):
68
+ parts = []
69
+ for message in messages:
70
+ role = "assistant" if message["role"] == "assistant" else message["role"]
71
+ if role == "tool":
72
+ role = "user"
73
+ parts.append(f"<|im_start|>{role}\n{message['content']}<|im_end|>\n")
74
+ parts.append("<|im_start|>assistant\n")
75
+ return "".join(parts)
76
+
77
+ def render_gemma4_turn(messages, empty_thought_channel=False):
78
+ parts = ["<bos>"]
79
+ for message in messages:
80
+ role = "model" if message["role"] == "assistant" else message["role"]
81
+ if role == "tool":
82
+ role = "user"
83
+ parts.append(f"<|turn>{role}\n{message['content'].strip()}<turn|>\n")
84
+ parts.append("<|turn>model\n")
85
+ if empty_thought_channel:
86
+ parts.append("<|channel>thought\n<channel|>")
87
+ return "".join(parts)
88
+
89
+ def render_prompt(model_id, tokenizer, messages):
90
+ model_key = model_id.lower()
91
+ if "gemma-4" in model_key:
92
+ try:
93
+ return tokenizer.apply_chat_template(
94
+ messages,
95
+ tokenize=False,
96
+ add_generation_prompt=True,
97
+ enable_thinking=False,
98
+ )
99
+ except Exception:
100
+ return render_gemma4_turn(
101
+ messages,
102
+ empty_thought_channel=("26b" in model_key or "31b" in model_key),
103
+ )
104
+ try:
105
+ return tokenizer.apply_chat_template(messages, tokenize=False, add_generation_prompt=True)
106
+ except Exception:
107
+ return render_chatml(messages)
108
+
109
+ prompt = render_prompt(model_id, tokenizer, messages)
110
+ sampling = SamplingParams(
111
+ temperature=0.0,
112
+ top_p=1.0,
113
+ max_tokens=1024,
114
+ repetition_penalty=1.0,
115
+ )
116
+ outputs = llm.generate([prompt], sampling_params=sampling)
117
+ print(outputs[0].outputs[0].text)
118
+ ```
119
+
120
+ 권장 출력 형식:
121
+
122
+ ```json
123
+ {
124
+ "analysis": "brief reasoning about the next terminal action",
125
+ "plan": "short execution plan",
126
+ "commands": [
127
+ {"keystrokes": "ls -la\n", "duration": 0.1}
128
+ ],
129
+ "task_complete": false
130
+ }
131
+ ```
132
+
133
+ 평가와 동일한 replay 명령:
134
+
135
+ ```bash
136
+ python tb2_lite/scripts/replay_eval.py \
137
+ --model LLM-OS-Models/gemma-4-E4B-Terminal-SFT-Native-Liquid-2Epoch \
138
+ --model-short gemma4_e4b_base_native_e2 \
139
+ --eval-path tb2_lite/data/replay_full.jsonl \
140
+ --output-dir /home/work/.data/tb2_lite_eval/corrected_readme_models_vllm \
141
+ --dtype bfloat16 \
142
+ --tp 1 \
143
+ --max-model-len 49152 \
144
+ --max-tokens 1024 \
145
+ --temperature 0.0 \
146
+ --top-p 1.0 \
147
+ --gpu-memory-utilization 0.92 \
148
+ --thinking-mode off \
149
+ --strip-thinking-history auto \
150
+ --gemma4-empty-thought-channel auto \
151
+ --language-model-only
152
  ```
153
+
154
+ - 기본 권장 tensor parallel: `1`. OOM이면 `--tp`와 `tensor_parallel_size`를 2/4/8로 올리세요.
155
+ - corrected TB2-lite 평가는 `temperature=0.0`, `top_p=1.0`, `max_tokens=1024`로 고정했습니다.
156
+ - Gemma 4는 JSON 출력을 위해 `enable_thinking=False`를 사용하고, 26B/31B 계열은 평가 코드에서 empty thought channel 처리를 자동 적용합니다.
157
+
158
+ ## 평가 결과
159
+
160
+ 평가는 corrected TB2-lite replay set에서 vLLM으로 수행했습니다. 순위 점수는 `100 * avg_command_f1`만 사용하고, `first_cmd_exact_pct`는 보조 지표로만 봅니다.
161
+
162
+ - Rank: `5 / 8`
163
+ - Score: `18.47`
164
+ - Command F1: `0.1847`
165
+ - Command precision: `0.2514`
166
+ - Command recall: `0.1980`
167
+ - First command exact: `16.8%`
168
+ - Valid JSON: `17.2%`
169
+ - Steps / tasks: `303 / 50`
170
+ - Sec/step: `0.302`
171
+ - Load time: `52.6s`
172
+ - Template status: `model_specific_or_mixed`
173
+ - Rank eligible: `True`
174
+ - Eval timestamp: `2026-05-09T19:40:31.454642`
175
+ - 현재 집계된 평가 결과 수: `8`
176
+
177
+ Prompt/template audit:
178
+
179
+ ```json
180
+ {
181
+ "template_status": "model_specific_or_mixed",
182
+ "rank_eligible": true,
183
+ "steps": 303,
184
+ "tasks": 50
185
+ }
186
+ ```
187
+
188
+ ## 장점
189
+
190
+ - 특정 크기/가속 경로에서 비용 대비 빠른 추론을 기대할 수 있습니다.
191
+ - 잘못된 명령을 많이 내기보다 보수적으로 맞는 명령을 내는 경향이 있습니다.
192
+
193
+ ## 모델군 해석
194
+
195
+ - 이 repo는 Gemma 4 전용 chat template, thinking history 제거, assistant JSON-only target, base 모델 template 주입 정책으로 다시 학습한 native Liquid 결과입니다.
196
+ - 기존 Gemma SFT의 낮은 점수는 template/target 포맷 충돌과 일부 checkpoint/export 문제를 포함했으므로, 이 native 결과를 새 기준으로 봐야 합니다.
197
+ - 속도는 `0.302` sec/step 수준으로 빠른 편입니다.
198
+ - RL 후보성: 현재 점수만으로는 주력 후보보다 보조/비교군에 가깝습니다.
199
+
200
+ ## 한계와 주의사항
201
+
202
+ - recall이 상대적으로 낮아 필요한 명령 일부를 빠뜨릴 수 있습니다.
203
+ - JSON 형식 실패가 있어 실행 전에 파싱 검증/재시도가 필요합니다.
204
+ - Gemma 계열은 학습/평가 chat template 불일치에 민감하므로 vLLM chat_template 경로로만 비교해야 합니다.
205
+ - 이 모델은 자동 터미널 조작 보조용 SFT 모델이며, 일반 대화/범용 추론 성능을 보장하지 않습니다.
206
+ - 생성 명령은 실제 실행 전에 sandbox, allowlist, human review 같은 안전장치를 거쳐야 합니다.
207
+
208
+ ## 해석 메모
209
+
210
+ TB2-lite 점수는 일반 지능 벤치마크가 아니라 터미널 next-action JSON 재현 능력을 측정합니다. 따라서 모델 크기, chat template 일치, assistant-only masking, tokenizer, 학습 데이터 holdout 여부가 모두 점수에 영향을 줍니다.
211
+
212
+ README.md와 MODEL_EVALUATION_REPORT.md의 값이 더 최신이면 해당 값을 우선 확인하세요. 이 모델카드는 완료된 평가 JSON을 기준으로 개별 저장소에 빠르게 반영한 스냅샷입니다.