Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions clean/reference/swin.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
4 changes: 2 additions & 2 deletions clean/runner/packing.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"}


Expand Down Expand Up @@ -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"):
Expand Down
2 changes: 1 addition & 1 deletion clean/runner/pipeline.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"):
Expand Down
42 changes: 40 additions & 2 deletions clean/tests/test_model_tables.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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$"):
Expand All @@ -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."""

Expand Down
Loading