Nekochu commited on
Commit
d0c692f
·
verified ·
1 Parent(s): bb452ca

Seeds match dflow/ComfyUI (torch.randn port); LoRA card example link; compact settings

Browse files
Files changed (3) hide show
  1. app.js +44 -14
  2. index.html +3 -1
  3. style.css +1 -0
app.js CHANGED
@@ -127,22 +127,43 @@ function vaeTables(gh, gw) {
127
  }
128
 
129
  // ---------- noise ----------
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
130
  function gaussianNoise(count, seed) {
131
- let s = (seed >>> 0) || 1;
132
- const next = () => { // mulberry32
133
- s = (s + 0x6d2b79f5) >>> 0;
134
- let t = s;
135
- t = Math.imul(t ^ (t >>> 15), t | 1);
136
- t ^= t + Math.imul(t ^ (t >>> 7), t | 61);
137
- return ((t ^ (t >>> 14)) >>> 0) / 4294967296;
 
 
138
  };
139
- const out = new Float32Array(count);
140
- for (let i = 0; i < count; i += 2) {
141
- const u = Math.max(next(), 1e-12), v = next(), r = Math.sqrt(-2 * Math.log(u));
142
- out[i] = r * Math.cos(2 * Math.PI * v);
143
- if (i + 1 < count) out[i + 1] = r * Math.sin(2 * Math.PI * v);
144
- }
145
- return out;
146
  }
147
 
148
  // ---------- downloads ----------
@@ -480,6 +501,15 @@ async function init() {
480
  ui.random.addEventListener('change', () => { ui.seed.disabled = ui.random.checked; });
481
  ui.seed.disabled = ui.random.checked;
482
  ui.save.addEventListener('click', (e) => { if (ui.save.classList.contains('disabled')) e.preventDefault(); });
 
 
 
 
 
 
 
 
 
483
  try { // drop files of older page versions
484
  for (const k of await caches.keys()) if (k.startsWith('dflow2-web-') && k !== CACHE) await caches.delete(k);
485
  } catch { /* no Cache API */ }
 
127
  }
128
 
129
  // ---------- noise ----------
130
+ // Same numbers as torch.randn(shape, generator=torch.Generator('cpu').manual_seed(seed)), which
131
+ // is how dflow draws its starting noise: mt19937, uniforms u = (r & 0xFFFFFF) / 2^24, then
132
+ // Box-Muller over blocks of 16 (ATen normal_fill). So a seed here gives the same picture as the
133
+ // same seed in dflow, ComfyUI or the LoRA card (within float rounding).
134
+ function mt19937(seed) {
135
+ const mt = new Uint32Array(624);
136
+ mt[0] = seed >>> 0;
137
+ for (let i = 1; i < 624; i++) mt[i] = (Math.imul(1812433253, mt[i - 1] ^ (mt[i - 1] >>> 30)) + i) >>> 0;
138
+ let idx = 624;
139
+ return () => {
140
+ if (idx >= 624) {
141
+ for (let i = 0; i < 624; i++) {
142
+ const y = (mt[i] & 0x80000000) | (mt[(i + 1) % 624] & 0x7fffffff);
143
+ mt[i] = mt[(i + 397) % 624] ^ (y >>> 1) ^ (y & 1 ? 0x9908b0df : 0);
144
+ }
145
+ idx = 0;
146
+ }
147
+ let y = mt[idx++];
148
+ y ^= y >>> 11; y ^= (y << 7) & 0x9d2c5680; y ^= (y << 15) & 0xefc60000; y ^= y >>> 18;
149
+ return y >>> 0;
150
+ };
151
+ }
152
+
153
  function gaussianNoise(count, seed) {
154
+ const next = mt19937(seed), d = new Float32Array(count);
155
+ const uniform = () => (next() & 0xffffff) / 16777216;
156
+ for (let i = 0; i < count; i++) d[i] = uniform();
157
+ const fill16 = (o) => {
158
+ for (let j = 0; j < 8; j++) {
159
+ const r = fr(Math.sqrt(fr(-2 * fr(Math.log(fr(1 - d[o + j]))))));
160
+ const th = fr(2 * Math.PI * d[o + j + 8]);
161
+ d[o + j] = fr(r * fr(Math.cos(th))); d[o + j + 8] = fr(r * fr(Math.sin(th)));
162
+ }
163
  };
164
+ for (let o = 0; o + 16 <= count; o += 16) fill16(o);
165
+ if (count % 16) { const o = count - 16; for (let j = 0; j < 16; j++) d[o + j] = uniform(); fill16(o); }
166
+ return d;
 
 
 
 
167
  }
168
 
169
  // ---------- downloads ----------
 
501
  ui.random.addEventListener('change', () => { ui.seed.disabled = ui.random.checked; });
502
  ui.seed.disabled = ui.random.checked;
503
  ui.save.addEventListener('click', (e) => { if (ui.save.classList.contains('disabled')) e.preventDefault(); });
504
+ $('example').addEventListener('click', (e) => { // the LoRA card's snow leopard: same prompt, seed, size
505
+ e.preventDefault();
506
+ ui.prompt.value = 'A snow leopard walking along a rocky ridge in falling snow, telephoto wildlife photograph, natural light';
507
+ ui.random.checked = false; ui.seed.disabled = false; ui.seed.value = 4242;
508
+ const card = [...ui.size.options].some((o) => o.value === '1824x1024');
509
+ if (card) ui.size.value = '1824x1024';
510
+ status(card ? 'Card example loaded. Generate, then compare with the card image.'
511
+ : 'Card example loaded, but this GPU cannot do 1824×1024, so the result will differ from the card image.', null, !card);
512
+ });
513
  try { // drop files of older page versions
514
  for (const k of await caches.keys()) if (k.startsWith('dflow2-web-') && k !== CACHE) await caches.delete(k);
515
  } catch { /* no Cache API */ }
index.html CHANGED
@@ -17,7 +17,9 @@
17
  <section id="input">
18
  <label for="prompt" class="sr">Prompt</label>
19
  <textarea id="prompt" rows="7" spellcheck="false">A snow leopard walking along a rocky ridge in falling snow, telephoto wildlife photograph, natural light</textarea>
20
- <p class="hint">Describe a photo or a painting: subject, setting, light, medium. Text in "double quotes" is spelled letter by letter. Detail grows with size: the model was trained at about 1 MP, 512² is a quick preview.</p>
 
 
21
  </section>
22
 
23
  <section id="settings">
 
17
  <section id="input">
18
  <label for="prompt" class="sr">Prompt</label>
19
  <textarea id="prompt" rows="7" spellcheck="false">A snow leopard walking along a rocky ridge in falling snow, telephoto wildlife photograph, natural light</textarea>
20
+ <p class="hint">Describe subject, setting, light and medium; "quoted text" is spelled letter by letter. Trained at about 1 MP, so 512² is only a preview.
21
+ Seeds match dflow: <a href="#" id="example">load the LoRA card example</a> (seed 4242, 1824×1024) and compare with
22
+ <a href="https://huggingface.co/lvladikov/DFlow2-Distill-4steps-eDMD-LADD-LoRA/blob/main/assets/images/snowleopard.jpg" target="_blank" rel="noopener">the card image</a>.</p>
23
  </section>
24
 
25
  <section id="settings">
style.css CHANGED
@@ -38,6 +38,7 @@ textarea {
38
  }
39
  .hint { margin: 2px 0 0; font-size: 12px; color: var(--muted); }
40
  @media (max-height: 480px) { .hint { display: none; } #line { font-size: 13px; } }
 
41
  label { font-size: 14px; display: inline-flex; gap: 6px; align-items: center; }
42
  select, input[type=number] {
43
  font: inherit; min-height: 30px; padding: 2px 6px; color: var(--ink); background: var(--panel);
 
38
  }
39
  .hint { margin: 2px 0 0; font-size: 12px; color: var(--muted); }
40
  @media (max-height: 480px) { .hint { display: none; } #line { font-size: 13px; } }
41
+ @media (max-width: 599px) { textarea { height: calc(5 * 1.4em + 14px); max-height: calc(5 * 1.4em + 14px); } }
42
  label { font-size: 14px; display: inline-flex; gap: 6px; align-items: center; }
43
  select, input[type=number] {
44
  font: inherit; min-height: 30px; padding: 2px 6px; color: var(--ink); background: var(--panel);