CompressedGemma commited on
Commit
e9e0544
·
verified ·
1 Parent(s): cec4bd4

Upload 8 files

Browse files
Files changed (4) hide show
  1. __main__.py +10 -0
  2. anneal.py +17 -8
  3. config.py +8 -0
  4. gui.py +10 -0
__main__.py CHANGED
@@ -49,6 +49,8 @@ def _config_from_args(args) -> HPCConfig:
49
  cfg.use_spectral = False
50
  if args.thermal is not None:
51
  cfg.therm_passes = int(args.thermal)
 
 
52
  if args.no_q4_fallback:
53
  cfg.enable_q4_fallback = False
54
  if args.keep_embd:
@@ -286,6 +288,14 @@ def main() -> None:
286
  metavar="PASSES",
287
  help="thermal refinery heat-bath passes after Phase 4 (default 0 = off; seeded, bit-exact per seed)",
288
  )
 
 
 
 
 
 
 
 
289
  parser.add_argument(
290
  "--format",
291
  choices=("mixed", "mixed_q1", "custom", "q1_0", "q3_k", "q4_0", "q2_k"),
 
49
  cfg.use_spectral = False
50
  if args.thermal is not None:
51
  cfg.therm_passes = int(args.thermal)
52
+ if args.thermal_tilt is not None:
53
+ cfg.therm_lambda_tilt = float(args.thermal_tilt)
54
  if args.no_q4_fallback:
55
  cfg.enable_q4_fallback = False
56
  if args.keep_embd:
 
288
  metavar="PASSES",
289
  help="thermal refinery heat-bath passes after Phase 4 (default 0 = off; seeded, bit-exact per seed)",
290
  )
291
+ parser.add_argument(
292
+ "--thermal-tilt",
293
+ type=float,
294
+ default=None,
295
+ metavar="TILT",
296
+ help="zero-residual anneal: multiplier (>=1, 1=off) on dc/vw lambdas during thermal passes; "
297
+ "~100-1e3 drives the coherent residual (row DC + vesica) toward zero, spending weighted SSE",
298
+ )
299
  parser.add_argument(
300
  "--format",
301
  choices=("mixed", "mixed_q1", "custom", "q1_0", "q3_k", "q4_0", "q2_k"),
anneal.py CHANGED
@@ -31,6 +31,19 @@ from .q2k import QK_K
31
  EPS_D = 1.0e-15
32
 
33
 
 
 
 
 
 
 
 
 
 
 
 
 
 
34
  def pair_energy(
35
  e: np.ndarray,
36
  w: np.ndarray | None,
@@ -188,8 +201,7 @@ def thermal_refine_codes(
188
  """
189
  n_blocks = X.shape[0]
190
  n_passes = cfg.therm_passes if passes is None else int(passes)
191
- lam_vw = (float(cfg.vw_lambda) / QK_K) if cfg.use_spectral else 0.0
192
- lam_dc = (float(cfg.dc_lambda) / QK_K) if cfg.use_spectral else 0.0
193
  if n_blocks == 0 or n_passes == 0 or (lam_vw == 0.0 and lam_dc == 0.0):
194
  return d, m, ls, lm, codes, 0
195
  if cfg.fold_depth > 1:
@@ -472,8 +484,7 @@ def thermal_refine_q4_0(
472
  a no-op when the refinery or spectrals are disabled.
473
  """
474
  n_blocks, n = X.shape
475
- lam_vw = (float(cfg.vw_lambda) / n) if cfg.use_spectral else 0.0
476
- lam_dc = (float(cfg.dc_lambda) / n) if cfg.use_spectral else 0.0
477
  if n_blocks == 0 or cfg.therm_passes == 0 or (lam_vw == 0.0 and lam_dc == 0.0):
478
  return q.copy(), 0
479
  d64 = np.asarray(d, dtype=np.float64)
@@ -505,8 +516,7 @@ def thermal_refine_q1_0(
505
  uint8 bits and the number of strictly improved blocks.
506
  """
507
  n_blocks, n = X.shape
508
- lam_vw = (float(cfg.vw_lambda) / n) if cfg.use_spectral else 0.0
509
- lam_dc = (float(cfg.dc_lambda) / n) if cfg.use_spectral else 0.0
510
  if n_blocks == 0 or cfg.therm_passes == 0 or (lam_vw == 0.0 and lam_dc == 0.0):
511
  return bits.copy(), 0
512
  d64 = np.asarray(d, dtype=np.float64)
@@ -539,8 +549,7 @@ def thermal_refine_q3_k(
539
  polish outputs) are handled exactly via signed steps.
540
  """
541
  n_blocks, n = X.shape
542
- lam_vw = (float(cfg.vw_lambda) / n) if cfg.use_spectral else 0.0
543
- lam_dc = (float(cfg.dc_lambda) / n) if cfg.use_spectral else 0.0
544
  if n_blocks == 0 or cfg.therm_passes == 0 or (lam_vw == 0.0 and lam_dc == 0.0):
545
  return np.asarray(codes).copy(), 0
546
  scale64 = np.asarray(scale, dtype=np.float64)
 
31
  EPS_D = 1.0e-15
32
 
33
 
34
+ def thermal_spectral_lams(cfg: HPCConfig, n: int) -> tuple[float, float]:
35
+ """Per-code-normalized ``(lam_vw, lam_dc)`` with the zero-residual tilt applied.
36
+
37
+ ``therm_lambda_tilt`` scales both spectral lambdas during annealing so the
38
+ exact Gibbs chain trades weighted SSE for coherent-residual (DC/vesica)
39
+ drain; ``1.0`` (default) is the shipping objective.
40
+ """
41
+ if not cfg.use_spectral:
42
+ return 0.0, 0.0
43
+ tilt = max(1.0, float(cfg.therm_lambda_tilt))
44
+ return (float(cfg.vw_lambda) / n) * tilt, (float(cfg.dc_lambda) / n) * tilt
45
+
46
+
47
  def pair_energy(
48
  e: np.ndarray,
49
  w: np.ndarray | None,
 
201
  """
202
  n_blocks = X.shape[0]
203
  n_passes = cfg.therm_passes if passes is None else int(passes)
204
+ lam_vw, lam_dc = thermal_spectral_lams(cfg, QK_K)
 
205
  if n_blocks == 0 or n_passes == 0 or (lam_vw == 0.0 and lam_dc == 0.0):
206
  return d, m, ls, lm, codes, 0
207
  if cfg.fold_depth > 1:
 
484
  a no-op when the refinery or spectrals are disabled.
485
  """
486
  n_blocks, n = X.shape
487
+ lam_vw, lam_dc = thermal_spectral_lams(cfg, n)
 
488
  if n_blocks == 0 or cfg.therm_passes == 0 or (lam_vw == 0.0 and lam_dc == 0.0):
489
  return q.copy(), 0
490
  d64 = np.asarray(d, dtype=np.float64)
 
516
  uint8 bits and the number of strictly improved blocks.
517
  """
518
  n_blocks, n = X.shape
519
+ lam_vw, lam_dc = thermal_spectral_lams(cfg, n)
 
520
  if n_blocks == 0 or cfg.therm_passes == 0 or (lam_vw == 0.0 and lam_dc == 0.0):
521
  return bits.copy(), 0
522
  d64 = np.asarray(d, dtype=np.float64)
 
549
  polish outputs) are handled exactly via signed steps.
550
  """
551
  n_blocks, n = X.shape
552
+ lam_vw, lam_dc = thermal_spectral_lams(cfg, n)
 
553
  if n_blocks == 0 or cfg.therm_passes == 0 or (lam_vw == 0.0 and lam_dc == 0.0):
554
  return np.asarray(codes).copy(), 0
555
  scale64 = np.asarray(scale, dtype=np.float64)
config.py CHANGED
@@ -83,6 +83,12 @@ class HPCConfig:
83
  therm_t0: float = 0.25
84
  therm_t_decay: float = 0.35
85
  therm_seed: int = 271828
 
 
 
 
 
 
86
 
87
  # ---- seed clamp -----------------------------------------------------
88
  clamp_kurtosis_off: float = 6.0
@@ -137,6 +143,8 @@ class HPCConfig:
137
  raise ValueError("therm_t0 must be positive")
138
  if not 0.0 < self.therm_t_decay < 1.0:
139
  raise ValueError("therm_t_decay must lie in (0, 1)")
 
 
140
  if self.device not in ("auto", "cuda", "cpu") and not self.device.startswith("cuda:"):
141
  raise ValueError("device must be 'auto', 'cuda', 'cuda:N', or 'cpu'")
142
  if self.quant_format not in ("mixed", "mixed_q1", "custom", "q1_0", "q3_k", "q4_0", "q2_k"):
 
83
  therm_t0: float = 0.25
84
  therm_t_decay: float = 0.35
85
  therm_seed: int = 271828
86
+ # Zero-residual anneal: multiplier >= 1 applied to the spectral lambdas
87
+ # (dc_lambda, vw_lambda) while annealing. At large tilts (~1e2-1e3) the
88
+ # exact-conditional Gibbs chain spends weighted SSE to drain the *coherent*
89
+ # residual (row DC + vesica pairs) toward the lattice floor, leaving an
90
+ # (almost) spectrally white error. 1.0 = off.
91
+ therm_lambda_tilt: float = 1.0
92
 
93
  # ---- seed clamp -----------------------------------------------------
94
  clamp_kurtosis_off: float = 6.0
 
143
  raise ValueError("therm_t0 must be positive")
144
  if not 0.0 < self.therm_t_decay < 1.0:
145
  raise ValueError("therm_t_decay must lie in (0, 1)")
146
+ if self.therm_lambda_tilt < 1.0:
147
+ raise ValueError("therm_lambda_tilt must be >= 1.0 (1.0 = off)")
148
  if self.device not in ("auto", "cuda", "cpu") and not self.device.startswith("cuda:"):
149
  raise ValueError("device must be 'auto', 'cuda', 'cuda:N', or 'cpu'")
150
  if self.quant_format not in ("mixed", "mixed_q1", "custom", "q1_0", "q3_k", "q4_0", "q2_k"):
gui.py CHANGED
@@ -182,6 +182,7 @@ class HPCQuantizeGUI:
182
  self.dc_decay_var = tk.DoubleVar(value=0.85)
183
  self.sse_budget_var = tk.DoubleVar(value=0.0005)
184
  self.thermal_var = tk.IntVar(value=0)
 
185
 
186
  self.cli_preview_var = tk.StringVar()
187
  self.status_var = tk.StringVar(value="Ready.")
@@ -474,6 +475,12 @@ class HPCQuantizeGUI:
474
  ttk.Spinbox(
475
  spec_f, from_=0, to=16, increment=1, textvariable=self.thermal_var, width=8
476
  ).grid(row=2, column=1, sticky=tk.EW, padx=4, pady=2)
 
 
 
 
 
 
477
 
478
  # Right: GGUF Tensor Browser
479
  browser_frame = ttk.LabelFrame(right_pane, text="3. GGUF Tensor Inspector & Live Status", padding=8)
@@ -801,6 +808,7 @@ class HPCQuantizeGUI:
801
  dc_decay=float(self.dc_decay_var.get()),
802
  sse_budget=float(self.sse_budget_var.get()),
803
  therm_passes=max(0, int(self.thermal_var.get())),
 
804
  quant_format=self.quant_format_var.get(),
805
  custom_quant_map=self._custom_map_for_plan() or {},
806
  enable_q4_fallback=bool(self.q4_fallback_var.get()) and self.quant_format_var.get() not in ("q2_k", "q3_k"),
@@ -850,6 +858,8 @@ class HPCQuantizeGUI:
850
  cmd.append("--promote-attn-q4")
851
  if self.thermal_var.get() > 0:
852
  cmd += ["--thermal", str(int(self.thermal_var.get()))]
 
 
853
  cmd.append("--verbose")
854
  return " ".join(shlex.quote(part) for part in cmd)
855
 
 
182
  self.dc_decay_var = tk.DoubleVar(value=0.85)
183
  self.sse_budget_var = tk.DoubleVar(value=0.0005)
184
  self.thermal_var = tk.IntVar(value=0)
185
+ self.thermal_tilt_var = tk.DoubleVar(value=1.0)
186
 
187
  self.cli_preview_var = tk.StringVar()
188
  self.status_var = tk.StringVar(value="Ready.")
 
475
  ttk.Spinbox(
476
  spec_f, from_=0, to=16, increment=1, textvariable=self.thermal_var, width=8
477
  ).grid(row=2, column=1, sticky=tk.EW, padx=4, pady=2)
478
+ ttk.Label(spec_f, text="Zero-Residual Tilt (1=off):").grid(row=2, column=2, sticky=tk.W, padx=4, pady=2)
479
+ ttk.Entry(spec_f, textvariable=self.thermal_tilt_var, width=8).grid(row=2, column=3, sticky=tk.EW, padx=4, pady=2)
480
+ ttk.Label(
481
+ spec_f, text="(λ multiplier ≥1 during thermal anneal; ~1e2–1e3 ≈ zero-coherent-residual '0-error' anneal)",
482
+ foreground="#93c5fd",
483
+ ).grid(row=3, column=0, columnspan=4, sticky=tk.W, padx=4, pady=(0, 2))
484
 
485
  # Right: GGUF Tensor Browser
486
  browser_frame = ttk.LabelFrame(right_pane, text="3. GGUF Tensor Inspector & Live Status", padding=8)
 
808
  dc_decay=float(self.dc_decay_var.get()),
809
  sse_budget=float(self.sse_budget_var.get()),
810
  therm_passes=max(0, int(self.thermal_var.get())),
811
+ therm_lambda_tilt=max(1.0, float(self.thermal_tilt_var.get())),
812
  quant_format=self.quant_format_var.get(),
813
  custom_quant_map=self._custom_map_for_plan() or {},
814
  enable_q4_fallback=bool(self.q4_fallback_var.get()) and self.quant_format_var.get() not in ("q2_k", "q3_k"),
 
858
  cmd.append("--promote-attn-q4")
859
  if self.thermal_var.get() > 0:
860
  cmd += ["--thermal", str(int(self.thermal_var.get()))]
861
+ if self.thermal_tilt_var.get() > 1.0:
862
+ cmd += ["--thermal-tilt", str(float(self.thermal_tilt_var.get()))]
863
  cmd.append("--verbose")
864
  return " ".join(shlex.quote(part) for part in cmd)
865