ML demo: a U-Net in SQL, for einfold to optimize convolutions against

未关闭
#291 0 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

维护者通常 3 天内回复

还没有人认领这个 Issue。

评估

难度
5/5
预计耗时
一周以上
新手友好度
38/100
Issue 类型
功能
描述清晰度
基本清楚
活跃度
活跃
技术栈
python, sql

调研方向

Start with benchmarks/ml/CONTRIBUTING.md and compare the structure of 01_attention.py and 02_nanogpt.py. Build a readable U-Net demo with a JAX reference, timed SQL steps across hosts in _hosts.py, and checks for forward results and input and weight gradients; completion means those comparisons agree to about 1e-15. einfold's shifted-key optimizer work is tracked separately, and results belong on #285.

由索引模型根据 Issue 内容生成。

描述

enhancement ml

🪭 Claude (einfold)

A request for a new demo in benchmarks/ml, following its CONTRIBUTING.md, which already lists "a small convolutional network over a grid, where a convolution is a join on shifted coordinates" among the demos that would fit. The proposal: a U-Net (Ronneberger, Fischer and Brox, U-Net: Convolutional Networks for Biomedical Image Segmentation, 2015), the encoder–decoder CNN with skip connections that geoscience uses for downscaling, nowcasting and segmentation.

einfold, XQL Systems' query optimizer that rewrites SQL plans into array algorithms, would use it the way it uses 01_attention.py: as the workload it optimizes against.

Why this model

  • It is the convolution shape einfold doesn't detect yet. A convolution is a fold over a join whose keys are shifted, i.y = o.y + w.dy, not equal columns. einfold's next design step for it is shifted keys in its fold IR, so that the dense kernels take convolutions directly. Strides and dilations become a multiplier on the offset. Padding needs no special case: border pixels simply have fewer taps, which is SQL's own result when the shifted rows don't exist. A demo gives that work a correctness reference (JAX) and a benchmark, as attention did for einfold's fused pipelines.
  • It exercises more than convolutions.
    • Convolution, then bias, then ReLU, is a fold pipeline, which einfold's M2 fuses.
    • Downsampling (a strided convolution, or a max-pool, which is MAX over shifted keys) and upsampling (a transposed convolution) are the same join with o.y = 2·i.y + dy and its inverse.
    • Skip connections concatenate channels from two levels: a UNION ALL, or a join on the pixel.
  • It fits xarray-sql's audience. A U-Net on an ERA5 field, such as downscaling a coarse temperature grid or predicting a field one step ahead, is a model geoscientists train on gridded data. Its input is an xarray Dataset registered as a table of (time, y, x, channel).
  • ddx gets new gradients to check. The gradient of a convolution with respect to its input is a transposed convolution, and with respect to its weights is a correlation of the input with the output gradient: the same shifted-key shape again.

Suggested shape

The pieces, as 02_nanogpt.py builds its model from functions named after the reference's:

  • conv(x, w, stride, dilation): SUM(x.v * w.v) over x JOIN w ON x.c = w.ci AND x.y = o.y * stride + w.dy * dilation AND …, grouped by the output's (n, y, x, co). One way to write o is a join against a coordinate table, or x.y - w.dy grouped directly;
  • relu, bias: derived factors;
  • down(x): a stride-2 convolution, or a 2 × 2 max-pool;
  • up(x): a stride-2 transposed convolution, or nearest-neighbour JOIN ON o.y / 2 = i.y;
  • skip(a, b): channels of two levels, concatenated;
  • unet(depth, width): two or three levels, 8–32 channels, 3 × 3 kernels, on a grid of about 64 × 64 to 256 × 256.

Checked against the same network in JAX: jax.lax.conv_general_dilated, or Flax's nn.Conv, with 64-bit floats, so they agree to about 1e-15. Check the forward pass, and ddx's gradients with respect to the input and to every weight table.

The interesting knobs for einfold's measurements:

  • grid size;
  • channel widths, which make the convolutions dense or near-dense;
  • depth, which is the number of folds in a pipeline;
  • stride, against pooling.

As in the other demos: the same SQL on every host in _hosts.py, each step timed, with its error against JAX.

Not asked here

Speed. The demo should be written to be read, as the others are. einfold's side, detecting and running shifted-key folds, will be tracked in einfold. Results go on #285.

主要语言
Python
星标
142
派生
19
平均合并
3 天 47 分钟
30 天内合并 PR
8

环境准备

  • 没有 Dockerfile 或 Docker Compose 文件
  • 没有 Pull Request 模板
  • 阅读贡献指南

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

xqlsystems/xarray-sql 的其他 Issue

查看 xqlsystems/xarray-sql 的全部 Issue

相似的 Issue

更多 Python Issue

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。