Text Generation
PEFT
Safetensors
Transformers
English
lora
qlora
bitsandbytes
connect4
game-playing
causal-lm
RenaudGaudron commited on
Commit
717d3dc
·
verified ·
1 Parent(s): 09015e3

v2.0.0 update with lower eval loss

Browse files
Files changed (3) hide show
  1. README.md +38 -33
  2. adapter_config.json +4 -4
  3. adapter_model.safetensors +2 -2
README.md CHANGED
@@ -1,6 +1,6 @@
1
  ---
2
  model_name: Connect4 QLoRA Adapter for Qwen3-0.6B-Base
3
- version: 1.0.0
4
  library_name: peft
5
  base_model: Qwen/Qwen3-0.6B-Base
6
  license: mit
@@ -28,7 +28,9 @@ quantization_config:
28
 
29
  ## Model Summary
30
 
31
- This repository distributes a QLoRA adapter trained to steer the **Qwen/Qwen3-0.6B-Base** model toward Connect Four next-move prediction and short-form move generation. Prompts encode game history as concatenated column indices (`0`–`6`) along with the starter and side-to-move context, allowing the adapter to focus on legal column selection. The weights are stored separately from the base checkpoint; load or merge them into the matching base revision before running inference. Runs on a single consumer GPU with 4 GB of VRAM in 4bit mode.
 
 
32
 
33
  ## How to Use
34
 
@@ -110,7 +112,7 @@ model.tokenizer.save_pretrained(OUTPUT_DIR)
110
  print(f"Merged model saved to {OUTPUT_DIR}. Review the base model license before redistribution.")
111
  ```
112
 
113
- > **Prompt format.** Every training example uses the template shown above. The `Moves so far` line encodes the move history as a contiguous string of digits where each character represents the column index (0–6) chosen at that ply. Use `none` when the position is empty, and keep the history aligned with the game starter so that column legality can be inferred correctly. The response should be exactly one digit; sampling or constrained decoding can help maintain this format.
114
 
115
  ## Training Details
116
 
@@ -123,65 +125,67 @@ print(f"Merged model saved to {OUTPUT_DIR}. Review the base model license before
123
  * Target modules: attention projections (`q_proj`, `k_proj`, `v_proj`, `o_proj`) and MLP projections (`gate_proj`, `up_proj`, `down_proj`).
124
  * Adapter bias: disabled; only rank update matrices are trainable.
125
 
126
- QLoRA keeps the dense Qwen3 backbone quantised to 4-bit NF4 while learning a lightweight set of low-rank matrices. This dramatically reduces memory pressure (the run fit comfortably in <10 GB of VRAM) and allows experimentation on modest hardware without sacrificing too much accuracy.
127
 
128
  ### Optimisation setup
129
 
130
  * Optimiser: `adamw_torch_fused` with β₂ = 0.98 and ε = 1e-6.
131
- * Learning rate: 5e-7 with `constant_with_warmup` scheduling and a warmup ratio of 5 % (no fixed warmup steps beyond the ratio).
132
  * Weight decay: 0.0.
133
  * Gradient accumulation: 8 steps with per-device batch size 8 → effective batch size 64 sequences.
134
- * Max gradient norm: 25.0 with gradient clipping applied to stabilise updates.
135
  * Label smoothing: disabled.
136
- * Attention backend: PyTorch SDPA with math kernel fallback (flash and memory-efficient kernels were unavailable on the training GPU).
 
137
 
138
  ### Precision and memory
139
 
140
- * Base model loaded in 4-bit NF4 with double quantisation; LoRA weights in float32.
141
- * Computation dtype: float16; BF16 enabled where supported (trainer configuration set `bf16=True`, `fp16=False`, `tf32=True`).
142
  * Gradient checkpointing: disabled.
143
 
144
  ### Data
145
 
146
- * Dataset: private self-play Connect Four rollouts.
147
- * Move encoding: each game history is serialised as digits `0`–`6`, one per ply, reflecting the column placements from left (0) to right (6).
148
- * Total generated prompt-response pairs: 54 657 (49 191 train / 5 466 validation).
149
- * Minimum move threshold: 6 plies before emitting supervision to ensure non-trivial contexts.
150
- * Validation split: 10 % stratified by shuffle.
151
 
152
  ### Training run
153
 
154
- * Epochs: 5 planned (converged by step 30 k of 30 745 total optimiser steps).
155
- * Total training runtime: ~26.7h (96 205 s) with 0 out-of-memory retries.
156
- * Throughput: 2.56 samples/s, 0.32 steps/s.
157
- * Hardware: single-GPU Accelerate run (device 0, 4-bit load) on Windows; memory planner reserved 90 % of the device for model weights according to the log.
158
- * Seed: 42 (applied to Python, NumPy, and PyTorch). Standard dataloader shuffles and CUDA kernels may still introduce nondeterminism.
159
 
160
  ## Evaluation
161
 
162
- Evaluation used the same prompt template and truncated each sequence to `eval_max_seq_length=128`. The primary metric is token-level cross-entropy (reported as loss), which acts as a proxy for perplexity over the next-move token.
163
 
164
- * Final checkpoint validation loss: **0.8570**.
165
- * Best observed validation loss during training: **0.7306** at step 30 000.
166
 
167
- These values indicate the adapter tracks legal play patterns and improves over the base model for move prediction, but decoding quality remains sensitive to sampling strategy and prompt fidelity. No additional metrics (win-rate or exact-match) were computed for this release.
168
 
169
- Stability controls included gradient clipping at a max norm of 25.0, continuous gradient-norm monitoring, and the warmup schedule above. No label smoothing or dropout beyond LoRA-specific dropout was used.
170
 
171
  ## Special Tokens
172
 
173
- The adapter relies on the base tokenizer without introducing new tokens. The provided `special_tokens.json` simply reuses token ID `151643` for both padding and EOS with right-side padding. No custom BOS token or move separator tokens were added.
174
 
175
  ## Intended Use & Limitations
176
 
177
- **Intended use.** Researchers and hobbyists experimenting with Connect Four agents can combine this adapter with Qwen/Qwen3-0.6B-Base to generate legal column suggestions. The model expects textual prompts that follow the documented template.
 
 
178
 
179
  **Limitations.**
180
 
181
- * The small 0.6 B parameter backbone limits long-horizon reasoning and nuanced board evaluation. Expect occasional illegal or weak moves, especially in edge cases near game end.
182
- * Outputs are single-digit column indices; free-form text prompts or multi-turn conversations fall outside the training distribution.
183
  * The adapter does not include safety layers, toxicity filtering, or alignment for open-domain generation. Avoid deploying it in user-facing production systems.
184
- * Quality depends heavily on providing complete, legal move histories and using deterministic decoding (`do_sample=False` or constrained vocab sampling).
185
 
186
  ## Compatibility
187
 
@@ -190,22 +194,23 @@ The adapter was trained and validated with the following stack:
190
  * `transformers` ≥ 4.39.0
191
  * `peft` ≥ 0.8.2
192
  * `bitsandbytes` ≥ 0.43.0
193
- * `torch` ≥ 2.1 (CUDA 12.4 compatible per bitsandbytes log)
194
  * `accelerate` ≥ 0.25.0
195
 
196
- The training environment ran on Windows with CUDA 12.4 bitsandbytes bindings. On Linux or other CUDA versions, Accelerate automatically falls back to the available SDPA kernels; if flash or memory-efficient SDPA kernels are missing (as during training), PyTorch will use the math implementation. Pin the same `Qwen/Qwen3-0.6B-Base` revision you fine-tune against to avoid key mismatches when loading the adapter.
197
 
198
  ## Reproducibility & Seeds
199
 
200
- The training script fixed the global seed to **42** across Python, NumPy, and PyTorch. Nevertheless, sources of nondeterminism remain (CUDA kernels, dataloader worker order, and filesystem scheduling). For faithful reproduction, combine the published configuration with deterministic CUDA flags and ensure dataset shuffling uses the same seed.
201
 
202
  ## Changelog
203
 
 
204
  * **2025-10-25** – Initial public adapter release.
205
 
206
  ## License
207
 
208
- The adapter is released under the **MIT License**. The base model, **Qwen/Qwen3-0.6B-Base**, is distributed under the Apache License 2.0; ensure downstream usage complies with both the adapter’s MIT terms and the base model’s requirements before deploying, fine-tuning further, or redistributing merged checkpoints.
209
 
210
  ## Citations
211
 
 
1
  ---
2
  model_name: Connect4 QLoRA Adapter for Qwen3-0.6B-Base
3
+ version: 2.0.0
4
  library_name: peft
5
  base_model: Qwen/Qwen3-0.6B-Base
6
  license: mit
 
28
 
29
  ## Model Summary
30
 
31
+ This repository distributes a QLoRA adapter trained to steer the **Qwen/Qwen3-0.6B-Base** model toward Connect Four next-move prediction and short-form move generation. Prompts encode game history as concatenated column indices (`0`–`6`) along with the starter and side-to-move context, allowing the adapter to focus on legal column selection. The weights are stored separately from the base checkpoint; load or merge them into the matching base revision before running inference. Runs on a single consumer GPU with 4 GB of VRAM in 4bit mode.
32
+
33
+ This updated version includes a larger training set and automatically selected the checkpoint with the lowest evaluation loss for improved reliability and performance.
34
 
35
  ## How to Use
36
 
 
112
  print(f"Merged model saved to {OUTPUT_DIR}. Review the base model license before redistribution.")
113
  ```
114
 
115
+ > **Prompt format.** Training examples follow the template above. The `Moves so far` string serialises column indices (`0``6`) without separators so column legality remains reconstructible. Use `none` when the board is empty, and always align the move history with the declared starter to avoid illegal column suggestions. Responses remain single digits; deterministic decoding or constrained vocabularies help preserve the format.
116
 
117
  ## Training Details
118
 
 
125
  * Target modules: attention projections (`q_proj`, `k_proj`, `v_proj`, `o_proj`) and MLP projections (`gate_proj`, `up_proj`, `down_proj`).
126
  * Adapter bias: disabled; only rank update matrices are trainable.
127
 
128
+ QLoRA keeps the dense Qwen3 backbone quantised to 4-bit NF4 while learning a lightweight LoRA stack initialised from the resumed checkpoint. The adapters stay in float32 while the quantised backbone executes in 4-bit, keeping peak VRAM well under 8 GB on the training GPU.
129
 
130
  ### Optimisation setup
131
 
132
  * Optimiser: `adamw_torch_fused` with β₂ = 0.98 and ε = 1e-6.
133
+ * Learning rate: 5e-7 with `constant_with_warmup` scheduling and a warmup ratio of 5 %.
134
  * Weight decay: 0.0.
135
  * Gradient accumulation: 8 steps with per-device batch size 8 → effective batch size 64 sequences.
136
+ * Max gradient norm: 25.0 with clipping applied every optimisation step.
137
  * Label smoothing: disabled.
138
+ * Attention backend: PyTorch SDPA with math kernel fallback; flash and memory-efficient kernels were unavailable on the training GPU.
139
+ * Length-aware sampling: 64-bucket sampler enabled to reduce padding skew during both training and evaluation.
140
 
141
  ### Precision and memory
142
 
143
+ * Base model loaded in 4-bit NF4 with double quantisation; LoRA weights stored in float32.
144
+ * Computation dtype: BF16 with TF32 matmuls enabled; FP16 disabled.
145
  * Gradient checkpointing: disabled.
146
 
147
  ### Data
148
 
149
+ * Dataset source: private self-play Connect Four rollouts across three CSV files.
150
+ * Aggregated examples: 114 363 generated prompts (102 926 train / 11 437 validation) from 4 200 games.
151
+ * Per-file caps: 100 level-0 games (two players making random legal moves), 4 000 games played between Minimax agents of depth 8, and 100 mixed-level games (depth 4 vs 8). Each game is expanded into multiple move-prefix supervision sequences for training.
152
+ * Minimum move threshold: unset (`min_moves=0`) so every legal position contributes.
153
+ * Validation split: 10 % stratified after shuffle.
154
 
155
  ### Training run
156
 
157
+ * Epochs: 5 planned
158
+ * Best observed validation loss: **0.7196** at step 50000 (saved as the published checkpoint).
159
+ * Training log span: ~60h with periodic evaluations every 1 000 steps.
160
+ * Hardware: single-process Accelerate session on a Windows workstation loading bitsandbytes CUDA 12.4 bindings and operating on a CUDA device.
161
+ * Seed: 42 across Python, NumPy, and PyTorch. Dataloader workers (10) and CUDA kernels may still introduce nondeterminism.
162
 
163
  ## Evaluation
164
 
165
+ Evaluation reuses the training prompt template with `eval_max_seq_length=128` truncation. The primary metric is token-level cross-entropy (reported as loss) measuring next-move prediction quality.
166
 
167
+ * Published checkpoint validation loss: **0.7196** (best checkpoint at step 50 000).
 
168
 
169
+ Loss values indicate that the adapter reliably tracks legal play patterns after the expanded curriculum while remaining sensitive to decoding constraints near terminal states.
170
 
171
+ Stability controls mirrored training: gradient clipping at norm 25.0, SDPA math kernel fallback, and warmup scheduling. No extra label smoothing or dropout beyond the LoRA stack was introduced.
172
 
173
  ## Special Tokens
174
 
175
+ The adapter ships without introducing new tokens. The bundled tokenizer metadata mirrors the base checkpoint, reusing `<|endoftext|>` as both EOS and padding alongside the stock Qwen multimodal specials.
176
 
177
  ## Intended Use & Limitations
178
 
179
+ **Intended use.**
180
+
181
+ Pair the adapter with **Qwen/Qwen3-0.6B-Base** for Connect Four next-move suggestion or short move-sequence generation. Prompts should follow the documented template for reliable legality.
182
 
183
  **Limitations.**
184
 
185
+ * The compact 0.6B backbone cannot guarantee optimal play in deep tactical lines; illegal or low-quality moves remain possible, especially near endgame scenarios.
186
+ * Outputs are restricted to single-digit column indices; free-form chat or multi-turn dialogue falls outside the training distribution.
187
  * The adapter does not include safety layers, toxicity filtering, or alignment for open-domain generation. Avoid deploying it in user-facing production systems.
188
+ * Quality still depends on accurate, complete move histories and deterministic decoding (e.g., `do_sample=False` or constrained vocab sampling).
189
 
190
  ## Compatibility
191
 
 
194
  * `transformers` ≥ 4.39.0
195
  * `peft` ≥ 0.8.2
196
  * `bitsandbytes` ≥ 0.43.0
197
+ * `torch` ≥ 2.1 (CUDA 12.4 build per bitsandbytes log)
198
  * `accelerate` ≥ 0.25.0
199
 
200
+ Windows-based CUDA 12.4 bindings powered the training environment. On Linux or alternate CUDA releases, Accelerate falls back to available SDPA kernels; if flash or memory-efficient kernels are missing (as during training), PyTorch defaults to the math implementation. Always load the same **Qwen/Qwen3-0.6B-Base** revision used during fine-tuning to avoid key mismatches.
201
 
202
  ## Reproducibility & Seeds
203
 
204
+ The global seed remained **42** across Python, NumPy, and PyTorch. Despite deterministic settings, CUDA kernel scheduling, dataloader worker ordering, and filesystem timing can introduce minor nondeterminism.
205
 
206
  ## Changelog
207
 
208
+ * **2025-11-04** – Expanded dataset fine-tune with automated best-checkpoint capture.
209
  * **2025-10-25** – Initial public adapter release.
210
 
211
  ## License
212
 
213
+ The adapter is released under the **MIT License**. The base model, **Qwen/Qwen3-0.6B-Base**, ships under Apache 2.0. Please ensure that downstream usage respects both licenses before merging, redistributing, or further fine-tuning.
214
 
215
  ## Citations
216
 
adapter_config.json CHANGED
@@ -25,13 +25,13 @@
25
  "rank_pattern": {},
26
  "revision": null,
27
  "target_modules": [
 
28
  "v_proj",
29
  "down_proj",
30
- "k_proj",
31
- "o_proj",
32
  "q_proj",
33
- "up_proj",
34
- "gate_proj"
 
35
  ],
36
  "target_parameters": null,
37
  "task_type": "CAUSAL_LM",
 
25
  "rank_pattern": {},
26
  "revision": null,
27
  "target_modules": [
28
+ "k_proj",
29
  "v_proj",
30
  "down_proj",
 
 
31
  "q_proj",
32
+ "gate_proj",
33
+ "o_proj",
34
+ "up_proj"
35
  ],
36
  "target_parameters": null,
37
  "task_type": "CAUSAL_LM",
adapter_model.safetensors CHANGED
@@ -1,3 +1,3 @@
1
  version https://git-lfs.github.com/spec/v1
2
- oid sha256:b66474a92f61223dcbd73507a84ea9d78a35e3808edbaf650e1706578d852eac
3
- size 161533944
 
1
  version https://git-lfs.github.com/spec/v1
2
+ oid sha256:c71d0547a48a213002ff430fd2d9608266b543bbe6d8038c3254815457a2b237
3
+ size 323014520