Skip to content

Commit 4c451ad

Browse files
physicsrobclaude
andcommitted
publish: per-bundle width overrides; compact n=3 trio shipped
build_bundle and the modal spec grammar (name:n[:d[:d_hidden]]) gain d / d_hidden overrides for right-sized small-n bundles; d_head stays graph-baked. The card states each bundle's own compile width instead of assuming the family geometry, and push_remote prunes stale remote shards when a replacement bundle has fewer. Shipped 2026-07-26: the three n=3 repos replaced at 2048:4096 — the measured free-shrink geometry (scripts/measure_calculator_compiled_ layers: floor-optimal at 27/29/18 layers, same as canonical; the publish path's RMS reserved column cost zero). simple n=3 drops 14.26GB -> 4.08GB. Depth-sweep artifacts (n>=5 repos, layer table, blog figure) stay at the canonical shared geometry. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
1 parent 856d281 commit 4c451ad

2 files changed

Lines changed: 68 additions & 13 deletions

File tree

examples/compile.py

Lines changed: 41 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -89,8 +89,8 @@
8989
9090
## Size
9191
92-
The checkpoint stores {size_gb} GB of dense fp32 weights ({total} entries) at
93-
the example family's shared compile width. {zero_pct}% of those entries are
92+
The checkpoint stores {size_gb} GB of dense fp32 weights ({total} entries){width}.
93+
{zero_pct}% of those entries are
9494
exactly zero: the vast majority of the model is unused canvas, so size reflects
9595
the compile geometry rather than stored knowledge.
9696
@@ -245,7 +245,15 @@ def write_card(
245245
card += _CARD_LIMITS
246246
card += _CARD_VERIFICATION
247247
nonzero, total, size_bytes = _weight_stats(out_dir)
248+
config_path = Path(out_dir, "config.json")
249+
width = ""
250+
if config_path.is_file():
251+
with config_path.open() as f:
252+
hidden = json.load(f).get("hidden_size")
253+
if hidden:
254+
width = f" at compile width d={hidden}"
248255
card += _CARD_SIZE.format(
256+
width=width,
249257
zero_pct=f"{100.0 * (1.0 - nonzero / total):.2f}",
250258
total=f"{total:,}",
251259
size_gb=f"{size_bytes / 1e9:.2f}",
@@ -335,14 +343,20 @@ def build_bundle(
335343
*,
336344
max_digits: int | None = None,
337345
optimize: int = 0,
346+
d: int | None = None,
347+
d_hidden: int | None = None,
338348
) -> tuple[str, list[str] | None, int]:
339349
"""Compile ``examples.<name>`` into an HF bundle with its model card.
340350
341351
``max_digits`` threads through to ``create_network_parts`` for the
342352
examples that take it (the calculator family); passing it for one
343-
that doesn't raises. Returns ``(out_dir, demo prompts or None,
344-
generation budget)`` — the demo itself is the caller's decision,
345-
not part of the build.
353+
that doesn't raises. ``d`` / ``d_hidden`` override the module's
354+
family geometry — for right-sized small-n bundles whose free-shrink
355+
region is measured (scripts/measure_calculator_compiled_layers);
356+
``d_head`` is never overridable (it is baked into the graph at
357+
build time). Returns ``(out_dir, demo prompts or None, generation
358+
budget)`` — the demo itself is the caller's decision, not part of
359+
the build.
346360
"""
347361
module = importlib.import_module(f"examples.{name}")
348362
if not hasattr(module, "create_network_parts"):
@@ -365,10 +379,12 @@ def build_bundle(
365379
output_node,
366380
embedding,
367381
out_dir,
368-
d=getattr(module, "D_MODEL", 1024),
382+
d=d if d is not None else int(getattr(module, "D_MODEL", 1024)),
369383
d_head=getattr(module, "D_HEAD", 16),
370384
n_heads=getattr(module, "N_HEADS", None),
371-
d_hidden=getattr(module, "D_HIDDEN", None),
385+
d_hidden=d_hidden
386+
if d_hidden is not None
387+
else getattr(module, "D_HIDDEN", None),
372388
optimize=optimize,
373389
)
374390
write_card(name, out_dir, max_digits)
@@ -391,6 +407,18 @@ def main() -> None:
391407
help="operand digit width, for examples whose create_network_parts "
392408
"takes max_digits (default: the example's own default)",
393409
)
410+
ap.add_argument(
411+
"--d",
412+
type=int,
413+
default=None,
414+
help="override the module's D_MODEL (right-sized small-n bundles)",
415+
)
416+
ap.add_argument(
417+
"--d-hidden",
418+
type=int,
419+
default=None,
420+
help="override the module's D_HIDDEN",
421+
)
394422
ap.add_argument(
395423
"--optimize",
396424
type=int,
@@ -401,7 +429,12 @@ def main() -> None:
401429

402430
try:
403431
out_dir, prompts, max_new_tokens = build_bundle(
404-
args.name, args.out, max_digits=args.max_digits, optimize=args.optimize
432+
args.name,
433+
args.out,
434+
max_digits=args.max_digits,
435+
optimize=args.optimize,
436+
d=args.d,
437+
d_hidden=args.d_hidden,
405438
)
406439
except ValueError as exc:
407440
raise SystemExit(str(exc)) from None

modal_compile.py

Lines changed: 27 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ def repo_name(name: str, max_digits: int | None) -> str:
6666
def compile_remote(spec: tuple) -> dict:
6767
from examples.compile import build_bundle, bundle_dirname, run_prompts
6868

69-
name, max_digits, optimize = spec
69+
name, max_digits, optimize, d, d_hidden = (*spec, None, None)[:5]
7070
dirname = bundle_dirname(name, max_digits)
7171
t0 = time.time()
7272
try:
@@ -75,6 +75,8 @@ def compile_remote(spec: tuple) -> dict:
7575
str(Path(BUNDLE_ROOT) / dirname),
7676
max_digits=max_digits,
7777
optimize=optimize,
78+
d=d,
79+
d_hidden=d_hidden,
7880
)
7981
except (ValueError, RuntimeError) as exc:
8082
# A cell can refuse to build (calculator_memorize past n=2) or to
@@ -263,19 +265,39 @@ def push_remote(dirname: str, repo_id: str) -> str:
263265

264266
api = HfApi()
265267
api.create_repo(repo_id, exist_ok=True)
266-
api.upload_folder(folder_path=str(Path(BUNDLE_ROOT) / dirname), repo_id=repo_id)
268+
api.upload_folder(
269+
folder_path=str(Path(BUNDLE_ROOT) / dirname),
270+
repo_id=repo_id,
271+
# A replacement bundle may have fewer shards than its
272+
# predecessor; stale remote shards would linger (the index
273+
# ignores them, but they bloat and confuse the repo).
274+
delete_patterns=["model-*.safetensors"],
275+
)
267276
return f"https://huggingface.co/{repo_id}"
268277

269278

270279
@app.local_entrypoint()
271280
def main(specs: str, optimize: int = 0, push_prefix: str = "") -> None:
272281
cells = []
273282
for cell_spec in specs.split(","):
274-
cell_name, _, digits = cell_spec.partition(":")
275-
cells.append((cell_name.strip(), int(digits) if digits else None, optimize))
283+
# name[:max_digits[:d[:d_hidden]]] — trailing fields optional.
284+
fields = [f or None for f in cell_spec.strip().split(":")]
285+
fields += [None] * (4 - len(fields))
286+
name_part, digits, d, d_hidden = fields[:4]
287+
if not name_part:
288+
raise ValueError(f"bad spec: {cell_spec!r}")
289+
cells.append(
290+
(
291+
name_part,
292+
int(digits) if digits else None,
293+
optimize,
294+
int(d) if d else None,
295+
int(d_hidden) if d_hidden else None,
296+
)
297+
)
276298

277299
to_push = []
278-
for (name, n, _), row in zip(cells, compile_remote.map(cells), strict=True):
300+
for (name, n, *_rest), row in zip(cells, compile_remote.map(cells), strict=True):
279301
print(row, flush=True)
280302
if push_prefix and "error" not in row:
281303
to_push.append((row["bundle"], f"{push_prefix}{repo_name(name, n)}"))

0 commit comments

Comments
 (0)