Skip to content

qwen_m2_decode: --m-per-prompt (per-prompt max_len, as the M1 reference ran) - #27

Merged
joshuaswarren merged 2 commits into
mainfrom
agent/qwen-per-m
Oct 1, 2026
Merged

joshuaswarren merged 2 commits into
mainfrom
agent/qwen-per-m

Conversation

@joshuaswarren

Copy link
Copy Markdown
Owner

The M1 reference (chunk_00) ran ANEForge generate() without max_len, so its six attention programs (prog_006/012/018/025/031/037: ctx oh/inv [1,M,1], mask [1,1,M], KV states [2,M,256]) were built at M = len(prompt) + 32 per prompt (43..50), while the M2 decode used M = 50 for every prompt.

--m-per-prompt decodes each prompt at that M: every manifest dimension equal to max_len becomes M, the programs whose shapes change come from <per-m-dir>/M<M>/prog_NNN/{program-0.anec,ports.json}, the other 32 from the M = 50 set, and the resident states restart as zeros at the new shapes. --dump (an M = 50 execution) is refused with it.

Tests (tests/test_qwen_m2_decode.py): the context tables and rope rows at M = 43..50 equal the dump-checked M = 50 tables cut to M; per-M program, port-table and state selection, and a port table built for another M is refused. pytest tests/test_qwen_m2_decode.py tests/test_qwen_precision.py tests/test_qwen_m2_conform.py tests/test_qwen_prog_run.py: 19 passed. Host smoke against the real manifest and the converted M = 43 tables: exactly the six attention programs switch to the per-M dir, KV states (2, 43, 256).

No device run. A max_len 50 run of the M1 reference on H13 gives logits bit-identical to chunk_00, so M does not change the reference; the mode stays for an H14 check of the same property.

…mpt) + new tokens

The M1 reference ran ANEForge generate() without max_len, so its six
attention programs (ctx oh/inv [1,M,1], mask [1,1,M], KV states [2,M,256])
were built at M = len(prompt) + 32 per prompt; the M2 run used M = 50 for all.
configure(m) scales every manifest dimension equal to max_len to m, takes the
programs whose shapes change from <per-m-dir>/M<m>/prog_NNN and the rest from
the max_len 50 set, and zeroes the states at the new shapes. Host tests: the
context tables and rope rows at M equal the dump-checked M=50 tables cut to M,
and per-M program, port-table and state selection.
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 1, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-10-01T15:54:59.362426Z 01d5aec PR opened
🔒 Security Review ✅ Completed 2026-10-01T15:55:36.009747Z 01d5aec PR opened
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 01d5aec109

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread tools/qwen_m2_decode.py
ap.add_argument("--ane-run", default="/var/tmp/inst/tools/ane-run")
ap.add_argument("--timeout", type=int, default=120)
ap.add_argument("--summary", action="store_true")
ap.add_argument("--m-per-prompt", action="store_true",

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P1 Badge Author the commit with the required repository identity

The reviewed commit is authored and committed as Codex <codex@openai.com>, but this repository requires every commit to use Joshua Warren <816217+joshuaswarren@users.noreply.github.com>. Recreate this commit with the mandated author and committer identity before it is integrated.

AGENTS.md reference: AGENTS.md:L250-L257

Useful? React with 👍 / 👎.

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.

Not reproduced: GET /repos/joshuaswarren/omarchy-ane/commits/01d5aec1095cad8f3deb5343229b8d26ce573ce1 reports author and committer Joshua Warren <816217+joshuaswarren@users.noreply.github.com>, and git log --format="%an <%ae> | %cn <%ce>" origin/main..HEAD shows the same for the one commit in this PR. No Codex identity is in the branch.

Comment thread tools/qwen_m2_decode.py
path = Path(args.ports_dir) / prog / "ports.resolved.json" if args.ports_dir \
else Path(args.anec_dir) / prog / "ports.json"
if pr != pr0:
anec_dir = path_dir = Path(args.per_m_dir) / f"M{m}"

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

WARNING: A missing or out-of-range per-M table raises FileNotFoundError, not Refuse

<per-m-dir>/M<M>/prog_NNN/ports.json is read at line 161 with no existence check, and __main__ only catches Refuse (line 408), so a run with the default --per-m-dir /var/tmp/qwen-perM that has not been built, or a prompt whose len(prompt) + new_tokens exceeds the largest prepared M, dies with a raw traceback instead of the documented REFUSE: message and exit 2. The rest of configure is careful to raise Refuse with the offending path, so this is the one input that fails unhelpfully. Consider validating the per-M directory up front (and that m is within the prepared range) before the loop.


Reply with @kilocode-bot fix it to have Kilo Code address this issue.

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 28dc62c: configure raises Refuse naming the port table and ANEC when either is missing, so a max_len without a prepared set exits 2 with REFUSE:. Test: configure(6) with no M6 set.

Comment thread tools/qwen_m2_decode.py
name = "ports.json"
else:
anec_dir = Path(args.anec_dir)
path_dir, name = (Path(args.ports_dir), "ports.resolved.json") if args.ports_dir \

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

SUGGESTION: --ports-dir is silently ignored for the per-M programs

When a program's shapes change at M, the port table always comes from <per-m-dir>/M<M>/prog_NNN/ports.json; the resolved tables under --ports-dir (the ports.resolved.json produced by qwen_m2_conform.py) are never consulted for those six attention programs. If a resolved table is required for conformance, a run with both --m-per-prompt and --ports-dir fails at line 162 with wrong program or unresolved exceptions on a table the user never meant to use, with nothing pointing at the flag combination. Either honour --ports-dir for the per-M programs or refuse the combination explicitly.


Reply with @kilocode-bot fix it to have Kilo Code address this issue.

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.

Kept as documented in the module docstring: the per-M programs come from <per-m-dir>/M<M>/prog_NNN/{program-0.anec,ports.json}. --ports-dir holds conformance-resolved tables for the max_len 50 programs only; no resolved tables exist at other M. The derived per-M tables carry no exceptions (all 38 resolutions at max_len 50 were identity), so the failure described does not occur.

Comment thread tools/qwen_m2_decode.py
prog = f"prog_{i:03d}"
path = Path(args.ports_dir) / prog / "ports.resolved.json" if args.ports_dir \
else Path(args.anec_dir) / prog / "ports.json"
if pr != pr0:

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

SUGGESTION: The per-M table is validated by element count only, not by shape

pr != pr0 routes a program to the per-M directory, and the check at lines 168-170 then compares int(np.prod(shape)) per port. A per-M table whose port dimensions are permuted relative to the manifest at M (for example mask as [1, M, 1] where the manifest says [1, 1, M]) has the same element count and passes, and ane_call reshapes the host arrays to the port shape, so the run would proceed with a silently wrong surface layout. This was low-risk when every table came from one compiled set; with per-M tables from a separate directory it is the main guard against a stale or mismatched table, so comparing the shape list itself would be stronger.


Reply with @kilocode-bot fix it to have Kilo Code address this issue.

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 28dc62c: ports are compared by their non-unit dimensions in order (port tables are NCHW, the manifest shapes are not, so the leading 1s differ). The 38 max_len 50 tables and the max_len 43 tables pass; a [2, 3, M] table for a [2, M, 3] port is refused (test case M5).

@kilo-code-bot

kilo-code-bot Bot commented Oct 1, 2026 •

Copy link
Copy Markdown

Code Review Summary

Status: No Issues Found | Recommendation: Merge

All three findings from the previous review are resolved in 28dc62c: a missing or out-of-range per-M table now raises Refuse naming the missing path (tools/qwen_m2_decode.py:161), port tables are compared by their non-unit dimensions rather than element count (tools/qwen_m2_decode.py:167), and the per-M programs keep using ports.json with --ports-dir ignored, as documented in the module docstring.

Files Reviewed (2 files)
  • tools/qwen_m2_decode.py
  • tests/test_qwen_m2_decode.py
Previous Review Summary (commit 01d5aec)

Current summary above is authoritative. Previous snapshots are kept for context only.

Previous review (commit 01d5aec)

Status: 3 Issues Found | Recommendation: Address before merge

Overview

Severity Count
CRITICAL 0
WARNING 1
SUGGESTION 2
Issue Details (click to expand)

WARNING

File Line Issue
tools/qwen_m2_decode.py 154 Missing / out-of-range per-M table raises FileNotFoundError instead of Refuse (exit 2)

SUGGESTION

File Line Issue
tools/qwen_m2_decode.py 153 Per-M port table validated by element count only, not by shape
tools/qwen_m2_decode.py 158 --ports-dir silently ignored for the per-M programs
Files Reviewed (2 files)
  • tools/qwen_m2_decode.py - 3 issues
  • tests/test_qwen_m2_decode.py - 0 issues

Fix these issues in Kilo Cloud


Reviewed by free · Input: 0 · Output: 0 · Cached: 0

… not element counts

A missing port table or ANEC (a max_len without a prepared per-M set) now
raises Refuse (exit 2) instead of a FileNotFoundError traceback. Ports are
checked against the manifest by their non-unit dimensions in order, so a table
with permuted dimensions of the same size no longer passes; the 38 max_len 50
tables and the max_len 43 tables match this way.
@joshuaswarren
joshuaswarren merged commit 37a0972 into main Oct 1, 2026
1 check passed
joshuaswarren added a commit that referenced this pull request Oct 1, 2026
The Unreleased entries of #28 and the #25, #27, #29 tools and #22/#26 receipts go into 0.4.0, with honest known limits. CHANGELOG.md only.
@joshuaswarren
joshuaswarren deleted the agent/qwen-per-m branch October 3, 2026 12:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant