void0x14 commited on
Commit
33bb7d3
·
unverified ·
1 Parent(s): 2a2fb45

docs: define qwen35 pruning design and plan

Browse files
docs/superpowers/plans/2026-08-17-qwen35-pruning.md ADDED
@@ -0,0 +1,126 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Qwen3.5 Pruning and Vulkan Distillation Implementation Plan
2
+
3
+ > For agentic workers: use superpowers:executing-plans or superpowers:subagent-driven-development to execute this plan task by task. Steps use checkbox syntax for tracking.
4
+
5
+ Goal: Create and verify a 330M-350M text-only Qwen3.5 checkpoint and run GPU-only RX 460 Vulkan teacher/student inference and CE-plus-hidden-MSE distillation.
6
+
7
+ Architecture: Python utilities perform metadata-only measurement, text-prefix state-dict extraction, and final validation. A pinned llama.cpp Vulkan build performs all model forwards and training; its optimizer graph is patched for frozen teacher hidden targets, combined loss, and cosine warmup.
8
+
9
+ Tech Stack: Python 3, safetensors, transformers 5.2.0 config schema, pytest, llama.cpp 10068-compatible source, ggml Vulkan backend, AdamW.
10
+
11
+ ## Global Constraints
12
+
13
+ - Never run a model forward, inference, or training step on CPU.
14
+ - Use the live config.json; retain linear_num_value_heads=16.
15
+ - Keep the first complete hybrid prefix and reject incomplete prefixes.
16
+ - Drop every model.visual.* and mtp.* tensor.
17
+ - Preserve tie_word_embeddings=true and do not duplicate the tied LM head tensor.
18
+ - Final emitted parameter count must be measured inside [330000000, 350000000].
19
+ - Teacher is frozen; loss is CE plus hidden-state MSE.
20
+ - Optimizer is AdamW with cosine warmup.
21
+ - Use explicit-path git staging; never use git add ., git add -A, or git commit -a.
22
+
23
+ ---
24
+
25
+ ### Task 1: Add metadata and checkpoint contract tests
26
+
27
+ Files:
28
+ - Create: MVP/tests/test_pruning_contract.py
29
+ - Create: MVP/tests/fixtures/qwen35_metadata.json
30
+
31
+ Interfaces:
32
+ - Tests import MVP.qwen35_prune and MVP.validate_checkpoint.
33
+ - The fixture records live config values and measured tensor groups.
34
+
35
+ - [ ] Step 1: Write failing tests for choose_prefix(337299424) returning 4,
36
+ count_parameter_groups returning the measured groups, prefix translation of
37
+ model.language_model.layers.3.* to model.layers.3.*, vision/MTP exclusion,
38
+ tied embedding counting, and N=4 config construction.
39
+ - [ ] Step 2: Run python -m pytest MVP/tests/test_pruning_contract.py -q.
40
+ Expected before implementation: import errors for the missing modules.
41
+ - [ ] Step 3: Stage only the two test paths and commit
42
+ test: define qwen35 pruning contract.
43
+
44
+ ### Task 2: Implement metadata selection and text-only checkpoint extraction
45
+
46
+ Files:
47
+ - Create: MVP/qwen35_prune.py
48
+ - Create: MVP/validate_checkpoint.py
49
+
50
+ Interfaces:
51
+ - load_live_config(path) -> dict
52
+ - count_parameter_groups(safetensors_path, config) -> ParameterReport
53
+ - choose_prefix(report, minimum, maximum) -> PrefixChoice
54
+ - translate_text_key(key) -> str or None
55
+ - build_text_config(full_config, layer_count) -> dict
56
+ - prune_checkpoint(input_weights, input_config, output_dir, layer_count) -> ValidationReport
57
+ - validate_checkpoint(config_path, weights_path, minimum, maximum) -> ValidationReport
58
+
59
+ - [ ] Step 1: Implement only the functions needed by the red tests.
60
+ - [ ] Step 2: Run the focused tests and keep the output green.
61
+ - [ ] Step 3: Add CLI commands measure, prune, and validate; each command
62
+ fails closed on missing or inconsistent input.
63
+ - [ ] Step 4: Commit explicit paths as feat: add qwen35 text checkpoint pruner.
64
+
65
+ ### Task 3: Produce and re-measure the real N=4 checkpoint
66
+
67
+ Files:
68
+ - Create: MVP/artifacts/ outputs from the live snapshot.
69
+ - Create or modify: MVP/PROGRESS.md.
70
+
71
+ - [ ] Step 1: Run metadata-only measurement against the live snapshot.
72
+ - [ ] Step 2: Run the pruner with --layers 4 and the live safetensors file.
73
+ - [ ] Step 3: Run the validator against the emitted files and save raw output.
74
+ - [ ] Step 4: Confirm output config has model_type=qwen3_5_text, four layer
75
+ types, and no vision/MTP keys.
76
+ - [ ] Step 5: Commit tools and evidence documentation with explicit paths.
77
+
78
+ ### Task 4: Build a reproducible Vulkan runtime
79
+
80
+ Files:
81
+ - Create: MVP/runtime/README.md
82
+ - Create: MVP/runtime/build-vulkan.sh
83
+ - Create: MVP/patches/ for the source patch.
84
+
85
+ - [ ] Step 1: Clone or unpack a pinned llama.cpp source commit and record it.
86
+ - [ ] Step 2: Build with Vulkan enabled and verify llama-cli --list-devices
87
+ contains RX 460 as Vulkan0.
88
+ - [ ] Step 3: Convert the text-only checkpoint to GGUF using a verified tokenizer.
89
+ - [ ] Step 4: Run student and authoritative teacher inference with
90
+ --device Vulkan0; save complete logs including device initialization.
91
+ - [ ] Step 5: Commit runtime scripts and evidence paths.
92
+
93
+ ### Task 5: Add and test combined distillation loss
94
+
95
+ Files:
96
+ - Modify: pinned llama.cpp optimizer/runtime sources in the reproducible runtime checkout.
97
+ - Create: MVP/patches/qwen35-hidden-distillation.patch
98
+ - Create: MVP/tests/test_distillation_loss.py
99
+
100
+ - [ ] Step 1: Write a synthetic test for CE + lambda*MSE and the cosine-warmup
101
+ schedule; verify frozen teacher parameters are excluded from updates.
102
+ - [ ] Step 2: Run it red before changing runtime code.
103
+ - [ ] Step 3: Patch the optimizer graph to accept teacher hidden targets and
104
+ expose CE, hidden MSE, total loss, and learning rate in logs.
105
+ - [ ] Step 4: Build the patched Vulkan runtime and run the synthetic test green.
106
+ - [ ] Step 5: Run a bounded real distillation job with teacher and student on
107
+ Vulkan0; preserve raw logs.
108
+ - [ ] Step 6: Commit patch and test as
109
+ feat: add qwen35 hidden-state distillation loss.
110
+
111
+ ### Task 6: Final verification and atomic handoff
112
+
113
+ Files:
114
+ - Modify: MVP/PROGRESS.md
115
+ - Create: MVP/evidence/ logs and validator output.
116
+
117
+ - [ ] Step 1: Re-run the final validator on the post-distillation checkpoint.
118
+ - [ ] Step 2: Verify measured count is inside [330000000,350000000] and
119
+ visual/MTP tensor count is zero.
120
+ - [ ] Step 3: Verify every model execution log names
121
+ Vulkan0: AMD Radeon RX 460 Graphics.
122
+ - [ ] Step 4: Record any missing proof as kanıt yok; do not infer success from
123
+ file presence or command exit status alone.
124
+ - [ ] Step 5: Run final fresh verification, inspect git diff --cached --name-only,
125
+ and commit only explicit paths.
126
+
docs/superpowers/specs/2026-08-17-qwen35-pruning-design.md ADDED
@@ -0,0 +1,82 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Qwen3.5 Text-Only Pruning and Vulkan Distillation Design
2
+
3
+ ## Goal
4
+
5
+ Produce a verifiable text-only Qwen/Qwen3.5-0.8B-Base checkpoint by removing the
6
+ vision tower and MTP head, keeping the first complete hybrid block prefix, and
7
+ then run teacher/student inference and distillation through the RX 460 Vulkan
8
+ backend. The final text checkpoint must measure between 330,000,000 and
9
+ 350,000,000 parameters from its emitted tensors.
10
+
11
+ ## Constraints
12
+
13
+ - Model forward, inference, and training are GPU-only through Vulkan0.
14
+ - CPU is allowed for configuration, safetensors metadata, tensor copying, and
15
+ static validation; it is not allowed for a model forward or training step.
16
+ - The live config is authoritative. In particular,
17
+ linear_num_value_heads=16 is not replaced by a library default.
18
+ - The student keeps the first complete four-layer hybrid prefix. No activation
19
+ ranking is used for this depth-only target because N=4 is inside the measured
20
+ parameter interval.
21
+ - Teacher weights are frozen. The training objective is
22
+ CE(student logits) + lambda * MSE(student final hidden, teacher final hidden).
23
+ - Optimizer is AdamW and the learning-rate schedule is cosine with warmup.
24
+ - Every phase has explicit-path staging and an atomic commit.
25
+ - A claim of GPU execution requires a saved log containing the Vulkan device.
26
+
27
+ ## Architecture
28
+
29
+ MVP/qwen35_prune.py reads the live JSON config and safetensors metadata,
30
+ selects the largest complete hybrid prefix that fits the required interval,
31
+ renames only the text-backbone prefixes, drops model.visual.* and mtp.*,
32
+ and emits a text-only safetensors checkpoint plus a qwen3_5_text config. It
33
+ never constructs or forwards the model.
34
+
35
+ MVP/validate_checkpoint.py re-counts emitted tensors, checks that vision/MTP
36
+ tensors are absent, checks layer-prefix continuity and the exact text config,
37
+ and verifies tied embeddings without duplicating lm_head.weight in the saved
38
+ state dict.
39
+
40
+ The runtime phase uses a pinned llama.cpp source checkout with Vulkan enabled.
41
+ The required patch adds a frozen teacher hidden-state input and a second loss
42
+ term to the optimizer graph, while retaining the existing AdamW update path and
43
+ adding cosine warmup scheduling. The patch is kept under MVP/patches/ so the
44
+ runtime source and build can be reproduced.
45
+
46
+ ## Data flow
47
+
48
+ live HF config + safetensors
49
+ |
50
+ v
51
+ metadata measurement -> complete-prefix selection (N=4)
52
+ |
53
+ v
54
+ text-only safetensors + qwen3_5_text config
55
+ |
56
+ v
57
+ HF -> GGUF conversion -> llama-cli Vulkan0 teacher/student inference
58
+ |
59
+ v
60
+ teacher hidden target (GPU) + student logits/hidden (GPU)
61
+ |
62
+ v
63
+ CE + lambda*MSE -> AdamW + cosine warmup -> student checkpoint
64
+
65
+ ## Failure handling
66
+
67
+ - Missing or inconsistent metadata is a hard error.
68
+ - A layer count that is not a complete hybrid prefix is rejected.
69
+ - Any retained visual or mtp tensor is a hard validation failure.
70
+ - A non-Vulkan runtime log is not accepted as model execution evidence.
71
+ - If the installed llama.cpp runtime cannot support the combined loss or the
72
+ RX 460 cannot hold the requested graph, the progress file records the exact
73
+ failing command and output; CE-only output is never reported as distillation.
74
+
75
+ ## Testing
76
+
77
+ Pure Python tests cover metadata-derived counts, N=4 selection, prefix
78
+ translation, tensor exclusion, tied embeddings, config fields, and final
79
+ interval validation. A runtime test uses a synthetic tiny graph to verify the
80
+ combined loss numerically before a real model run. Real model checks re-count
81
+ the produced checkpoint and require Vulkan logs.
82
+