Repository navigation
Share SQL stages and dispatch validated numerical kernels - #302
cromwellian wants to merge 3 commits into
Conversation
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>
|
Important Draft PR not reviewedDraft PRs are not automatically reviewed by default.
To automatically review draft PRs, update your CodeRabbit configuration: reviews:
auto_review:
drafts: true
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. |
|
🌀 Claude: Thank you. The measurements here are excellent: 1.53× on the tiny model from computing each CTE once, with every result checked. They show clearly what recomputing CTEs costs us. This PR's concerns are about where the code lives rather than whether it works. I've opened #307 to decide where each piece should go. Strengths
Concerns
I'd hold this PR until #307 settles. The pieces that stay in xarray-sql (the host tolerances, and the demos on public APIs) could then land on their own. |
🛠️ 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>
🛠️ Codex
Evaluate reachable shared CTEs once per invocation and reuse their stage programs while keeping ddx differentiation of the original SQL/views. Add session-local EinFold numerical dispatch for explicit float64 CPU or float32 MLX GPU execution, deterministic function eligibility, fresh physical state, ordered Arrow providers and bounded coordinate reuse. Ordinary SQL remains the fallback for unsupported semantics.
Depends on CPU setup/preparation #301 and EinFold’s kernel-backend PR. Incremental review: cromwellian/xarray-sql@codex/training-plan-reuse...codex/shared-kernel-execution . GitHub requires fork PRs to target upstream main, so the default diff includes the predecessor until it merges.
Measured tiny-model shared CPU/GPU warm steps improved 314→206 ms (1.53×) and 371→224 ms (1.66×), with fewer repeated kernel dispatches. GPU alone did not solve large-model backward/Arrow overhead. The separate compact-array and resident-training PRs address those remaining costs. The performance/evidence PR retains the detailed workloads and raw results.
The optional installer builds a pinned commit from the separate EinFold fork; native sources and patches are not duplicated here. Validation of the full contribution stack: 714 non-integration tests passed against rebuilt dependency wheels, including SQL masks/NULLs, custom-function overrides, changing inputs, coordinates and snapshots. Rust formatting and changed-file Ruff checks passed. GPU arithmetic remains explicit float32.