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:
Jack Ye
2026-11-21 15:04:34 -08:00
committed by GitHub
parent e3e55844bc
commit 2b1b2a29dd
50 changed files with 2110 additions and 946 deletions
+35
View File
@@ -286,6 +286,11 @@ export abstract class Connection {
where?: string;
limit?: number;
withNoData?: boolean;
totalCpuMillis?: number;
totalMemoryBytes?: number;
totalGpuCount?: number;
gpuClass?: string;
gpuCount?: number;
},
): Promise<MaterializedView>;
@@ -674,9 +679,34 @@ export class LocalConnection extends Connection {
where?: string;
limit?: number;
withNoData?: boolean;
totalCpuMillis?: number;
totalMemoryBytes?: number;
totalGpuCount?: number;
gpuClass?: string;
gpuCount?: number;
},
): Promise<MaterializedView> {
validateNonNegativeInteger(options?.limit, "limit");
for (const [name, value] of [
["totalCpuMillis", options?.totalCpuMillis],
["totalMemoryBytes", options?.totalMemoryBytes],
["totalGpuCount", options?.totalGpuCount],
["gpuCount", options?.gpuCount],
] as const) {
validateNonNegativeInteger(value, name);
if (value === 0 && name !== "totalGpuCount") {
throw new Error(`${name} must be positive`);
}
}
if (
options?.totalGpuCount !== undefined &&
options.totalGpuCount > 4294967295
) {
throw new Error("totalGpuCount exceeds 4294967295");
}
if (options?.gpuCount !== undefined && options.gpuCount > 4294967295) {
throw new Error("gpuCount exceeds 4294967295");
}
const innerTable = await this.inner.createMaterializedView(
name,
source,
@@ -684,6 +714,11 @@ export class LocalConnection extends Connection {
options?.where,
options?.limit,
options?.withNoData ?? false,
options?.totalCpuMillis,
options?.totalMemoryBytes,
options?.totalGpuCount,
options?.gpuClass,
options?.gpuCount,
);
return new MaterializedView(new LocalTable(innerTable));
}
-1
View File
@@ -60,7 +60,6 @@ export {
FunctionRefreshPlanningConfig,
FunctionRefreshPodResources,
FunctionRetryPolicy,
FunctionWorkerResourceBudget,
RefreshColumnResult,
FunctionErrors,
FunctionErrorsOptions,
+28
View File
@@ -197,11 +197,39 @@ export class MaterializedView {
async refresh(options?: {
full?: boolean;
sourceVersion?: number;
totalCpuMillis?: number;
totalMemoryBytes?: number;
totalGpuCount?: number;
gpuClass?: string;
gpuCount?: number;
}): Promise<RefreshMaterializedViewResult> {
validateNonNegativeInteger(options?.sourceVersion, "sourceVersion");
for (const [name, value] of [
["totalCpuMillis", options?.totalCpuMillis],
["totalMemoryBytes", options?.totalMemoryBytes],
["totalGpuCount", options?.totalGpuCount],
["gpuCount", options?.gpuCount],
] as const) {
validateNonNegativeInteger(value, name);
if (value === 0 && name !== "totalGpuCount") {
throw new Error(`${name} must be positive`);
}
if (
(name === "gpuCount" || name === "totalGpuCount") &&
value !== undefined &&
value > 4294967295
) {
throw new Error(`${name} exceeds 4294967295`);
}
}
return await this.inner.refreshMaterializedView(
options?.sourceVersion,
options?.full,
options?.totalCpuMillis,
options?.totalMemoryBytes,
options?.totalGpuCount,
options?.gpuClass,
options?.gpuCount,
);
}
}
+28 -20
View File
@@ -962,26 +962,18 @@ export abstract class Table {
* `REFRESH COLUMN ... WHERE ... WITH (...)` form: `where` narrows the rows,
* `errorPolicy`, `maxFailedFraction`, `maxFailedRows`, `rowTimeoutSeconds`
* and `initTimeoutSeconds` govern failing rows. `batchSize`, `gpuClass`,
* `maxConcurrency`, `resourceBudget`, `supervisorResources`,
* `maxConcurrency`, `totalCpuMillis`, `totalMemoryBytes`, `supervisorResources`,
* `planningWorkers` and `maxExecutorProcessesPerWorker` size registered
* Function refreshes. `retryPolicy` overrides user-code retries only when
* repeating partial work is safe; set `maxAttempts: 1` to disable retries.
* `maxConcurrency` overrides the registered default for this logical
* execution only and is a positive integer; it is not an account-wide
* quota. A `resourceBudget` requires `cpuMillis` and
* `memoryBytes`; its `gpuCount` defaults to zero for a CPU-only Function.
* `supervisorResources` and each `planningWorkers.resources` entry require
* positive `cpuMillis`, `memoryBytes` and `ephemeralStorageBytes`.
* `planningWorkers` also requires positive `maxWorkers`,
* `rowsPerWorker` and `fragmentsPerWorker`.
* The budget applies only to this explicit refresh and does not configure
* a later automatic refresh.
* `gpuCount` at the top level is the shorthand that preserves the
* deployment defaults for CPU and memory, and cannot be combined with
* `resourceBudget`. `numWorkers` applies only to expression columns; use
* `resourceBudget` for registered Functions. All are LanceDB Enterprise
* only; a LanceDB Embedded refresh rejects every option other than
* `batchSize`, `gpuClass` and `gpuCount`.
* quota. `totalCpuMillis`, `totalMemoryBytes`, and `totalGpuCount` override
* their corresponding execution-wide resource limits independently. Unset
* values inherit column defaults, then Function defaults, then deployment
* defaults. A zero GPU limit is valid for CPU-only Functions.
* `supervisorResources` and `planningWorkers.resources` are per-pod sizes.
* `numWorkers` applies only to expression columns.
* `publicationIntervalRows` opts into publishing completed Function split
* ranges once their accumulated unpublished rows reach the threshold.
* It must be a positive safe integer and requires non-Blob Function outputs.
@@ -991,10 +983,8 @@ export abstract class Table {
* ```ts
* const job = await table.refreshColumnAsync("embedding", {
* where: "published_at > '2026-01-01'",
* resourceBudget: {
* cpuMillis: 8000,
* memoryBytes: 16 * 1024 ** 3,
* },
* totalCpuMillis: 8000,
* totalMemoryBytes: 16 * 1024 ** 3,
* maxConcurrency: 4,
* publicationIntervalRows: 10000,
* errorPolicy: "skip",
@@ -1067,6 +1057,11 @@ export abstract class Table {
abstract refreshMaterializedView(
sourceVersion?: number,
full?: boolean,
totalCpuMillis?: number,
totalMemoryBytes?: number,
totalGpuCount?: number,
gpuClass?: string,
gpuCount?: number,
): Promise<RefreshMaterializedViewResult>;
/** @ignore */
@@ -2048,8 +2043,21 @@ export class LocalTable extends Table {
async refreshMaterializedView(
sourceVersion?: number,
full?: boolean,
totalCpuMillis?: number,
totalMemoryBytes?: number,
totalGpuCount?: number,
gpuClass?: string,
gpuCount?: number,
): Promise<RefreshMaterializedViewResult> {
return await this.inner.refreshMaterializedView(sourceVersion, full);
return await this.inner.refreshMaterializedView(
sourceVersion,
full,
totalCpuMillis,
totalMemoryBytes,
totalGpuCount,
gpuClass,
gpuCount,
);
}
async materializedViewDefinition(): Promise<string> {