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:
@@ -305,6 +305,7 @@ pub enum PythonRuntimeSpec {
|
||||
/// },
|
||||
/// env: BTreeMap::new(),
|
||||
/// gpu_class: Some("a10g".to_string()),
|
||||
/// gpus_per_worker: std::num::NonZeroU32::new(2),
|
||||
/// };
|
||||
/// assert!(runtime.requires_gpu());
|
||||
/// ```
|
||||
@@ -312,8 +313,10 @@ pub enum PythonRuntimeSpec {
|
||||
python_version: String,
|
||||
environment: PythonEnvironmentSpec,
|
||||
env: BTreeMap<String, String>,
|
||||
/// Operator-defined GPU class; absent uses the deployment default.
|
||||
/// Operator-defined GPU class; absent accepts any eligible configured class.
|
||||
gpu_class: Option<String>,
|
||||
/// GPUs allocated together to each worker.
|
||||
gpus_per_worker: Option<std::num::NonZeroU32>,
|
||||
},
|
||||
/// A runtime kind introduced by a newer server.
|
||||
///
|
||||
@@ -365,17 +368,30 @@ impl PythonRuntimeSpec {
|
||||
matches!(self, Self::PythonV2 { .. })
|
||||
}
|
||||
|
||||
/// Operator-defined GPU class, or `None` to use the deployment default.
|
||||
/// Requested GPU class; `None` and `"any"` both accept any eligible class.
|
||||
/// This does not identify the hardware selected for execution.
|
||||
pub fn gpu_class(&self) -> Option<&str> {
|
||||
match self {
|
||||
Self::PythonV2 { gpu_class, .. } => gpu_class.as_deref(),
|
||||
_ => None,
|
||||
}
|
||||
}
|
||||
|
||||
/// GPUs allocated to one worker; zero for CPU runtimes.
|
||||
pub fn gpus_per_worker(&self) -> u32 {
|
||||
match self {
|
||||
Self::PythonV2 {
|
||||
gpus_per_worker, ..
|
||||
} => gpus_per_worker.map_or(1, std::num::NonZeroU32::get),
|
||||
_ => 0,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Deserialize)]
|
||||
struct PythonRuntimeV1Wire {
|
||||
#[serde(default)]
|
||||
gpus_per_worker: Option<Value>,
|
||||
python_version: String,
|
||||
environment: PythonEnvironmentSpec,
|
||||
#[serde(default)]
|
||||
@@ -388,6 +404,8 @@ struct PythonRuntimeV1Wire {
|
||||
|
||||
#[derive(Deserialize)]
|
||||
struct PythonRuntimeV2Wire {
|
||||
#[serde(default)]
|
||||
gpus_per_worker: Option<std::num::NonZeroU32>,
|
||||
python_version: String,
|
||||
environment: PythonEnvironmentSpec,
|
||||
#[serde(default)]
|
||||
@@ -420,6 +438,11 @@ impl<'de> Deserialize<'de> for PythonRuntimeSpec {
|
||||
"python runtime with gpu_class requires kind='python_v2'",
|
||||
));
|
||||
}
|
||||
if wire.gpus_per_worker.is_some() {
|
||||
return Err(de::Error::custom(
|
||||
"gpus_per_worker requires kind='python_v2'",
|
||||
));
|
||||
}
|
||||
Ok(Self::Python {
|
||||
python_version: wire.python_version,
|
||||
environment: wire.environment,
|
||||
@@ -440,6 +463,7 @@ impl<'de> Deserialize<'de> for PythonRuntimeSpec {
|
||||
environment: wire.environment,
|
||||
env: wire.env,
|
||||
gpu_class: wire.gpu_class,
|
||||
gpus_per_worker: wire.gpus_per_worker,
|
||||
})
|
||||
}
|
||||
_ => Ok(Self::Unrecognized { kind }),
|
||||
@@ -460,6 +484,8 @@ impl Serialize for PythonRuntimeSpec {
|
||||
gpu: Option<bool>,
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
gpu_class: Option<&'a str>,
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
gpus_per_worker: Option<std::num::NonZeroU32>,
|
||||
}
|
||||
|
||||
#[derive(Serialize)]
|
||||
@@ -479,6 +505,7 @@ impl Serialize for PythonRuntimeSpec {
|
||||
env,
|
||||
gpu: None,
|
||||
gpu_class: None,
|
||||
gpus_per_worker: None,
|
||||
}
|
||||
.serialize(serializer),
|
||||
Self::PythonV2 {
|
||||
@@ -486,6 +513,7 @@ impl Serialize for PythonRuntimeSpec {
|
||||
environment,
|
||||
env,
|
||||
gpu_class,
|
||||
gpus_per_worker,
|
||||
} => PythonRuntimeRef {
|
||||
kind: "python_v2",
|
||||
python_version,
|
||||
@@ -493,6 +521,7 @@ impl Serialize for PythonRuntimeSpec {
|
||||
env,
|
||||
gpu: Some(true),
|
||||
gpu_class: gpu_class.as_deref(),
|
||||
gpus_per_worker: *gpus_per_worker,
|
||||
}
|
||||
.serialize(serializer),
|
||||
Self::Unrecognized { kind } => UnrecognizedRuntimeRef { kind }.serialize(serializer),
|
||||
@@ -675,6 +704,24 @@ pub struct FunctionVersion {
|
||||
deserialize_with = "deserialize_max_concurrency"
|
||||
)]
|
||||
max_concurrency: Option<u32>,
|
||||
#[serde(
|
||||
default,
|
||||
skip_serializing_if = "Option::is_none",
|
||||
deserialize_with = "deserialize_total_cpu_millis"
|
||||
)]
|
||||
total_cpu_millis: Option<u64>,
|
||||
#[serde(
|
||||
default,
|
||||
skip_serializing_if = "Option::is_none",
|
||||
deserialize_with = "deserialize_total_memory_bytes"
|
||||
)]
|
||||
total_memory_bytes: Option<u64>,
|
||||
#[serde(
|
||||
default,
|
||||
skip_serializing_if = "Option::is_none",
|
||||
deserialize_with = "deserialize_total_gpu_count"
|
||||
)]
|
||||
total_gpu_count: Option<u32>,
|
||||
/// Per-call deadline in seconds.
|
||||
#[serde(default, skip_serializing_if = "Option::is_none")]
|
||||
row_timeout_seconds: Option<RowTimeoutSeconds>,
|
||||
@@ -773,6 +820,21 @@ impl FunctionVersion {
|
||||
self.gpu_class.as_deref()
|
||||
}
|
||||
|
||||
/// Default total CPU budget for executions of this pinned Function.
|
||||
pub fn total_cpu_millis(&self) -> Option<u64> {
|
||||
self.total_cpu_millis
|
||||
}
|
||||
|
||||
/// Default total memory budget for executions of this pinned Function.
|
||||
pub fn total_memory_bytes(&self) -> Option<u64> {
|
||||
self.total_memory_bytes
|
||||
}
|
||||
|
||||
/// Default aggregate GPU budget, independent of the per-worker device count.
|
||||
pub fn total_gpu_count(&self) -> Option<u32> {
|
||||
self.total_gpu_count
|
||||
}
|
||||
|
||||
/// Default maximum rows in one callable batch, when declared.
|
||||
pub fn batch_size(&self) -> Option<u32> {
|
||||
self.batch_size
|
||||
@@ -900,6 +962,44 @@ where
|
||||
Ok(value)
|
||||
}
|
||||
|
||||
fn deserialize_total_cpu_millis<'de, D>(
|
||||
deserializer: D,
|
||||
) -> std::result::Result<Option<u64>, D::Error>
|
||||
where
|
||||
D: Deserializer<'de>,
|
||||
{
|
||||
let value = Option::<u64>::deserialize(deserializer)
|
||||
.map_err(|error| de::Error::custom(format!("total_cpu_millis: {error}")))?;
|
||||
if value == Some(0) {
|
||||
return Err(de::Error::custom("total_cpu_millis must be positive"));
|
||||
}
|
||||
Ok(value)
|
||||
}
|
||||
|
||||
fn deserialize_total_memory_bytes<'de, D>(
|
||||
deserializer: D,
|
||||
) -> std::result::Result<Option<u64>, D::Error>
|
||||
where
|
||||
D: Deserializer<'de>,
|
||||
{
|
||||
let value = Option::<u64>::deserialize(deserializer)
|
||||
.map_err(|error| de::Error::custom(format!("total_memory_bytes: {error}")))?;
|
||||
if value == Some(0) {
|
||||
return Err(de::Error::custom("total_memory_bytes must be positive"));
|
||||
}
|
||||
Ok(value)
|
||||
}
|
||||
|
||||
fn deserialize_total_gpu_count<'de, D>(
|
||||
deserializer: D,
|
||||
) -> std::result::Result<Option<u32>, D::Error>
|
||||
where
|
||||
D: Deserializer<'de>,
|
||||
{
|
||||
Option::<u32>::deserialize(deserializer)
|
||||
.map_err(|error| de::Error::custom(format!("total_gpu_count: {error}")))
|
||||
}
|
||||
|
||||
fn deserialize_max_concurrency<'de, D>(
|
||||
deserializer: D,
|
||||
) -> std::result::Result<Option<u32>, D::Error>
|
||||
@@ -970,6 +1070,27 @@ pub struct FunctionRegistrationRequest {
|
||||
deserialize_with = "deserialize_max_concurrency"
|
||||
)]
|
||||
pub max_concurrency: Option<u32>,
|
||||
/// Default total CPU capacity for one execution, in millicores.
|
||||
#[serde(
|
||||
default,
|
||||
skip_serializing_if = "Option::is_none",
|
||||
deserialize_with = "deserialize_total_cpu_millis"
|
||||
)]
|
||||
pub total_cpu_millis: Option<u64>,
|
||||
/// Default total memory for one execution, in bytes.
|
||||
#[serde(
|
||||
default,
|
||||
skip_serializing_if = "Option::is_none",
|
||||
deserialize_with = "deserialize_total_memory_bytes"
|
||||
)]
|
||||
pub total_memory_bytes: Option<u64>,
|
||||
/// Default total GPUs across one execution's workers.
|
||||
#[serde(
|
||||
default,
|
||||
skip_serializing_if = "Option::is_none",
|
||||
deserialize_with = "deserialize_total_gpu_count"
|
||||
)]
|
||||
pub total_gpu_count: Option<u32>,
|
||||
/// Deadline for each Python call, in seconds: one row for scalar Functions
|
||||
/// and one batch for vectorized Functions. It does not govern Function
|
||||
/// initialization.
|
||||
@@ -1010,6 +1131,11 @@ impl FunctionRegistrationRequest {
|
||||
let invalid_input = |message: &'static str| Error::InvalidInput {
|
||||
message: message.to_string(),
|
||||
};
|
||||
if self.total_cpu_millis == Some(0) || self.total_memory_bytes == Some(0) {
|
||||
return Err(invalid_input(
|
||||
"total_cpu_millis and total_memory_bytes must be positive integers",
|
||||
));
|
||||
}
|
||||
validate_batch_size_value(self.batch_size).map_err(invalid_input)?;
|
||||
validate_max_concurrency_value(self.max_concurrency).map_err(invalid_input)?;
|
||||
validate_row_timeout_value(self.row_timeout_seconds).map_err(invalid_input)?;
|
||||
@@ -1618,6 +1744,7 @@ mod refresh_result_tests {
|
||||
#[cfg(test)]
|
||||
mod conda_environment_tests {
|
||||
use super::{PythonEnvironmentSpec, PythonRuntimeSpec};
|
||||
use serde_json::Value;
|
||||
|
||||
#[test]
|
||||
fn conda_channels_round_trip_and_pip_stays_bare() {
|
||||
@@ -1679,6 +1806,28 @@ mod conda_environment_tests {
|
||||
super::canonical_json(&runtime).unwrap(),
|
||||
r#"{"environment":{"kind":"pip"},"gpu":true,"gpu_class":"a10g","kind":"python_v2","python_version":"3.12"}"#
|
||||
);
|
||||
let runtime: PythonRuntimeSpec = serde_json::from_str(
|
||||
r#"{"kind":"python_v2","python_version":"3.12","environment":{"kind":"pip"},"gpu":true,"gpu_class":"any","gpus_per_worker":2}"#,
|
||||
).unwrap();
|
||||
assert_eq!(runtime.gpus_per_worker(), 2);
|
||||
assert_eq!(runtime.gpu_class(), Some("any"));
|
||||
let encoded = super::canonical_json(&runtime).unwrap();
|
||||
assert_eq!(
|
||||
serde_json::from_str::<Value>(&encoded).unwrap()["gpus_per_worker"],
|
||||
2
|
||||
);
|
||||
for count in [
|
||||
serde_json::json!(0),
|
||||
serde_json::json!(-1),
|
||||
serde_json::json!(true),
|
||||
serde_json::json!("2"),
|
||||
serde_json::json!(1.5),
|
||||
serde_json::json!(4294967296_u64),
|
||||
] {
|
||||
let mut value: Value = serde_json::from_str(&encoded).unwrap();
|
||||
value["gpus_per_worker"] = count;
|
||||
assert!(serde_json::from_value::<PythonRuntimeSpec>(value).is_err());
|
||||
}
|
||||
|
||||
for invalid in [
|
||||
r#"{"kind":"python","python_version":"3.12","environment":{"kind":"pip"},"gpu":true}"#,
|
||||
|
||||
@@ -301,6 +301,11 @@ pub struct CreateMaterializedViewRequest {
|
||||
pub auto_refresh_enabled: Option<bool>,
|
||||
/// Refresh interval in seconds. When absent, the server determines when to refresh.
|
||||
pub auto_refresh_interval_seconds: Option<f64>,
|
||||
pub total_cpu_millis: Option<u64>,
|
||||
pub total_memory_bytes: Option<u64>,
|
||||
pub total_gpu_count: Option<u32>,
|
||||
pub gpu_class: Option<String>,
|
||||
pub gpu_count: Option<u32>,
|
||||
}
|
||||
|
||||
/// Prefix of the internal columns holding source columns a computed column
|
||||
@@ -1591,6 +1596,11 @@ pub struct CreateMaterializedViewBuilder {
|
||||
exist_ok: bool,
|
||||
auto_refresh_enabled: Option<bool>,
|
||||
auto_refresh_interval_seconds: Option<f64>,
|
||||
total_cpu_millis: Option<u64>,
|
||||
total_memory_bytes: Option<u64>,
|
||||
total_gpu_count: Option<u32>,
|
||||
gpu_class: Option<String>,
|
||||
gpu_count: Option<u32>,
|
||||
}
|
||||
|
||||
enum MaterializedViewInput {
|
||||
@@ -1632,6 +1642,11 @@ impl CreateMaterializedViewBuilder {
|
||||
exist_ok: false,
|
||||
auto_refresh_enabled: None,
|
||||
auto_refresh_interval_seconds: None,
|
||||
total_cpu_millis: None,
|
||||
total_memory_bytes: None,
|
||||
total_gpu_count: None,
|
||||
gpu_class: None,
|
||||
gpu_count: None,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1783,6 +1798,36 @@ impl CreateMaterializedViewBuilder {
|
||||
Ok(query)
|
||||
}
|
||||
|
||||
/// Set the default total cpu millis budget for this materialized view.
|
||||
pub fn total_cpu_millis(mut self, value: u64) -> Self {
|
||||
self.total_cpu_millis = Some(value);
|
||||
self
|
||||
}
|
||||
|
||||
/// Set the default total memory bytes budget for this materialized view.
|
||||
pub fn total_memory_bytes(mut self, value: u64) -> Self {
|
||||
self.total_memory_bytes = Some(value);
|
||||
self
|
||||
}
|
||||
|
||||
/// Set the default total gpu count budget for this materialized view.
|
||||
pub fn total_gpu_count(mut self, value: u32) -> Self {
|
||||
self.total_gpu_count = Some(value);
|
||||
self
|
||||
}
|
||||
|
||||
/// Set the default GPU pool for initial population and later refreshes.
|
||||
pub fn gpu_class(mut self, class: impl Into<String>) -> Self {
|
||||
self.gpu_class = Some(class.into());
|
||||
self
|
||||
}
|
||||
|
||||
/// Set the default positive GPU count for each worker.
|
||||
pub fn gpu_count(mut self, count: u32) -> Self {
|
||||
self.gpu_count = Some(count);
|
||||
self
|
||||
}
|
||||
|
||||
/// Submit creation and initial population, returning a [`Job`] that
|
||||
/// settles when the view is ready. Remote creation submits SQL; the handle's
|
||||
/// [`Job::job_type`] is `"query"` and its ID identifies that query.
|
||||
@@ -1799,6 +1844,11 @@ impl CreateMaterializedViewBuilder {
|
||||
with_no_data: self.with_no_data,
|
||||
auto_refresh_enabled: self.auto_refresh_enabled,
|
||||
auto_refresh_interval_seconds: self.auto_refresh_interval_seconds,
|
||||
total_cpu_millis: self.total_cpu_millis,
|
||||
total_memory_bytes: self.total_memory_bytes,
|
||||
total_gpu_count: self.total_gpu_count,
|
||||
gpu_class: self.gpu_class.clone(),
|
||||
gpu_count: self.gpu_count,
|
||||
})
|
||||
.await;
|
||||
}
|
||||
@@ -1832,7 +1882,14 @@ impl CreateMaterializedViewBuilder {
|
||||
{
|
||||
return Ok(view);
|
||||
}
|
||||
if self.auto_refresh_enabled == Some(true) || self.auto_refresh_interval_seconds.is_some() {
|
||||
if self.auto_refresh_enabled == Some(true)
|
||||
|| self.auto_refresh_interval_seconds.is_some()
|
||||
|| self.total_cpu_millis.is_some()
|
||||
|| self.total_memory_bytes.is_some()
|
||||
|| self.total_gpu_count.is_some()
|
||||
|| self.gpu_class.is_some()
|
||||
|| self.gpu_count.is_some()
|
||||
{
|
||||
return Err(Error::NotSupported {
|
||||
message: "automatic materialized-view refresh requires LanceDB Enterprise"
|
||||
.to_string(),
|
||||
@@ -1961,49 +2018,53 @@ impl MaterializedView {
|
||||
/// Per-execution resource caps and GPU placement for Enterprise MV refreshes.
|
||||
///
|
||||
/// CPU is in millicores (1000 = one core), memory is bytes, and GPUs are a
|
||||
/// simultaneous cap across the refresh, not a per-Function allocation. CPU or
|
||||
/// memory requires all three budget fields. Embedded refreshes reject options.
|
||||
/// simultaneous cap across the refresh. Each omitted resource inherits the
|
||||
/// view defaults, then Function defaults, then deployment defaults.
|
||||
/// Embedded refreshes reject these options.
|
||||
#[derive(Debug, Clone, Default, PartialEq, Eq)]
|
||||
#[non_exhaustive]
|
||||
pub struct RefreshMaterializedViewOptions {
|
||||
pub cpu_millis: Option<u64>,
|
||||
pub memory_bytes: Option<u64>,
|
||||
pub gpu_count: Option<u32>,
|
||||
pub total_cpu_millis: Option<u64>,
|
||||
pub total_memory_bytes: Option<u64>,
|
||||
pub total_gpu_count: Option<u32>,
|
||||
pub gpu_class: Option<String>,
|
||||
pub gpu_count: Option<u32>,
|
||||
}
|
||||
|
||||
impl RefreshMaterializedViewOptions {
|
||||
pub(crate) fn is_empty(&self) -> bool {
|
||||
self.cpu_millis.is_none()
|
||||
&& self.memory_bytes.is_none()
|
||||
&& self.gpu_count.is_none()
|
||||
self.total_cpu_millis.is_none()
|
||||
&& self.total_memory_bytes.is_none()
|
||||
&& self.total_gpu_count.is_none()
|
||||
&& self.gpu_class.is_none()
|
||||
&& self.gpu_count.is_none()
|
||||
}
|
||||
|
||||
pub(crate) fn validate(&self) -> Result<()> {
|
||||
let invalid = |message: &str| Error::InvalidInput {
|
||||
message: message.into(),
|
||||
};
|
||||
if self.cpu_millis == Some(0) || self.memory_bytes == Some(0) {
|
||||
if self.total_cpu_millis == Some(0) || self.total_memory_bytes == Some(0) {
|
||||
return Err(invalid(
|
||||
"cpu_millis and memory_bytes must be positive integers",
|
||||
));
|
||||
}
|
||||
if (self.cpu_millis.is_some() || self.memory_bytes.is_some())
|
||||
&& !(self.cpu_millis.is_some()
|
||||
&& self.memory_bytes.is_some()
|
||||
&& self.gpu_count.is_some())
|
||||
{
|
||||
return Err(invalid(
|
||||
"cpu_millis, memory_bytes, and gpu_count must be specified together",
|
||||
"total_cpu_millis and total_memory_bytes must be positive integers",
|
||||
));
|
||||
}
|
||||
if let Some(class) = &self.gpu_class {
|
||||
crate::function::validate_gpu_class_name(class)?;
|
||||
if self.gpu_count == Some(0) {
|
||||
if self.total_gpu_count == Some(0) {
|
||||
return Err(invalid("gpu_class requires a positive GPU budget"));
|
||||
}
|
||||
}
|
||||
if self.gpu_count == Some(0) {
|
||||
return Err(invalid("gpu_count must be positive"));
|
||||
}
|
||||
if self
|
||||
.gpu_count
|
||||
.zip(self.total_gpu_count)
|
||||
.is_some_and(|(per_worker, total)| per_worker > total)
|
||||
{
|
||||
return Err(invalid("total_gpu_count cannot fit one Function worker"));
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
|
||||
@@ -2013,18 +2074,21 @@ impl RefreshMaterializedViewOptions {
|
||||
if full {
|
||||
values.push("full = true".to_string());
|
||||
}
|
||||
if let Some(cpu) = self.cpu_millis {
|
||||
values.push(format!("cpu_millis = {cpu}"));
|
||||
if let Some(cpu) = self.total_cpu_millis {
|
||||
values.push(format!("total_cpu_millis = {cpu}"));
|
||||
}
|
||||
if let Some(memory) = self.memory_bytes {
|
||||
values.push(format!("memory_bytes = {memory}"));
|
||||
if let Some(memory) = self.total_memory_bytes {
|
||||
values.push(format!("total_memory_bytes = {memory}"));
|
||||
}
|
||||
if let Some(gpu) = self.gpu_count {
|
||||
values.push(format!("gpu_count = {gpu}"));
|
||||
if let Some(gpu) = self.total_gpu_count {
|
||||
values.push(format!("total_gpu_count = {gpu}"));
|
||||
}
|
||||
if let Some(class) = &self.gpu_class {
|
||||
values.push(format!("gpu_class = '{class}'"));
|
||||
}
|
||||
if let Some(count) = self.gpu_count {
|
||||
values.push(format!("gpu_count = {count}"));
|
||||
}
|
||||
Ok(if values.is_empty() {
|
||||
String::new()
|
||||
} else {
|
||||
@@ -2042,25 +2106,31 @@ pub struct RefreshMaterializedViewBuilder {
|
||||
}
|
||||
|
||||
impl RefreshMaterializedViewBuilder {
|
||||
/// Cap total CPU capacity in millicores; requires memory and GPU budgets.
|
||||
pub fn cpu_millis(mut self, cpu_millis: u64) -> Self {
|
||||
self.options.cpu_millis = Some(cpu_millis);
|
||||
/// Override total CPU capacity in millicores for this refresh.
|
||||
pub fn total_cpu_millis(mut self, total_cpu_millis: u64) -> Self {
|
||||
self.options.total_cpu_millis = Some(total_cpu_millis);
|
||||
self
|
||||
}
|
||||
|
||||
/// Cap total memory in bytes; requires CPU and GPU budgets.
|
||||
pub fn memory_bytes(mut self, memory_bytes: u64) -> Self {
|
||||
self.options.memory_bytes = Some(memory_bytes);
|
||||
/// Override total memory in bytes for this refresh.
|
||||
pub fn total_memory_bytes(mut self, total_memory_bytes: u64) -> Self {
|
||||
self.options.total_memory_bytes = Some(total_memory_bytes);
|
||||
self
|
||||
}
|
||||
|
||||
/// Cap concurrent GPUs for this refresh. Zero is CPU-only.
|
||||
pub fn gpu_count(mut self, gpu_count: u32) -> Self {
|
||||
self.options.gpu_count = Some(gpu_count);
|
||||
pub fn total_gpu_count(mut self, total_gpu_count: u32) -> Self {
|
||||
self.options.total_gpu_count = Some(total_gpu_count);
|
||||
self
|
||||
}
|
||||
|
||||
/// Select an operator-configured GPU class for this execution only.
|
||||
/// Set the positive number of GPUs allocated to each worker.
|
||||
pub fn gpu_count(mut self, count: u32) -> Self {
|
||||
self.options.gpu_count = Some(count);
|
||||
self
|
||||
}
|
||||
|
||||
pub fn gpu_class(mut self, gpu_class: impl Into<String>) -> Self {
|
||||
self.options.gpu_class = Some(gpu_class.into());
|
||||
self
|
||||
@@ -2448,7 +2518,7 @@ mod tests {
|
||||
.unwrap();
|
||||
|
||||
assert!(matches!(
|
||||
view.refresh().gpu_count(0).execute().await,
|
||||
view.refresh().total_gpu_count(0).execute().await,
|
||||
Err(Error::NotSupported { .. })
|
||||
));
|
||||
assert!(matches!(
|
||||
|
||||
@@ -823,6 +823,33 @@ impl<S: HttpSend> Database for RemoteDatabase<S> {
|
||||
if let Some(seconds) = request.auto_refresh_interval_seconds {
|
||||
options.push(format!("auto_refresh_interval_seconds = {seconds}"));
|
||||
}
|
||||
if request.total_cpu_millis == Some(0) || request.total_memory_bytes == Some(0) {
|
||||
return Err(Error::InvalidInput {
|
||||
message: "total_cpu_millis and total_memory_bytes must be positive integers".into(),
|
||||
});
|
||||
}
|
||||
for (key, value) in [
|
||||
("total_cpu_millis", request.total_cpu_millis),
|
||||
("total_memory_bytes", request.total_memory_bytes),
|
||||
("total_gpu_count", request.total_gpu_count.map(u64::from)),
|
||||
] {
|
||||
if let Some(value) = value {
|
||||
options.push(format!("{key} = {value}"));
|
||||
}
|
||||
}
|
||||
|
||||
if let Some(class) = &request.gpu_class {
|
||||
crate::function::validate_gpu_class_name(class)?;
|
||||
options.push(format!("gpu_class = '{class}'"));
|
||||
}
|
||||
if let Some(count) = request.gpu_count {
|
||||
if count == 0 {
|
||||
return Err(Error::InvalidInput {
|
||||
message: "gpu_count must be positive".into(),
|
||||
});
|
||||
}
|
||||
options.push(format!("gpu_count = {count}"));
|
||||
}
|
||||
let name = request.name.replace('"', "\"\"");
|
||||
let options = if options.is_empty() {
|
||||
String::new()
|
||||
@@ -5137,6 +5164,12 @@ mod tests {
|
||||
for seconds in [0.0, -1.0, f64::NAN, f64::INFINITY] {
|
||||
let result = db
|
||||
.create_materialized_view_async(CreateMaterializedViewRequest {
|
||||
gpu_class: Default::default(),
|
||||
gpu_count: Default::default(),
|
||||
total_cpu_millis: None,
|
||||
total_memory_bytes: None,
|
||||
total_gpu_count: None,
|
||||
|
||||
exist_ok: false,
|
||||
name: "adults".into(),
|
||||
namespace_path: vec![],
|
||||
|
||||
@@ -1253,17 +1253,38 @@ async fn remote_create_uses_sql_and_preserves_options_and_namespace() {
|
||||
panic!("CREATE must use SQL, not REST: {}", request.url().path());
|
||||
})
|
||||
.with_sql_client(sql_client.clone());
|
||||
for (enabled, interval, expected) in [
|
||||
(None, None, ""),
|
||||
(Some(true), None, " WITH (auto_refresh_enabled = true)"),
|
||||
for (enabled, interval, cpu, gpu, expected) in [
|
||||
(None, None, None, None, ""),
|
||||
(
|
||||
Some(true),
|
||||
None,
|
||||
None,
|
||||
None,
|
||||
" WITH (auto_refresh_enabled = true)",
|
||||
),
|
||||
(
|
||||
Some(false),
|
||||
Some(0.5),
|
||||
None,
|
||||
None,
|
||||
" WITH (auto_refresh_enabled = false, auto_refresh_interval_seconds = 0.5)",
|
||||
),
|
||||
(
|
||||
None,
|
||||
None,
|
||||
Some(8000),
|
||||
Some(0),
|
||||
" WITH (total_cpu_millis = 8000, total_gpu_count = 0)",
|
||||
),
|
||||
] {
|
||||
let job = db
|
||||
.create_materialized_view_async(CreateMaterializedViewRequest {
|
||||
gpu_class: Default::default(),
|
||||
gpu_count: Default::default(),
|
||||
total_cpu_millis: cpu,
|
||||
total_memory_bytes: None,
|
||||
total_gpu_count: gpu,
|
||||
|
||||
exist_ok: false,
|
||||
name: "adults".into(),
|
||||
namespace_path: vec!["team".into(), "reports".into()],
|
||||
@@ -1292,7 +1313,7 @@ async fn remote_create_uses_sql_and_preserves_options_and_namespace() {
|
||||
);
|
||||
}
|
||||
assert_eq!(count.load(Ordering::SeqCst), 0);
|
||||
assert_eq!(statements.lock().unwrap().len(), 3);
|
||||
assert_eq!(statements.lock().unwrap().len(), 4);
|
||||
assert!(
|
||||
headers
|
||||
.lock()
|
||||
@@ -1347,6 +1368,12 @@ async fn remote_create_returns_the_registry_job_from_the_early_status_row() {
|
||||
|
||||
let job = db
|
||||
.create_materialized_view_async(CreateMaterializedViewRequest {
|
||||
gpu_class: Default::default(),
|
||||
gpu_count: Default::default(),
|
||||
total_cpu_millis: None,
|
||||
total_memory_bytes: None,
|
||||
total_gpu_count: None,
|
||||
|
||||
exist_ok: false,
|
||||
name: "adults".into(),
|
||||
namespace_path: vec!["team".into(), "reports".into()],
|
||||
@@ -1410,6 +1437,12 @@ async fn remote_create_if_not_exists_accepts_a_completed_noop_without_a_registry
|
||||
.with_sql_client(client);
|
||||
let job = db
|
||||
.create_materialized_view_async(CreateMaterializedViewRequest {
|
||||
gpu_class: Default::default(),
|
||||
gpu_count: Default::default(),
|
||||
total_cpu_millis: None,
|
||||
total_memory_bytes: None,
|
||||
total_gpu_count: None,
|
||||
|
||||
exist_ok: true,
|
||||
name: "adults".into(),
|
||||
namespace_path: vec!["team".into()],
|
||||
@@ -1497,6 +1530,12 @@ async fn remote_create_registry_handle_reopens_describes_and_cancels() {
|
||||
|
||||
let job = db
|
||||
.create_materialized_view_async(CreateMaterializedViewRequest {
|
||||
gpu_class: Default::default(),
|
||||
gpu_count: Default::default(),
|
||||
total_cpu_millis: None,
|
||||
total_memory_bytes: None,
|
||||
total_gpu_count: None,
|
||||
|
||||
exist_ok: false,
|
||||
name: "adults".into(),
|
||||
namespace_path: vec!["team".into(), "reports".into()],
|
||||
@@ -1731,10 +1770,11 @@ async fn remote_refresh_omits_unknown_metrics_and_forwards_full() {
|
||||
let third = view
|
||||
.refresh()
|
||||
.full(true)
|
||||
.cpu_millis(8000)
|
||||
.memory_bytes(16 << 30)
|
||||
.gpu_count(2)
|
||||
.total_cpu_millis(8000)
|
||||
.total_memory_bytes(16 << 30)
|
||||
.total_gpu_count(2)
|
||||
.gpu_class("h100")
|
||||
.gpu_count(2)
|
||||
.execute_async()
|
||||
.await
|
||||
.unwrap()
|
||||
@@ -1742,9 +1782,8 @@ async fn remote_refresh_omits_unknown_metrics_and_forwards_full() {
|
||||
.await
|
||||
.unwrap();
|
||||
for invalid in [
|
||||
view.refresh().cpu_millis(1),
|
||||
view.refresh().gpu_class("H200:8"),
|
||||
view.refresh().gpu_count(0).gpu_class("h100"),
|
||||
view.refresh().total_gpu_count(0).gpu_class("h100"),
|
||||
] {
|
||||
assert!(matches!(
|
||||
invalid.execute_async().await,
|
||||
@@ -1772,7 +1811,7 @@ async fn remote_refresh_omits_unknown_metrics_and_forwards_full() {
|
||||
"DESCRIBE MATERIALIZED VIEW \"view\"",
|
||||
"REFRESH MATERIALIZED VIEW \"view\"",
|
||||
"REFRESH MATERIALIZED VIEW \"view\" WITH (full = true)",
|
||||
"REFRESH MATERIALIZED VIEW \"view\" WITH (full = true, cpu_millis = 8000, memory_bytes = 17179869184, gpu_count = 2, gpu_class = 'h100')",
|
||||
"REFRESH MATERIALIZED VIEW \"view\" WITH (full = true, total_cpu_millis = 8000, total_memory_bytes = 17179869184, total_gpu_count = 2, gpu_class = 'h100', gpu_count = 2)",
|
||||
]
|
||||
);
|
||||
assert!(
|
||||
@@ -3236,6 +3275,9 @@ async fn function_creation_and_description_use_sql_query_handles() {
|
||||
let mut request_json: serde_json::Value = serde_json::from_str(REQUEST).unwrap();
|
||||
request_json["batch_size"] = serde_json::json!(2);
|
||||
request_json["max_concurrency"] = serde_json::json!(4);
|
||||
request_json["total_cpu_millis"] = serde_json::json!(8000);
|
||||
request_json["total_memory_bytes"] = serde_json::json!(17179869184_u64);
|
||||
request_json["total_gpu_count"] = serde_json::json!(0);
|
||||
request_json["row_timeout_seconds"] = serde_json::json!(0.75);
|
||||
request_json["secret_bindings"] = serde_json::json!([{
|
||||
"kind": "env",
|
||||
@@ -3244,6 +3286,9 @@ async fn function_creation_and_description_use_sql_query_handles() {
|
||||
}]);
|
||||
let mut version_json: serde_json::Value = serde_json::from_str(VERSION).unwrap();
|
||||
version_json["batch_size"] = serde_json::json!(12);
|
||||
for field in ["total_cpu_millis", "total_memory_bytes", "total_gpu_count"] {
|
||||
version_json[field] = request_json[field].clone();
|
||||
}
|
||||
version_json["max_concurrency"] = serde_json::json!(4);
|
||||
version_json["row_timeout_seconds"] = serde_json::json!(8.0);
|
||||
version_json["result_stability"] = serde_json::json!("input_and_context");
|
||||
@@ -3322,6 +3367,9 @@ async fn function_creation_and_description_use_sql_query_handles() {
|
||||
assert_eq!(created.name(), "embed");
|
||||
assert_eq!(created.version(), "1");
|
||||
assert_eq!(created.batch_size(), Some(12));
|
||||
assert_eq!(created.total_cpu_millis(), Some(8000));
|
||||
assert_eq!(created.total_memory_bytes(), Some(17179869184));
|
||||
assert_eq!(created.total_gpu_count(), Some(0));
|
||||
assert_eq!(created.max_concurrency(), Some(4));
|
||||
assert_eq!(created.row_timeout_seconds(), Some(8.0));
|
||||
assert_eq!(created.result_stability(), Some("input_and_context"));
|
||||
|
||||
@@ -4490,8 +4490,20 @@ impl<S: HttpSend> BaseTable for RemoteTable<S> {
|
||||
if let Some(interval) = options.auto_refresh_interval_seconds {
|
||||
body["auto_refresh_interval_seconds"] = serde_json::json!(interval);
|
||||
}
|
||||
if let Some(budget) = options.auto_refresh_resource_budget {
|
||||
body["auto_refresh_resource_budget"] = serde_json::json!(budget);
|
||||
for (key, value) in [
|
||||
("total_cpu_millis", options.total_cpu_millis),
|
||||
("total_memory_bytes", options.total_memory_bytes),
|
||||
("total_gpu_count", options.total_gpu_count.map(u64::from)),
|
||||
] {
|
||||
if let Some(value) = value {
|
||||
body[key] = serde_json::json!(value);
|
||||
}
|
||||
}
|
||||
if let Some(class) = &options.gpu_class {
|
||||
body["gpu_class"] = serde_json::json!(class);
|
||||
}
|
||||
if let Some(count) = options.gpu_count {
|
||||
body["gpu_count"] = serde_json::json!(count);
|
||||
}
|
||||
self.apply_branch_body(&mut body);
|
||||
let request = self
|
||||
@@ -11310,9 +11322,13 @@ mod tests {
|
||||
.add_columns()
|
||||
.computed("doubled", "x * 2")
|
||||
.computed_options(crate::table::computed_columns::ComputedColumnOptions {
|
||||
gpu_class: Default::default(),
|
||||
gpu_count: Default::default(),
|
||||
auto_refresh_enabled: false,
|
||||
auto_refresh_interval_seconds: interval,
|
||||
auto_refresh_resource_budget: None,
|
||||
total_cpu_millis: None,
|
||||
total_memory_bytes: None,
|
||||
total_gpu_count: None,
|
||||
})
|
||||
.execute()
|
||||
.await
|
||||
@@ -11899,11 +11915,11 @@ mod tests {
|
||||
))
|
||||
.unwrap();
|
||||
expected["auto_refresh_enabled"] = serde_json::json!(true);
|
||||
expected["auto_refresh_resource_budget"] = serde_json::json!({
|
||||
"cpu_millis": 8_000,
|
||||
"memory_bytes": 17_179_869_184_u64,
|
||||
"gpu_count": 2,
|
||||
});
|
||||
expected["total_cpu_millis"] = serde_json::json!(8000);
|
||||
expected["total_memory_bytes"] = serde_json::json!(17179869184_u64);
|
||||
expected["total_gpu_count"] = serde_json::json!(2);
|
||||
expected["gpu_class"] = serde_json::json!("any");
|
||||
expected["gpu_count"] = serde_json::json!(2);
|
||||
assert_eq!(actual, expected);
|
||||
http::Response::builder()
|
||||
.status(200)
|
||||
@@ -11932,12 +11948,13 @@ mod tests {
|
||||
.add_columns()
|
||||
.function(application)
|
||||
.computed_options(crate::table::computed_columns::ComputedColumnOptions {
|
||||
gpu_class: Some("any".into()),
|
||||
gpu_count: Some(2),
|
||||
auto_refresh_enabled: true,
|
||||
auto_refresh_interval_seconds: None,
|
||||
auto_refresh_resource_budget: Some(
|
||||
crate::table::FunctionWorkerResourceBudget::new(8_000, 17_179_869_184)
|
||||
.with_gpu_count(2),
|
||||
),
|
||||
total_cpu_millis: Some(8000),
|
||||
total_memory_bytes: Some(17179869184),
|
||||
total_gpu_count: Some(2),
|
||||
})
|
||||
.execute()
|
||||
.await
|
||||
@@ -12142,7 +12159,7 @@ mod tests {
|
||||
serde_json::json!({
|
||||
"column": "quality",
|
||||
"gpu_class": "a10g",
|
||||
"gpu_count": 2,
|
||||
"total_gpu_count": 2,
|
||||
})
|
||||
);
|
||||
http::Response::builder()
|
||||
@@ -12152,7 +12169,7 @@ mod tests {
|
||||
});
|
||||
let options = RefreshColumnOptions::default()
|
||||
.gpu_class("a10g")
|
||||
.gpu_count(2);
|
||||
.total_gpu_count(2);
|
||||
let job = table
|
||||
.refresh_column_async_with_options("quality", options)
|
||||
.await
|
||||
@@ -12165,7 +12182,7 @@ mod tests {
|
||||
#[case(Some(2), 2)]
|
||||
#[tokio::test]
|
||||
async fn test_refresh_column_async_resource_budget(
|
||||
#[case] gpu_count: Option<u32>,
|
||||
#[case] total_gpu_count: Option<u32>,
|
||||
#[case] expected_gpu_count: u32,
|
||||
) {
|
||||
use crate::table::{FunctionWorkerResourceBudget, RefreshColumnOptions};
|
||||
@@ -12176,11 +12193,9 @@ mod tests {
|
||||
request_body_json(&request),
|
||||
serde_json::json!({
|
||||
"column": "quality",
|
||||
"resource_budget": {
|
||||
"cpu_millis": 8_000,
|
||||
"memory_bytes": 17_179_869_184_u64,
|
||||
"gpu_count": expected_gpu_count,
|
||||
},
|
||||
"total_cpu_millis": 8_000,
|
||||
"total_memory_bytes": 17_179_869_184_u64,
|
||||
"total_gpu_count": expected_gpu_count,
|
||||
})
|
||||
);
|
||||
http::Response::builder()
|
||||
@@ -12189,13 +12204,16 @@ mod tests {
|
||||
.unwrap()
|
||||
});
|
||||
let mut budget = FunctionWorkerResourceBudget::new(8_000, 17_179_869_184);
|
||||
if let Some(gpu_count) = gpu_count {
|
||||
budget = budget.with_gpu_count(gpu_count);
|
||||
if let Some(total_gpu_count) = total_gpu_count {
|
||||
budget = budget.with_total_gpu_count(total_gpu_count);
|
||||
}
|
||||
let job = table
|
||||
.refresh_column_async_with_options(
|
||||
"quality",
|
||||
RefreshColumnOptions::default().resource_budget(budget),
|
||||
RefreshColumnOptions::default()
|
||||
.total_cpu_millis((budget).total_cpu_millis)
|
||||
.total_memory_bytes((budget).total_memory_bytes)
|
||||
.total_gpu_count((budget).total_gpu_count),
|
||||
)
|
||||
.await
|
||||
.unwrap();
|
||||
@@ -12453,22 +12471,23 @@ mod tests {
|
||||
RefreshColumnOptions::default().gpu_class("-a10g"),
|
||||
"gpu_class",
|
||||
),
|
||||
(RefreshColumnOptions::default().gpu_count(0), "gpu_count"),
|
||||
(
|
||||
RefreshColumnOptions::default()
|
||||
.resource_budget(FunctionWorkerResourceBudget::new(0, 1)),
|
||||
"resource_budget.cpu_millis",
|
||||
.total_cpu_millis((FunctionWorkerResourceBudget::new(0, 1)).total_cpu_millis)
|
||||
.total_memory_bytes(
|
||||
(FunctionWorkerResourceBudget::new(0, 1)).total_memory_bytes,
|
||||
)
|
||||
.total_gpu_count((FunctionWorkerResourceBudget::new(0, 1)).total_gpu_count),
|
||||
"total_cpu_millis",
|
||||
),
|
||||
(
|
||||
RefreshColumnOptions::default()
|
||||
.resource_budget(FunctionWorkerResourceBudget::new(1, 0)),
|
||||
"resource_budget.memory_bytes",
|
||||
),
|
||||
(
|
||||
RefreshColumnOptions::default()
|
||||
.resource_budget(FunctionWorkerResourceBudget::new(1, 1))
|
||||
.gpu_count(1),
|
||||
"gpu_count cannot be combined with resource_budget",
|
||||
.total_cpu_millis((FunctionWorkerResourceBudget::new(1, 0)).total_cpu_millis)
|
||||
.total_memory_bytes(
|
||||
(FunctionWorkerResourceBudget::new(1, 0)).total_memory_bytes,
|
||||
)
|
||||
.total_gpu_count((FunctionWorkerResourceBudget::new(1, 0)).total_gpu_count),
|
||||
"total_memory_bytes",
|
||||
),
|
||||
] {
|
||||
let error = table
|
||||
|
||||
@@ -2364,10 +2364,10 @@ impl Table {
|
||||
/// [`RefreshColumnOptions::publication_interval_rows()`] sets an opt-in
|
||||
/// row-count publication threshold for completed Function outputs; unset
|
||||
/// keeps whole-fragment publication.
|
||||
/// [`RefreshColumnOptions::resource_budget()`] sets the aggregate CPU,
|
||||
/// [`RefreshColumnOptions::total_memory_bytes()`] sets the aggregate CPU,
|
||||
/// memory, and GPU budget for a Function refresh.
|
||||
/// [`RefreshColumnOptions::gpu_class()`] selects a GPU pool and
|
||||
/// [`RefreshColumnOptions::gpu_count()`] sets the aggregate GPU budget
|
||||
/// [`RefreshColumnOptions::total_gpu_count()`] sets the aggregate GPU budget
|
||||
/// without changing the deployment's CPU and memory defaults.
|
||||
/// Batch-size and GPU options have no effect on expression-backed columns
|
||||
/// in LanceDB Embedded; a resource budget and publication threshold are
|
||||
@@ -2432,9 +2432,9 @@ impl Table {
|
||||
/// [`RefreshColumnOptions::publication_interval_rows()`] to publish
|
||||
/// completed Function outputs at a row-count threshold; unset keeps
|
||||
/// whole-fragment publication. Set
|
||||
/// [`RefreshColumnOptions::resource_budget()`] to pass a complete aggregate
|
||||
/// [`RefreshColumnOptions::total_memory_bytes()`] to pass a complete aggregate
|
||||
/// CPU, memory, and GPU budget for a Function refresh. The standalone
|
||||
/// [`RefreshColumnOptions::gpu_count()`] shorthand and
|
||||
/// [`RefreshColumnOptions::total_gpu_count()`] shorthand and
|
||||
/// [`RefreshColumnOptions::gpu_class()`] placement remain available; a
|
||||
/// resource budget cannot be combined with the gpu-count shorthand. Unset
|
||||
/// values use the Function and server defaults; invalid counts and malformed
|
||||
@@ -2474,7 +2474,7 @@ impl Table {
|
||||
/// RefreshColumnOptions::default()
|
||||
/// .batch_size(8)
|
||||
/// .gpu_class("a10g")
|
||||
/// .gpu_count(2),
|
||||
/// .total_gpu_count(2),
|
||||
/// ).await?;
|
||||
/// let result = job.wait().await?;
|
||||
/// # Ok(())
|
||||
|
||||
@@ -180,9 +180,13 @@ impl AddColumnsBuilder {
|
||||
/// # async fn declare(table: &Table) -> lancedb::Result<()> {
|
||||
/// table.add_columns().computed("doubled", "x * 2")
|
||||
/// .computed_options(ComputedColumnOptions {
|
||||
/// gpu_class: Default::default(),
|
||||
/// gpu_count: Default::default(),
|
||||
/// auto_refresh_enabled: true,
|
||||
/// auto_refresh_interval_seconds: Some(300),
|
||||
/// auto_refresh_resource_budget: None,
|
||||
/// total_cpu_millis: None,
|
||||
/// total_memory_bytes: None,
|
||||
/// total_gpu_count: None,
|
||||
/// }).execute().await?;
|
||||
/// # Ok(())
|
||||
/// # }
|
||||
@@ -202,7 +206,7 @@ impl AddColumnsBuilder {
|
||||
read_columns,
|
||||
options,
|
||||
} = self;
|
||||
if let Some(options) = options {
|
||||
if let Some(options) = &options {
|
||||
options.validate()?;
|
||||
if computed.is_empty() && function.is_none() {
|
||||
return Err(Error::InvalidInput {
|
||||
@@ -210,11 +214,9 @@ impl AddColumnsBuilder {
|
||||
.into(),
|
||||
});
|
||||
}
|
||||
if options.auto_refresh_resource_budget.is_some() && function.is_none() {
|
||||
if options.has_resource_defaults() && function.is_none() {
|
||||
return Err(Error::InvalidInput {
|
||||
message:
|
||||
"auto_refresh_resource_budget requires a registered Function declaration"
|
||||
.into(),
|
||||
message: "total_* resources require a registered Function declaration".into(),
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -297,14 +299,18 @@ mod tests {
|
||||
let table = table_with_two_columns("options").await;
|
||||
let version = table.version().await.unwrap();
|
||||
let options = ComputedColumnOptions {
|
||||
gpu_class: Default::default(),
|
||||
gpu_count: Default::default(),
|
||||
auto_refresh_enabled: false,
|
||||
auto_refresh_interval_seconds: Some(300),
|
||||
auto_refresh_resource_budget: None,
|
||||
total_cpu_millis: None,
|
||||
total_memory_bytes: None,
|
||||
total_gpu_count: None,
|
||||
};
|
||||
let result = table
|
||||
.add_columns()
|
||||
.computed("doubled", "x * 2")
|
||||
.computed_options(options)
|
||||
.computed_options(options.clone())
|
||||
.execute()
|
||||
.await
|
||||
.unwrap();
|
||||
@@ -320,7 +326,7 @@ mod tests {
|
||||
for interval in [0, u64::MAX] {
|
||||
let invalid = ComputedColumnOptions {
|
||||
auto_refresh_interval_seconds: Some(interval),
|
||||
..options
|
||||
..options.clone()
|
||||
};
|
||||
assert!(
|
||||
table
|
||||
@@ -339,7 +345,7 @@ mod tests {
|
||||
"once".into(),
|
||||
"x".into()
|
||||
)]))
|
||||
.computed_options(options)
|
||||
.computed_options(options.clone())
|
||||
.execute()
|
||||
.await
|
||||
.is_err()
|
||||
@@ -391,11 +397,13 @@ mod tests {
|
||||
.add_columns()
|
||||
.computed("doubled", "x * 2")
|
||||
.computed_options(ComputedColumnOptions {
|
||||
gpu_class: Default::default(),
|
||||
gpu_count: Default::default(),
|
||||
auto_refresh_enabled: true,
|
||||
auto_refresh_interval_seconds: None,
|
||||
auto_refresh_resource_budget: Some(
|
||||
crate::table::FunctionWorkerResourceBudget::new(1_000, 1_024),
|
||||
),
|
||||
total_cpu_millis: Some(1000),
|
||||
total_memory_bytes: Some(1024),
|
||||
total_gpu_count: Some(0),
|
||||
})
|
||||
.execute()
|
||||
.await
|
||||
|
||||
@@ -42,7 +42,6 @@ use serde_json::Value;
|
||||
|
||||
use crate::function::{FUNCTION_BLOB_V2_TYPE, FunctionApplication, FunctionBinding, OutputMapping};
|
||||
use crate::materialized_view::without_declarations;
|
||||
use crate::table::FunctionWorkerResourceBudget;
|
||||
use crate::utils::resolve_arrow_field_path;
|
||||
use crate::{Error, Result};
|
||||
|
||||
@@ -62,13 +61,9 @@ pub const INPUTS_META_KEY: &str = "computed_column.inputs";
|
||||
pub const AUTO_REFRESH_ENABLED_META_KEY: &str = "computed_column.auto_refresh_enabled";
|
||||
/// Minimum interval between successful automatic refreshes, in seconds.
|
||||
pub const AUTO_REFRESH_INTERVAL_META_KEY: &str = "computed_column.auto_refresh_interval_seconds";
|
||||
/// Aggregate worker-resource budget for automatic Function refreshes.
|
||||
pub const AUTO_REFRESH_RESOURCE_BUDGET_META_KEY: &str =
|
||||
"computed_column.auto_refresh_resource_budget";
|
||||
|
||||
/// Scheduling settings persisted on each computed output. LanceDB Embedded
|
||||
/// stores these settings; automatic scheduling requires LanceDB Enterprise.
|
||||
#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash, Serialize, Deserialize)]
|
||||
#[derive(Debug, Clone, PartialEq, Eq, PartialOrd, Ord, Hash, Serialize, Deserialize)]
|
||||
#[serde(default, deny_unknown_fields)]
|
||||
pub struct ComputedColumnOptions {
|
||||
/// Permit automatic refresh. Manual refresh is always available.
|
||||
@@ -77,10 +72,22 @@ pub struct ComputedColumnOptions {
|
||||
/// When omitted, the server determines when to refresh.
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
pub auto_refresh_interval_seconds: Option<u64>,
|
||||
/// Aggregate worker-resource budget for automatic Function refreshes.
|
||||
/// This option requires a registered Function output.
|
||||
/// Default total CPU budget in millicores for manual and automatic refreshes.
|
||||
/// Requires a registered Function output.
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
pub auto_refresh_resource_budget: Option<FunctionWorkerResourceBudget>,
|
||||
pub total_cpu_millis: Option<u64>,
|
||||
/// Default total memory budget in bytes for manual and automatic refreshes.
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
pub total_memory_bytes: Option<u64>,
|
||||
/// Default total GPU budget for manual and automatic refreshes.
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
pub total_gpu_count: Option<u32>,
|
||||
/// GPU pool used by each Function worker unless overridden at refresh.
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
pub gpu_class: Option<String>,
|
||||
/// Positive number of GPUs per worker, independent of the total budget.
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
pub gpu_count: Option<u32>,
|
||||
}
|
||||
|
||||
impl Default for ComputedColumnOptions {
|
||||
@@ -88,12 +95,24 @@ impl Default for ComputedColumnOptions {
|
||||
Self {
|
||||
auto_refresh_enabled: true,
|
||||
auto_refresh_interval_seconds: None,
|
||||
auto_refresh_resource_budget: None,
|
||||
total_cpu_millis: None,
|
||||
total_memory_bytes: None,
|
||||
total_gpu_count: None,
|
||||
gpu_class: None,
|
||||
gpu_count: None,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl ComputedColumnOptions {
|
||||
pub fn has_resource_defaults(&self) -> bool {
|
||||
self.total_cpu_millis.is_some()
|
||||
|| self.total_memory_bytes.is_some()
|
||||
|| self.total_gpu_count.is_some()
|
||||
|| self.gpu_class.is_some()
|
||||
|| self.gpu_count.is_some()
|
||||
}
|
||||
|
||||
/// Reject intervals that cannot be represented by the server scheduler.
|
||||
pub fn validate(&self) -> Result<()> {
|
||||
if self
|
||||
@@ -104,8 +123,28 @@ impl ComputedColumnOptions {
|
||||
message: "auto_refresh_interval_seconds must be a positive integer no greater than u64::MAX / 1000".into(),
|
||||
});
|
||||
}
|
||||
if let Some(budget) = &self.auto_refresh_resource_budget {
|
||||
budget.validate()?;
|
||||
if self.total_cpu_millis == Some(0) || self.total_memory_bytes == Some(0) {
|
||||
return Err(Error::InvalidInput {
|
||||
message: "total_cpu_millis and total_memory_bytes must be positive integers".into(),
|
||||
});
|
||||
}
|
||||
if let Some(class) = &self.gpu_class {
|
||||
crate::function::validate_gpu_class_name(class)?;
|
||||
}
|
||||
if self.gpu_count == Some(0) {
|
||||
return Err(Error::InvalidInput {
|
||||
message: "gpu_count must be positive".into(),
|
||||
});
|
||||
}
|
||||
if self
|
||||
.gpu_count
|
||||
.zip(self.total_gpu_count)
|
||||
.is_some_and(|(per_worker, total)| per_worker > total)
|
||||
|| (self.gpu_class.is_some() && self.total_gpu_count == Some(0))
|
||||
{
|
||||
return Err(Error::InvalidInput {
|
||||
message: "total_gpu_count cannot fit one Function worker".into(),
|
||||
});
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
@@ -124,15 +163,29 @@ impl ComputedColumnOptions {
|
||||
message: "auto_refresh_interval_seconds must be a positive integer".into(),
|
||||
})?);
|
||||
}
|
||||
if let Some(value) = metadata.get(AUTO_REFRESH_RESOURCE_BUDGET_META_KEY) {
|
||||
options.auto_refresh_resource_budget = Some(serde_json::from_str(value).map_err(
|
||||
|error| Error::InvalidInput {
|
||||
message: format!(
|
||||
"auto_refresh_resource_budget must be a valid resource budget: {error}"
|
||||
),
|
||||
},
|
||||
)?);
|
||||
if let Some(value) = metadata.get("computed_column.total_cpu_millis") {
|
||||
options.total_cpu_millis = Some(value.parse().map_err(|_| Error::InvalidInput {
|
||||
message: "invalid total_cpu_millis".into(),
|
||||
})?);
|
||||
}
|
||||
if let Some(value) = metadata.get("computed_column.total_memory_bytes") {
|
||||
options.total_memory_bytes = Some(value.parse().map_err(|_| Error::InvalidInput {
|
||||
message: "invalid total_memory_bytes".into(),
|
||||
})?);
|
||||
}
|
||||
if let Some(value) = metadata.get("computed_column.total_gpu_count") {
|
||||
options.total_gpu_count = Some(value.parse().map_err(|_| Error::InvalidInput {
|
||||
message: "invalid total_gpu_count".into(),
|
||||
})?);
|
||||
}
|
||||
options.gpu_class = metadata.get("computed_column.gpu_class").cloned();
|
||||
options.gpu_count = metadata
|
||||
.get("computed_column.gpu_count")
|
||||
.map(|value| value.parse())
|
||||
.transpose()
|
||||
.map_err(|_| Error::InvalidInput {
|
||||
message: "invalid gpu_count".into(),
|
||||
})?;
|
||||
options.validate()?;
|
||||
Ok(options)
|
||||
}
|
||||
@@ -175,13 +228,20 @@ impl ComputedColumnOptions {
|
||||
if let Some(interval) = self.auto_refresh_interval_seconds {
|
||||
metadata.insert(AUTO_REFRESH_INTERVAL_META_KEY.into(), interval.to_string());
|
||||
}
|
||||
if let Some(budget) = &self.auto_refresh_resource_budget {
|
||||
metadata.insert(
|
||||
AUTO_REFRESH_RESOURCE_BUDGET_META_KEY.into(),
|
||||
serde_json::to_string(budget).map_err(|error| Error::InvalidInput {
|
||||
message: format!("failed to encode auto_refresh_resource_budget: {error}"),
|
||||
})?,
|
||||
);
|
||||
for (key, value) in [
|
||||
("total_cpu_millis", self.total_cpu_millis),
|
||||
("total_memory_bytes", self.total_memory_bytes),
|
||||
("total_gpu_count", self.total_gpu_count.map(u64::from)),
|
||||
] {
|
||||
if let Some(value) = value {
|
||||
metadata.insert(format!("computed_column.{key}"), value.to_string());
|
||||
}
|
||||
}
|
||||
if let Some(class) = &self.gpu_class {
|
||||
metadata.insert("computed_column.gpu_class".into(), class.clone());
|
||||
}
|
||||
if let Some(count) = self.gpu_count {
|
||||
metadata.insert("computed_column.gpu_count".into(), count.to_string());
|
||||
}
|
||||
Ok(metadata)
|
||||
}
|
||||
@@ -2702,68 +2762,70 @@ pub(crate) mod test_support {
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use arrow_array::{RecordBatch, record_batch};
|
||||
use arrow_schema::{DataType, TimeUnit};
|
||||
use futures::TryStreamExt;
|
||||
use lance::dataset::ColumnAlteration;
|
||||
|
||||
use super::*;
|
||||
use crate::connect;
|
||||
use crate::query::{ExecutableQuery, QueryBase, Select};
|
||||
use crate::{Error, Table};
|
||||
|
||||
#[test]
|
||||
fn computed_auto_refresh_resource_budget_metadata_round_trips() {
|
||||
let budget = crate::table::FunctionWorkerResourceBudget::new(8_000, 17_179_869_184)
|
||||
.with_gpu_count(2);
|
||||
fn gpu_worker_defaults_round_trip_independently_of_totals() {
|
||||
let options = super::ComputedColumnOptions {
|
||||
auto_refresh_enabled: true,
|
||||
auto_refresh_interval_seconds: Some(300),
|
||||
auto_refresh_resource_budget: Some(budget),
|
||||
gpu_class: Some("any".into()),
|
||||
gpu_count: Some(2),
|
||||
total_gpu_count: Some(8),
|
||||
..Default::default()
|
||||
};
|
||||
assert_eq!(
|
||||
super::ComputedColumnOptions::from_metadata(&HashMap::new()).unwrap(),
|
||||
super::ComputedColumnOptions::default()
|
||||
);
|
||||
let metadata = options.metadata().unwrap();
|
||||
assert_eq!(
|
||||
metadata
|
||||
.get(super::AUTO_REFRESH_RESOURCE_BUDGET_META_KEY)
|
||||
.map(String::as_str),
|
||||
Some(r#"{"cpu_millis":8000,"memory_bytes":17179869184,"gpu_count":2}"#)
|
||||
);
|
||||
assert_eq!(metadata["computed_column.gpu_count"], "2");
|
||||
assert_eq!(metadata["computed_column.total_gpu_count"], "8");
|
||||
assert_eq!(
|
||||
super::ComputedColumnOptions::from_metadata(&metadata).unwrap(),
|
||||
options
|
||||
);
|
||||
|
||||
let mut omitted_gpu = metadata.clone();
|
||||
omitted_gpu.insert(
|
||||
super::AUTO_REFRESH_RESOURCE_BUDGET_META_KEY.into(),
|
||||
r#"{"cpu_millis":8000,"memory_bytes":17179869184}"#.into(),
|
||||
assert!(
|
||||
super::ComputedColumnOptions {
|
||||
gpu_count: Some(0),
|
||||
..Default::default()
|
||||
}
|
||||
.validate()
|
||||
.is_err()
|
||||
);
|
||||
let decoded = super::ComputedColumnOptions::from_metadata(&omitted_gpu).unwrap();
|
||||
assert_eq!(decoded.auto_refresh_resource_budget.unwrap().gpu_count, 0);
|
||||
assert!(
|
||||
super::ComputedColumnOptions {
|
||||
gpu_count: Some(4),
|
||||
total_gpu_count: Some(2),
|
||||
..Default::default()
|
||||
}
|
||||
.validate()
|
||||
.is_err()
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn computed_default_resource_metadata_round_trips_partial_dimensions() {
|
||||
let options = super::ComputedColumnOptions {
|
||||
total_cpu_millis: Some(8000),
|
||||
total_memory_bytes: None,
|
||||
total_gpu_count: Some(0),
|
||||
..Default::default()
|
||||
};
|
||||
let metadata = options.metadata().unwrap();
|
||||
assert_eq!(metadata["computed_column.total_cpu_millis"], "8000");
|
||||
assert_eq!(metadata["computed_column.total_gpu_count"], "0");
|
||||
assert!(!metadata.contains_key("computed_column.total_memory_bytes"));
|
||||
assert_eq!(
|
||||
decoded
|
||||
.metadata()
|
||||
.unwrap()
|
||||
.get(super::AUTO_REFRESH_RESOURCE_BUDGET_META_KEY)
|
||||
.map(String::as_str),
|
||||
Some(r#"{"cpu_millis":8000,"memory_bytes":17179869184,"gpu_count":0}"#)
|
||||
super::ComputedColumnOptions::from_metadata(&metadata).unwrap(),
|
||||
options
|
||||
);
|
||||
|
||||
for invalid in [
|
||||
r#"{"memory_bytes":17179869184,"gpu_count":2}"#,
|
||||
r#"{"cpu_millis":8000,"gpu_count":2}"#,
|
||||
r#"{"cpu_millis":"8000","memory_bytes":17179869184,"gpu_count":2}"#,
|
||||
r#"{"cpu_millis":-1,"memory_bytes":17179869184,"gpu_count":2}"#,
|
||||
r#"{"cpu_millis":18446744073709551616,"memory_bytes":17179869184,"gpu_count":2}"#,
|
||||
r#"{"cpu_millis":8000,"memory_bytes":17179869184,"gpu_count":-1}"#,
|
||||
r#"{"cpu_millis":8000,"memory_bytes":17179869184,"gpu_count":4294967296}"#,
|
||||
r#"{"cpu_millis":8000,"memory_bytes":17179869184,"gpu_count":2,"unknown":1}"#,
|
||||
r#"{"cpu_millis":0,"memory_bytes":17179869184,"gpu_count":2}"#,
|
||||
r#"{"cpu_millis":8000,"memory_bytes":0,"gpu_count":2}"#,
|
||||
] {
|
||||
let mut malformed = metadata.clone();
|
||||
malformed.insert(
|
||||
super::AUTO_REFRESH_RESOURCE_BUDGET_META_KEY.into(),
|
||||
invalid.into(),
|
||||
);
|
||||
assert!(
|
||||
super::ComputedColumnOptions::from_metadata(&malformed).is_err(),
|
||||
"accepted invalid budget: {invalid}"
|
||||
);
|
||||
for invalid in ["0", "-1", "1.5", "18446744073709551616"] {
|
||||
let malformed =
|
||||
HashMap::from([("computed_column.total_cpu_millis".into(), invalid.into())]);
|
||||
assert!(super::ComputedColumnOptions::from_metadata(&malformed).is_err());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2797,9 +2859,11 @@ mod tests {
|
||||
function_field("assignment", super::FUNCTION_ASSIGNMENT_OUTPUT_ORDINAL),
|
||||
]);
|
||||
let budget = crate::table::FunctionWorkerResourceBudget::new(8_000, 17_179_869_184)
|
||||
.with_gpu_count(2);
|
||||
.with_total_gpu_count(2);
|
||||
let updated = super::ComputedColumnOptions {
|
||||
auto_refresh_resource_budget: Some(budget),
|
||||
total_cpu_millis: Some((budget).total_cpu_millis),
|
||||
total_memory_bytes: Some((budget).total_memory_bytes),
|
||||
total_gpu_count: Some((budget).total_gpu_count),
|
||||
..Default::default()
|
||||
}
|
||||
.apply_to_schema(&schema)
|
||||
@@ -2808,8 +2872,8 @@ mod tests {
|
||||
for name in ["first", "second"] {
|
||||
let metadata = updated.field_with_name(name).unwrap().metadata();
|
||||
assert_eq!(
|
||||
metadata.get(super::AUTO_REFRESH_RESOURCE_BUDGET_META_KEY),
|
||||
Some(&serde_json::to_string(&budget).unwrap())
|
||||
metadata.get("computed_column.total_cpu_millis"),
|
||||
Some(&"8000".to_string())
|
||||
);
|
||||
assert_eq!(
|
||||
metadata.get("custom").map(String::as_str),
|
||||
@@ -2821,7 +2885,7 @@ mod tests {
|
||||
.field_with_name("assignment")
|
||||
.unwrap()
|
||||
.metadata()
|
||||
.contains_key(super::AUTO_REFRESH_RESOURCE_BUDGET_META_KEY)
|
||||
.contains_key("computed_column.total_cpu_millis")
|
||||
);
|
||||
}
|
||||
|
||||
@@ -2928,16 +2992,6 @@ mod tests {
|
||||
}
|
||||
}
|
||||
|
||||
use arrow_array::{RecordBatch, record_batch};
|
||||
use arrow_schema::{DataType, TimeUnit};
|
||||
use futures::TryStreamExt;
|
||||
use lance::dataset::ColumnAlteration;
|
||||
|
||||
use super::*;
|
||||
use crate::connect;
|
||||
use crate::query::{ExecutableQuery, QueryBase, Select};
|
||||
use crate::{Error, Table};
|
||||
|
||||
async fn table_with_ints(name: &str) -> Table {
|
||||
let conn = connect("memory://").execute().await.unwrap();
|
||||
let batch = record_batch!(("x", Int32, [1, 2, 3])).unwrap();
|
||||
|
||||
@@ -65,39 +65,39 @@ use crate::{Error, Result};
|
||||
#[serde(deny_unknown_fields)]
|
||||
#[non_exhaustive]
|
||||
pub struct FunctionWorkerResourceBudget {
|
||||
pub cpu_millis: u64,
|
||||
pub memory_bytes: u64,
|
||||
pub total_cpu_millis: u64,
|
||||
pub total_memory_bytes: u64,
|
||||
/// Aggregate GPU budget across the refresh. Zero is CPU-only.
|
||||
#[serde(default)]
|
||||
pub gpu_count: u32,
|
||||
pub total_gpu_count: u32,
|
||||
}
|
||||
|
||||
impl FunctionWorkerResourceBudget {
|
||||
/// Create a CPU-only aggregate budget.
|
||||
pub fn new(cpu_millis: u64, memory_bytes: u64) -> Self {
|
||||
pub fn new(total_cpu_millis: u64, total_memory_bytes: u64) -> Self {
|
||||
Self {
|
||||
cpu_millis,
|
||||
memory_bytes,
|
||||
gpu_count: 0,
|
||||
total_cpu_millis,
|
||||
total_memory_bytes,
|
||||
total_gpu_count: 0,
|
||||
}
|
||||
}
|
||||
|
||||
/// Set the aggregate GPU budget.
|
||||
pub fn with_gpu_count(mut self, gpu_count: u32) -> Self {
|
||||
self.gpu_count = gpu_count;
|
||||
pub fn with_total_gpu_count(mut self, total_gpu_count: u32) -> Self {
|
||||
self.total_gpu_count = total_gpu_count;
|
||||
self
|
||||
}
|
||||
|
||||
/// Require every per-tier resource limit to request at least one unit.
|
||||
pub fn validate(&self) -> Result<()> {
|
||||
if self.cpu_millis == 0 {
|
||||
if self.total_cpu_millis == 0 {
|
||||
return Err(Error::InvalidInput {
|
||||
message: "resource_budget.cpu_millis must be greater than zero".into(),
|
||||
message: "total_cpu_millis must be greater than zero".into(),
|
||||
});
|
||||
}
|
||||
if self.memory_bytes == 0 {
|
||||
if self.total_memory_bytes == 0 {
|
||||
return Err(Error::InvalidInput {
|
||||
message: "resource_budget.memory_bytes must be greater than zero".into(),
|
||||
message: "total_memory_bytes must be greater than zero".into(),
|
||||
});
|
||||
}
|
||||
Ok(())
|
||||
@@ -270,7 +270,7 @@ pub struct RefreshColumnOptions {
|
||||
/// Override the registered Function's maximum concurrent user-code calls
|
||||
/// for this logical execution. Must be greater than zero. `None` uses the
|
||||
/// registration default, or disabled when the Function declares none.
|
||||
/// This is not an account quota and does not change `resource_budget`.
|
||||
/// This is not an account quota and does not change total resource limits.
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
pub max_concurrency: Option<u32>,
|
||||
/// Opt-in row-count threshold for publishing completed Function outputs.
|
||||
@@ -281,10 +281,12 @@ pub struct RefreshColumnOptions {
|
||||
/// rejects this option.
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
pub publication_interval_rows: Option<u64>,
|
||||
/// Complete aggregate CPU, memory, and GPU budget for a registered
|
||||
/// Function refresh. Cannot be combined with `gpu_count`.
|
||||
/// Total CPU budget for this execution, in millicores.
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
pub resource_budget: Option<FunctionWorkerResourceBudget>,
|
||||
pub total_cpu_millis: Option<u64>,
|
||||
/// Total memory budget for this execution, in bytes.
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
pub total_memory_bytes: Option<u64>,
|
||||
/// CPU, memory, and ephemeral-storage limits for the Function refresh
|
||||
/// supervisor pod. Enterprise only.
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
@@ -299,12 +301,14 @@ pub struct RefreshColumnOptions {
|
||||
/// when the Function does not declare one.
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
pub gpu_class: Option<String>,
|
||||
/// Positive aggregate GPU budget for Function workers in LanceDB
|
||||
/// Enterprise.
|
||||
///
|
||||
/// `None` leaves the server's configured budget unchanged.
|
||||
/// Positive number of GPUs allocated to each Function worker.
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
pub gpu_count: Option<u32>,
|
||||
/// Nonnegative total GPU budget for Function workers in LanceDB Enterprise.
|
||||
/// Omitted values inherit column defaults, then Function defaults, then
|
||||
/// deployment defaults.
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
pub total_gpu_count: Option<u32>,
|
||||
}
|
||||
|
||||
impl RefreshColumnOptions {
|
||||
@@ -415,12 +419,15 @@ impl RefreshColumnOptions {
|
||||
self
|
||||
}
|
||||
|
||||
/// Set the aggregate worker resource budget for a Function refresh.
|
||||
///
|
||||
/// Use [`FunctionWorkerResourceBudget::new`] for a CPU-only budget, or
|
||||
/// [`FunctionWorkerResourceBudget::with_gpu_count`] to include GPUs.
|
||||
pub fn resource_budget(mut self, budget: FunctionWorkerResourceBudget) -> Self {
|
||||
self.resource_budget = Some(budget);
|
||||
/// Override the total CPU budget for this refresh.
|
||||
pub fn total_cpu_millis(mut self, value: u64) -> Self {
|
||||
self.total_cpu_millis = Some(value);
|
||||
self
|
||||
}
|
||||
|
||||
/// Override the total memory budget for this refresh.
|
||||
pub fn total_memory_bytes(mut self, value: u64) -> Self {
|
||||
self.total_memory_bytes = Some(value);
|
||||
self
|
||||
}
|
||||
|
||||
@@ -442,12 +449,18 @@ impl RefreshColumnOptions {
|
||||
self
|
||||
}
|
||||
|
||||
/// Request an aggregate GPU budget of `gpu_count`.
|
||||
/// Set the number of GPUs allocated to each Function worker.
|
||||
pub fn gpu_count(mut self, gpu_count: u32) -> Self {
|
||||
self.gpu_count = Some(gpu_count);
|
||||
self
|
||||
}
|
||||
|
||||
/// Request an aggregate GPU budget of `total_gpu_count`.
|
||||
pub fn total_gpu_count(mut self, total_gpu_count: u32) -> Self {
|
||||
self.total_gpu_count = Some(total_gpu_count);
|
||||
self
|
||||
}
|
||||
|
||||
/// The first set option a LanceDB Embedded refresh cannot honor, if any.
|
||||
pub fn enterprise_only_option(&self) -> Option<&'static str> {
|
||||
[
|
||||
@@ -474,7 +487,9 @@ impl RefreshColumnOptions {
|
||||
"publication_interval_rows",
|
||||
self.publication_interval_rows.is_some(),
|
||||
),
|
||||
("resource_budget", self.resource_budget.is_some()),
|
||||
("gpu_count", self.gpu_count.is_some()),
|
||||
("total_cpu_millis", self.total_cpu_millis.is_some()),
|
||||
("total_memory_bytes", self.total_memory_bytes.is_some()),
|
||||
("supervisor_resources", self.supervisor_resources.is_some()),
|
||||
("planning_workers", self.planning_workers.is_some()),
|
||||
]
|
||||
@@ -564,14 +579,12 @@ impl RefreshColumnOptions {
|
||||
message: "publication_interval_rows must be greater than zero".into(),
|
||||
});
|
||||
}
|
||||
if self.resource_budget.is_some() && self.gpu_count.is_some() {
|
||||
if self.total_cpu_millis == Some(0) || self.total_memory_bytes == Some(0) {
|
||||
return Err(Error::InvalidInput {
|
||||
message: "gpu_count cannot be combined with resource_budget".into(),
|
||||
message: "total_cpu_millis and total_memory_bytes must be positive integers".into(),
|
||||
});
|
||||
}
|
||||
if let Some(budget) = &self.resource_budget {
|
||||
budget.validate()?;
|
||||
}
|
||||
|
||||
if let Some(resources) = &self.supervisor_resources {
|
||||
resources.validate("supervisor_resources")?;
|
||||
}
|
||||
@@ -583,9 +596,19 @@ impl RefreshColumnOptions {
|
||||
}
|
||||
if self.gpu_count == Some(0) {
|
||||
return Err(Error::InvalidInput {
|
||||
message: "gpu_count must be greater than zero".into(),
|
||||
message: "gpu_count must be positive".into(),
|
||||
});
|
||||
}
|
||||
if self
|
||||
.gpu_count
|
||||
.zip(self.total_gpu_count)
|
||||
.is_some_and(|(per_worker, total)| per_worker > total)
|
||||
{
|
||||
return Err(Error::InvalidInput {
|
||||
message: "total_gpu_count cannot fit one Function worker".into(),
|
||||
});
|
||||
}
|
||||
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
@@ -2803,3 +2826,47 @@ mod tests {
|
||||
assert_eq!(payloads.value(0), payload);
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod resource_validation_tests {
|
||||
use super::{FunctionRefreshPlanningConfig, FunctionRefreshPodResources, RefreshColumnOptions};
|
||||
|
||||
#[test]
|
||||
fn independent_totals_preserve_placement_and_pod_validation() {
|
||||
assert!(
|
||||
RefreshColumnOptions::default()
|
||||
.total_cpu_millis(1000)
|
||||
.validate()
|
||||
.is_ok()
|
||||
);
|
||||
assert!(
|
||||
RefreshColumnOptions::default()
|
||||
.total_gpu_count(0)
|
||||
.validate()
|
||||
.is_ok()
|
||||
);
|
||||
assert!(
|
||||
RefreshColumnOptions::default()
|
||||
.gpu_class("H100:2")
|
||||
.validate()
|
||||
.is_err()
|
||||
);
|
||||
assert!(
|
||||
RefreshColumnOptions::default()
|
||||
.supervisor_resources(FunctionRefreshPodResources::new(0, 1024, 1024))
|
||||
.validate()
|
||||
.is_err()
|
||||
);
|
||||
assert!(
|
||||
RefreshColumnOptions::default()
|
||||
.planning_workers(FunctionRefreshPlanningConfig::new(
|
||||
FunctionRefreshPodResources::new(1000, 1024, 1024),
|
||||
0,
|
||||
1,
|
||||
1
|
||||
))
|
||||
.validate()
|
||||
.is_err()
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -85,6 +85,9 @@ fn execution_controls_require_their_positive_ranges() {
|
||||
("max_concurrency", Value::from(4_294_967_296_u64)),
|
||||
("max_concurrency", Value::from(-1)),
|
||||
("max_concurrency", Value::from(1.5)),
|
||||
("total_cpu_millis", Value::from(0)),
|
||||
("total_memory_bytes", Value::from(0)),
|
||||
("total_gpu_count", Value::from(4_294_967_296_u64)),
|
||||
("row_timeout_seconds", Value::from(0)),
|
||||
("row_timeout_seconds", Value::from(-0.25)),
|
||||
] {
|
||||
|
||||
Reference in New Issue
Block a user