mirror of
https://github.com/lancedb/lancedb.git
synced 2026-11-26 12:33:59 +00:00
feat!: layer GPU settings and total execution limits (#5146)
BREAKING CHANGE: Resource inputs use the same names at Function
registration, column/MV creation, and refresh. Use total_cpu_millis,
total_memory_bytes, and total_gpu_count for execution-wide worker
budgets, plus gpu_class and positive gpu_count for each worker. Replace
budget dictionary inputs and unprefixed aggregate limits with these
fields. Move existing refresh gpu_count caps to total_gpu_count;
gpu_count now selects devices per worker.
Each setting resolves independently: refresh > column/MV creation >
Function annotation > deployment. Creation settings also apply to
initial MV population and automatic refresh. MVs sum total budgets
across distinct pinned Function versions; per-worker GPU counts use the
largest Function default unless overridden. An unset GPU class resolves
to gpu_class="any" after inheritance; an explicit "any" overrides a
registered concrete class. Use gpu_class="default" to pin the default
pool explicitly.
```python
@function(
gpu=True, gpu_class="h100", gpu_count=2,
total_cpu_millis=8000,
total_memory_bytes=16 * 1024**3,
total_gpu_count=4,
)
def embed(text: str) -> list[float]: ...
version = db.create_function(embed)
table.add_columns(
{"embedding": version(text=col("text"))},
gpu_class="any", gpu_count=1, total_gpu_count=8,
)
table.refresh_column_async(
"embedding", gpu_class="h100", gpu_count=4, total_gpu_count=8,
)
mv = db.create_materialized_view(
"embeddings", query="SELECT embed(text) AS embedding FROM documents",
gpu_class="any", gpu_count=2, total_gpu_count=8,
)
mv.refresh(gpu_count=4, total_gpu_count=8)
```
```mermaid
flowchart TD
R["Refresh settings"] --> E["Effective settings, resolved per field"]
D["Column or MV creation settings"] --> E
F["Function settings"] --> E
C["Deployment defaults"] --> E
E --> W["GPU class and device count per worker"]
E --> T["Total CPU, memory and GPU ceilings"]
```
Pinned Function images retain their identity. Registration GPU counts
are defaults; execution overrides determine worker allocation. Admission
rejects GPU counts below an image's minimum requirement or above the
total budget. Python, Rust, SQL/REST and supported TypeScript operations
use the same resource model.
No local builds or tests, as requested; regression coverage runs in CI.
This commit is contained in:
@@ -63,8 +63,9 @@ version is unaffected.
|
||||
| `apt` | OS packages to install in the worker environment |
|
||||
| `image` | a specific container image to run the worker in, such as `'host/repo@sha256:...'` |
|
||||
| `python_version` | worker Python version; `3.12` when omitted, whatever Python you send the statement from |
|
||||
| `gpu` | `'true'` when every execution needs a GPU |
|
||||
| `gpu_class` | which configured GPU class to run on, when `gpu = 'true'` |
|
||||
| `gpu` | Enable GPU execution with `True` (Python) or `true` (SQL); defaults to CPU execution |
|
||||
| `gpu_class` | Operator-configured GPU class, such as `h100`; requires GPU execution |
|
||||
| `gpu_count` | GPUs allocated together per Function worker; positive integer, defaults to one; requires GPU execution |
|
||||
| `result_stability` | `'input_and_context'` or `'per_call'` |
|
||||
| `batch_size` | maximum rows per Function call |
|
||||
| `row_timeout_seconds` | per-row (or per-batch, for a vectorized Function) execution timeout |
|
||||
@@ -76,7 +77,7 @@ version is unaffected.
|
||||
| `LANGUAGE` other than `python` | refused |
|
||||
| `pip` and `conda` together | refused (pick one) |
|
||||
| `conda_channels` without `conda` | refused |
|
||||
| `gpu` set to anything but `'true'` | refused |
|
||||
| An invalid GPU class, zero GPU count, or a count above the configured class limit | refused; use a configured `gpu_class` and a positive `gpu_count` |
|
||||
| An empty body | refused |
|
||||
| Any other option | refused, and the message lists what is supported |
|
||||
|
||||
|
||||
@@ -155,3 +155,23 @@ same underlying job as dropping any table, `drop_table` or `drop_object`.
|
||||
How a refresh works, in LanceDB Enterprise.
|
||||
</Card>
|
||||
</CardGroup>
|
||||
|
||||
|
||||
### Resource settings
|
||||
|
||||
Creation accepts `total_cpu_millis`, `total_memory_bytes`, and `total_gpu_count`
|
||||
as execution-wide defaults, plus `gpu_class` and positive `gpu_count` for each
|
||||
worker. Refresh accepts the same names and overrides each supplied field.
|
||||
Unspecified fields inherit creation settings, then Function settings, then
|
||||
deployment defaults. A materialized view sums total budgets across distinct
|
||||
pinned Function versions; per-worker counts use the largest Function default
|
||||
unless overridden.
|
||||
|
||||
```sql
|
||||
CREATE MATERIALIZED VIEW embeddings
|
||||
WITH (gpu_class = 'any', gpu_count = 2, total_gpu_count = 8)
|
||||
AS SELECT embed(text) AS embedding FROM documents;
|
||||
|
||||
REFRESH MATERIALIZED VIEW embeddings
|
||||
WITH (gpu_class = 'h100', gpu_count = 4, total_gpu_count = 8);
|
||||
```
|
||||
|
||||
@@ -52,10 +52,11 @@ to let LanceDB track which outputs need updating.
|
||||
| Option | Meaning |
|
||||
| --- | --- |
|
||||
| `num_workers` | fixed worker count for SQL-expression columns; rejected for registered Function columns |
|
||||
| `cpu_millis` | aggregate CPU ceiling across the refresh's Function workers, in thousandths of a CPU |
|
||||
| `memory_bytes` | aggregate memory ceiling across the refresh's Function workers, in bytes |
|
||||
| `gpu_count` | aggregate GPU budget across the refresh's workers. Function columns only |
|
||||
| `gpu_class` | GPU class name for the refresh's workers. Function columns only |
|
||||
| `total_cpu_millis` | aggregate CPU ceiling across the refresh's Function workers, in thousandths of a CPU |
|
||||
| `total_memory_bytes` | aggregate memory ceiling across the refresh's Function workers, in bytes |
|
||||
| `total_gpu_count` | aggregate GPU budget across the refresh's workers. Function columns only |
|
||||
| `gpu_class` | GPU class name for the refresh's workers; `any` accepts any eligible pool. Function columns only |
|
||||
| `gpu_count` | positive number of GPUs allocated together to each worker. Function columns only |
|
||||
| `batch_size` | maximum rows passed to one Function call; actual calls can be smaller. Function columns only |
|
||||
| `max_executor_processes_per_worker` | cap on executor processes per worker. Function columns only |
|
||||
| `row_timeout_seconds` | deadline for one Function call. Function columns only |
|
||||
@@ -66,14 +67,15 @@ to let LanceDB track which outputs need updating.
|
||||
<CodeGroup>
|
||||
```sql SQL icon="database"
|
||||
REFRESH COLUMN embedding ON documents
|
||||
WITH (cpu_millis = 8000, memory_bytes = 17179869184, gpu_count = 2)
|
||||
WITH (total_cpu_millis = 8000, total_memory_bytes = 17179869184, total_gpu_count = 2)
|
||||
```
|
||||
</CodeGroup>
|
||||
|
||||
The example allows up to 8 CPUs, 16 GiB of memory, and 2 GPUs across the
|
||||
Function workers together. It does not reserve those resources per worker or
|
||||
guarantee a worker count. When setting CPU or memory, provide all three budget
|
||||
fields. A complete CPU-only budget uses `gpu_count = 0`.
|
||||
guarantee a worker count. Set each resource independently; omitted values inherit
|
||||
column `total_*` settings, then Function defaults, then deployment defaults.
|
||||
A CPU-only GPU budget uses `total_gpu_count = 0`.
|
||||
|
||||
Set `error_policy` on the refresh, not on the Function definition. With `skip`,
|
||||
inspect failures with `SHOW ERRORS` or `table.function_errors()` and retry the
|
||||
|
||||
@@ -14,8 +14,8 @@ A LanceDB extension with no DataFusion equivalent.
|
||||
<CodeGroup>
|
||||
```sql SQL icon="database"
|
||||
REFRESH MATERIALIZED VIEW <name>
|
||||
[WITH (full = <boolean>, cpu_millis = <integer>, memory_bytes = <integer>,
|
||||
gpu_count = <integer>, gpu_class = '<class>')]
|
||||
[WITH (full = <boolean>, total_cpu_millis = <integer>, total_memory_bytes = <integer>,
|
||||
total_gpu_count = <integer>, gpu_class = '<class>')]
|
||||
```
|
||||
</CodeGroup>
|
||||
|
||||
@@ -43,20 +43,20 @@ Set budgets for one refresh execution:
|
||||
|
||||
```sql
|
||||
REFRESH MATERIALIZED VIEW curated_training_set WITH (
|
||||
cpu_millis = 8000,
|
||||
memory_bytes = 17179869184,
|
||||
gpu_count = 2,
|
||||
total_cpu_millis = 8000,
|
||||
total_memory_bytes = 17179869184,
|
||||
total_gpu_count = 2,
|
||||
gpu_class = 'h100'
|
||||
);
|
||||
```
|
||||
|
||||
`cpu_millis` is CPU capacity in millicores (1000 = one core), not CPU time.
|
||||
`memory_bytes` caps memory in bytes. `gpu_count` caps concurrent GPUs for the
|
||||
`total_cpu_millis` is CPU capacity in millicores (1000 = one core), not CPU time.
|
||||
`total_memory_bytes` caps memory in bytes. `total_gpu_count` caps concurrent GPUs for the
|
||||
refresh. These are aggregate caps across its SQL execution and Function
|
||||
processes; they are not multiplied by the number of Functions in the query.
|
||||
|
||||
CPU or memory requires all three budget fields. CPU and memory must be positive;
|
||||
`gpu_count = 0` is allowed for CPU-only views. A GPU budget alone is also accepted.
|
||||
Each resource may be overridden independently. CPU and memory must be positive;
|
||||
`total_gpu_count = 0` is allowed for CPU-only views. A GPU budget alone is also accepted.
|
||||
A cap does not reserve all of its GPUs or increase refresh parallelism. Current
|
||||
MV refreshes use at most one GPU, shared by their GPU Function calls.
|
||||
|
||||
|
||||
Reference in New Issue
Block a user