Skip to content

Make "never more memory than the host" a principle (design v18) - #91

Closed
alxmrs wants to merge 1 commit into
m2/fold-statisticsfrom
m2/memory-goal
Closed

alxmrs wants to merge 1 commit into
m2/fold-statisticsfrom
m2/memory-goal

Conversation

@alxmrs

@alxmrs alxmrs commented Oct 28, 2026

Copy link
Copy Markdown
Member

🪭 Claude (einfold)

Answers #79's second ask, and opens its third, as design v18.

The goal. For models trained in SQL, such as the GPT in xarray-sql's ML demos (xarray-sql's benchmarks/ml/02_nanogpt.py), memory limits model size as much as time does. Principle 9, "never more memory than the host", says how einfold's operators keep to it. They reserve what they read, and what their kernels allocate, from the host's memory pool, before allocating it. Where the pool can't give it, they run the host's own plan, whose operators can spill to disk. Every benchmark measures peak memory next to time.

What changes in the design.

Where the stack stands on #79, at its size (128 channels, context 64, batch 12, one layer), through datafusion-python on an Intel i7-8700:

DataFusion alone einfold, before #86 einfold, with #86–#90
the loss 108 s, 8.9 GB peak 42 s, 11.8 GB 13.6 s, 6.9 GB
the gradients 36.5 s, 9.8 GB 4.2 s, 1.8 GB

The peak is above the loaded tables. So the GPT already keeps to the principle at this size. Streaming in row blocks would make that hold by construction, not only under a pool.

🤖 Generated with Claude Code

https://claude.ai/code/session_01M96xSez6PZwTmfaGh2eJgS

@coderabbitai

coderabbitai Bot commented Oct 28, 2026 •

Copy link
Copy Markdown

Important

Review skipped

Auto reviews are disabled on base/target branches other than the default branch.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

Run configuration
  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: defaults
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 06453927-e75d-41d4-8cca-6a7dede4ef6e

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Comment @coderabbitai help to get the list of available commands.

@alxmrs alxmrs left a comment

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

LGTM

For models trained in SQL, such as the GPT in xarray-sql's ML demos,
memory limits size as much as time does (#79). Principle 9 says how
einfold's operators keep to the host's memory: they reserve what they
read and what their kernels allocate from the host's pool, and run the
host's own plan, which spills, where the pool can't give it. Section 10.2
says how EinFoldExec does this, and what comes next: streaming the
positional fold's larger operand in row blocks, which needs each
dimension's extent before reading. Section 15's benchmarks report peak
memory next to time, and section 14 opens dense chains of folds. The
lessons record what running einfold under the GPT taught.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01M96xSez6PZwTmfaGh2eJgS
@alxmrs
alxmrs force-pushed the m2/fold-statistics branch from a6982bc to 47036ba Compare October 29, 2026 02:31
alxmrs added a commit that referenced this pull request Oct 29, 2026
🪭 Claude (einfold): This is #91's commit, moved onto `main` so that it
can merge ahead of the stack it was part of. #91 is closed in its favor.

Answers #79's second ask, and opens its third, as design v18.

**The goal.** For models trained in SQL, such as the GPT in the ML demos
of xarray-sql, an XQL Systems project for querying xarray datasets with
SQL (its `benchmarks/ml/02_nanogpt.py`), memory limits model size as
much as time does. Principle 9, "never more memory than the host", says
how einfold's operators keep to it. They reserve what they read, and
what their kernels allocate, from the host's memory pool, before
allocating it. Where the pool can't give it, they run the host's own
plan, whose operators can spill to disk. Every benchmark measures peak
memory next to time.

**What changes in the design.**

- **Section 4** adds principle 9.
- **Section 10.2** gains a bullet on memory: what `EinFoldExec` does
(#89, #90), and what comes next. The positional fold should stream its
larger operand in row blocks, so that its peak stays below the host's
even without a pool to enforce it. That needs each dimension's extent
before reading, and #80's dictionaries answer it: the dictionary's
length, when it is the whole axis. Exact statistics or a first pass over
the keys also give it.
- **Section 15** reports peak memory next to time, which
`python/benchmarks/memory.py` (#85) does for the Python extension.
- **Section 14** opens #79's third ask, dense chains of folds: handing
the dense form from one einfold operator to the next, so the joined
intermediates never exist as rows. It lists what is open: the form
handed on, how a host operator between two folds reads it, and when a
chain is worth keeping dense.
- **`lessons.md`** records what running einfold under the GPT taught
(#77, #79, #81):
  - profile through the real bridge;
  - report statistics, and cache them;
  - plan a fallback only if it runs;
  - batch dimensions are common.

**Where the stack stands on #79**, at its size (128 channels, context
64, batch 12, one layer), through datafusion-python on an Intel i7-8700:

| | DataFusion alone | einfold, before #86 | einfold, with #86–#90 |
|---|---:|---:|---:|
| the loss | 108 s, 8.9 GB peak | 42 s, 11.8 GB | 13.6 s, 6.9 GB |
| the gradients | 36.5 s, 9.8 GB | | 4.2 s, 1.8 GB |

The peak is above the loaded tables. So the GPT already keeps to the
principle at this size. Streaming in row blocks would make that hold by
construction, not only under a pool.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

https://claude.ai/code/session_01M96xSez6PZwTmfaGh2eJgS



<!-- This is an auto-generated comment: release notes by coderabbit.ai
-->

<!-- coderabbit-ai-generated:v1 -->

## Summary by CodeRabbit

* **Documentation**
* Updated the design guidance to cover host-managed memory use, fallback
behavior, peak-memory benchmarks, and current limitations around
whole-input processing.
* Added lessons on measuring end-to-end performance, reporting row-count
statistics, delaying fallback planning until execution, and supporting
shared batch dimensions.
* Clarified that success benchmarks compare speed while keeping memory
use within the host’s plan.

<!-- end of auto-generated comment: release notes by coderabbit.ai -->

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
@alxmrs

alxmrs commented Oct 29, 2026

Copy link
Copy Markdown
Member Author

🪭 Claude (einfold): Merged as #106, which is this PR's commit moved onto main so that it could go ahead of the rest of the stack. Closing this one; #92 now targets #90's branch.

@alxmrs alxmrs closed this Oct 29, 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.

1 participant