Skip to content

Write Qwen3.5 output in bounded chunks - #4296

Merged
ashhart merged 6 commits into
ashhart:mainfrom
joshuaswarren:w7p/forward-write-clean
Nov 24, 2026
Merged

ashhart merged 6 commits into
ashhart:mainfrom
joshuaswarren:w7p/forward-write-clean

Conversation

@joshuaswarren

@joshuaswarren joshuaswarren commented Nov 21, 2026 •

Copy link
Copy Markdown
Contributor

What this changes

On large Qwen3.5 diagnostic output files, write in chunks of at most 256 MiB instead of issuing one oversized write. The bytes and order are preserved; this changes file output only, not inference arithmetic or GPU kernels. A review pass also made the cap a parameter, let sink and file errors pass through unflattened, and added a compile-time assertion that the production cap stays under INT_MAX.

Checks on this head

  • Head commit: bb21321d7571e5fdf2b72de9f7f16659a8a51273.
  • Lean checker, python3 tools/zig/lean_check.py: base 1587c8caee631dcc97c8fbb68f4bba353353c4c5 had 167 findings; this head had 167; lean_new.py reports 0 new findings.
  • Tests run, on this head:
    • zig build test-chunked-write --summary all: 4 passed, 0 failed, 0 skipped (cached rerun at this head; the rebase changed no content of the touched files); the step's peak RSS dropped from about 675 MB to 5 MB because the cap-and-order test now injects a 64-byte cap instead of allocating the production 256 MiB. A writer-level negative control asserts a sink-refused request surfaces as the sink's own error, and writeFileChunked's real file round-trip is unchanged. comptime asserts max_write_bytes < maxInt(c_int) in the module.
    • zig build -Dfixed-cpu test-golden --summary all at this head: 5/5 steps succeeded; 324/337 corpus cases equal, 0 unexpected differences; 69/69 server goldens equal, 0 unexpected differences.
    • git diff --check and zig fmt --check build.zig zig: passed.
    • The earlier combined zig build test test-golden on a prior head 46eb448d67f8a4741bc1a786cc1dddd8e64a3f7e failed with 27 test subprocesses, including fake-target lane-host failure messages and three golden-related hash mismatches. Standalone server goldens pass on every base/head pair since; that aggregate run stays unclassified and no GPU or device run was made.
  • CI on exact head ddff720e7e169333033ed641e2f150c36c4cdd87 (pre-rebase): all 9 checks passed, host-nightly-linux and host-nightly-macos skip on PRs. CI on exact head bb21321d7571e5fdf2b72de9f7f16659a8a51273: No-GPU run 44910204188 and format run 44910204186 queued at last check.
  • Not run: local Metal checks are unavailable on this Linux host. No GPU kernel changed, so the kernel contract does not apply to this change. The macOS host/golden nightly job skips for PRs.

Receipt

n/a — this is bounded diagnostic/test-file output; it does not change model inference, token generation, arithmetic, or kernels. The focused file test verifies byte-for-byte round-trip output.

  • Main against branch: n/a — no inference path changed.
  • Boxes it reaches: Qwen3.5 diagnostic/test output files only; no production serving path.
  • New switch: n/a — no setting or runtime mode added.
  • Environment: inference receipt n/a; local build uses Zig 0.17.0. No checkpoint, backend, or GPU measurement was made.
  • Paths and platforms: changed callers are the Qwen3.5 logits, hidden-state, stage, pipe, forward and CUDA-main diagnostic tools. Focused writer test and standalone goldens passed on Linux; CI's zig-macos-dev-tools passed and compiled the tools. Metal hardware was not exercised locally.
  • Exactness: inference token equality n/a; the focused tests verify exact bytes and order across a buffer larger than the cap, and the file test round-trips the real write path.
  • Main against this branch: n/a — no inference path changed.
  • Decode speed: n/a — no inference path changed.
  • Prompt speed: n/a — no prompt-processing path changed.
  • Licence of new weights or drafter: n/a — none added.

Checklist

  • The title and description match the head commit, receipt and stack.
  • New tests fail before the change, pass after it, and skip cleanly without their dependency. Fail-before receipt: on base 44a3529b5762, zig build test-chunked-write exits 1 with error: no such step: test-chunked-write (Zig 0.17.0, 2026-11-21). On this head the same step succeeds (3/3 steps; a cached rerun of the recorded 4-pass run). The tests are host-only and have no optional dependency to skip.
  • Comments and docstrings are one line. No measurements or history in the source.
  • No personal data, machine names, internal hosts or local paths in the diff or its commits. No AI attribution lines.

@joshuaswarren

Copy link
Copy Markdown
Contributor Author

The ATC overlap retry returned an incomplete result. Limits: myPullRequestsLimit, otherPullRequestsLimit, pullFilesUnavailable, and timeLimit. Reported overlaps have conflict status unknown; this does not establish a conflict-free result.

@AIFlowML

Copy link
Copy Markdown
Contributor

I trial-merged bb21321d7 into main 308d5e1fd on M5 Max with macOS 27.2 and Zig 0.17.0. The trial merged cleanly and git diff --cached --check passed.

  • zig build test-chunked-write -Dcpu=apple_m1 --summary all passed all four tests. This covers chunk order and the size bound, the original sink error, empty and exact-cap buffers, and the file round trip.
  • zig build -Dfixed-cpu test-golden --summary all finished 5/5 steps with 324/337 parity fixtures and 69/69 server fixtures matching, zero unexpected differences. The scratch setup emitted the missing libtfgrammar.dylib warning.

This adds macOS host coverage for the clean trial merge. I did not run a multi-GiB checkpoint export or the full host suite.

Igor Lessio - AIFLOW LABS

@ashhart

ashhart commented Nov 23, 2026

Copy link
Copy Markdown
Owner

Thanks for the bounded-write fix, @joshuaswarren. writeChunked currently makes no progress when called with nonempty input and a zero cap: each iteration writes an empty slice and leaves the offset unchanged. Please reject a zero cap before entering the loop and add a regression covering nonempty input with that cap. The existing file-writing callers use a positive constant, so this is an API edge case rather than a claim about their output.

  • Synthena

joshuaswarren added a commit to joshuaswarren/TensorFold that referenced this pull request Nov 23, 2026
Review on ashhart#4296 (ashhart): writeChunked made no progress with nonempty
input and a zero cap - every round wrote an empty slice and left the
offset unchanged. Reject the cap before the loop (ZeroWriteCap) and add
the regression: a nonempty buffer at a zero cap refuses with no bytes
written; an empty buffer passes.
@joshuaswarren

Copy link
Copy Markdown
Contributor Author

Fixed at 4118614d9: writeChunked rejects a zero cap before the loop (error.ZeroWriteCap), so a nonempty buffer can no longer stall the writer in an empty-slice round.

Regression added to chunked_write_test_file.zig: a nonempty buffer at a zero cap refuses with zero bytes written, and an empty buffer at a zero cap still passes (nothing to write).

Gate: zig build test-chunked-write green (all steps, cap/order/sink-error/empty/exact-cap and the new zero-cap cases). The file-writing callers keep their positive production cap (max_write_bytes), so their paths are unchanged.

@ashhart
ashhart force-pushed the w7p/forward-write-clean branch from 4118614 to 8276aa4 Compare November 24, 2026 01:30
ashhart pushed a commit to joshuaswarren/TensorFold that referenced this pull request Nov 24, 2026
Review on ashhart#4296 (ashhart): writeChunked made no progress with nonempty
input and a zero cap - every round wrote an empty slice and left the
offset unchanged. Reject the cap before the loop (ZeroWriteCap) and add
the regression: a nonempty buffer at a zero cap refuses with no bytes
written; an empty buffer passes.
joshuaswarren and others added 6 commits November 24, 2026 12:06
Darwin rejects a single write larger than INT_MAX.
Use bounded writes for Qwen 3.5 output files.
Verify with the chunked writer tests.
Remove multiline comments that fail the project lean check.
The focused writer tests pass.
Review on ashhart#4296 (ashhart): writeChunked made no progress with nonempty
input and a zero cap - every round wrote an empty slice and left the
offset unchanged. Reject the cap before the loop (ZeroWriteCap) and add
the regression: a nonempty buffer at a zero cap refuses with no bytes
written; an empty buffer passes.
@ashhart
ashhart force-pushed the w7p/forward-write-clean branch from 8276aa4 to 0ce4c1b Compare November 24, 2026 12:07
@ashhart
ashhart merged commit efa287b into ashhart:main Nov 24, 2026
2 of 12 checks passed
ashhart pushed a commit that referenced this pull request Nov 24, 2026
Review on #4296 (ashhart): writeChunked made no progress with nonempty
input and a zero cap - every round wrote an empty slice and left the
offset unchanged. Reject the cap before the loop (ZeroWriteCap) and add
the regression: a nonempty buffer at a zero cap refuses with no bytes
written; an empty buffer passes.
@ashhart

ashhart commented Nov 24, 2026

Copy link
Copy Markdown
Owner

Thank you @joshuaswarren. This is merged into main with your commits under your own name, so you're listed as a TensorFold contributor. It ships in the next release, credited to you in the changelog and the release notes.

ashhart added a commit to jschmied/TensorFold that referenced this pull request Nov 24, 2026
ashhart added a commit that referenced this pull request Nov 24, 2026
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.

3 participants