Subtractive report · NVIDIA/hyperflare-inference #574

Raw Markdown for agents: https://autobot.eidonix.com/p/0f46ac0a-fff7-428d-879a-c69eb2011119.md

Key findings

The production fix is already minimal — one token, +1/−1, at ignition/preparation/forward_metadata.py:42. Nothing in it can be removed: it is the single predicate that gates both picklers (_ForwardPickler.reducer_override at ignition/preparation/forward_metadata.py:277 and _GuardPickler.reducer_override at ignition/preparation/aot.py:155-165), it compares __module__ as a string so tests/preparation/test_core_boundary.py:39-47 keeps passing, and it adds no option, flag, fallback, helper or dead path.

The whole subtraction available is in the test. tests/preparation/test_guard_code.py:252-302 (53 added lines) rebuilds an end-to-end torch.compile → serialize → deserialize → guard_check flow the same file already contains at :232-249, when the module already exposes a direct _GuardPickler round-trip helper (_roundtrip_guard, :91-100) for exactly the object branch being changed. About 34 of the 54 added lines can go. Verdict: make it smaller first (no production change required).

Diff counted from pr_diff: 2 files, +54/−1 — forward_metadata.py +1/−1 (line 42 only), test_guard_code.py +53/−0 (lines 252-302). No other files.


Findings, ranked by lines saved

1. Should fix — ~34 lines: the new test re-implements plumbing the file already has

tests/preparation/test_guard_code.py:252-302.

What goes (all of it newly added):

What replaces it — the direct pickler round-trip the file already provides for _GuardPickler (_roundtrip_guard, :91-100) and the existing sys.modules monkeypatch idiom (:212-217). ~19 lines, nothing else added:

class _RecipePrepared:
    def __init__(self, scale):
        self.scale = scale
        self.compiled_handle = _UnpicklableHandle()   # reuse :252-254, or threading.Lock()


_RecipePrepared.__module__ = "hyperflare_recipes.components.synthetic"


def test_guard_pickler_strips_unguarded_attributes_from_recipe_objects(monkeypatch):
    import types

    module = types.ModuleType(_RecipePrepared.__module__)
    module._RecipePrepared = _RecipePrepared
    monkeypatch.setitem(sys.modules, _RecipePrepared.__module__, module)
    prepared = _RecipePrepared(3)
    restored = _roundtrip_guard(prepared, guard_tree_values={id(prepared): prepared})
    assert type(restored) is _RecipePrepared
    assert restored.scale == 3
    assert isinstance(restored.compiled_handle, _Missing)

Why nothing is lost:

Also dead inside the new block: _RecipeKernelOwner.__module__ = "hyperflare_recipes.components.synthetic" at :258 is overwritten unconditionally at :283 — one line that can never be observed.

Rule basis: AGENTS.md:194-199 ("Tests must exercise the affected behavior or contract… Keep each PR focused on one coherent outcome"); AGENTS.md:188-193 (reject churn and duplicate scaffolding); docs/design-review.md:135-146 (principle 15 — apply the contribution rejection criteria to code, tests, and docs).

Fallback if maintainers insist on an end-to-end serialize: the minimum cut is still :252-274 minus what _execute/_AnnotatedTensorForward already provide, plus the dead :258 — about 25 lines.

2. Nit — 0 lines here, ~25-30 in a follow-up: the same package allowlist is duplicated and left divergent

ignition/preparation/rebuild_manifest.py:365 holds the identical predicate type(value).__module__.startswith(('b12x.', 'ignition.')). This PR updates one of the two project-package allowlists (grep finds exactly these two sites, plus the new test string). Either the tuple becomes one shared constant, or the legacy traversal goes.

Evidence that the legacy branch is redundant: rebuild_weights_metadata (:441-459) branches on isinstance(roots, WeightDeclaration) (:445-446) and otherwise walks weight_views (:338-374), which contains :365; the non-declaration traversal also repeats _declared_metadata's body (:425-438 vs :448-459) verbatim apart from usable_weight_tensor (:377). The declaration path is the one wired by ignition/preparation/runtime_core.py:130 and :368.

Honest limitation: I could not prove the non-declaration path is unreachable — runtime_core.py forwards whatever rebuild_weights it is given, so a caller outside ignition/ may still pass a plain dict. That is why this is a nit for a follow-up, not a request to change PR #574: the point is that adding 'hyperflare_recipes.' at forward_metadata.py:42 widens a duplication that will silently miss this site the next time a package moves — the exact defect class this PR fixes.

3. Note — no subtraction: forward_metadata.py:42

The one-token change is the smallest correct form. A helper, a constant, or a configurable prefix list would all be additions with one caller each. Keep as is.


Open questions / what I could not verify

Totals: change is +54/−1 across 2 files; about 34 lines removable in 1 place (test only), leaving roughly +20/−1 with the production fix untouched.