Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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: 2 additions & 2 deletions atom/compass/memory/graph_pool.py
Original file line number Diff line number Diff line change
Expand Up @@ -132,8 +132,8 @@ def reserves(
inferring it from an engine it is not allowed to import.

**Two of ATOM's own adjustments inside those branches are not mirrored
here, and they pull in opposite directions.** Neither fires at M1 -- no
drafter, one data-parallel rank -- and both are named because the cut that
here, and they pull in opposite directions.** Neither fires with no
drafter and one data-parallel rank, and both are named because the cut that
wires this into `get_num_blocks` under a block-count gate would otherwise
read "nothing else" as fidelity:

Expand Down
10 changes: 5 additions & 5 deletions atom/compass/memory/readings.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,8 @@
tree, which needs the engine, which this tier does not import; and there is no
recording of a card nobody has run. So `ModelTerms` takes those two terms rather
than deriving them, with no default -- the same shape as the spec's "a runtime
constant has no default" rule, and for the same reason. `declared_for_m1` fills
all three with declared formulas for M1 and labels every one of them. For the
constant has no default" rule, and for the same reason. `declared` fills
all three with declared formulas and labels every one of them. For the
activation term a declared formula is the only answer while no op graph
exists; this module gives the other two the same treatment, visibly.
"""
Expand Down Expand Up @@ -108,7 +108,7 @@ class ModelTerms:
activations: Term

@classmethod
def declared_for_m1(
def declared(

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Blocking (principle 4): declared is already a query in this package, and this makes it a constructor too.

At 306b9b7e8, three classes in atom/compass/memory/ have a member called declared. Measured on node 18 with inspect.getattr_static against the merged tree:

member kind returns
readings.DeviceReadings.declared (this file, :219) property tuple[str, ...], the names of terms still on a declared basis
terms.Reading.declared (terms.py:159) property tuple[str, ...], the same question for one reading
readings.ModelTerms.declared (here) classmethod a new ModelTerms

So x.declared asks "which terms are declared?" on two classes and means "build me declared terms" on the third. On a ModelTerms instance, .declared is a bound method: tuple(model_terms.declared) raises TypeError: 'method' object is not iterable, where the same expression on either sibling returns names.

The two meanings already sit side by side in the same files:

  • readings.py:224 iterates reading.declared, 113 lines below this definition.
  • test_memory_readings.py calls ModelTerms.declared(...) nine times, and at :324 asserts on readings.peak_torch.declared.

The old name did not collide. This PR is a naming change, so the name is the deliverable.

Fix: use an alternate-constructor name that no query in the package uses. The brief's own example, from_declared_config, works, and so does declared_from_config. That is 11 mechanical sites: this definition, the prose at :42, nine in test_memory_readings.py and one in test_memory_compare.py. Neither name trips _TAGS.

Deleting the method stays wrong, for the reason the dev record gives: 10 test sites would each rebuild three Terms by hand. Keeping it with no production caller is justified. Only the name needs to change.

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed in 40ae3faad. The method is renamed to ModelTerms.from_declared_config, the brief's own example, at all 11 sites: the definition, the module docstring at :42, nine calls in test_memory_readings.py and one in test_memory_compare.py.

DeviceReadings.declared (:219) and Reading.declared (terms.py:159) are untouched, so declared is now only ever the query.

AST check, tip 2565b5f57 against head 40ae3faad, with declared_for_m1 normalised to from_declared_config, run on node 18:

  • test_memory_readings.py is identical.
  • readings.py and graph_pool.py are identical once docstrings are masked.

Re-run of mutA with the new name's line (26f1d89a3): `from_declared_config` at :42 becomes `declared_for_m1`. test_no_module_in_the_package_carries_a_design_reference[readings.py] fails, with readings.py carries design references: ['declared_for_m1']. "def declared_for_m1(" stays in the driven list.

cls,
config,
*,
Expand All @@ -119,7 +119,7 @@ def declared_for_m1(
) -> ModelTerms:
"""All three from geometry and declared coefficients, each labelled.

For M1, with fake models, a declared formula suffices and must say so.
With fake models, a declared formula suffices and must say so.
Every term below is `Basis.DECLARED` and every one names its
successor, because none of the three is its eventual source: weights
are owed a meta build, buffers a recording, and
Expand All @@ -128,7 +128,7 @@ def declared_for_m1(
with no law behind it. The measured spread that makes it load-bearing
is 0.1 KB/token on the 0.6B against 39.6 KB/token on the 27B, the
difference between -35.0% and +3.4% held out. A formula does not
stand in for that past M1.
stand in for that on a real model.
"""
if tp_size < 1:
raise ValueError(f"tensor-parallel width is at least 1: {tp_size}")
Expand Down
36 changes: 11 additions & 25 deletions tests/compass/test_memory_compare.py
Original file line number Diff line number Diff line change
Expand Up @@ -450,7 +450,7 @@ def live_readings(spec, qwen, tp_width=1):
return device_readings(
spec,
tp_width=tp_width,
model=ModelTerms.declared_for_m1(
model=ModelTerms.declared(
qwen,
parameter_count=PARAMETERS,
tp_size=tp_width,
Expand Down Expand Up @@ -1035,19 +1035,15 @@ def test_the_footprint_is_peak_torch_and_non_torch_and_nothing_else(spec, qwen):
#: lets the guard below read the file it is written in if it is ever widened.
#: `P\d+\.\d+` is in the banned list by name; the two-to-four letter form with
#: a dash is every task label, not just the one this cut happened to leave.
#: A milestone label is `M1` in prose and `_m1` as an identifier suffix; a bare
#: letter-and-digit is not matched, because it would take `TP1`, `w1` and
#: every dtype width in this package with it. No group captures, so a failure
#: prints the forms it found.
_TAGS = re.compile(
r"\b[DTW]\d+(\.\d+)?\b|\bP\d+\.\d+\b|\b[A-Z]{2,4}-\d+\b"
r"\b[DTW]\d+(?:\.\d+)?\b|\bP\d+\.\d+\b|\b[A-Z]{2,4}-\d+\b|\bM\d+\b|\w*_m\d+\b"

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Non-blocking (principle 6): near variants of the removed form escape. They pass silently, not loudly.

The named result holds for the exact forms: declared_for_m1 and M1 both fail the guard by name at the head (details in the review comment). One step away, they pass. Measured two ways at 306b9b7e8:

  1. A line-count-preserving edit to readings.py, tree 1bd8572e3. Three prose lines became `declared_for_m1_terms` fills, At m1, with fake models, and past M1a or declared_for_M1. Result: 109 passed. test_no_module_in_the_package_carries_a_design_reference[readings.py] is green.
  2. Probing this compiled pattern directly (findall, node 18):
form caught?
declared_for_m1, M1, M1's, M1.2, M01 yes
declared_for_m1_terms, _m1_ no. \w*_m\d+\b needs a non-word character after the digits, and _ is a word character.
declared_for_M1, declaredForM1, m1_declared no. The suffix form is lowercase-only and suffix-only, and \bM has no boundary after _.
m1, at m1, M1a, Milestone1 no

Nothing else in the suite notices either. git grep for any other design-reference guard over this package finds only this file. The whole CPU gate on tree 1bd8572e3 gave 5209 passed, 155 skipped, 3 xfailed, GATE_CPU_RC=0: the same count as the head on its own base.

Ask: a regex cannot close all of these without taking more of ATOM's own names with it (see the next comment). So I am not asking for a wider pattern. Instead, state the escapes beside the benign list, the way the deleted KEPT comment stated its absence. The test file's own standard is that "an absence nobody explained is the same defect one level up."

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Recorded in 40ae3faad; the pattern is not widened. test_what_the_pattern_matches_beside_its_targets_is_on_record asserts that declared_for_m1_terms, At m1, M1a and declared_for_M1 are not matched. Its docstring says why: a pattern wide enough to take them would take more of ATOM's names.

If someone later widens the pattern to catch one of them, this assertion fails. That forces them to update the record, instead of the record going stale.

r"|principles? \d+|Gate \d+|`\d{2}`|#\d+"
)

#: What this pattern deliberately does not catch, and why, because an absence
#: nobody explained is the same defect one level up. `M1` is a milestone that
#: the public `ModelTerms.declared_for_m1` is named after: it says when a
#: declared term stops being allowed, which is what the code does, and it
#: points at no document. Matching a bare letter-and-digit would also take
#: `TP1`, `w1` and every dtype width in this package with it.
KEPT = ("M1", "declared_for_m1")

#: The package as the suite imported it, never a walk up from this file: if
#: `atom` resolves from another root, a path-derived location would scan one
#: tree while every other test here imports another, and pass.
Expand All @@ -1070,7 +1066,7 @@ def test_no_module_in_the_package_carries_a_design_reference(module):
`test_memory_readings.py`, and for the same reason.
"""
found = _TAGS.findall((PACKAGE / module).read_text())
assert not found, f"{module} carries {len(found)} design references"
assert not found, f"{module} carries design references: {found}"


def test_the_guard_catches_the_forms_that_were_actually_removed():
Expand All @@ -1090,6 +1086,8 @@ def test_the_guard_catches_the_forms_that_were_actually_removed():
"an open owner ruling (**#87**)",
"proving it is MEM-2's",
"`16` row W2.2",
"For M1, with fake models, a declared formula suffices",
"def declared_for_m1(",
]
# Two forms this package never carried, driven anyway because a guard is
# worth what it catches rather than what it happened to meet. `P0.4` is
Expand All @@ -1105,19 +1103,7 @@ def test_the_guard_catches_the_forms_that_were_actually_removed():
assert not _TAGS.search(replacement)


def test_the_kept_forms_are_kept_on_purpose_and_stay_readable():
"""An absence with a stated reason is a decision; without one it is a gap.

`M1` is the one letter-and-digit form this package keeps. It names the
milestone at which a declared term stops being allowed -- which is what
the code does, not a pointer into a document -- and the public
`ModelTerms.declared_for_m1` is named after it, so removing it would
rename an API to satisfy a pattern.
"""
assert all(not _TAGS.search(kept) for kept in KEPT)
sources = "".join((PACKAGE / p.name).read_text() for p in PACKAGE.glob("*.py"))
assert "declared_for_m1" in sources
# And the widened pattern does not sweep up the widths and dtypes that
# share its shape, which is why it is not a bare letter-and-digit.
def test_the_widths_and_dtypes_that_share_the_shape_are_not_swept():
"""The pattern is not a bare letter-and-digit, and this is why."""
for benign in ("TP1", "w1_base_bytes", "fp8", "int8", "bf16"):

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Non-blocking (principle 8): this list claims to cover what shares the pattern's shape, but ATOM's own model names are not in it, and both new alternatives match them.

Measured over the merged tree (d45ecb5b5, tree 149965dee), with this file's compiled _TAGS:

  • In the guard's actual scope (atom/compass/memory/*.py, 6 files, no subdirectories): 0 hits. So there is nothing to fix today, and any future hit fails loudly.
  • In atom/ outside compass/:
    • \bM\d+\b hits 140 times, all M3, across 28 files. Almost all of it is ATOM's MiniMax-M3, for example atom/entrypoints/openai/chat_encoders.py:162.
    • \w*_m\d+\b hits 50 times: minimax_m3 45 times and minimax_m2 5 times. These are ATOM's module and model-type names, for example atom/config.py:766 and atom/model_engine/model_runner.py:124.
  • Probes:
    • Matched: MiniMax-M1 gives ['M1'], MiniMax-M2.5 gives ['M2'], M128 gives ['M128'], tile_m128, block_m16, seq_len_m1, n_m1, fp8_m3 and int4_m2.
    • Clear: float8_e4m3fn, fp8_e5m2, BLOCK_M128 and MI308X.
  • A line-count-preserving edit to readings.py (tree e7a5729db) put MiniMax-M1, an M128 tile and seq_len_m1 = seq_len - 1 into prose. It fails test_no_module_in_the_package_carries_a_design_reference[readings.py] with ['M1', 'M128', 'seq_len_m1'].

This package sizes model memory, so a sentence or a key naming one of ATOM's supported models is plausible here. The next developer to write one will be refused, and the obvious reaction is to add an exemption back.

Ask: say it where the next reader looks. Either:

  • add MiniMax-M3 and minimax_m3 to this test as known collisions, asserting that they are matched, so the trade-off is on record; or
  • narrow the prose form with a lookbehind ((?<![-\w])M\d+\b leaves MiniMax-M3 alone), then add the model name to the benign loop.

Either way the docstring's claim then matches its assertions.

I measured the lookbehind on node 18:

  • MiniMax-M3 and MiniMax-M1 give [].
  • at M1, (M1), M1-era, For M1, with and past M1. give ['M1'].
  • Its cost: a hyphenated the-M1 would escape.

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Recorded in 40ae3faad, using your first option. The same test now asserts that MiniMax-M3, minimax_m3, M128, tile_m128, seq_len_m1 and fp8_m3 are matched. Its docstring says that none occurs in this package, and that a hit is fixed by rewording the line, not by adding an exemption. I left the lookbehind out, so _TAGS is unchanged this round.

The record also holds the pattern. On mutE, which puts back the tip's _TAGS, this test fails with AssertionError: MiniMax-M3, alongside test_the_guard_catches_the_forms_that_were_actually_removed.

assert not _TAGS.search(benign), benign
18 changes: 9 additions & 9 deletions tests/compass/test_memory_readings.py
Original file line number Diff line number Diff line change
Expand Up @@ -228,7 +228,7 @@ def readings_at(spec, qwen, tp_width):
return device_readings(
spec,
tp_width=tp_width,
model=ModelTerms.declared_for_m1(
model=ModelTerms.declared(
qwen,
parameter_count=PARAMETERS,
tp_size=tp_width,
Expand Down Expand Up @@ -376,7 +376,7 @@ def test_a_configuration_that_does_not_fit_refuses_rather_than_clamping(spec, qw
device_readings(
spec,
tp_width=1,
model=ModelTerms.declared_for_m1(
model=ModelTerms.declared(
qwen,
parameter_count=400_000_000_000,
tp_size=1,
Expand All @@ -397,7 +397,7 @@ def test_the_predicting_function_cannot_be_spent_as_the_reserving_one(spec, qwen
device_readings(
spec,
tp_width=1,
model=ModelTerms.declared_for_m1(
model=ModelTerms.declared(
qwen,
parameter_count=PARAMETERS,
tp_size=1,
Expand Down Expand Up @@ -492,10 +492,10 @@ def test_an_absent_partial_rotary_factor_says_so_in_the_table(qwen):
# row must not look the same as a config that states 1.0.
full = copy.deepcopy(qwen)
del full.partial_rotary_factor
stated = ModelTerms.declared_for_m1(
stated = ModelTerms.declared(
qwen, parameter_count=PARAMETERS, tp_size=1, warmup_tokens=WARMUP_TOKENS
)
assumed = ModelTerms.declared_for_m1(
assumed = ModelTerms.declared(
full, parameter_count=PARAMETERS, tp_size=1, warmup_tokens=WARMUP_TOKENS
)
assert "absent from config, assumed" in assumed.buffers.source
Expand All @@ -507,7 +507,7 @@ def test_the_model_dtype_sizes_the_model_terms(qwen):
# Read off the config, not a module constant: a term sized in fp32 where
# the tensors are resident in bf16 is twice what the model holds.
assert str(qwen.dtype).endswith("bfloat16")
terms = ModelTerms.declared_for_m1(
terms = ModelTerms.declared(
qwen, parameter_count=PARAMETERS, tp_size=1, warmup_tokens=WARMUP_TOKENS
)
assert terms.buffers.nbytes == 262_144 * 64 * 2
Expand All @@ -530,7 +530,7 @@ def test_a_config_with_no_dtype_refuses_rather_than_assuming_one(qwen):
nameless = copy.deepcopy(qwen)
del nameless.dtype
with pytest.raises(MemoryRefusal, match="states no `dtype`, and every byte"):
ModelTerms.declared_for_m1(
ModelTerms.declared(
nameless,
parameter_count=PARAMETERS,
tp_size=1,
Expand All @@ -545,7 +545,7 @@ def test_a_config_missing_a_geometry_field_refuses_naming_that_field(qwen, field
shapeless = copy.deepcopy(qwen)
delattr(shapeless, field)
with pytest.raises(MemoryRefusal) as refusal:
ModelTerms.declared_for_m1(
ModelTerms.declared(
shapeless,
parameter_count=PARAMETERS,
tp_size=1,
Expand All @@ -564,7 +564,7 @@ def test_the_negative_box_refusal_carries_its_decomposition(spec, qwen):
device_readings(
spec,
tp_width=1,
model=ModelTerms.declared_for_m1(
model=ModelTerms.declared(
qwen,
parameter_count=400_000_000_000,
tp_size=1,
Expand Down