From 7c20cbe4967a8a970ef0bcaf3356c8133fe842a7 Mon Sep 17 00:00:00 2001 From: phantoslayer21 <156617979+phantoslayer21@users.noreply.github.com> Date: Fri, 13 Nov 2026 17:29:31 -0500 Subject: [PATCH] Reference and packers: Model L rows (Model M's stage tables) Model L's ten Swin stages are Model M's stages with its own weights, so its rows in the model-keyed tables are Model M's rows, the same objects: the reference stage table and window offsets, the bneck and mid stage lists, the pipeline's Swin order. The stage runner accepts model="L" for them. Model M unchanged. Refs #89 Signed-off-by: phantoslayer21 <156617979+phantoslayer21@users.noreply.github.com> --- clean/reference/swin.py | 4 +++ clean/runner/packing.py | 4 +-- clean/runner/pipeline.py | 2 +- clean/tests/test_model_tables.py | 42 ++++++++++++++++++++++++++++++-- 4 files changed, 47 insertions(+), 5 deletions(-) diff --git a/clean/reference/swin.py b/clean/reference/swin.py index d6f6eaac..84591e7d 100644 --- a/clean/reference/swin.py +++ b/clean/reference/swin.py @@ -32,6 +32,10 @@ # and the model's default pair for every other stage (also for a name the model does not have, as before). _M_SHIFTED = {s: ((0, 0), (2, 0)) for s in ("b1", "b3", "b5", "dec2", "dec1")} WINDOW_OFFSETS = {"M": {"stages": _M_SHIFTED, "default": ((2, 2), (0, 2))}} +# Model L (#89, clean/l): its ten Swin stages are Model M's stages (same shapes, offsets and blobs, its own weights), so +# its rows are Model M's rows (the same objects). Its extra width-32 blocks live in clean/l/reference/table.py. +MODEL_STAGES["L"] = MODEL_STAGES["M"] +WINDOW_OFFSETS["L"] = WINDOW_OFFSETS["M"] def _model_row(table, model, what): diff --git a/clean/runner/packing.py b/clean/runner/packing.py index 43f2694f..45f5294b 100644 --- a/clean/runner/packing.py +++ b/clean/runner/packing.py @@ -265,7 +265,7 @@ def pack_stage(stage, tensors, d_row="gfx12", model="M"): BNECK_STAGES = tuple(f"b{k}" for k in range(6)) # Model-keyed (#89): the bneck and mid stage lists per model (Model M: BNECK_STAGES, MID_STAGES below); a model adds # its rows next to its stage table (clean/reference/swin.py MODEL_STAGES). -MODEL_BNECK_STAGES = {"M": BNECK_STAGES} +MODEL_BNECK_STAGES = {"M": BNECK_STAGES, "L": BNECK_STAGES} # L: Model M's stages (clean/reference/swin.py) _COUNT_WORDS = {6: "six", 8: "eight"} @@ -313,7 +313,7 @@ def split_bneck(blob, model="M"): # Pseudo-stage "mid": enc2 (with its merge), b0..b5, dec2 (with its expand) as one unit (persistent kernel swin_mid, # FORMATS.md). Its blob is the eight stage blobs back to back, in this order. MID_STAGES = ("enc2",) + BNECK_STAGES + ("dec2",) -MODEL_MID_STAGES = {"M": MID_STAGES} +MODEL_MID_STAGES = {"M": MID_STAGES, "L": MID_STAGES} def mid_stages(model="M"): diff --git a/clean/runner/pipeline.py b/clean/runner/pipeline.py index dffc724c..9d20ec1b 100644 --- a/clean/runner/pipeline.py +++ b/clean/runner/pipeline.py @@ -56,7 +56,7 @@ SWIN_ORDER = ["enc1", "enc2", "b0", "b1", "b2", "b3", "b4", "b5", "dec2", "dec1"] # Model-keyed (#89): the Swin stage order per model (Model M: SWIN_ORDER); a model adds its row next to its stage # table (clean/reference/swin.py MODEL_STAGES). -MODEL_SWIN_ORDER = {"M": SWIN_ORDER} +MODEL_SWIN_ORDER = {"M": SWIN_ORDER, "L": SWIN_ORDER} # L: Model M's ten Swin stages, same order (#89) def swin_order(model="M"): diff --git a/clean/tests/test_model_tables.py b/clean/tests/test_model_tables.py index 3cd4f689..d689a8af 100644 --- a/clean/tests/test_model_tables.py +++ b/clean/tests/test_model_tables.py @@ -24,6 +24,10 @@ M_SWIN_ORDER = ["enc1", "enc2", "b0", "b1", "b2", "b3", "b4", "b5", "dec2", "dec1"] +# the two kinds of window offsets of the rule below (parity 0, parity 1): the default stages and the shifted ones +WINDOW_KINDS = {"first": ((2, 2), (0, 2)), "second": ((0, 0), (2, 0))} + + def m_window_offset(stage, parity): # the rule as it was written before if stage in ("b1", "b3", "b5", "dec2", "dec1"): return (0, 0) if parity == 0 else (2, 0) @@ -51,7 +55,7 @@ def test_stage_lists(self): from clean.runner import pipeline self.assertEqual(pipeline.SWIN_ORDER, M_SWIN_ORDER) self.assertIs(pipeline.swin_order(), pipeline.SWIN_ORDER) - self.assertEqual(R.MODELS, ("M", "K")) + self.assertEqual(R.MODELS, ("M", "L", "K")) # L: Model M's stage table (ModelLRows) def test_messages_unchanged_for_m(self): with self.assertRaisesRegex(ValueError, r"^bneck needs the tensors of the six blocks b0\.\.b5$"): @@ -68,10 +72,44 @@ def test_messages_unchanged_for_m(self): def test_unknown_model(self): for f in (lambda: S.stage_table("Z"), lambda: S.window_offset("b0", 0, "Z"), lambda: P.bneck_stages("Z"), lambda: P.mid_stages("Z"), lambda: P.stage_sections("b0", "Z")): - with self.assertRaisesRegex(ValueError, r"for model 'Z'; known: M"): + with self.assertRaisesRegex(ValueError, r"for model 'Z'; known: L, M"): f() +class ModelLRows(unittest.TestCase): + """Model L's ten Swin stages are Model M's (#89): its rows are Model M's rows, the same objects.""" + + def test_rows_are_m_rows(self): + from clean.runner import pipeline + self.assertIs(S.stage_table("L"), S.STAGES) + self.assertIs(S.WINDOW_OFFSETS["L"], S.WINDOW_OFFSETS["M"]) + self.assertIs(P.bneck_stages("L"), P.BNECK_STAGES) + self.assertIs(P.mid_stages("L"), P.MID_STAGES) + self.assertIs(pipeline.swin_order("L"), pipeline.SWIN_ORDER) + for stage in M_STAGES: + for parity in (0, 1): + self.assertEqual(S.window_offset(stage, parity, "L"), m_window_offset(stage, parity)) + + def test_same_bytes_as_m(self): + rng = np.random.default_rng(11) + for s in M_STAGES: + p = S.random_params(s, rng, model="L") + self.assertEqual(P.pack_stage(s, p, model="L"), P.pack_stage(s, p)) + self.assertEqual(P.stage_blob_size(s, "L"), P.stage_blob_size(s)) + + def test_matches_l_table_offsets(self): + """The L table's window offsets (clean/l/reference/table.py) are the two kinds of these rows.""" + try: + from clean.l.reference import table as LT + except ImportError: + self.skipTest("no clean/l/reference/table.py") + t = LT.TABLE if hasattr(LT, "TABLE") else None + if t is None or "window_offsets" not in t: + self.skipTest("the L table has no window_offsets entry") + self.assertEqual(tuple(t["window_offsets"]["first"]), WINDOW_KINDS["first"]) + self.assertEqual(tuple(t["window_offsets"]["second"]), WINDOW_KINDS["second"]) + + class SecondModel(unittest.TestCase): """A synthetic model "T": Model M's enc2, b0 and dec2 under new names, with its own offsets and lists."""