mirror of
https://github.com/lancedb/lancedb.git
synced 2026-11-26 20:44:00 +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:
@@ -71,45 +71,46 @@ Both a Function application and a SQL expression accept
|
||||
`auto_refresh_enabled` and `auto_refresh_interval_seconds`, and both refresh
|
||||
and toggle the same way; see [Auto Refresh](/enterprise/auto-refresh).
|
||||
|
||||
Python and Rust Function declarations can also set
|
||||
`auto_refresh_resource_budget` to give their automatic refreshes an aggregate
|
||||
CPU, memory, and optional GPU budget. CPU and memory are required. The nested
|
||||
`gpu_count` defaults to zero, so omitting it requests CPU-only workers:
|
||||
Function declarations can set `total_cpu_millis`,
|
||||
`total_memory_bytes`, and `total_gpu_count`. Each optional
|
||||
value supplies a default for both manual and automatic refreshes. `gpu_class`
|
||||
and `gpu_count` similarly override the Function's per-worker GPU defaults.
|
||||
|
||||
<CodeGroup>
|
||||
```python Python icon="python"
|
||||
table.add_columns(
|
||||
{"caption": version(jpeg=col("jpeg"))},
|
||||
auto_refresh_resource_budget={
|
||||
"cpu_millis": 8000,
|
||||
"memory_bytes": 16 * 1024**3,
|
||||
},
|
||||
total_cpu_millis=8000,
|
||||
total_memory_bytes=16 * 1024**3,
|
||||
total_gpu_count=4,
|
||||
gpu_class="any",
|
||||
gpu_count=2,
|
||||
)
|
||||
```
|
||||
|
||||
```rust Rust icon="rust"
|
||||
use lancedb::table::computed_columns::ComputedColumnOptions;
|
||||
|
||||
table
|
||||
.add_columns()
|
||||
.function(function_application)
|
||||
.computed_options(ComputedColumnOptions {
|
||||
auto_refresh_enabled: true,
|
||||
auto_refresh_interval_seconds: None,
|
||||
auto_refresh_resource_budget: Some(
|
||||
FunctionWorkerResourceBudget::new(8000, 17_179_869_184),
|
||||
),
|
||||
total_cpu_millis: Some(8000),
|
||||
total_memory_bytes: Some(16 * 1024_u64.pow(3)),
|
||||
total_gpu_count: Some(4),
|
||||
gpu_class: Some("any".into()),
|
||||
gpu_count: Some(2),
|
||||
..Default::default()
|
||||
})
|
||||
.execute()
|
||||
.await?;
|
||||
```
|
||||
</CodeGroup>
|
||||
|
||||
This setting applies to every output in the Function binding. SQL-expression
|
||||
columns do not use Function workers, so they reject
|
||||
`auto_refresh_resource_budget` instead of accepting an option that has no
|
||||
effect. The separate `resource_budget` refresh option configures one explicit
|
||||
refresh and does not change this automatic-refresh declaration. The Node.js
|
||||
SDK does not currently expose a Function declaration through `addColumns`, so
|
||||
this option is not added to an unsupported surface.
|
||||
Refresh values with the same names override these column defaults. Unspecified column
|
||||
values inherit the pinned Function's `total_*` settings, then the
|
||||
deployment defaults. The GPU budget must fit one Function worker. These
|
||||
settings apply to registered Function columns in LanceDB Enterprise.
|
||||
|
||||
## Fill a column with a SQL expression {#expressions}
|
||||
|
||||
|
||||
@@ -333,7 +333,7 @@ too slow or too expensive:
|
||||
<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>
|
||||
|
||||
@@ -342,75 +342,65 @@ up to 8 CPUs, 16 GiB of memory, and 2 GPUs across the fleet. They are not
|
||||
per-worker allocations or a guaranteed worker count. `num_workers` is only
|
||||
accepted for SQL-expression columns; registered Function columns reject it.
|
||||
|
||||
In particular, `gpu_count = 2` does not request two devices inside one Python
|
||||
In particular, `total_gpu_count = 2` does not request two devices inside one Python
|
||||
process or enable tensor parallelism. Inspect configured GPU classes and their
|
||||
per-worker limits with `db.list_gpu_classes()` or `SHOW GPU CLASSES`. Choose a
|
||||
model that fits the worker shape supported by your deployment; see
|
||||
[GPU placement and budgets](/enterprise/function-operations#gpu).
|
||||
|
||||
The SDKs accept the same nested budget. CPU and memory are required; the GPU
|
||||
count inside the budget defaults to zero, so a CPU-only Function can omit it:
|
||||
The SDKs expose the same independent total limits:
|
||||
|
||||
<CodeGroup>
|
||||
```python Python icon="python"
|
||||
job = table.refresh_column_async(
|
||||
"embedding",
|
||||
resource_budget={
|
||||
"cpu_millis": 8000,
|
||||
"memory_bytes": 16 * 1024**3,
|
||||
},
|
||||
total_cpu_millis=8000,
|
||||
total_memory_bytes=16 * 1024**3,
|
||||
total_gpu_count=2,
|
||||
)
|
||||
job.wait()
|
||||
```
|
||||
|
||||
```rust Rust icon="rust"
|
||||
use lancedb::table::{
|
||||
FunctionWorkerResourceBudget,
|
||||
RefreshColumnOptions,
|
||||
};
|
||||
use lancedb::table::RefreshColumnOptions;
|
||||
|
||||
let _job = table
|
||||
.refresh_column_async_with_options(
|
||||
"embedding",
|
||||
RefreshColumnOptions::default().resource_budget(
|
||||
FunctionWorkerResourceBudget::new(8000, 17_179_869_184),
|
||||
),
|
||||
RefreshColumnOptions::default()
|
||||
.total_cpu_millis(8000)
|
||||
.total_memory_bytes(17_179_869_184)
|
||||
.total_gpu_count(2),
|
||||
)
|
||||
.await?;
|
||||
```
|
||||
|
||||
```typescript TypeScript icon="typescript"
|
||||
const job = await table.refreshColumnAsync("embedding", {
|
||||
resourceBudget: {
|
||||
cpuMillis: 8000,
|
||||
memoryBytes: 16 * 1024 ** 3,
|
||||
},
|
||||
totalCpuMillis: 8000,
|
||||
totalMemoryBytes: 16 * 1024 ** 3,
|
||||
totalGpuCount: 2,
|
||||
});
|
||||
await job.wait();
|
||||
```
|
||||
</CodeGroup>
|
||||
|
||||
On current SQL servers, the equivalent `REFRESH COLUMN ... WITH (...)` form
|
||||
still takes all three fields when CPU or memory is set; use `gpu_count = 0`
|
||||
for a CPU-only Function. The SDK normalizes an omitted nested GPU count to a
|
||||
numeric zero before sending the request.
|
||||
|
||||
The existing top-level `gpu_count` / `gpuCount` option remains the shorthand
|
||||
for changing only the aggregate GPU budget. It cannot be combined with the
|
||||
complete resource budget. Omitting both preserves the server's existing
|
||||
defaults.
|
||||
Each supplied `total_*` value overrides that resource for this refresh.
|
||||
Unspecified values inherit the column's `total_*` settings, then the
|
||||
pinned Function's defaults, then the deployment defaults. `total_gpu_count=0`
|
||||
limits the refresh to CPU workers and cannot run a GPU Function.
|
||||
|
||||
{/*
|
||||
Draft for the Function refresh control-plane resource release.
|
||||
|
||||
`resource_budget` above sizes the Function workers. Two independent options
|
||||
`total_cpu_millis`, `total_memory_bytes`, and `total_gpu_count` above sizes the Function workers. Two independent options
|
||||
size the refresh control plane for a registered Function.
|
||||
`supervisor_resources` sets the CPU, memory and ephemeral-storage limits of
|
||||
the supervisor pod. `planning_workers` sets the resources of one planning
|
||||
worker and the sizing of the CPU-only planning fleet: `max_workers`,
|
||||
`rows_per_worker` and `fragments_per_worker`. Every field is required and
|
||||
must be positive. Omitting either option leaves the server's configured
|
||||
defaults unchanged, and either can be combined with `resource_budget`.
|
||||
defaults unchanged, and either can be combined with `total_cpu_millis`, `total_memory_bytes`, and `total_gpu_count`.
|
||||
|
||||
<CodeGroup>
|
||||
```python Python icon="python"
|
||||
@@ -495,11 +485,11 @@ The SDK validates the shape and sends these values only with this explicit
|
||||
refresh request. A supporting LanceDB Enterprise server is required.
|
||||
*/}
|
||||
|
||||
These examples configure only the explicit refresh shown. A registered
|
||||
Function declaration can separately set `auto_refresh_resource_budget` on
|
||||
`add_columns`; that declaration controls the budget for its automatic
|
||||
refreshes. SQL-expression columns reject the automatic resource-budget option
|
||||
because they do not use Function workers.
|
||||
A Function column may set `total_cpu_millis`,
|
||||
`total_memory_bytes`, and `total_gpu_count` on `add_columns`.
|
||||
These override the Function defaults for both manual and automatic refreshes.
|
||||
The settings apply to registered Function columns; SQL-expression columns use
|
||||
`num_workers` instead.
|
||||
|
||||
To override the registered Function's call concurrency for this logical
|
||||
execution only:
|
||||
@@ -531,7 +521,7 @@ await job.wait();
|
||||
|
||||
`max_concurrency` caps user-code calls in flight for one Function within one
|
||||
logical execution. It is not an account-wide quota and does not resize or
|
||||
rewrite `resource_budget`. Omitting it uses the registration default; a
|
||||
rewrite `total_cpu_millis`, `total_memory_bytes`, and `total_gpu_count`. Omitting it uses the registration default; a
|
||||
refresh value overrides that default for this execution only.
|
||||
|
||||
`batch_size` caps rows in one Function call; LanceDB adapts actual call and
|
||||
@@ -613,7 +603,7 @@ gpu_class = next(gpu.name for gpu in classes if gpu.gpu_model == "NVIDIA H100")
|
||||
job = table.refresh_column_async(
|
||||
"embedding",
|
||||
gpu_class=gpu_class,
|
||||
gpu_count=4,
|
||||
total_gpu_count=4,
|
||||
batch_size=32,
|
||||
)
|
||||
```
|
||||
@@ -637,7 +627,7 @@ async fn refresh(
|
||||
"embedding",
|
||||
RefreshColumnOptions::default()
|
||||
.gpu_class(gpu_class)
|
||||
.gpu_count(4)
|
||||
.total_gpu_count(4)
|
||||
.batch_size(32),
|
||||
)
|
||||
.await?;
|
||||
@@ -646,19 +636,21 @@ async fn refresh(
|
||||
```
|
||||
</CodeGroup>
|
||||
|
||||
`gpu_count` is the aggregate GPU budget for the refresh's Function workers,
|
||||
not a request for that many GPUs per worker. It must be positive and preserves
|
||||
the deployment's CPU and memory defaults.
|
||||
`total_gpu_count` is the aggregate GPU budget for the refresh's Function workers,
|
||||
and `gpu_count` is the positive number of devices allocated together to each
|
||||
worker. The total budget must fit at least one worker. Omitted CPU and memory
|
||||
values inherit column settings, then Function settings, then deployment defaults.
|
||||
`gpu_class` must name a class returned by `list_gpu_classes()`; class names
|
||||
are lowercase DNS labels. Omit either option to use the Function's registered
|
||||
class or the server's configured budget. `list_gpu_classes()` requires System
|
||||
are lowercase DNS labels; `"any"` accepts any eligible configured class. Each
|
||||
omitted setting inherits the column's setting, then the Function's setting.
|
||||
If no layer specifies a GPU class, omission is equivalent to `"any"`. `list_gpu_classes()` requires System
|
||||
Usage permission, and raises `NotImplementedError` when the server predates
|
||||
GPU class discovery.
|
||||
|
||||
<Note>
|
||||
The Rust GPU discovery and refresh controls are not in the latest Rust
|
||||
release. TypeScript does not expose GPU class discovery; pass `gpuClass`
|
||||
and `gpuCount` in the `refreshColumnAsync` options.
|
||||
and `totalGpuCount` in the `refreshColumnAsync` options.
|
||||
</Note>
|
||||
|
||||
Completed Function outputs publish with their fragment by default. To opt into
|
||||
@@ -750,8 +742,8 @@ The SDK rejects a blank `where`, a `max_failed_fraction` outside 0 to 1, a
|
||||
timeout that is not a positive number and a zero worker or process count
|
||||
before sending the request; the server validates everything else. A LanceDB
|
||||
Embedded refresh rejects every option other than `batch_size`, `gpu_class`
|
||||
and `gpu_count`; in particular, it rejects `resource_budget` rather than
|
||||
silently ignoring it.
|
||||
and `total_gpu_count`; in particular, it rejects `total_cpu_millis` and
|
||||
`total_memory_bytes` rather than silently ignoring them.
|
||||
|
||||
## When a refresh fails {#failures}
|
||||
|
||||
|
||||
@@ -60,20 +60,20 @@ LanceDB Embedded it always matches `rows_written` from the most recent
|
||||
refresh.
|
||||
|
||||
{/*
|
||||
Draft: publish this section after the Python/Rust resource-budget SDK support
|
||||
is released. TypeScript parity is tracked separately in issue #4903.
|
||||
Draft: publish this section after the resource-control SDK support is released.
|
||||
|
||||
## Resource budgets {#resources}
|
||||
|
||||
For training-data curation, bound the resources used to recompute a view:
|
||||
Bound the resources used to recompute a view:
|
||||
|
||||
<CodeGroup>
|
||||
```python Python icon="python"
|
||||
job = view.refresh_async(
|
||||
cpu_millis=8000,
|
||||
memory_bytes=16 * 1024**3,
|
||||
gpu_count=2,
|
||||
total_cpu_millis=8000,
|
||||
total_memory_bytes=16 * 1024**3,
|
||||
total_gpu_count=4,
|
||||
gpu_class="h100",
|
||||
gpu_count=2,
|
||||
)
|
||||
job.wait()
|
||||
```
|
||||
@@ -84,38 +84,45 @@ use lancedb::materialized_view::MaterializedView;
|
||||
async fn refresh(view: &MaterializedView) -> lancedb::Result<()> {
|
||||
let job = view
|
||||
.refresh()
|
||||
.cpu_millis(8000)
|
||||
.memory_bytes(16_u64 << 30)
|
||||
.gpu_count(2)
|
||||
.total_cpu_millis(8000)
|
||||
.total_memory_bytes(16_u64 << 30)
|
||||
.total_gpu_count(4)
|
||||
.gpu_class("h100")
|
||||
.gpu_count(2)
|
||||
.execute_async()
|
||||
.await?;
|
||||
job.wait().await?;
|
||||
Ok(())
|
||||
}
|
||||
```
|
||||
|
||||
```typescript TypeScript icon="js"
|
||||
await view.refresh({
|
||||
totalCpuMillis: 8000,
|
||||
totalMemoryBytes: 16 * 1024 ** 3,
|
||||
totalGpuCount: 4,
|
||||
gpuClass: "h100",
|
||||
gpuCount: 2,
|
||||
});
|
||||
```
|
||||
</CodeGroup>
|
||||
|
||||
The same options are available on `refresh`, asynchronous Python connections,
|
||||
and the Rust refresh builder (`cpu_millis`, `memory_bytes`, `gpu_count`, and
|
||||
`gpu_class`). CPU is in millicores (8000 means eight cores), memory is bytes,
|
||||
and GPU count is an aggregate concurrent cap. CPU or memory requires all three
|
||||
budget fields. Use zero GPUs for a CPU-only view, or specify a GPU cap alone.
|
||||
CPU is in millicores (8000 means eight cores), memory is in bytes, and
|
||||
`total_gpu_count` is the aggregate concurrent GPU cap. `gpu_count` allocates
|
||||
that many devices together to each worker; the total cap must fit at least
|
||||
one worker. Use `total_gpu_count=0` for a CPU-only view.
|
||||
|
||||
The cap covers the refresh execution and its Function processes together.
|
||||
It does not allocate that budget separately to each Function. A GPU class
|
||||
selects placement for this execution; discover configured classes with
|
||||
`db.list_gpu_classes()`. A cap does not promise more parallelism: current MV
|
||||
refreshes use at most one GPU. Omitted settings keep existing defaults.
|
||||
Each omitted setting inherits the view's creation setting, then the Function
|
||||
setting. Total budgets across distinct pinned Function versions are summed;
|
||||
the per-worker count uses their largest default. Remaining total budgets use
|
||||
deployment defaults. An unresolved GPU class is equivalent to `"any"`, and
|
||||
an explicit `gpu_class="any"` overrides a concrete creation or Function class.
|
||||
Discover configured classes with `db.list_gpu_classes()`.
|
||||
|
||||
These controls require an Enterprise server with an isolated backend that can
|
||||
enforce them; Embedded and unsupported execution backends reject them. Earlier
|
||||
Enterprise servers reject the new SQL options. See the
|
||||
These controls require LanceDB Enterprise with an isolated backend that can
|
||||
enforce them; Embedded and unsupported execution backends reject them. See the
|
||||
[SQL resource options](/sql/dml/refresh-materialized-view#resources).
|
||||
|
||||
TypeScript does not expose these options yet; SDK parity is tracked in
|
||||
[issue #4903](https://github.com/lancedb/lancedb/issues/4903).
|
||||
|
||||
*/}
|
||||
|
||||
## Automatic refresh {#auto-refresh}
|
||||
|
||||
Reference in New Issue
Block a user