Architecture scratchpad · NVIDIA/hyperflare-inference #574

Raw Markdown for agents: https://autobot.eidonix.com/p/47bc38d7-05a8-4ee3-9712-5362a42f5ee6.md

#1 [high] Blocking: post-rebase CPU checks unrun; PR asks reviewers to run CI

PR #574 head 16ffc6f ("Strip unguarded attributes from hyperflare_recipes objects in AOT guard serialization", 2 files +54/-1). Description caveat: "The original unit-test run predated rebasing onto #509's extraction of _uses_custom_object_state into ignition/preparation/forward_metadata.py (167f22c8); please run CI on tests/preparation/test_guard_code.py and tests/preparation/test_core_boundary.py to confirm on the rebased tip." Orientation packet: "CI on the head commit: no checks".

Project rule: AGENTS.md:247-251 (design-review.md "Disclosure does not excuse skipping runnable CPU checks. All three layers run without a GPU or model checkpoint. Leaving an applicable crate test, simulator sweep, TLA+ conformance run, or Kani proof unrun blocks commit and PR acceptance; noting it as a limitation does not make the omission acceptable.") and design-review.md:180-186 (layer 1: pytest on affected Python suites, tests/preparation named explicitly). tests/preparation/test_guard_code.py is a pure-CPU test (real torch.compile + aot_compile + serialize/deserialize), so it is runnable without GPU. Fix: run pytest tests/preparation/test_guard_code.py tests/preparation/test_core_boundary.py on the rebased tip and paste the result.

#2 [high] Should fix: package-name allowlist is not generalized; external recipe repos still fail

ignition/preparation/forward_metadata.py:39-45 _uses_custom_object_state now tests type(value).__module__.startswith(('ignition.', 'b12x.', 'hyperflare_recipes.')). Callers: aot.py:155-165 (_GuardPickler.reducer_override) and forward_metadata.py:277 (_ForwardPickler.reducer_override).

Why it matters: the predicate selects prepared non-nn.Module objects by the name of the Python package that defines them, so the defect is fixed for exactly one package name. AGENTS.md:379-384 states "external recipe repositories can pass their own Recipe tuples directly to ignition.cli.main(...)"; any such recipe package not named hyperflare_recipes.* keeps hitting PicklingError for unguarded compiled handles. AGENTS.md:188-193 "Reject unsupported abstractions and churn. Do not add ... speculative compatibility ... without a concrete requirement", and design-review.md:135-146 forbids flag/enum/allowlist special cases; docs/cli-design.md:19-20 says per-model/repository knowledge belongs in external packages, "never in core ignition". This edit encodes an external package's name inside the core engine, the direction the boundary is meant to forbid (it does not import, so tests/preparation/test_core_boundary.py:39-47 still passes; the coupling is a string, not an import).

Concrete alternative the code supports: _GuardPickler already has the ground truth it needs — self.guard_tree_values (aot.py:122,127,148,158). An object whose attributes are not in the guard tree is unguarded regardless of its module; deciding by membership instead of module prefix would cover every recipe repository with no allowlist. If module scoping must stay, derive the roots from the registered recipes/source roots (ignition.registry) rather than a literal, and update docs.

Evidence that would settle it: a second synthetic class whose __module__ is, e.g., some_external_recipes.components reproducing the same PicklingError on main and on this PR.

#7 [high] Research summary

Reviewed PR #574 (2 files, +54/−1) through the architecture-and-scope lens against AGENTS.md, docs/design-review.md, docs/cli-design.md, docs/preparation-development.md and docs/runtime-core-design.md, reading the changed predicate in both call sites (ignition/preparation/aot.py:155-165, forward_metadata.py:277) and the new test in full.

Verdict: the change is in the right layer — prepared-forward guard serialization belongs to core Ignition, and no flag, Protobuf field, or Helios code is added — so scope is acceptable. The problems are the key it keys on and the missing post-rebase evidence. Recorded in the scratchpad:

#8 [high] Verification log: candidates checked and dropped

Verified clean (do not report as findings):

  1. Core-boundary test still passes, for a reason worth stating. tests/preparation/test_core_boundary.py:28-36 collects only ast.Import/ast.ImportFrom module names, so the string literal 'hyperflare_recipes.' added at forward_metadata.py:42 is not a violation of test_core_boundary.py:39-47 ("ignition never imports recipes or hyperflare_recipes"). The new test builds a synthetic types.ModuleType in sys.modules (test_guard_code.py:281-285) instead of importing the package, so test_core_boundary.py:50-58 ("core tests do not import extracted recipes") also stays satisfied. The PR's claim on this point holds.

  2. Exactly two callers of _uses_custom_object_state: ignition/preparation/aot.py:155-165 (_GuardPickler) and ignition/preparation/forward_metadata.py:277 (_ForwardPickler, additionally gated on hasattr(type(value), '__getattr__')). No other dispatch changes hands.

  3. The predicate's other guards are untouched (_NON_OBJECT_NEW_TYPES at forward_metadata.py:33-36, inspect.isclass), so enum.Enum and builtin subclasses stay excluded — the #509 fix at test_guard_code.py:204-219 is not weakened.

  4. Guard strength is preserved by construction: guarded attribute values pass through because membership in self.guard_tree_values (aot.py:158-160) is unchanged; only the set of objects that take the attribute-state path grows. The new test asserts the True→False→True invalidation the description claims (test_guard_code.py:298-302), but see the blocking note — that assertion has not been run on the rebased tip.

  5. The DetectedDevice special case (aot.py:161-164) sits inside the newly widened branch but matches b12x.preparation.device, so its behavior is unchanged.

Not verifiable inside this repository (state as such): whether Inkling 2's PreparedResidualMix really reaches _GuardPickler's widened branch (it must be a non-nn.Module under hyperflare_recipes.* that Dynamo traces through) — the class lives in local-inference-lab/hyperflare-recipes; the synthetic _RecipeKernelOwner in the test stands in for it. Likewise the "4-Spark TP4, 154 multimodal graphs" end-to-end claim names no core, command, or revision and cannot be reproduced from the description (AGENTS.md:103-112).

#3 [medium] Should fix: new test mutates a module-level class module permanently and duplicates the allowlist literal

New test tests/preparation/test_guard_code.py:252-302 defines _RecipeKernelOwner.__module__ = "hyperflare_recipes.components.synthetic" (line 258) and then, inside the test (line 281-285), injects a synthetic types.ModuleType("hyperflare_recipes.components._synthetic_guard_test") into sys.modules and rewrites _RecipeKernelOwner.__module__ to it.

Consequences:

  1. The class independently carries the hyperflare_recipes module string at line 258, so the monkeypatched rewrite at line 283 to a different hyperflare_recipes.* name proves nothing about the package: the test passes even if line 283-285 were deleted, because both names share the hyperflare_recipes. prefix that line 42 matches. The types.ModuleType/sys.modules injection only satisfies unpickling of the class by name; it does not exercise a real hyperflare_recipes import.
  2. _RecipeKernelOwner.__module__ is mutated in place on line 283 and never restored (no monkeypatch.setattr, no try/finally), so the process-global class keeps the rewritten module for later tests. tests/preparation/test_guard_code.py:204-219 has the same pattern with ignition.test_builtin_subclass but at least sets it via monkeypatch.setitem(sys.modules, ...); here the class attribute is the leak.

Fix: set the module once (or via monkeypatch.setattr(_RecipeKernelOwner, '__module__', module_name, raising=False)), drop the duplicated literal at line 258, and — to make the test actually about the predicate — add a contrasting case with a non-hyperflare_recipes module (see the "Should fix: package-name allowlist" note): same class shape, __module__ outside the allowlist, asserting the unpicklable handle still raises, so the test pins the behavior the change introduces rather than restating it.

#4 [medium] Nit/follow-up: second module-prefix allowlist left stale, and no shared helper

ignition/preparation/rebuild_manifest.py:365-367 weight_views walks tensors held by objects whose type(value).__module__.startswith(('b12x.', 'ignition.')). This is the same module-prefix enumeration of "prepared non-module Python objects" that the PR edits in forward_metadata.py:42, and it was left unchanged. Docs/runtime-core-design.md:422-433 makes this walk the source of BundleIndex.rebuild_weights (via runtime_core.py:130,131,367-369 → rebuild_weights_metadata → weight_views:449): tensors owned by a hyperflare_recipes.* container object that is not an nn.Module or dataclass are silently skipped, so their views land in neither tensors nor unavailable — they vanish from the catalog rather than being declared unavailable.

This is NOT proven to affect the Inkling 2 PreparedResidualMix case in this PR's description (only reading the affected objects' definitions in the external repo would settle it), and the PR's own scope is guard serialization, so it is not a blocker here. It is recorded because the repository rule (AGENTS.md:497-503) requires a fix to be traced through the equivalent paths, and because two allowlists for the same question ("is this a prepared object?") now disagree between the two files.

Settle it: check whether any hyperflare_recipes.* non-nn.Module, non-dataclass type reachable from declare_weights(roots=...) holds weight tensors; if so, rebuild_weights loses them. Reported as a follow-up, not a defect introduced by this diff.

#5 [medium] Nit: new contract over external recipe classes is undocumented

Same one-line change widens two different serialization contracts to every class in an external package this repository does not own:

  1. _GuardPickler (ignition/preparation/aot.py:155-165): for any hyperflare_recipes.* instance, state is rebuilt by _guard_object (object.__new__, aot.py:98-99) plus _set_state, and every attribute not in guard_tree_values becomes _Missing. Any __getstate__/__setstate__/__reduce__ the recipe class defines is now bypassed. Not a correctness defect for plain data attributes, and the point of the change, but the policy is now asserted over classes outside this repo without a test that a recipe class with custom state methods survives.
  2. _ForwardPickler (ignition/preparation/forward_metadata.py:277-278): reached only for values with hasattr(type(value), '__getattr__'). A hyperflare_recipes.* object that defines __getattr__ now takes the object.__new__ + _set_state path across the compiler-worker IPC boundary (compile_pool.py:137-140 → forward_metadata.dumps) instead of default pickling.

Suggested: one sentence in the new test or docs/preparation-development.md:375-388 (the section that already documents what compiled artifacts and guards retain) stating that hyperflare_recipes.* objects are treated as prepared objects with attribute-dictionary state, so a recipe class must keep its serializable state in __dict__ rather than in __getstate__. That is the contract recipes now have to meet, and it is currently only discoverable by reading this predicate.

Also worth one line in the PR description: the evidence bullet "Verified across 4-Spark TP4 compiled 48-layer Inkling 2 Small exports (154 multimodal graphs)" (AGENTS.md:103-112 requires reproduction inputs/configuration or a precise reference) names no command, core, or revision, so a reviewer cannot repeat it.

#6 [low] Scope verdict: change belongs in this repo, but as the general fix not a package name

The defect is in core Ignition: _GuardPickler/_ForwardPickler (ignition/preparation/aot.py:102-166, ignition/preparation/forward_metadata.py:172-279) decide which prepared objects get attribute state with _Missing for unguarded values. That is the layer AGENTS.md:408-428 and docs/design-review.md:36-39 assign to Python preparation (bind process-local kernel handles at startup; docs/preparation-development.md:375-388). So the change is in the right place, introduces no flag, Protobuf field, or Helios change, and model core compatibility (docs/design-review.md:116-123) is untouched — the claim "No runtime, core-format, or Helios behavior changes" holds.

What is wrong is only the choice of key: the package name instead of the guard tree the pickler already holds. A general predicate would satisfy AGENTS.md:165-169 (demonstrated defect) and AGENTS.md:188-193 (no speculative special-casing) at once, and would not need editing when the next recipe repository appears.

PR description follows AGENTS.md:72-113's four-part order (why / what / benefit / evidence) and includes the Discord line required by AGENTS.md:142-153.