Context.prepare can't prepare a query that calls grad, vjp or jvp

Aperta
#294 0 commenti 0 reazioni 0 assegnatari Vedi su GitHub

I maintainer di solito rispondono entro 3 giorni

Nessuno ha ancora preso questa issue.

Valutazione

Difficoltà
4/5
Tempo stimato
3-5 giorni
Idoneità per principianti
25/100
Tipo di issue
Funzionalità
Chiarezza
Abbastanza chiara
Stato di attività
Attiva
Stack tecnologico
python, sql

Direzione di ricerca

Start from Context.prepare() and Context.sql() in the xarray_sql package, and reproduce the ValueError from the snippet to see where DataFusion planning rejects grad. Then read xarray_sql.ad.sql_all and ddxdb's own prepare, and check how PreparedQuery handles writes into registered Datasets. Done means prepare() runs a query that calls grad, vjp or jvp and gives the same results as sql(). The interim NotImplementedError is tied to the unmerged #269 branch, so coordinate there first.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

ml

🌀 Claude: Context.sql() computes a query's grad, vjp and jvp calls through ddx (the ml extra, on the ml-demos branch of #269), but Context.prepare() plans the query with DataFusion alone, so it fails on the call:

import numpy as np, xarray as xr, xarray_sql as xql

ctx = xql.Context()
ctx.from_dataset("w", xr.Dataset({"val": ("feature", np.array([1.0, 2.0]))}, coords={"feature": [0, 1]}))
q = ("WITH loss AS (SELECT SUM(val * val) AS l FROM w) "
     "SELECT feature, grad(loss, val) AS g FROM w ORDER BY feature")
ctx.sql(q).to_pandas()   # g = [2.0, 4.0]
ctx.prepare(q)           # ValueError: Error during planning: Invalid function 'grad'. Did you mean 'rpad'?

(ddxdb 0.4.6, DataFusion 55.)

A training loop is where prepare matters most: it runs the same gradient step on every iteration, and planning ddx's programs costs far more than running them at small sizes. ddxdb has its own prepare, which plans the forward and backward programs once.

Proposal:

  • Until this is done, #269 makes prepare() raise a NotImplementedError that names sql() and xarray_sql.ad.sql_all, rather than DataFusion's planning error.
  • Then route a query that calls grad, vjp or jvp through ddxdb's prepare, keeping PreparedQuery's contract: writes into registered Datasets before a call, and the check that a table hasn't been registered again since the query was prepared.
  • sql_all's several statements over one backward pass would want the same, as a prepare_all or a prepare that takes several statements.
Lingua principale
Python
Stelle
142
Fork
19
Merge medio
3g 47m
PR unite (30g)
8

Preparare l'ambiente

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di xqlsystems/xarray-sql

Tutte le issue di xqlsystems/xarray-sql

Issue simili

Altre issue su Python

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.