Skip to content

Retain compact arrays across numerical SQL programs - #303

Draft
cromwellian wants to merge 5 commits into
xqlsystems:mainfrom
cromwellian:codex/compact-sql-execution
Draft

cromwellian wants to merge 5 commits into
xqlsystems:mainfrom
cromwellian:codex/compact-sql-execution

Conversation

@cromwellian

@cromwellian cromwellian commented Nov 2, 2026 •

Copy link
Copy Markdown
Contributor

🛠️ Codex

Add DenseExecutor to retain compact numerical arrays across shared DataFusion/ddx SQL stages through EinFold's optional array-program module. Axis domains, row-presence and NULL masks remain explicit; joins become gathers/contractions and UNION reductions accumulate gradients. Ordinary calls import current inputs afresh and produce independent Arrow snapshots. Bounded intermediates and strict refusal preserve original SQL fallback before caller-visible mutation.

Depends on shared-kernel execution #302 and EinFold compact programs. Incremental review: cromwellian/xarray-sql@codex/shared-kernel-execution...codex/compact-sql-execution . The upstream fork PR's default diff includes predecessors until they merge.

Measured five-step 123.6M/context-16 training improved shared CPU 164.034→4.037 s (40.6×) and shared GPU 163.646→2.434 s (67.2×) per warm loss/update pair. GPU sampled RSS fell 40.0→17.91 GiB on that case. These use batch 1, tanh GELU, SGD and a padded 50,257-class vocabulary; they are separate from the real-character AdamW recipe. All losses/weight updates were checked against JAX outside the API timer. The complete performance/evidence report records first-use and full-context results and failed trials separately.

Full-stack validation: 714 non-integration tests passed on rebuilt ddx/EinFold wheels. Ordinary state still crosses the Arrow boundary; owned GPU state and whole-step compilation follow in the resident-training PR. No model/framework backward pass replaces ddx.

Ray and others added 5 commits November 1, 2026 23:24
Support prepared SQL gradients, arithmetic chunk-grid counts and direct Arrow registration. Preserve Context metadata through extension installation, expose target partitions and guard physical reuse against value-dependent filters.

Co-Authored-By: GPT-6 <noreply@openai.com>
Materialize shared reachable CTEs once, reuse stage programs with fresh physical state, and retain ddx differentiation of original views. Add optional session-local float64 CPU and float32 MLX kernel execution with SQL validation and fallback, using the separately maintained EinFold feature build.

Co-Authored-By: GPT-6 <noreply@openai.com>
Build the upstream-compatible feature commit from the contribution fork.

Co-Authored-By: GPT-6 <noreply@openai.com>
Lower supported DataFusion and ddx stages through EinFold compact programs, importing live inputs on each ordinary query and expanding coordinates only at Arrow snapshot boundaries. Bound computed intermediates, preserve row/NULL masks and retain conservative SQL fallback.

Co-Authored-By: GPT-6 <noreply@openai.com>
Keep the compact executor build reproducible without copying native or array-program sources into this repository.

Co-Authored-By: GPT-6 <noreply@openai.com>
@coderabbitai

coderabbitai Bot commented Nov 2, 2026

Copy link
Copy Markdown

Important

Draft PR not reviewed

Draft PRs are not automatically reviewed by default.

  • Trigger a manual review

To automatically review draft PRs, update your CodeRabbit configuration:

reviews:
  auto_review:
    drafts: true
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

Share

@alxmrs

alxmrs commented Nov 4, 2026

Copy link
Copy Markdown
Member

🌀 Claude: Thank you. Compact arrays across stages are the biggest win in the stack: 164 → 2.4 s per warm update on the 123.6M-parameter model, with 40.0 → 17.9 GiB of memory, all checked against JAX. The care taken over masks, bag semantics and declining before anything a caller can see changes shows.

Concerns

  • Where it lives. DenseExecutor and _dense_mlx.py are execution-engine code. They sit on einfold#157's DenseProgram, and Where should shared CTE execution, compact arrays and GPU-resident training live? #307 proposes they live with it in einfold.
  • Private imports. xarray_sql/dense.py imports _CACHE, _EXECUTION, _MAX_BYTES, _OPS, _ComputedCache, _Decline and _read_dataset from einfold.dense_program, and _dense_mlx.py imports _OPS, _align, _Decline and _op. These need a public interface.
  • Behavior set at import time. Whether MLX is used depends on MLX_ENABLE_TF32 at import time. Setting it later, or in a different order, silently changes the backend. An explicit argument, like MLX(precision=...) in Share SQL stages and dispatch validated numerical kernels #302, would be clearer.

I'd hold this until #307 and einfold#157's design question settle.

alxmrs added a commit that referenced this pull request Nov 15, 2026
🛠️ Codex

Repeated training calls can prepare a SQL grad/VJP/JVP statement once
with `Context.prepare` and write new Dataset values into existing input
buffers. Fine-chunk registration counts partitions arithmetically and
registers Arrow batches directly; extension handles retain Dataset
metadata and invalidation state. `Context(threads=...)` exposes target
parallel partitions.

This independently useful change starts the NanoGPT optimization stack;
shared/compact execution, resident training and the evidence report
follow separately.

Apple M5 Ultra measurements: one-cell-chunk registration 31.372→0.405 ms
(77.44× for that specific case), update-and-sum 2.769→1.027 ms (2.70×),
repeated-CTE preparation 1.709→1.307 ms (1.31×). Tiny-model warm time
improved 1.11×, but its five-step total regressed due to setup; this
does not claim universally faster startup.

Validation: 47 focused AD/preparation tests passed, covering current
inputs, changing join-key ranges, old-result snapshots, coordinate
rejection and shared Context invalidation. The complete downstream stack
passed 714 non-integration tests. Changed Python files pass Ruff.

Review order: this PR → #302 (shared kernels) → #303 (compact arrays) →
#305 (resident training). #304 contains the separate consolidated report
and evidence.



Closes #294


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

## Summary by CodeRabbit

* **New Features**
* Prepared queries now support gradient, vector-Jacobian product, and
Jacobian-vector product operations, including repeated execution after
registered table data is updated or re-registered.
  * Added an option to configure the number of query threads.
  * Added support for creating contexts with extensions.
* **Bug Fixes**
* Improved prepared-query results when join-key values change and when
datasets are registered in smaller chunks.
  * Improved in-memory partitioning for datasets.
* **Documentation**
* Clarified that prepared queries retain programs for repeated
execution.
<!-- end of auto-generated comment: release notes by coderabbit.ai -->

---------

Co-authored-by: Ray <cromwellian@Rays-Mac-Studio.local>
Co-authored-by: GPT-6 <noreply@openai.com>
Co-authored-by: Alex Merose <al@merose.com>
Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>

This branch has not been deployed

No deployments
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.

2 participants