ntc-ai commited on
Commit
a50298f
·
verified ·
1 Parent(s): b2d2fae

Explain the winning architecture, exact distillation loss, and inference path

Browse files

Document active and inactive losses, frozen versus updated parameters, mask calibration, and the expanded-source alternative. Refresh documentation checksums; all checkpoint weights are unchanged.

Files changed (4) hide show
  1. FORMULATION.md +213 -0
  2. README.md +63 -0
  3. SHA256SUMS +3 -2
  4. manifest.json +6 -2
FORMULATION.md ADDED
@@ -0,0 +1,213 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # The released SD1.5 → SANA winner: architecture, loss, and inference
2
+
3
+ The default [released checkpoint](https://huggingface.co/ntc-ai/model-glue-sd15-sana-text)
4
+ is a **7,182,917-parameter text-conditioning bridge**. Its winning continuation
5
+ trained the final linear output projection using paired embeddings and frozen-SANA
6
+ response distillation. The parent came from earlier ParticleGAN experiments,
7
+ but this continuation has **no active GAN or b_cap loss**. Its learned particle
8
+ cloud is retained as fixed network weights.
9
+
10
+ `model.safetensors` is the EMA checkpoint selected at update 1,250 of 1,500,
11
+ followed by one validation-fitted mask-bias adjustment. The uncalibrated control
12
+ and expanded-source alternative are also released. See the [results](https://github.com/255BITS/model-glue/blob/main/docs/results/formulation-retraining-20260905.md),
13
+ [download instructions](https://github.com/255BITS/model-glue/blob/main/docs/sana-transfer.md#released-sd15-text-checkpoints), and
14
+ [exact recipe](https://github.com/255BITS/model-glue/blob/main/configs/formulation/linear-distill-fixed.json).
15
+
16
+ ## Architecture
17
+
18
+ ```mermaid
19
+ flowchart LR
20
+ A[Prompt] --> B[Frozen SD1.5 CLIP]
21
+ B --> C[77 x 768 contextual states]
22
+ C --> D[LayerNorm and 768-to-384 projection]
23
+ C --> R[Mean pooling and particle router]
24
+ P[Fixed 256 x 4 learned cloud] --> R
25
+ D --> Q[77 learned queries plus source and particle offsets]
26
+ R --> Q
27
+ Q --> T[4 cross-attention blocks; width 384]
28
+ D --> T
29
+ T --> O[Linear output and fixed feature calibration]
30
+ T --> M[Linear mask head and threshold]
31
+ O --> S[Frozen SANA: 20 sampling steps]
32
+ M --> S
33
+ U[Stored native empty conditioning] --> S
34
+ S --> V[Frozen DC-AE decoder]
35
+ V --> I[Image]
36
+ ```
37
+
38
+ The input is the full contextual CLIP sequence, not a pooled embedding. For
39
+ source states $X$ with shape 77 × 768:
40
+
41
+ $$
42
+ E=\operatorname{Linear}_{768\to384}(\operatorname{LN}(X)),\qquad
43
+ r=\operatorname{MLP}_{768\to64\to4}(\operatorname{mean}_{tokens}X).
44
+ $$
45
+
46
+ The router MLP uses SiLU. With saved cloud $P$ of shape 256 × 4:
47
+
48
+ $$
49
+ a=\operatorname{softmax}(rP^T/\sqrt4),\qquad p=aP,\qquad
50
+ H_0=Q+E+\operatorname{Linear}_{4\to384}(p).
51
+ $$
52
+
53
+ $Q$ contains 77 learned queries of width 384. The same four-dimensional $p$
54
+ provides a global query offset. This is attention over shared parameter vectors,
55
+ not a lookup of training captions. The cloud and router stayed fixed during the
56
+ winning continuation; no particle advantage is established.
57
+
58
+ Each of four blocks performs six-head cross-attention to $E$, then a residual
59
+ feed-forward network:
60
+
61
+ $$
62
+ A_l=H_l+\operatorname{MHA}(\operatorname{LN}(H_l),E,E),\qquad
63
+ H_{l+1}=A_l+\operatorname{MLP}_{384\to1152\to384}(\operatorname{LN}(A_l)).
64
+ $$
65
+
66
+ The feed-forward activation is GELU and attention dropout is zero. These bridge
67
+ blocks have no additional target-query self-attention layer. CLIP has already
68
+ contextualized the source states. Output features and mask logits are:
69
+
70
+ $$
71
+ \widehat Y_j=\mu_j+\sigma\odot(W_oH_{4,j}+b_o),\qquad
72
+ \ell_j=w_m^TH_{4,j}+b_m.
73
+ $$
74
+
75
+ The saved target mean $\mu$ is per slot and channel (77 × 2304); the standard
76
+ deviation $\sigma$ is per channel (2304). Both come from teacher-valid training
77
+ positions and were retained from the parent; standard deviation has a floor of
78
+ 0.1. The linear 384 → 2304 output head retains the old per-slot affine rank
79
+ restriction of at most 384. Winning validation does not imply that this model
80
+ incorporates every architectural repair or can represent arbitrary target states.
81
+
82
+ This transfers the donor's text representation. The SD1.5 diffusion U-Net never
83
+ runs in this path, so the bridge does not establish transfer of its generated
84
+ style or composition. Spatial donor-feature transfer is a separate interface.
85
+
86
+ ## Exact active loss
87
+
88
+ The winning objective is:
89
+
90
+ $$
91
+ \boxed{L=0.1L_{embed}+L_{functional}.}
92
+ $$
93
+
94
+ For native teacher conditioning $Y$, teacher-valid mask $M$, and bridge output
95
+ $\widehat Y$, embedding loss is masked, channel-normalized squared error:
96
+
97
+ $$
98
+ L_{embed}=\frac{\sum_{b,j,c}M_{b,j}
99
+ \left((\widehat Y_{b,j,c}-Y_{b,j,c})/\sigma_c\right)^2}
100
+ {2304\max(1,\sum_{b,j}M_{b,j})}.
101
+ $$
102
+
103
+ Functional distillation asks whether the **same frozen SANA** makes the same
104
+ denoising prediction under bridged and native conditioning. Student predictions
105
+ carry gradients through SANA into the bridge. Teacher predictions are detached
106
+ or read from the native-state cache; SANA's parameters remain frozen.
107
+
108
+ At the same latent state and timestep, let $s_+,s_0$ denote SANA predictions
109
+ under student positive/empty conditioning, and $t_+,t_0$ its teacher predictions.
110
+ All MSEs average across the functional minibatch and latent coordinates:
111
+
112
+ $$
113
+ g_s=s_0+4.5(s_+-s_0),\qquad g_t=t_0+4.5(t_+-t_0),
114
+ $$
115
+
116
+ $$
117
+ L_{functional}=\frac{
118
+ \operatorname{MSE}(s_+,t_+)+\operatorname{MSE}(s_0,t_0)
119
+ +0.05\operatorname{MSE}(g_s,g_t)}
120
+ {\max(10^{-5},\operatorname{mean}((t_+-t_0)^2))}.
121
+ $$
122
+
123
+ The denominator is detached **native prompt-effect power**. It measures error
124
+ relative to how strongly the teacher responds to the prompt. The positive
125
+ student uses its predicted hard mask; the teacher uses its cached native mask.
126
+ Their mismatch matters when predicted slots are wrong.
127
+
128
+ Both empty branches use native empty conditioning. When their predictions agree
129
+ exactly, empty error vanishes and the guided error becomes $4.5^2$ times positive
130
+ error. The numerator then simplifies to **2.0125 times positive MSE**. The code
131
+ retains the full expression, including any cached-versus-live numerical
132
+ discrepancy. This run principally matches the conditional recipient response;
133
+ it does not learn a new unconditional branch.
134
+
135
+ LPIPS, pixel error, and CLIP judge rendered outputs for selection/evaluation;
136
+ they are not differentiable image losses in this run. Full-sampler
137
+ backpropagation was tested in separate arms and did not win the combined
138
+ validation ranking.
139
+
140
+ ## What training changes
141
+
142
+ The run initializes the already-trained parent and updates the **887,040 output
143
+ projection parameters** that receive nonzero gradients. The `heads` setting also
144
+ enables 385 mask-head parameters, but mask BCE has weight zero and hard thresholds
145
+ supply no functional mask gradient. Their values remain unchanged during training.
146
+
147
+ | Setting | Winning continuation |
148
+ |---|---|
149
+ | Optimizer | Adam, betas (0.0, 0.999), epsilon 1e-8, no weight decay |
150
+ | Learning rate | 1e-5; held through 60% of the run, then cosine toward a 5% floor |
151
+ | Updates and selection | 1,500 completed; EMA update 1,250 selected |
152
+ | EMA | Decay 0.98 |
153
+ | Gradient clipping | Global bridge gradient norm at 1.0 |
154
+ | Embedding batch | 32 rows: 31 sampled captions plus one empty row |
155
+ | Functional batch | Four positive examples every update |
156
+ | State mixture | Each update chooses cached native states with probability 0.5, otherwise fresh initial noise |
157
+ | Native cache | 512 training captions × five states, with cached teacher predictions |
158
+ | Training data | 8,192 paired captions; no image reconstruction cache in this run |
159
+ | Frozen components | Source projection, queries, four blocks, router, cloud, particle projection, calibration buffers, CLIP, SANA, DC-AE |
160
+ | Inactive loss terms | GAN/b_cap, critic features, mask BCE, particle VICReg/centering, padding, soft masks, full rollouts |
161
+
162
+ After training, mask calibration **subtracts 2.0417721271514893** from the old
163
+ mask bias, equivalent to raising the old-logit threshold by that amount. It
164
+ minimizes mask errors on 58 validation prompts. Ordinary inference thresholds
165
+ the resulting logits at zero and always preserves the first BOS slot.
166
+ Calibration changes one scalar and requires no fitting during deployment.
167
+
168
+ Checkpoint selection uses rendered validation LPIPS and is separate from the
169
+ optimized loss. The release contains EMA weights, not the last live optimizer
170
+ iterate. Final testing occurred after freezing selection.
171
+
172
+ The observed improvement is **1.42% lower held-out LPIPS and 2.50% lower pixel
173
+ MAE**, with confidence intervals including no improvement and composition errors
174
+ remaining. Calibration adds two missed test positions. A nonlinear frozen
175
+ recipient can respond better to an improved linear head without that head
176
+ recovering all inaccessible target directions.
177
+
178
+ ## Expanded-source alternative
179
+
180
+ The alternative preserves the parent and adds this branch to normalized output:
181
+
182
+ $$
183
+ z_j=W_oH_{4,j}+b_o+
184
+ W_2\operatorname{SiLU}(W_1H_{4,j}+b_1+W_sX_j)+b_2.
185
+ $$
186
+
187
+ $W_1$ maps 384 → 2304, $W_s$ maps the full 768 source channels directly to 2304
188
+ without bias, and $W_2$ maps 2304 → 2304. Source information can bypass the old
189
+ 768 → 384 projection, and the nonlinear branch removes its affine-output
190
+ restriction. This does not promise arbitrary mappings or aligned word positions.
191
+
192
+ This model has **15,150,149 parameters**, including **7,967,232 added branch
193
+ parameters** trained with the same active loss and schedule. The last added
194
+ projection starts at zero to preserve parent predictions; the source projection
195
+ uses full fan-in initialization scale 1.0. Its selected EMA update is 1,000,
196
+ followed by the same mask calibration. It improves mean test fidelity but loses
197
+ the combined validation ranking to the linear continuation. Both branches run
198
+ within one ordinary bridge forward.
199
+
200
+ ## Deployment and source of truth
201
+
202
+ The deployment CLI uses CLIP FP16 with batches padded to 16 to match the cached
203
+ encoder kernel shape, a FP32 bridge, and BF16 SANA. It supplies predicted positive
204
+ conditioning and the stored native empty conditioning to the pinned 20-step DPM
205
+ sampler at guidance 4.5 and 512 × 512. The bridge output is computed once and
206
+ reused throughout sampling; the original DC-AE decodes the final latent. No Gemma
207
+ encoder, teacher cache, retrieval, optimizer, or best-of-N is needed by inference.
208
+
209
+ The equations follow [the bridge](https://github.com/255BITS/model-glue/blob/main/model_glue/text_bridge.py),
210
+ [training and guidance metrics](https://github.com/255BITS/model-glue/blob/main/model_glue/text_train.py),
211
+ [inference](https://github.com/255BITS/model-glue/blob/main/model_glue/sana_infer.py), and
212
+ [mask calibration](https://github.com/255BITS/model-glue/blob/main/scripts/calibrate_text_mask.py). Exact model/checkpoint
213
+ revisions are recorded in the release manifest and experiment JSON.
README.md CHANGED
@@ -13,6 +13,7 @@ tags:
13
  base_model:
14
  - stable-diffusion-v1-5/stable-diffusion-v1-5
15
  - Efficient-Large-Model/Sana_600M_512px_diffusers
 
16
  inference: false
17
  ---
18
 
@@ -42,6 +43,68 @@ retains the linear head. All three checkpoints include the complete bridge, clou
42
  calibration buffers, architecture metadata, and pinned source/recipient identities.
43
  They load directly without the parent checkpoint or training caches.
44
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
45
  ## Run
46
 
47
  Use the implementation revision that was tested for this release:
 
13
  base_model:
14
  - stable-diffusion-v1-5/stable-diffusion-v1-5
15
  - Efficient-Large-Model/Sana_600M_512px_diffusers
16
+ base_model_relation: adapter
17
  inference: false
18
  ---
19
 
 
43
  calibration buffers, architecture metadata, and pinned source/recipient identities.
44
  They load directly without the parent checkpoint or training caches.
45
 
46
+ ## Architecture and winning objective
47
+
48
+ The default contains **7,182,917 parameters**. SD1.5 CLIP provides 77 × 768
49
+ contextual states. LayerNorm and a linear 768 → 384 layer produce source features.
50
+ A mean-pooled source passes through a 768 → 64 → 4 SiLU router; softmax attention
51
+ over the saved 256 × 4 particle cloud gives a deterministic four-dimensional
52
+ mixture. Its projection offsets 77 learned queries, which also receive the
53
+ projected source states.
54
+
55
+ Four width-384 blocks each apply six-head cross-attention to the source followed
56
+ by a 384 → 1152 → 384 GELU feed-forward network, with residual connections and
57
+ LayerNorm. A final linear 384 → 2304 head produces normalized conditioning,
58
+ rescaled with saved target statistics. A separate linear 384 → 1 head predicts
59
+ mask logits. The first BOS slot is always kept.
60
+
61
+ The donor diffusion U-Net is outside this path. This checkpoint transfers CLIP
62
+ text states; it does not establish transfer of SD's generated style or composition.
63
+
64
+ The winning continuation updates only the **887,040 output-projection parameters**
65
+ that receive nonzero gradients. The parent stem, router, cloud, and mask values
66
+ remain fixed during training. Afterward, validation calibration subtracts
67
+ 2.0417721271514893 from the old mask-head bias. The release stores that fixed
68
+ adjustment and thresholds its logits at zero.
69
+
70
+ The active training objective is:
71
+
72
+ $$
73
+ L=0.1L_{embed}+
74
+ \frac{\operatorname{MSE}(s_+,t_+)+\operatorname{MSE}(s_0,t_0)
75
+ +0.05\operatorname{MSE}(g_s,g_t)}
76
+ {\max(10^{-5},\operatorname{mean}((t_+-t_0)^2))},
77
+ $$
78
+
79
+ where $L_{embed}$ is embedding squared error on teacher-valid tokens, divided by
80
+ the saved per-channel variance. $s_+,s_0$ and $t_+,t_0$ are frozen-SANA predictions
81
+ with student and native positive/empty conditioning at the same latent and
82
+ timestep. The guided predictions are $g_s=s_0+4.5(s_+-s_0)$ and
83
+ $g_t=t_0+4.5(t_+-t_0)$. The denominator is detached native prompt-effect power.
84
+ Student calls backpropagate into the bridge; teacher calls and SANA parameters
85
+ remain frozen. Both empty branches use stored native conditioning.
86
+
87
+ The run uses Adam at initial LR 1e-5, betas (0.0, 0.999), delayed cosine decay,
88
+ gradient clipping at 1.0, and EMA 0.98. Each update uses 32 embedding rows and
89
+ four functional examples; it chooses cached native states with probability 0.5
90
+ and fresh initial noise otherwise. Selection uses rendered validation LPIPS.
91
+
92
+ **GAN, b_cap, critic-feature, particle, mask-BCE, soft-mask, and full-rollout losses
93
+ are inactive in this winning continuation.** Its parent has ParticleGAN provenance.
94
+ LPIPS and CLIP are evaluation signals here, not differentiable image losses.
95
+ The bridge runs once per prompt; ordinary SANA sampling reuses its conditioning.
96
+
97
+ The expanded-source alternative adds
98
+ $W_2\operatorname{SiLU}(W_1h+W_sx+b_1)+b_2$ alongside the original output head.
99
+ Its hidden branch is 2304-wide and sees the full 768-channel source directly.
100
+ It has **15,150,149 parameters**, with **7,967,232 new branch parameters** trained
101
+ under the same active loss. It removes the old source-projection blind space and
102
+ affine-output restriction but did not win combined validation.
103
+
104
+ The [complete formulation](https://huggingface.co/ntc-ai/model-glue-sd15-sana-text/blob/main/FORMULATION.md)
105
+ includes equations, an architecture diagram, parameter counts, the mask
106
+ calibration sign, training controls, and deployment details.
107
+
108
  ## Run
109
 
110
  Use the implementation revision that was tested for this release:
SHA256SUMS CHANGED
@@ -1,5 +1,6 @@
 
1
  f50d7a3340d8e33d65e6905d6471ee64c2217a0a20f54a67922f96e02ec6a42b LICENSE
2
- 8786e5eaf37799205bbc1f25cdd4cf4d965a9ad208e544e3a53d2656f7ae62a6 README.md
3
  1a2db74c6c2d940ee15a845a7e60404ffbe32573757672586a18c578db36a10a alternatives/expanded-source.safetensors
4
  fc7f44369cf21791c4f9ad6b74978dd420be41a76330a1fe32b11f440f3bf925 alternatives/linear-uncalibrated.safetensors
5
  aea09893f34769c9b4eef9c30ab9711c935854ec3cf29571aee81cc2367109d7 config.json
@@ -10,7 +11,7 @@ ceca1ec0fcac308fc6a565452f3dc67ce90dcd21e323acefd6df21cc9c1b78b4 configs/source
10
  4dc2536374ff7b33c85e7bf21e55977737d4e3cd7d0a6db9189812972dbdf469 configs/validation-confirmation.json
11
  12de8ae1a69eff31879911c50068af1a2fe77bd5f56dbbf5cf1e6743464eca06 figures/bench-comparison.jpg
12
  d3f12c915d977e11bbffc83b6e1ba94fabe5feafe2a3a35b0ee6c84e34e77654 figures/first-four-test-prompts.jpg
13
- 635da76e075a43329ac4700a2f3a0e5cb71434be04f0828de29fc0a5b69acbcb manifest.json
14
  d3be2492e49f6eb1bc28a406d35108f1055e3dd19e412792442b4c5d9274bb4d model.safetensors
15
  5416eac9605b2e0af6b5325be168dbd86bdb8a7d5f241f5481dee417e439c349 reports/mask-metrics.json
16
  fabd67b38e5a5e878f63bbb0f6de0278c4bcc459d0603957ce3603417f1fddf2 reports/retraining.json
 
1
+ cd4bee587e4e1d8dc12049bccc5ce11e8aba5f1c3d3de74b160d67a1535562e8 FORMULATION.md
2
  f50d7a3340d8e33d65e6905d6471ee64c2217a0a20f54a67922f96e02ec6a42b LICENSE
3
+ 749dc3da10cbb821da5a47641e047fe85192ffa696939865b9f6451e0cb01c5c README.md
4
  1a2db74c6c2d940ee15a845a7e60404ffbe32573757672586a18c578db36a10a alternatives/expanded-source.safetensors
5
  fc7f44369cf21791c4f9ad6b74978dd420be41a76330a1fe32b11f440f3bf925 alternatives/linear-uncalibrated.safetensors
6
  aea09893f34769c9b4eef9c30ab9711c935854ec3cf29571aee81cc2367109d7 config.json
 
11
  4dc2536374ff7b33c85e7bf21e55977737d4e3cd7d0a6db9189812972dbdf469 configs/validation-confirmation.json
12
  12de8ae1a69eff31879911c50068af1a2fe77bd5f56dbbf5cf1e6743464eca06 figures/bench-comparison.jpg
13
  d3f12c915d977e11bbffc83b6e1ba94fabe5feafe2a3a35b0ee6c84e34e77654 figures/first-four-test-prompts.jpg
14
+ 97e480871c159c26545f77c87bc81d6c9b83e55bd5817c6beba16d9701f6656a manifest.json
15
  d3be2492e49f6eb1bc28a406d35108f1055e3dd19e412792442b4c5d9274bb4d model.safetensors
16
  5416eac9605b2e0af6b5325be168dbd86bdb8a7d5f241f5481dee417e439c349 reports/mask-metrics.json
17
  fabd67b38e5a5e878f63bbb0f6de0278c4bcc459d0603957ce3603417f1fddf2 reports/retraining.json
manifest.json CHANGED
@@ -142,13 +142,17 @@
142
  }
143
  },
144
  "files": {
 
 
 
 
145
  "LICENSE": {
146
  "sha256": "f50d7a3340d8e33d65e6905d6471ee64c2217a0a20f54a67922f96e02ec6a42b",
147
  "size_bytes": 1064
148
  },
149
  "README.md": {
150
- "sha256": "8786e5eaf37799205bbc1f25cdd4cf4d965a9ad208e544e3a53d2656f7ae62a6",
151
- "size_bytes": 7968
152
  },
153
  "alternatives/expanded-source.safetensors": {
154
  "sha256": "1a2db74c6c2d940ee15a845a7e60404ffbe32573757672586a18c578db36a10a",
 
142
  }
143
  },
144
  "files": {
145
+ "FORMULATION.md": {
146
+ "sha256": "cd4bee587e4e1d8dc12049bccc5ce11e8aba5f1c3d3de74b160d67a1535562e8",
147
+ "size_bytes": 10246
148
+ },
149
  "LICENSE": {
150
  "sha256": "f50d7a3340d8e33d65e6905d6471ee64c2217a0a20f54a67922f96e02ec6a42b",
151
  "size_bytes": 1064
152
  },
153
  "README.md": {
154
+ "sha256": "749dc3da10cbb821da5a47641e047fe85192ffa696939865b9f6451e0cb01c5c",
155
+ "size_bytes": 11406
156
  },
157
  "alternatives/expanded-source.safetensors": {
158
  "sha256": "1a2db74c6c2d940ee15a845a7e60404ffbe32573757672586a18c578db36a10a",