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:
@@ -303,6 +303,7 @@ impl Connection {
|
||||
}
|
||||
|
||||
#[napi(catch_unwind)]
|
||||
#[allow(clippy::too_many_arguments)]
|
||||
pub async fn create_materialized_view(
|
||||
&self,
|
||||
name: String,
|
||||
@@ -311,6 +312,11 @@ impl Connection {
|
||||
filter: Option<String>,
|
||||
limit: Option<i64>,
|
||||
with_no_data: bool,
|
||||
total_cpu_millis: Option<f64>,
|
||||
total_memory_bytes: Option<f64>,
|
||||
total_gpu_count: Option<f64>,
|
||||
gpu_class: Option<String>,
|
||||
gpu_count: Option<f64>,
|
||||
) -> napi::Result<Table> {
|
||||
let mut builder = self.get_inner()?.create_materialized_view(name, source);
|
||||
if let Some(projections) = projections {
|
||||
@@ -331,6 +337,45 @@ impl Connection {
|
||||
.map_err(|_| napi::Error::from_reason("limit must be a non-negative integer"))?;
|
||||
builder = builder.limit(limit);
|
||||
}
|
||||
const MAX_SAFE_INTEGER: f64 = 9_007_199_254_740_991.0;
|
||||
for (name, value, maximum, minimum) in [
|
||||
("total_cpu_millis", total_cpu_millis, MAX_SAFE_INTEGER, 1.0),
|
||||
(
|
||||
"total_memory_bytes",
|
||||
total_memory_bytes,
|
||||
MAX_SAFE_INTEGER,
|
||||
1.0,
|
||||
),
|
||||
("total_gpu_count", total_gpu_count, u32::MAX as f64, 0.0),
|
||||
] {
|
||||
if let Some(value) = value {
|
||||
if !value.is_finite() || value.fract() != 0.0 || value < minimum || value > maximum
|
||||
{
|
||||
return Err(napi::Error::from_reason(format!(
|
||||
"{name} must be an integer between {minimum} and {maximum}"
|
||||
)));
|
||||
}
|
||||
builder = match name {
|
||||
"total_cpu_millis" => builder.total_cpu_millis(value as u64),
|
||||
"total_memory_bytes" => builder.total_memory_bytes(value as u64),
|
||||
_ => builder.total_gpu_count(value as u32),
|
||||
};
|
||||
}
|
||||
}
|
||||
if let Some(class) = gpu_class {
|
||||
builder = builder.gpu_class(class);
|
||||
}
|
||||
if let Some(count) = gpu_count {
|
||||
if !count.is_finite()
|
||||
|| count.fract() != 0.0
|
||||
|| !(1.0..=u32::MAX as f64).contains(&count)
|
||||
{
|
||||
return Err(napi::Error::from_reason(
|
||||
"gpuCount must be an integer between 1 and 4294967295",
|
||||
));
|
||||
}
|
||||
builder = builder.gpu_count(count as u32);
|
||||
}
|
||||
builder = builder.with_no_data(with_no_data);
|
||||
let view = builder.execute().await.default_error()?;
|
||||
Ok(Table::new(view.table().clone()))
|
||||
|
||||
Reference in New Issue
Block a user