hellohazime commited on
Commit
b098ea1
·
verified ·
1 Parent(s): 26c5006

Add/update README (model card)

Browse files
Files changed (1) hide show
  1. README.md +134 -143
README.md CHANGED
@@ -3,207 +3,198 @@ base_model: Qwen/Qwen3-1.7B
3
  library_name: peft
4
  pipeline_tag: text-generation
5
  tags:
6
- - base_model:adapter:Qwen/Qwen3-1.7B
7
  - lora
8
  - sft
9
  - transformers
10
  - trl
 
 
 
 
11
  ---
12
 
13
- # Model Card for Model ID
14
-
15
- <!-- Provide a quick summary of what the model is/does. -->
16
 
 
 
 
 
17
 
 
18
 
19
  ## Model Details
20
 
21
- ### Model Description
22
-
23
- <!-- Provide a longer summary of what this model is. -->
24
-
 
 
 
 
 
25
 
 
 
 
26
 
27
- - **Developed by:** [More Information Needed]
28
- - **Funded by [optional]:** [More Information Needed]
29
- - **Shared by [optional]:** [More Information Needed]
30
- - **Model type:** [More Information Needed]
31
- - **Language(s) (NLP):** [More Information Needed]
32
- - **License:** [More Information Needed]
33
- - **Finetuned from model [optional]:** [More Information Needed]
34
-
35
- ### Model Sources [optional]
36
-
37
- <!-- Provide the basic links for the model. -->
38
-
39
- - **Repository:** [More Information Needed]
40
- - **Paper [optional]:** [More Information Needed]
41
- - **Demo [optional]:** [More Information Needed]
42
 
43
  ## Uses
44
 
45
- <!-- Address questions around how the model is intended to be used, including the foreseeable users of the model and those affected by the model. -->
46
-
47
  ### Direct Use
 
 
48
 
49
- <!-- This section is for the model use without fine-tuning or plugging into a larger ecosystem/app. -->
50
-
51
- [More Information Needed]
52
-
53
- ### Downstream Use [optional]
54
-
55
- <!-- This section is for the model use when fine-tuned for a task, or when plugged into a larger ecosystem/app -->
56
-
57
- [More Information Needed]
58
-
59
- ### Out-of-Scope Use
60
-
61
- <!-- This section addresses misuse, malicious use, and uses that the model will not work well for. -->
62
 
63
- [More Information Needed]
 
64
 
65
- ## Bias, Risks, and Limitations
66
-
67
- <!-- This section is meant to convey both technical and sociotechnical limitations. -->
68
-
69
- [More Information Needed]
70
-
71
- ### Recommendations
72
-
73
- <!-- This section is meant to convey recommendations with respect to the bias, risk, and technical limitations. -->
74
-
75
- Users (both direct and downstream) should be made aware of the risks, biases and limitations of the model. More information needed for further recommendations.
76
-
77
- ## How to Get Started with the Model
78
 
79
- Use the code below to get started with the model.
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
80
 
81
- [More Information Needed]
82
 
83
  ## Training Details
84
 
85
  ### Training Data
86
 
87
- <!-- This should link to a Dataset Card, perhaps with a short stub of information on what the training data is all about as well as documentation related to data pre-processing or additional filtering. -->
88
-
89
- [More Information Needed]
90
-
91
- ### Training Procedure
92
 
93
- <!-- This relates heavily to the Technical Specifications. Content here should link to that section when it is relevant to the training procedure. -->
 
 
94
 
95
- #### Preprocessing [optional]
96
 
97
- [More Information Needed]
 
 
98
 
 
99
 
100
- #### Training Hyperparameters
 
 
 
 
 
 
 
 
101
 
102
- - **Training regime:** [More Information Needed] <!--fp32, fp16 mixed precision, bf16 mixed precision, bf16 non-mixed precision, fp16 non-mixed precision, fp8 mixed precision -->
103
 
104
- #### Speeds, Sizes, Times [optional]
105
-
106
- <!-- This section provides information about throughput, start/end time, checkpoint size if relevant, etc. -->
107
-
108
- [More Information Needed]
109
 
110
  ## Evaluation
111
 
112
- <!-- This section describes the evaluation protocols and provides the results. -->
113
 
114
- ### Testing Data, Factors & Metrics
 
 
115
 
116
- #### Testing Data
117
 
118
- <!-- This should link to a Dataset Card if possible. -->
 
 
 
 
119
 
120
- [More Information Needed]
 
121
 
122
- #### Factors
123
-
124
- <!-- These are the things the evaluation is disaggregating by, e.g., subpopulations or domains. -->
125
-
126
- [More Information Needed]
127
-
128
- #### Metrics
129
-
130
- <!-- These are the evaluation metrics being used, ideally with a description of why. -->
131
-
132
- [More Information Needed]
133
-
134
- ### Results
135
-
136
- [More Information Needed]
137
-
138
- #### Summary
139
-
140
-
141
-
142
- ## Model Examination [optional]
143
-
144
- <!-- Relevant interpretability work for the model goes here -->
145
-
146
- [More Information Needed]
147
-
148
- ## Environmental Impact
149
-
150
- <!-- Total emissions (in grams of CO2eq) and additional considerations, such as electricity usage, go here. Edit the suggested text below accordingly -->
151
-
152
- Carbon emissions can be estimated using the [Machine Learning Impact calculator](https://mlco2.github.io/impact#compute) presented in [Lacoste et al. (2019)](https://arxiv.org/abs/1910.09700).
153
-
154
- - **Hardware Type:** [More Information Needed]
155
- - **Hours used:** [More Information Needed]
156
- - **Cloud Provider:** [More Information Needed]
157
- - **Compute Region:** [More Information Needed]
158
- - **Carbon Emitted:** [More Information Needed]
159
-
160
- ## Technical Specifications [optional]
161
-
162
- ### Model Architecture and Objective
163
-
164
- [More Information Needed]
165
-
166
- ### Compute Infrastructure
167
-
168
- [More Information Needed]
169
-
170
- #### Hardware
171
-
172
- [More Information Needed]
173
 
174
- #### Software
175
 
176
- [More Information Needed]
 
 
 
177
 
178
- ## Citation [optional]
179
 
180
- <!-- If there is a paper or blog post introducing the model, the APA and Bibtex information for that should go in this section. -->
 
181
 
182
- **BibTeX:**
183
 
184
- [More Information Needed]
185
 
186
- **APA:**
187
 
188
- [More Information Needed]
189
 
190
- ## Glossary [optional]
191
 
192
- <!-- If relevant, include terms and calculations in this section that can help readers understand the model or model card. -->
 
193
 
194
- [More Information Needed]
195
 
196
- ## More Information [optional]
197
 
198
- [More Information Needed]
 
199
 
200
- ## Model Card Authors [optional]
201
 
202
- [More Information Needed]
203
 
204
- ## Model Card Contact
205
 
206
- [More Information Needed]
207
  ### Framework versions
208
 
209
- - PEFT 0.17.1
 
 
3
  library_name: peft
4
  pipeline_tag: text-generation
5
  tags:
 
6
  - lora
7
  - sft
8
  - transformers
9
  - trl
10
+ - pokemon
11
+ - pokemon-showdown
12
+ - gen9ou
13
+ - action-selection
14
  ---
15
 
16
+ # Qwen3-1.7B PokéLLM LoRA (Gen9 OU / JSON Action Selector)
 
 
17
 
18
+ **Summary:**
19
+ Qwen/Qwen3-1.7B を LoRA で事後学習し、ポケモン Showdown の Gen9 OU 対戦における **単手意思決定**(行動選択)を行う軽量アダプタです。
20
+ 本モデルは、与えられた候補集合に対して **厳密 JSON** で `{"action":"index::<k>"}` を返すことを目的に最適化されています。
21
+ (`index::<k>` は、あなたのエージェントが提示する候補リストの 0-based インデックス)
22
 
23
+ ---
24
 
25
  ## Model Details
26
 
27
+ - **Base model:** `Qwen/Qwen3-1.7B`
28
+ - **Adapter type:** LoRA (PEFT)
29
+ - **Task:** Pokémon Showdown Gen9 OU の 1 手意思決定(行動選択)
30
+ - **I/O 仕様:**
31
+ 入力: 観測(軽量テキスト or 構造化を文字列化)+候補 `CANDIDATES`(内部で index にマッピング)
32
+ 出力: 厳密 JSON 一個 `{ "action": "index::<k>" }`
33
+ - **Intended framework:** 🤗 Transformers + PEFT(PyTorch)
34
+ - **License:** Base モデルに準拠(Qwen/Qwen3-1.7B のライセンスをご確認ください)
35
+ - **Author :** _波浪 創(hellohazime)_
36
 
37
+ ### What this model is / isn’t
38
+ - ✅ **すること**: 候補(技 / 交代など)から **1 つ**を選ぶ。
39
+ - ⚠️ **しないこと**: 一般的な雑談・長文生成・マルチターン方策学習・ダメージ計算の厳密再現。
40
 
41
+ ---
 
 
 
 
 
 
 
 
 
 
 
 
 
 
42
 
43
  ## Uses
44
 
 
 
45
  ### Direct Use
46
+ - 対戦中の観測テキストと、候補キー(内部で `index` に変換したもの)を提示し、**1 手**を選択させる。
47
+ - 出力は **必ず 1 行 1 JSON**。解析側は `action` を読み取り、あなたの `index_map[k]` に解決して実行してください。
48
 
49
+ ### Downstream Use
50
+ - poke-env / Pokémon Showdown クライアントと組み合わせれば、**ローカル対戦エージェント**として利用できます。
51
+ - 学習済みプロンプト・スキーマに依存します。異なるスキーマで使う場合は再学習を推奨。
 
 
 
 
 
 
 
 
 
 
52
 
53
+ ### Out-of-Scope
54
+ - 一般領域の対話、長文化・推論タスク、Gen9 OU 以外のフォーマットへの強い汎化は想定していません。
55
 
56
+ ---
 
 
 
 
 
 
 
 
 
 
 
 
57
 
58
+ ## How to Get Started
59
+
60
+ ### Load with PEFT (Transformers)
61
+
62
+ ```python
63
+ from transformers import AutoTokenizer, AutoModelForCausalLM
64
+ from peft import PeftModel
65
+
66
+ BASE = "Qwen/Qwen3-1.7B"
67
+ ADAPTER = "YOUR_USERNAME/qwen3-1p7b-pokellm-lora" # ← あなたのリポ名に置換
68
+
69
+ tok = AutoTokenizer.from_pretrained(BASE, trust_remote_code=True)
70
+ if tok.pad_token_id is None and tok.eos_token_id is not None:
71
+ tok.pad_token = tok.eos_token
72
+
73
+ base = AutoModelForCausalLM.from_pretrained(BASE, trust_remote_code=True, device_map="auto")
74
+ model = PeftModel.from_pretrained(base, ADAPTER)
75
+
76
+ # --- 推論の例(厳密JSONを狙うプロンプト) ---
77
+ obs = "turn | 3\nyour_active | Gholdengo\nopp_active | Great Tusk\nmoves | Make It Rain, Shadow Ball, Trick, Focus Blast"
78
+ # 例: allowed は内部で index に並べ替えた候補(move群→switch群)に対応
79
+ allowed = ["index::0","index::1","index::2","index::3"] # 例
80
+ prompt = (
81
+ "You are a Gen9 OU single-battle agent.\n"
82
+ "Return exactly one JSON object on a single line.\n"
83
+ 'Schema: {"action": "index::<k>"} No markdown, no extra text.\n'
84
+ f"ALLOWED: {' | '.join(allowed)}\n\n"
85
+ f"{obs}\n\n"
86
+ "Action:"
87
+ )
88
+
89
+ inputs = tok(prompt, return_tensors="pt").to(model.device)
90
+ out_ids = model.generate(
91
+ **inputs,
92
+ max_new_tokens=48,
93
+ do_sample=False, # 温度0相当
94
+ eos_token_id=tok.eos_token_id,
95
+ pad_token_id=tok.eos_token_id
96
+ )
97
+ print(tok.decode(out_ids[0], skip_special_tokens=True))
98
+ ````
99
+
100
+ > **Note:** MLX ランタイムで LoRA を直接ロードするには別途変換が必要です(標準の PEFT/Torch では上記のように動作します)。
101
 
102
+ ---
103
 
104
  ## Training Details
105
 
106
  ### Training Data
107
 
108
+ * 出典: `jakegrigsby/metamon-parsed-replays`(Showdown リプレイの構造化アーカイブ)
109
+ * フィルタ: **Gen9 OU / Elo ≥ 1500** を中心に抽出・整形
110
+ * 生成された SFT データは以下の**index スキーマ**(簡略):
 
 
111
 
112
+ * `system`: 「厳密 JSON で 1 手のみ返す」等の指示
113
+ * `user`: `{ "state": {...}, "CANDIDATES": ["index::0", ...] }`
114
+ * `assistant`: `{ "action": "index::<k>" }`
115
 
116
+ ### Preprocessing
117
 
118
+ * 候補(move / switch)を **アルファベット順**に整列し、`index::<k>` に対応付け。
119
+ * 観測は軽量テキスト(ターン/自他アクティブ/使用可能技の見出し名 etc.)に要約。
120
+ * 長さ上限(cutoff): 1024 tokens 目安。
121
 
122
+ ### Training Procedure (LoRA / SFT)
123
 
124
+ * **PEFT LoRA:** `r=8, alpha=16, dropout=0.05, bias="none"`
125
+ **target\_modules:** `q_proj, k_proj, v_proj, o_proj, gate_proj, up_proj, down_proj`
126
+ * **Optimizer:** AdamW(`transformers.TrainingArguments(optim="adamw_torch")`)
127
+ * **LR:** 2e-4 近辺(スモーク→本学習でスケール)
128
+ * **Batch size:** 端末依存(例: `per_device_train_batch_size=8`, `gradient_accumulation_steps=1`)
129
+ * **Max steps:** データサイズに応じて設定(例: 10–25k)
130
+ * **Evaluation:** `eval_ratio ≈ 5%`, `eval_steps=500` 前後
131
+ `EarlyStoppingCallback(patience=3, metric=eval_loss)`
132
+ * **Precision:** fp32(Mac/MPS で安定運用)
133
 
134
+ > 実行スクリプトは TRL `SFTTrainer` を用いた標準的な SFT(packing 無効、`formatting_func` で chat template を適用)構成です。
135
 
136
+ ---
 
 
 
 
137
 
138
  ## Evaluation
139
 
140
+ ### Protocol
141
 
142
+ * **環境:** ローカル Pokémon Showdown (:8080), `poke-env` 経由
143
+ * **形式:** `gen9ou`(同一チーム同士で LLM vs Random の簡易ベースライン)
144
+ * **強制スキーマ:** 厳密 JSON 一個(`{"action": "index::<k>"}`)
145
 
146
+ ### Result (example)
147
 
148
+ ```
149
+ | Model | Backend | Format | Schema | Win% | Fallback% | Avg Lat(ms) | p95(ms) | Decis. | Battles |
150
+ |-----------------------------------------|---------|--------|--------|-----:|----------:|------------:|--------:|-------:|--------:|
151
+ | Qwen/Qwen3-1.7B + <this adapter> | hf | gen9ou | index | 80.0 | 0.0 | 1645.4 | 1728.6 | 346 | 10 |
152
+ ```
153
 
154
+ * **補足:** 対戦相手は poke-env の `RandomPlayer`。本 LoRA の “index スキーマ厳守” と最小限観測だけで、安定した JSON 出力を確認。
155
+ * さらなる妥当性評価(他フォーマット、強い相手、別チーム、長期戦)や人手検証は今後の課題です。
156
 
157
+ ---
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
158
 
159
+ ## Bias, Risks, and Limitations
160
 
161
+ * 単手方策であり、**長期的なプランニングやリソース管理**は学習していません。
162
+ * **index スキーマ依存**のため、プロンプト逸脱や候補整列順の不一致で性能が大きく劣化します。
163
+ * データは公開リプレイ由来で、**プレイヤースキルやメタ**に偏りがあり得ます。
164
+ * ダメージ計算・乱数・特性相互作用は**簡略観測**のみで与えており、**完全再現ではありません**。
165
 
166
+ ### Recommendations
167
 
168
+ * 生成の健全性チェック(JSON 解析、候補外出力のフォールバック)を必ず実装してください。
169
+ * 実運用では **評価対戦の拡充**(様々な構築・相手・ルール)を推奨します。
170
 
171
+ ---
172
 
173
+ ## Technical Specifications
174
 
175
+ ### Architecture
176
 
177
+ * Qwen3-1.7B(Causal LM)+ LoRA(PEFT)
178
 
179
+ ### Software
180
 
181
+ * Transformers / TRL / PEFT / PyTorch(MPS)
182
+ * Tokenizer は base に付属の chat template を使用(無い場合は簡易フォールバック)
183
 
184
+ ---
185
 
186
+ ## How to Cite / Credit
187
 
188
+ * Base: **Qwen/Qwen3-1.7B**
189
+ * Data inspiration: **metamon-parsed-replays**(Showdown 由来の公開リプレイ構造化)
190
 
191
+ ---
192
 
193
+ ## Model Card Authors
194
 
195
+ * 波浪 創(hellohazime) *
196
 
 
197
  ### Framework versions
198
 
199
+ * PEFT 0.17.1(動作確認)
200
+ * Transformers / TRL は 2025 時点の安定版で確認(詳細は `training_args.bin` を参照)