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:
@@ -388,6 +388,11 @@ class Connection(object):
|
||||
with_no_data: bool = False,
|
||||
auto_refresh_enabled: Optional[bool] = None,
|
||||
auto_refresh_interval_seconds: Optional[float] = None,
|
||||
total_cpu_millis: Optional[int] = None,
|
||||
total_memory_bytes: Optional[int] = None,
|
||||
total_gpu_count: Optional[int] = None,
|
||||
gpu_class: Optional[str] = None,
|
||||
gpu_count: Optional[int] = None,
|
||||
*,
|
||||
query: Optional[str] = None,
|
||||
exist_ok: bool = False,
|
||||
@@ -402,6 +407,11 @@ class Connection(object):
|
||||
with_no_data: bool = False,
|
||||
auto_refresh_enabled: Optional[bool] = None,
|
||||
auto_refresh_interval_seconds: Optional[float] = None,
|
||||
total_cpu_millis: Optional[int] = None,
|
||||
total_memory_bytes: Optional[int] = None,
|
||||
total_gpu_count: Optional[int] = None,
|
||||
gpu_class: Optional[str] = None,
|
||||
gpu_count: Optional[int] = None,
|
||||
*,
|
||||
query: Optional[str] = None,
|
||||
exist_ok: bool = False,
|
||||
@@ -754,7 +764,11 @@ class Table:
|
||||
columns: list[tuple[str, str]],
|
||||
auto_refresh_enabled: Optional[bool] = None,
|
||||
auto_refresh_interval_seconds: Optional[int] = None,
|
||||
auto_refresh_resource_budget: Optional[dict[str, int]] = None,
|
||||
total_cpu_millis: Optional[int] = None,
|
||||
total_memory_bytes: Optional[int] = None,
|
||||
total_gpu_count: Optional[int] = None,
|
||||
gpu_class: Optional[str] = None,
|
||||
gpu_count: Optional[int] = None,
|
||||
) -> AddColumnsResult: ...
|
||||
async def add_function_columns(
|
||||
self,
|
||||
@@ -762,7 +776,11 @@ class Table:
|
||||
output_name: Optional[str],
|
||||
auto_refresh_enabled: Optional[bool] = None,
|
||||
auto_refresh_interval_seconds: Optional[int] = None,
|
||||
auto_refresh_resource_budget: Optional[dict[str, int]] = None,
|
||||
total_cpu_millis: Optional[int] = None,
|
||||
total_memory_bytes: Optional[int] = None,
|
||||
total_gpu_count: Optional[int] = None,
|
||||
gpu_class: Optional[str] = None,
|
||||
gpu_count: Optional[int] = None,
|
||||
) -> AddColumnsResult: ...
|
||||
async def refresh_column(
|
||||
self,
|
||||
@@ -772,11 +790,13 @@ class Table:
|
||||
batch_size: Optional[int] = None,
|
||||
max_concurrency: Optional[int] = None,
|
||||
publication_interval_rows: Optional[int] = None,
|
||||
resource_budget: Optional[dict[str, int]] = None,
|
||||
total_cpu_millis: Optional[int] = None,
|
||||
total_memory_bytes: Optional[int] = None,
|
||||
supervisor_resources: Optional[dict[str, int]] = None,
|
||||
planning_workers: Optional[dict[str, Any]] = None,
|
||||
gpu_class: Optional[str] = None,
|
||||
gpu_count: Optional[int] = None,
|
||||
total_gpu_count: Optional[int] = None,
|
||||
retry_policy: Optional[str] = None,
|
||||
error_policy: Optional[str] = None,
|
||||
max_failed_fraction: Optional[float] = None,
|
||||
@@ -800,11 +820,13 @@ class Table:
|
||||
batch_size: Optional[int] = None,
|
||||
max_concurrency: Optional[int] = None,
|
||||
publication_interval_rows: Optional[int] = None,
|
||||
resource_budget: Optional[dict[str, int]] = None,
|
||||
total_cpu_millis: Optional[int] = None,
|
||||
total_memory_bytes: Optional[int] = None,
|
||||
supervisor_resources: Optional[dict[str, int]] = None,
|
||||
planning_workers: Optional[dict[str, Any]] = None,
|
||||
gpu_class: Optional[str] = None,
|
||||
gpu_count: Optional[int] = None,
|
||||
total_gpu_count: Optional[int] = None,
|
||||
retry_policy: Optional[str] = None,
|
||||
error_policy: Optional[str] = None,
|
||||
max_failed_fraction: Optional[float] = None,
|
||||
@@ -856,20 +878,22 @@ class Table:
|
||||
source_version: Optional[int] = None,
|
||||
*,
|
||||
full: bool = False,
|
||||
cpu_millis: Optional[int] = None,
|
||||
memory_bytes: Optional[int] = None,
|
||||
gpu_count: Optional[int] = None,
|
||||
total_cpu_millis: Optional[int] = None,
|
||||
total_memory_bytes: Optional[int] = None,
|
||||
total_gpu_count: Optional[int] = None,
|
||||
gpu_class: Optional[str] = None,
|
||||
gpu_count: Optional[int] = None,
|
||||
) -> RefreshMaterializedViewResult: ...
|
||||
async def refresh_materialized_view_async(
|
||||
self,
|
||||
source_version: Optional[int] = None,
|
||||
*,
|
||||
full: bool = False,
|
||||
cpu_millis: Optional[int] = None,
|
||||
memory_bytes: Optional[int] = None,
|
||||
gpu_count: Optional[int] = None,
|
||||
total_cpu_millis: Optional[int] = None,
|
||||
total_memory_bytes: Optional[int] = None,
|
||||
total_gpu_count: Optional[int] = None,
|
||||
gpu_class: Optional[str] = None,
|
||||
gpu_count: Optional[int] = None,
|
||||
) -> Job: ...
|
||||
async def materialized_view_definition(self) -> str: ...
|
||||
async def add_columns_with_schema(self, schema: pa.Schema) -> AddColumnsResult: ...
|
||||
|
||||
@@ -118,6 +118,7 @@ from .namespace_utils import (
|
||||
_normalize_drop_namespace_mode,
|
||||
_normalize_drop_namespace_behavior,
|
||||
)
|
||||
from .resources import _resource_options
|
||||
|
||||
|
||||
def _view_description(
|
||||
@@ -764,6 +765,11 @@ class DBConnection(EnforceOverrides):
|
||||
exist_ok: bool = False,
|
||||
auto_refresh_enabled: Optional[bool] = None,
|
||||
auto_refresh_interval_seconds: Optional[float] = None,
|
||||
total_cpu_millis: Optional[int] = None,
|
||||
total_memory_bytes: Optional[int] = None,
|
||||
total_gpu_count: Optional[int] = None,
|
||||
gpu_class: Optional[str] = None,
|
||||
gpu_count: Optional[int] = None,
|
||||
) -> MaterializedView:
|
||||
"""Define a materialized view named ``name`` over the table ``source``.
|
||||
|
||||
@@ -807,6 +813,14 @@ class DBConnection(EnforceOverrides):
|
||||
Positive, finite refresh interval in seconds in LanceDB Enterprise.
|
||||
When omitted, the server determines when to refresh.
|
||||
|
||||
total_cpu_millis: int, optional
|
||||
Default total CPU budget in millicores for initial population and
|
||||
refreshes. Overrides Function defaults. LanceDB Enterprise only.
|
||||
total_memory_bytes: int, optional
|
||||
Default total memory budget in bytes. LanceDB Enterprise only.
|
||||
total_gpu_count: int, optional
|
||||
Default total GPU budget across workers. LanceDB Enterprise only.
|
||||
|
||||
Returns
|
||||
-------
|
||||
MaterializedView
|
||||
@@ -818,6 +832,13 @@ class DBConnection(EnforceOverrides):
|
||||
... query="SELECT kind, count(*) AS n FROM events GROUP BY kind",
|
||||
... )
|
||||
"""
|
||||
_resource_options(
|
||||
total_cpu_millis,
|
||||
total_memory_bytes,
|
||||
total_gpu_count,
|
||||
gpu_class=gpu_class,
|
||||
gpu_count=gpu_count,
|
||||
)
|
||||
raise NotImplementedError(
|
||||
_append_doc_url(
|
||||
"materialized views are not supported on this connection type",
|
||||
@@ -838,6 +859,11 @@ class DBConnection(EnforceOverrides):
|
||||
exist_ok: bool = False,
|
||||
auto_refresh_enabled: Optional[bool] = None,
|
||||
auto_refresh_interval_seconds: Optional[float] = None,
|
||||
total_cpu_millis: Optional[int] = None,
|
||||
total_memory_bytes: Optional[int] = None,
|
||||
total_gpu_count: Optional[int] = None,
|
||||
gpu_class: Optional[str] = None,
|
||||
gpu_count: Optional[int] = None,
|
||||
) -> Job[None]:
|
||||
"""Submit materialized-view creation and return its job.
|
||||
|
||||
@@ -854,6 +880,13 @@ class DBConnection(EnforceOverrides):
|
||||
Servers without early registry-handle support return a connection-scoped
|
||||
query job instead. Its ID cannot be reopened with :meth:`open_job`.
|
||||
"""
|
||||
_resource_options(
|
||||
total_cpu_millis,
|
||||
total_memory_bytes,
|
||||
total_gpu_count,
|
||||
gpu_class=gpu_class,
|
||||
gpu_count=gpu_count,
|
||||
)
|
||||
raise NotImplementedError(
|
||||
_append_doc_url(
|
||||
"materialized views are not supported on this connection type",
|
||||
@@ -2322,6 +2355,11 @@ class LanceDBConnection(DBConnection):
|
||||
exist_ok: bool = False,
|
||||
auto_refresh_enabled: Optional[bool] = None,
|
||||
auto_refresh_interval_seconds: Optional[float] = None,
|
||||
total_cpu_millis: Optional[int] = None,
|
||||
total_memory_bytes: Optional[int] = None,
|
||||
total_gpu_count: Optional[int] = None,
|
||||
gpu_class: Optional[str] = None,
|
||||
gpu_count: Optional[int] = None,
|
||||
) -> MaterializedView:
|
||||
"""Define a materialized view named ``name`` over the table ``source``.
|
||||
|
||||
@@ -2349,6 +2387,13 @@ class LanceDBConnection(DBConnection):
|
||||
>>> view.table.count_rows() # doctest: +SKIP
|
||||
1
|
||||
"""
|
||||
_resource_options(
|
||||
total_cpu_millis,
|
||||
total_memory_bytes,
|
||||
total_gpu_count,
|
||||
gpu_class=gpu_class,
|
||||
gpu_count=gpu_count,
|
||||
)
|
||||
LOOP.run(
|
||||
self._conn.create_materialized_view(
|
||||
name,
|
||||
@@ -2361,6 +2406,11 @@ class LanceDBConnection(DBConnection):
|
||||
exist_ok=exist_ok,
|
||||
auto_refresh_enabled=auto_refresh_enabled,
|
||||
auto_refresh_interval_seconds=auto_refresh_interval_seconds,
|
||||
total_cpu_millis=total_cpu_millis,
|
||||
total_memory_bytes=total_memory_bytes,
|
||||
total_gpu_count=total_gpu_count,
|
||||
gpu_class=gpu_class,
|
||||
gpu_count=gpu_count,
|
||||
)
|
||||
)
|
||||
return MaterializedView(self.open_table(name))
|
||||
@@ -2379,7 +2429,19 @@ class LanceDBConnection(DBConnection):
|
||||
exist_ok: bool = False,
|
||||
auto_refresh_enabled: Optional[bool] = None,
|
||||
auto_refresh_interval_seconds: Optional[float] = None,
|
||||
total_cpu_millis: Optional[int] = None,
|
||||
total_memory_bytes: Optional[int] = None,
|
||||
total_gpu_count: Optional[int] = None,
|
||||
gpu_class: Optional[str] = None,
|
||||
gpu_count: Optional[int] = None,
|
||||
) -> Job[None]:
|
||||
_resource_options(
|
||||
total_cpu_millis,
|
||||
total_memory_bytes,
|
||||
total_gpu_count,
|
||||
gpu_class=gpu_class,
|
||||
gpu_count=gpu_count,
|
||||
)
|
||||
job = LOOP.run(
|
||||
self._conn.create_materialized_view_async(
|
||||
name,
|
||||
@@ -2392,6 +2454,11 @@ class LanceDBConnection(DBConnection):
|
||||
exist_ok=exist_ok,
|
||||
auto_refresh_enabled=auto_refresh_enabled,
|
||||
auto_refresh_interval_seconds=auto_refresh_interval_seconds,
|
||||
total_cpu_millis=total_cpu_millis,
|
||||
total_memory_bytes=total_memory_bytes,
|
||||
total_gpu_count=total_gpu_count,
|
||||
gpu_class=gpu_class,
|
||||
gpu_count=gpu_count,
|
||||
)
|
||||
)
|
||||
return Job(job)
|
||||
@@ -3711,6 +3778,11 @@ class AsyncConnection(object):
|
||||
exist_ok: bool = False,
|
||||
auto_refresh_enabled: Optional[bool] = None,
|
||||
auto_refresh_interval_seconds: Optional[float] = None,
|
||||
total_cpu_millis: Optional[int] = None,
|
||||
total_memory_bytes: Optional[int] = None,
|
||||
total_gpu_count: Optional[int] = None,
|
||||
gpu_class: Optional[str] = None,
|
||||
gpu_count: Optional[int] = None,
|
||||
) -> AsyncMaterializedView:
|
||||
"""Define a materialized view named ``name`` over the table ``source``.
|
||||
|
||||
@@ -3723,6 +3795,13 @@ class AsyncConnection(object):
|
||||
See
|
||||
[DBConnection.create_materialized_view][lancedb.DBConnection.create_materialized_view].
|
||||
"""
|
||||
_resource_options(
|
||||
total_cpu_millis,
|
||||
total_memory_bytes,
|
||||
total_gpu_count,
|
||||
gpu_class=gpu_class,
|
||||
gpu_count=gpu_count,
|
||||
)
|
||||
_validate_create_materialized_view(source, query, select, where, limit)
|
||||
if source is not None:
|
||||
source, native_options = await self._materialized_view_source(
|
||||
@@ -3742,7 +3821,12 @@ class AsyncConnection(object):
|
||||
exist_ok=exist_ok,
|
||||
auto_refresh_enabled=auto_refresh_enabled,
|
||||
auto_refresh_interval_seconds=auto_refresh_interval_seconds,
|
||||
total_cpu_millis=total_cpu_millis,
|
||||
total_memory_bytes=total_memory_bytes,
|
||||
total_gpu_count=total_gpu_count,
|
||||
**native_options,
|
||||
gpu_class=gpu_class,
|
||||
gpu_count=gpu_count,
|
||||
)
|
||||
return AsyncMaterializedView(AsyncTable(inner))
|
||||
|
||||
@@ -3759,6 +3843,11 @@ class AsyncConnection(object):
|
||||
exist_ok: bool = False,
|
||||
auto_refresh_enabled: Optional[bool] = None,
|
||||
auto_refresh_interval_seconds: Optional[float] = None,
|
||||
total_cpu_millis: Optional[int] = None,
|
||||
total_memory_bytes: Optional[int] = None,
|
||||
total_gpu_count: Optional[int] = None,
|
||||
gpu_class: Optional[str] = None,
|
||||
gpu_count: Optional[int] = None,
|
||||
) -> AsyncJob[None]:
|
||||
"""Submit materialized-view creation and return its job.
|
||||
|
||||
@@ -3769,6 +3858,13 @@ class AsyncConnection(object):
|
||||
Enterprise, creation uses SQL; ``job_type`` is ``"query"`` and ``id``
|
||||
identifies that query on this connection.
|
||||
"""
|
||||
_resource_options(
|
||||
total_cpu_millis,
|
||||
total_memory_bytes,
|
||||
total_gpu_count,
|
||||
gpu_class=gpu_class,
|
||||
gpu_count=gpu_count,
|
||||
)
|
||||
_validate_create_materialized_view(source, query, select, where, limit)
|
||||
if source is not None:
|
||||
source, native_options = await self._materialized_view_source(
|
||||
@@ -3788,7 +3884,12 @@ class AsyncConnection(object):
|
||||
exist_ok=exist_ok,
|
||||
auto_refresh_enabled=auto_refresh_enabled,
|
||||
auto_refresh_interval_seconds=auto_refresh_interval_seconds,
|
||||
total_cpu_millis=total_cpu_millis,
|
||||
total_memory_bytes=total_memory_bytes,
|
||||
total_gpu_count=total_gpu_count,
|
||||
**native_options,
|
||||
gpu_class=gpu_class,
|
||||
gpu_count=gpu_count,
|
||||
)
|
||||
return AsyncJob(inner)
|
||||
|
||||
|
||||
@@ -65,15 +65,13 @@ from .schema import is_blob_v2_field as _is_blob_v2_field
|
||||
from ._blob_reader import BlobReader
|
||||
from ._lancedb import _validate_conda_requirement
|
||||
from .secrets import EnvVarSecret
|
||||
from .resources import _validate_gpu_class_name
|
||||
|
||||
_Int32 = conint(strict=True, ge=-(2**31), le=2**31 - 1)
|
||||
_UInt32 = conint(strict=True, ge=0, le=2**32 - 1)
|
||||
_PositiveUInt32 = conint(strict=True, ge=1, le=2**32 - 1)
|
||||
_UInt64 = conint(strict=True, ge=0, le=2**64 - 1)
|
||||
_GPU_CLASS_NAME = re.compile(r"^[a-z0-9](?:[a-z0-9-]{0,61}[a-z0-9])?$")
|
||||
_GPU_CLASS_ERROR = (
|
||||
"gpu_class must be a lowercase name of at most 63 letters, digits, or "
|
||||
"hyphens, and cannot start or end with a hyphen"
|
||||
)
|
||||
_PositiveUInt64 = conint(strict=True, ge=1, le=2**64 - 1)
|
||||
|
||||
|
||||
def _validate_gpu_wire_marker(value: Any) -> bool:
|
||||
@@ -82,16 +80,24 @@ def _validate_gpu_wire_marker(value: Any) -> bool:
|
||||
return True
|
||||
|
||||
|
||||
def _normalize_gpu_marker(value: bool) -> Optional[bool]:
|
||||
if not isinstance(value, bool):
|
||||
def _normalize_gpu_request(
|
||||
gpu: Optional[bool], gpu_class: Optional[str], gpu_count: Optional[int]
|
||||
) -> tuple[Optional[bool], Optional[str], Optional[int]]:
|
||||
if gpu is not None and not isinstance(gpu, bool):
|
||||
raise ValueError("gpu must be a boolean")
|
||||
return True if value else None
|
||||
|
||||
|
||||
def _validate_gpu_class_name(value: Any) -> str:
|
||||
if not isinstance(value, str) or not _GPU_CLASS_NAME.fullmatch(value):
|
||||
raise ValueError(_GPU_CLASS_ERROR)
|
||||
return value
|
||||
if gpu is not True:
|
||||
if gpu_class is not None or gpu_count is not None:
|
||||
raise ValueError("gpu_class and gpu_count require gpu=True")
|
||||
return None, None, None
|
||||
if gpu_class is not None:
|
||||
gpu_class = _validate_gpu_class_name(gpu_class)
|
||||
if gpu_count is None:
|
||||
gpu_count = 1
|
||||
if isinstance(gpu_count, bool) or not isinstance(gpu_count, int):
|
||||
raise ValueError("gpu_count must be a positive integer")
|
||||
if not 1 <= gpu_count <= 2**32 - 1:
|
||||
raise ValueError("gpu_count must be between 1 and 4294967295")
|
||||
return True, gpu_class, gpu_count
|
||||
|
||||
|
||||
def _validate_batch_size(value: Any) -> Optional[int]:
|
||||
@@ -452,8 +458,10 @@ class PythonRuntimeSpec(_RemoteValue):
|
||||
|
||||
V1 supports ``kind="python"``. Newer runtime kinds remain readable, while
|
||||
their unknown payload fields are intentionally not retained by the client.
|
||||
``kind="python_v2"`` requires ``gpu=True`` and may name an operator-defined
|
||||
``gpu_class``.
|
||||
``kind="python_v2"`` requires ``gpu=True``. Its ``gpu_class`` records the
|
||||
requested operator-defined class or ``"any"`` for any eligible class;
|
||||
omitting it also accepts any eligible class. It does not identify the
|
||||
hardware selected for execution.
|
||||
"""
|
||||
|
||||
kind: str
|
||||
@@ -462,6 +470,7 @@ class PythonRuntimeSpec(_RemoteValue):
|
||||
env: Optional[Mapping[str, str]] = None
|
||||
gpu: Optional[bool] = None
|
||||
gpu_class: Optional[str] = None
|
||||
gpus_per_worker: Optional[_PositiveUInt32] = None
|
||||
|
||||
@model_validator(mode="before")
|
||||
@classmethod
|
||||
@@ -499,6 +508,8 @@ class PythonRuntimeSpec(_RemoteValue):
|
||||
raise ValueError(
|
||||
"python runtime with gpu_class requires kind='python_v2'"
|
||||
)
|
||||
if self.gpus_per_worker is not None:
|
||||
raise ValueError("gpus_per_worker requires kind='python_v2'")
|
||||
elif self.kind == "python_v2":
|
||||
if self.python_version is None:
|
||||
raise ValueError("python_v2 runtime requires python_version")
|
||||
@@ -512,6 +523,7 @@ class PythonRuntimeSpec(_RemoteValue):
|
||||
object.__setattr__(self, "env", None)
|
||||
object.__setattr__(self, "gpu", None)
|
||||
object.__setattr__(self, "gpu_class", None)
|
||||
object.__setattr__(self, "gpus_per_worker", None)
|
||||
return self
|
||||
|
||||
@property
|
||||
@@ -713,8 +725,9 @@ class FunctionVersion(_RemoteValue):
|
||||
version also requires matching the source and all other registration inputs,
|
||||
including signature, Secret bindings, models, and execution controls.
|
||||
|
||||
``gpu_class`` is the operator-defined GPU pool fixed into this Function
|
||||
version, or ``None`` when registration used the deployment default.
|
||||
``gpu_class`` records the default GPU pool for this Function version.
|
||||
Column/MV creation and refresh can override it independently of the
|
||||
per-worker ``gpu_count`` in the requested runtime.
|
||||
|
||||
``batch_size``, ``max_concurrency``, ``row_timeout_seconds``, and
|
||||
``result_stability`` retain the execution controls reported by the
|
||||
@@ -749,6 +762,9 @@ class FunctionVersion(_RemoteValue):
|
||||
gpu_class: Optional[str] = None
|
||||
batch_size: Optional[int] = None
|
||||
max_concurrency: Optional[int] = None
|
||||
total_cpu_millis: Optional[_PositiveUInt64] = None
|
||||
total_memory_bytes: Optional[_PositiveUInt64] = None
|
||||
total_gpu_count: Optional[_UInt32] = None
|
||||
row_timeout_seconds: Optional[float] = None
|
||||
result_stability: Optional[str] = None
|
||||
runtime: Optional[PythonRuntimeSpec] = None
|
||||
@@ -941,6 +957,9 @@ class FunctionRegistrationRequest(_RemoteValue):
|
||||
runtime: PythonRuntimeSpec
|
||||
batch_size: Optional[int] = None
|
||||
max_concurrency: Optional[int] = None
|
||||
total_cpu_millis: Optional[_PositiveUInt64] = None
|
||||
total_memory_bytes: Optional[_PositiveUInt64] = None
|
||||
total_gpu_count: Optional[_UInt32] = None
|
||||
row_timeout_seconds: Optional[float] = None
|
||||
retry_policy: Optional[FunctionRetryPolicy] = None
|
||||
secret_bindings: tuple[SecretBinding, ...] = ()
|
||||
@@ -3213,8 +3232,12 @@ class FunctionDefinition:
|
||||
max_concurrency: Optional[int] = None,
|
||||
row_timeout_seconds: Optional[float] = None,
|
||||
retry_policy: Optional[FunctionRetryPolicy] = None,
|
||||
gpu: bool = False,
|
||||
gpu: Optional[bool] = None,
|
||||
gpu_class: Optional[str] = None,
|
||||
gpu_count: Optional[int] = None,
|
||||
total_cpu_millis: Optional[int] = None,
|
||||
total_memory_bytes: Optional[int] = None,
|
||||
total_gpu_count: Optional[int] = None,
|
||||
conda: tuple[str, ...] = (),
|
||||
conda_channels: tuple[str, ...] = (),
|
||||
apt: tuple[str, ...] = (),
|
||||
@@ -3235,11 +3258,9 @@ class FunctionDefinition:
|
||||
if conda_channels and not conda:
|
||||
raise ValueError("conda_channels requires conda packages")
|
||||
_validate_package_requirements("conda" if conda else "pip", conda or pip)
|
||||
gpu_marker = _normalize_gpu_marker(gpu)
|
||||
if gpu_class is not None:
|
||||
_validate_gpu_class_name(gpu_class)
|
||||
if gpu_marker is None:
|
||||
raise ValueError("gpu_class requires gpu=True")
|
||||
gpu_marker, gpu_class, gpus_per_worker = _normalize_gpu_request(
|
||||
gpu, gpu_class, gpu_count
|
||||
)
|
||||
packages = tuple(sorted(set(conda if conda else pip)))
|
||||
system_packages = tuple(sorted(set(apt)))
|
||||
if any(
|
||||
@@ -3357,6 +3378,7 @@ class FunctionDefinition:
|
||||
env=environment,
|
||||
gpu=gpu_marker,
|
||||
gpu_class=gpu_class,
|
||||
gpus_per_worker=gpus_per_worker,
|
||||
)
|
||||
self._function = function
|
||||
self._request = FunctionRegistrationRequest(
|
||||
@@ -3378,6 +3400,9 @@ class FunctionDefinition:
|
||||
runtime=runtime,
|
||||
batch_size=batch_size,
|
||||
max_concurrency=max_concurrency,
|
||||
total_cpu_millis=total_cpu_millis,
|
||||
total_memory_bytes=total_memory_bytes,
|
||||
total_gpu_count=total_gpu_count,
|
||||
row_timeout_seconds=row_timeout_seconds,
|
||||
retry_policy=retry_policy,
|
||||
models=models,
|
||||
@@ -3489,8 +3514,12 @@ def function(
|
||||
max_concurrency: Optional[int] = None,
|
||||
row_timeout_seconds: Optional[float] = None,
|
||||
retry_policy: Optional[FunctionRetryPolicy] = None,
|
||||
gpu: bool = False,
|
||||
gpu: Optional[bool] = None,
|
||||
gpu_class: Optional[str] = None,
|
||||
gpu_count: Optional[int] = None,
|
||||
total_cpu_millis: Optional[int] = None,
|
||||
total_memory_bytes: Optional[int] = None,
|
||||
total_gpu_count: Optional[int] = None,
|
||||
conda: tuple[str, ...] | list[str] = (),
|
||||
conda_channels: tuple[str, ...] | list[str] = (),
|
||||
apt: tuple[str, ...] | list[str] = (),
|
||||
@@ -3513,8 +3542,12 @@ def function(
|
||||
max_concurrency: Optional[int] = None,
|
||||
row_timeout_seconds: Optional[float] = None,
|
||||
retry_policy: Optional[FunctionRetryPolicy] = None,
|
||||
gpu: bool = False,
|
||||
gpu: Optional[bool] = None,
|
||||
gpu_class: Optional[str] = None,
|
||||
gpu_count: Optional[int] = None,
|
||||
total_cpu_millis: Optional[int] = None,
|
||||
total_memory_bytes: Optional[int] = None,
|
||||
total_gpu_count: Optional[int] = None,
|
||||
conda: tuple[str, ...] | list[str] = (),
|
||||
conda_channels: tuple[str, ...] | list[str] = (),
|
||||
apt: tuple[str, ...] | list[str] = (),
|
||||
@@ -3735,16 +3768,27 @@ def function(
|
||||
and backoff. A refresh may override this default. Retrying a partial
|
||||
call must be safe; completed calls are not repeated. For batch Functions,
|
||||
skip after exhaustion applies to the whole failed call.
|
||||
gpu : bool, default False
|
||||
Whether every remote execution requires a GPU. The execution platform
|
||||
selects one compatible GPU for each worker. The requirement is part of
|
||||
the immutable Function version.
|
||||
gpu : bool, optional
|
||||
Enable GPU execution. Defaults to CPU execution.
|
||||
gpu_class : str, optional
|
||||
Operator-defined GPU class for every execution of this Function, such
|
||||
as ``"a10g"`` or ``"h100"``. Requires ``gpu=True`` and follows the
|
||||
lowercase 63-character DNS-label rule. The class is part of the
|
||||
immutable Function version; per-refresh aggregate GPU budgets are
|
||||
selected through ``refresh_column`` instead of registration.
|
||||
Select an operator-configured GPU pool, such as ``"h100"``.
|
||||
Requires ``gpu=True``. Omitting it is equivalent to ``"any"`` and accepts
|
||||
any eligible configured GPU class. Use ``"default"`` to select the
|
||||
deployment's default pool explicitly.
|
||||
gpu_count : int, optional
|
||||
Default GPUs allocated together to each Function worker. Requires ``gpu=True``
|
||||
and defaults to one. Column/MV creation and refresh can override it.
|
||||
Must be a positive integer. Refresh
|
||||
``total_gpu_count`` limits the total GPUs across the worker fleet.
|
||||
total_cpu_millis : int, optional
|
||||
Default total CPU budget for an execution, in millicores (1000 = one
|
||||
core). A column/MV declaration or refresh may override this value.
|
||||
total_memory_bytes : int, optional
|
||||
Default total memory budget for an execution, in bytes.
|
||||
total_gpu_count : int, optional
|
||||
Default total GPU budget across an execution's workers. This is
|
||||
separate from ``gpu_count``, which allocates GPUs to each worker.
|
||||
MVs add the defaults of their distinct pinned Function versions.
|
||||
code : sequence of module, optional
|
||||
Top-level modules or packages shipped with the Function and importable
|
||||
by their own names. Package resources, including binary data and
|
||||
@@ -3788,13 +3832,13 @@ def function(
|
||||
... return value
|
||||
>>> batch_identity(pa.array([1, 2, 3])).to_pylist()
|
||||
[1, 2, 3]
|
||||
>>> @function(pip=["cupy-cuda12x"], gpu=True, gpu_class="a10g")
|
||||
>>> @function(pip=["cupy-cuda12x"], gpu=True, gpu_class="a10g", gpu_count=2)
|
||||
... def gpu_score(value: int) -> int:
|
||||
... return value * 2
|
||||
>>> gpu_score.registration_request.runtime.gpu
|
||||
True
|
||||
>>> gpu_score.registration_request.runtime.gpu_class
|
||||
'a10g'
|
||||
>>> gpu_score.registration_request.runtime.gpus_per_worker
|
||||
2
|
||||
>>> @function
|
||||
... class scale:
|
||||
... def __init__(self, factor: float, offset: float = 0.0):
|
||||
@@ -3871,6 +3915,10 @@ def function(
|
||||
retry_policy=retry_policy,
|
||||
gpu=gpu,
|
||||
gpu_class=gpu_class,
|
||||
gpu_count=gpu_count,
|
||||
total_cpu_millis=total_cpu_millis,
|
||||
total_memory_bytes=total_memory_bytes,
|
||||
total_gpu_count=total_gpu_count,
|
||||
conda=tuple(conda),
|
||||
conda_channels=tuple(conda_channels),
|
||||
apt=tuple(apt),
|
||||
|
||||
@@ -17,9 +17,9 @@ from typing import TYPE_CHECKING, Dict, List, Optional, Sequence, Tuple, Union
|
||||
import json
|
||||
from dataclasses import dataclass
|
||||
|
||||
from .functions import _validate_gpu_class_name
|
||||
from .background_loop import LOOP
|
||||
from .job import AsyncJob, Job, _typed_job
|
||||
from .resources import _resource_options
|
||||
|
||||
if TYPE_CHECKING:
|
||||
import pyarrow as pa
|
||||
@@ -167,31 +167,16 @@ def normalize_select(select: SelectArg) -> Optional[List[Tuple[str, str]]]:
|
||||
return normalized
|
||||
|
||||
|
||||
def _refresh_execution_options(cpu_millis, memory_bytes, gpu_count, gpu_class):
|
||||
values = {
|
||||
"cpu_millis": cpu_millis,
|
||||
"memory_bytes": memory_bytes,
|
||||
"gpu_count": gpu_count,
|
||||
}
|
||||
for name, value in values.items():
|
||||
maximum = 2**32 - 1 if name == "gpu_count" else 2**64 - 1
|
||||
minimum = 0 if name == "gpu_count" else 1
|
||||
if value is not None and (
|
||||
type(value) is not int or not minimum <= value <= maximum
|
||||
):
|
||||
raise ValueError(
|
||||
f"{name} must be an integer between {minimum} and {maximum}"
|
||||
)
|
||||
if (cpu_millis is not None or memory_bytes is not None) and any(
|
||||
value is None for value in values.values()
|
||||
):
|
||||
raise ValueError(
|
||||
"cpu_millis, memory_bytes, and gpu_count must be specified together"
|
||||
)
|
||||
if gpu_class is not None:
|
||||
values["gpu_class"] = _validate_gpu_class_name(gpu_class)
|
||||
if gpu_count == 0:
|
||||
raise ValueError("gpu_class requires a positive GPU budget")
|
||||
def _refresh_execution_options(
|
||||
total_cpu_millis, total_memory_bytes, total_gpu_count, gpu_class, gpu_count=None
|
||||
):
|
||||
values = _resource_options(
|
||||
total_cpu_millis,
|
||||
total_memory_bytes,
|
||||
total_gpu_count,
|
||||
gpu_class=gpu_class,
|
||||
gpu_count=gpu_count,
|
||||
)
|
||||
return {name: value for name, value in values.items() if value is not None}
|
||||
|
||||
|
||||
@@ -228,10 +213,11 @@ class AsyncMaterializedView:
|
||||
*,
|
||||
full: bool = False,
|
||||
source_version: Optional[int] = None,
|
||||
cpu_millis: Optional[int] = None,
|
||||
memory_bytes: Optional[int] = None,
|
||||
gpu_count: Optional[int] = None,
|
||||
total_cpu_millis: Optional[int] = None,
|
||||
total_memory_bytes: Optional[int] = None,
|
||||
total_gpu_count: Optional[int] = None,
|
||||
gpu_class: Optional[str] = None,
|
||||
gpu_count: Optional[int] = None,
|
||||
) -> "RefreshMaterializedViewResult":
|
||||
"""Recompute the view from its source.
|
||||
|
||||
@@ -240,11 +226,14 @@ class AsyncMaterializedView:
|
||||
and ``source_version`` selects a source version instead of the latest.
|
||||
LanceDB Enterprise SQL refreshes do not support source-version pinning.
|
||||
|
||||
``cpu_millis`` (1000 = one core), ``memory_bytes``, and ``gpu_count``
|
||||
cap aggregate resources for this execution, including its Function
|
||||
processes. CPU or memory requires all three budget fields; GPU count
|
||||
may be zero for CPU-only views. ``gpu_class`` selects an operator-defined
|
||||
GPU class for this execution only. Omitted options preserve defaults.
|
||||
``total_cpu_millis`` (1000 = one core), ``total_memory_bytes``, and
|
||||
``total_gpu_count`` cap aggregate resources for this execution,
|
||||
including its Function processes. Each resource may be overridden
|
||||
independently. Unset values inherit the view defaults, then the sum
|
||||
across distinct pinned Functions, then deployment defaults. GPU count
|
||||
may be zero for CPU-only views.
|
||||
``gpu_class`` selects an operator-defined GPU class for this execution
|
||||
only. Omitted options preserve defaults.
|
||||
These options require an Enterprise backend that enforces isolation;
|
||||
Embedded refreshes reject them. Other servers may reject the new options.
|
||||
|
||||
@@ -256,7 +245,11 @@ class AsyncMaterializedView:
|
||||
source_version=source_version,
|
||||
full=full,
|
||||
**_refresh_execution_options(
|
||||
cpu_millis, memory_bytes, gpu_count, gpu_class
|
||||
total_cpu_millis,
|
||||
total_memory_bytes,
|
||||
total_gpu_count,
|
||||
gpu_class,
|
||||
gpu_count=gpu_count,
|
||||
),
|
||||
)
|
||||
|
||||
@@ -265,10 +258,11 @@ class AsyncMaterializedView:
|
||||
*,
|
||||
full: bool = False,
|
||||
source_version: Optional[int] = None,
|
||||
cpu_millis: Optional[int] = None,
|
||||
memory_bytes: Optional[int] = None,
|
||||
gpu_count: Optional[int] = None,
|
||||
total_cpu_millis: Optional[int] = None,
|
||||
total_memory_bytes: Optional[int] = None,
|
||||
total_gpu_count: Optional[int] = None,
|
||||
gpu_class: Optional[str] = None,
|
||||
gpu_count: Optional[int] = None,
|
||||
) -> "AsyncJob[RefreshMaterializedViewResult]":
|
||||
"""Submit a refresh and return its job without waiting.
|
||||
|
||||
@@ -289,7 +283,11 @@ class AsyncMaterializedView:
|
||||
source_version=source_version,
|
||||
full=full,
|
||||
**_refresh_execution_options(
|
||||
cpu_millis, memory_bytes, gpu_count, gpu_class
|
||||
total_cpu_millis,
|
||||
total_memory_bytes,
|
||||
total_gpu_count,
|
||||
gpu_class,
|
||||
gpu_count=gpu_count,
|
||||
),
|
||||
),
|
||||
RefreshMaterializedViewResult.from_json,
|
||||
@@ -326,10 +324,11 @@ class MaterializedView:
|
||||
*,
|
||||
full: bool = False,
|
||||
source_version: Optional[int] = None,
|
||||
cpu_millis: Optional[int] = None,
|
||||
memory_bytes: Optional[int] = None,
|
||||
gpu_count: Optional[int] = None,
|
||||
total_cpu_millis: Optional[int] = None,
|
||||
total_memory_bytes: Optional[int] = None,
|
||||
total_gpu_count: Optional[int] = None,
|
||||
gpu_class: Optional[str] = None,
|
||||
gpu_count: Optional[int] = None,
|
||||
) -> "RefreshMaterializedViewResult":
|
||||
"""Recompute the view from its source. See
|
||||
[AsyncMaterializedView.refresh][lancedb.materialized_view.AsyncMaterializedView.refresh]."""
|
||||
@@ -338,7 +337,11 @@ class MaterializedView:
|
||||
full=full,
|
||||
source_version=source_version,
|
||||
**_refresh_execution_options(
|
||||
cpu_millis, memory_bytes, gpu_count, gpu_class
|
||||
total_cpu_millis,
|
||||
total_memory_bytes,
|
||||
total_gpu_count,
|
||||
gpu_class,
|
||||
gpu_count=gpu_count,
|
||||
),
|
||||
)
|
||||
)
|
||||
@@ -348,10 +351,11 @@ class MaterializedView:
|
||||
*,
|
||||
full: bool = False,
|
||||
source_version: Optional[int] = None,
|
||||
cpu_millis: Optional[int] = None,
|
||||
memory_bytes: Optional[int] = None,
|
||||
gpu_count: Optional[int] = None,
|
||||
total_cpu_millis: Optional[int] = None,
|
||||
total_memory_bytes: Optional[int] = None,
|
||||
total_gpu_count: Optional[int] = None,
|
||||
gpu_class: Optional[str] = None,
|
||||
gpu_count: Optional[int] = None,
|
||||
) -> "Job[RefreshMaterializedViewResult]":
|
||||
"""Submit a refresh and return its job without waiting.
|
||||
|
||||
@@ -364,7 +368,11 @@ class MaterializedView:
|
||||
full=full,
|
||||
source_version=source_version,
|
||||
**_refresh_execution_options(
|
||||
cpu_millis, memory_bytes, gpu_count, gpu_class
|
||||
total_cpu_millis,
|
||||
total_memory_bytes,
|
||||
total_gpu_count,
|
||||
gpu_class,
|
||||
gpu_count=gpu_count,
|
||||
),
|
||||
)
|
||||
)
|
||||
|
||||
@@ -738,6 +738,11 @@ class LanceNamespaceDBConnection(DBConnection):
|
||||
with_no_data: bool = False,
|
||||
auto_refresh_enabled: Optional[bool] = None,
|
||||
auto_refresh_interval_seconds: Optional[float] = None,
|
||||
total_cpu_millis: Optional[int] = None,
|
||||
total_memory_bytes: Optional[int] = None,
|
||||
total_gpu_count: Optional[int] = None,
|
||||
gpu_class: Optional[str] = None,
|
||||
gpu_count: Optional[int] = None,
|
||||
exist_ok: bool = False,
|
||||
) -> "MaterializedView":
|
||||
"""Define a materialized view over a table in the root namespace.
|
||||
@@ -757,7 +762,12 @@ class LanceNamespaceDBConnection(DBConnection):
|
||||
with_no_data=with_no_data,
|
||||
auto_refresh_enabled=auto_refresh_enabled,
|
||||
auto_refresh_interval_seconds=auto_refresh_interval_seconds,
|
||||
total_cpu_millis=total_cpu_millis,
|
||||
total_memory_bytes=total_memory_bytes,
|
||||
total_gpu_count=total_gpu_count,
|
||||
exist_ok=exist_ok,
|
||||
gpu_class=gpu_class,
|
||||
gpu_count=gpu_count,
|
||||
)
|
||||
).name
|
||||
)
|
||||
@@ -776,6 +786,11 @@ class LanceNamespaceDBConnection(DBConnection):
|
||||
with_no_data: bool = False,
|
||||
auto_refresh_enabled: Optional[bool] = None,
|
||||
auto_refresh_interval_seconds: Optional[float] = None,
|
||||
total_cpu_millis: Optional[int] = None,
|
||||
total_memory_bytes: Optional[int] = None,
|
||||
total_gpu_count: Optional[int] = None,
|
||||
gpu_class: Optional[str] = None,
|
||||
gpu_count: Optional[int] = None,
|
||||
exist_ok: bool = False,
|
||||
) -> Job[None]:
|
||||
job = LOOP.run(
|
||||
@@ -789,7 +804,12 @@ class LanceNamespaceDBConnection(DBConnection):
|
||||
with_no_data=with_no_data,
|
||||
auto_refresh_enabled=auto_refresh_enabled,
|
||||
auto_refresh_interval_seconds=auto_refresh_interval_seconds,
|
||||
total_cpu_millis=total_cpu_millis,
|
||||
total_memory_bytes=total_memory_bytes,
|
||||
total_gpu_count=total_gpu_count,
|
||||
exist_ok=exist_ok,
|
||||
gpu_class=gpu_class,
|
||||
gpu_count=gpu_count,
|
||||
)
|
||||
)
|
||||
return Job(job)
|
||||
@@ -1396,6 +1416,11 @@ class AsyncLanceNamespaceDBConnection:
|
||||
with_no_data: bool = False,
|
||||
auto_refresh_enabled: Optional[bool] = None,
|
||||
auto_refresh_interval_seconds: Optional[float] = None,
|
||||
total_cpu_millis: Optional[int] = None,
|
||||
total_memory_bytes: Optional[int] = None,
|
||||
total_gpu_count: Optional[int] = None,
|
||||
gpu_class: Optional[str] = None,
|
||||
gpu_count: Optional[int] = None,
|
||||
exist_ok: bool = False,
|
||||
) -> "AsyncMaterializedView":
|
||||
"""Define a materialized view over a table in the root namespace."""
|
||||
@@ -1409,7 +1434,12 @@ class AsyncLanceNamespaceDBConnection:
|
||||
with_no_data=with_no_data,
|
||||
auto_refresh_enabled=auto_refresh_enabled,
|
||||
auto_refresh_interval_seconds=auto_refresh_interval_seconds,
|
||||
total_cpu_millis=total_cpu_millis,
|
||||
total_memory_bytes=total_memory_bytes,
|
||||
total_gpu_count=total_gpu_count,
|
||||
exist_ok=exist_ok,
|
||||
gpu_class=gpu_class,
|
||||
gpu_count=gpu_count,
|
||||
)
|
||||
# Reopen through the namespace so the view's table carries the
|
||||
# namespace client and pushdown configuration a bare inner table lacks.
|
||||
@@ -1427,6 +1457,11 @@ class AsyncLanceNamespaceDBConnection:
|
||||
with_no_data: bool = False,
|
||||
auto_refresh_enabled: Optional[bool] = None,
|
||||
auto_refresh_interval_seconds: Optional[float] = None,
|
||||
total_cpu_millis: Optional[int] = None,
|
||||
total_memory_bytes: Optional[int] = None,
|
||||
total_gpu_count: Optional[int] = None,
|
||||
gpu_class: Optional[str] = None,
|
||||
gpu_count: Optional[int] = None,
|
||||
exist_ok: bool = False,
|
||||
) -> AsyncJob[None]:
|
||||
"""Submit materialized-view creation and return its job."""
|
||||
@@ -1440,7 +1475,12 @@ class AsyncLanceNamespaceDBConnection:
|
||||
with_no_data=with_no_data,
|
||||
auto_refresh_enabled=auto_refresh_enabled,
|
||||
auto_refresh_interval_seconds=auto_refresh_interval_seconds,
|
||||
total_cpu_millis=total_cpu_millis,
|
||||
total_memory_bytes=total_memory_bytes,
|
||||
total_gpu_count=total_gpu_count,
|
||||
exist_ok=exist_ok,
|
||||
gpu_class=gpu_class,
|
||||
gpu_count=gpu_count,
|
||||
)
|
||||
|
||||
async def open_materialized_view(self, name: str) -> "AsyncMaterializedView":
|
||||
|
||||
@@ -62,6 +62,7 @@ from lance_namespace import (
|
||||
from ..pydantic import LanceModel
|
||||
from ..table import Table
|
||||
from ..util import validate_table_name
|
||||
from ..resources import _resource_options
|
||||
|
||||
|
||||
def _duration_seconds(value: Optional[timedelta]) -> Optional[float]:
|
||||
@@ -822,7 +823,19 @@ class RemoteDBConnection(DBConnection):
|
||||
exist_ok: bool = False,
|
||||
auto_refresh_enabled: Optional[bool] = None,
|
||||
auto_refresh_interval_seconds: Optional[float] = None,
|
||||
total_cpu_millis: Optional[int] = None,
|
||||
total_memory_bytes: Optional[int] = None,
|
||||
total_gpu_count: Optional[int] = None,
|
||||
gpu_class: Optional[str] = None,
|
||||
gpu_count: Optional[int] = None,
|
||||
) -> MaterializedView:
|
||||
_resource_options(
|
||||
total_cpu_millis,
|
||||
total_memory_bytes,
|
||||
total_gpu_count,
|
||||
gpu_class=gpu_class,
|
||||
gpu_count=gpu_count,
|
||||
)
|
||||
from .table import RemoteTable
|
||||
|
||||
view = LOOP.run(
|
||||
@@ -837,6 +850,11 @@ class RemoteDBConnection(DBConnection):
|
||||
exist_ok=exist_ok,
|
||||
auto_refresh_enabled=auto_refresh_enabled,
|
||||
auto_refresh_interval_seconds=auto_refresh_interval_seconds,
|
||||
total_cpu_millis=total_cpu_millis,
|
||||
total_memory_bytes=total_memory_bytes,
|
||||
total_gpu_count=total_gpu_count,
|
||||
gpu_class=gpu_class,
|
||||
gpu_count=gpu_count,
|
||||
)
|
||||
)
|
||||
return MaterializedView(
|
||||
@@ -862,7 +880,19 @@ class RemoteDBConnection(DBConnection):
|
||||
exist_ok: bool = False,
|
||||
auto_refresh_enabled: Optional[bool] = None,
|
||||
auto_refresh_interval_seconds: Optional[float] = None,
|
||||
total_cpu_millis: Optional[int] = None,
|
||||
total_memory_bytes: Optional[int] = None,
|
||||
total_gpu_count: Optional[int] = None,
|
||||
gpu_class: Optional[str] = None,
|
||||
gpu_count: Optional[int] = None,
|
||||
) -> Job[None]:
|
||||
_resource_options(
|
||||
total_cpu_millis,
|
||||
total_memory_bytes,
|
||||
total_gpu_count,
|
||||
gpu_class=gpu_class,
|
||||
gpu_count=gpu_count,
|
||||
)
|
||||
job = LOOP.run(
|
||||
self._conn.create_materialized_view_async(
|
||||
name,
|
||||
@@ -875,6 +905,11 @@ class RemoteDBConnection(DBConnection):
|
||||
exist_ok=exist_ok,
|
||||
auto_refresh_enabled=auto_refresh_enabled,
|
||||
auto_refresh_interval_seconds=auto_refresh_interval_seconds,
|
||||
total_cpu_millis=total_cpu_millis,
|
||||
total_memory_bytes=total_memory_bytes,
|
||||
total_gpu_count=total_gpu_count,
|
||||
gpu_class=gpu_class,
|
||||
gpu_count=gpu_count,
|
||||
)
|
||||
)
|
||||
return Job(job)
|
||||
|
||||
@@ -1200,7 +1200,9 @@ class RemoteTable(Table):
|
||||
computed: Dict[str, str] | None = None,
|
||||
auto_refresh_enabled: bool | None = None,
|
||||
auto_refresh_interval_seconds: int | None = None,
|
||||
auto_refresh_resource_budget: Optional[Dict[str, int]] = None,
|
||||
total_cpu_millis: Optional[int] = None,
|
||||
total_memory_bytes: Optional[int] = None,
|
||||
total_gpu_count: Optional[int] = None,
|
||||
) -> AddColumnsResult:
|
||||
return LOOP.run(
|
||||
self._table.add_columns(
|
||||
@@ -1208,7 +1210,9 @@ class RemoteTable(Table):
|
||||
computed=computed,
|
||||
auto_refresh_enabled=auto_refresh_enabled,
|
||||
auto_refresh_interval_seconds=auto_refresh_interval_seconds,
|
||||
auto_refresh_resource_budget=auto_refresh_resource_budget,
|
||||
total_cpu_millis=total_cpu_millis,
|
||||
total_memory_bytes=total_memory_bytes,
|
||||
total_gpu_count=total_gpu_count,
|
||||
)
|
||||
)
|
||||
|
||||
@@ -1220,11 +1224,12 @@ class RemoteTable(Table):
|
||||
batch_size: Optional[int] = None,
|
||||
max_concurrency: Optional[int] = None,
|
||||
publication_interval_rows: Optional[int] = None,
|
||||
resource_budget: Optional[Dict[str, int]] = None,
|
||||
total_cpu_millis: Optional[int] = None,
|
||||
total_memory_bytes: Optional[int] = None,
|
||||
supervisor_resources: Optional[Dict[str, int]] = None,
|
||||
planning_workers: Optional[Dict[str, Any]] = None,
|
||||
gpu_class: Optional[str] = None,
|
||||
gpu_count: Optional[int] = None,
|
||||
total_gpu_count: Optional[int] = None,
|
||||
retry_policy: Optional[FunctionRetryPolicy] = None,
|
||||
error_policy: Optional[Literal["fail", "skip"]] = None,
|
||||
max_failed_fraction: Optional[float] = None,
|
||||
@@ -1247,11 +1252,12 @@ class RemoteTable(Table):
|
||||
batch_size=batch_size,
|
||||
max_concurrency=max_concurrency,
|
||||
publication_interval_rows=publication_interval_rows,
|
||||
resource_budget=resource_budget,
|
||||
total_cpu_millis=total_cpu_millis,
|
||||
total_memory_bytes=total_memory_bytes,
|
||||
supervisor_resources=supervisor_resources,
|
||||
planning_workers=planning_workers,
|
||||
gpu_class=gpu_class,
|
||||
gpu_count=gpu_count,
|
||||
total_gpu_count=total_gpu_count,
|
||||
retry_policy=retry_policy,
|
||||
error_policy=error_policy,
|
||||
max_failed_fraction=max_failed_fraction,
|
||||
@@ -1277,11 +1283,12 @@ class RemoteTable(Table):
|
||||
batch_size: Optional[int] = None,
|
||||
max_concurrency: Optional[int] = None,
|
||||
publication_interval_rows: Optional[int] = None,
|
||||
resource_budget: Optional[Dict[str, int]] = None,
|
||||
total_cpu_millis: Optional[int] = None,
|
||||
total_memory_bytes: Optional[int] = None,
|
||||
supervisor_resources: Optional[Dict[str, int]] = None,
|
||||
planning_workers: Optional[Dict[str, Any]] = None,
|
||||
gpu_class: Optional[str] = None,
|
||||
gpu_count: Optional[int] = None,
|
||||
total_gpu_count: Optional[int] = None,
|
||||
retry_policy: Optional[FunctionRetryPolicy] = None,
|
||||
error_policy: Optional[Literal["fail", "skip"]] = None,
|
||||
max_failed_fraction: Optional[float] = None,
|
||||
@@ -1305,11 +1312,12 @@ class RemoteTable(Table):
|
||||
batch_size=batch_size,
|
||||
max_concurrency=max_concurrency,
|
||||
publication_interval_rows=publication_interval_rows,
|
||||
resource_budget=resource_budget,
|
||||
total_cpu_millis=total_cpu_millis,
|
||||
total_memory_bytes=total_memory_bytes,
|
||||
supervisor_resources=supervisor_resources,
|
||||
planning_workers=planning_workers,
|
||||
gpu_class=gpu_class,
|
||||
gpu_count=gpu_count,
|
||||
total_gpu_count=total_gpu_count,
|
||||
retry_policy=retry_policy,
|
||||
error_policy=error_policy,
|
||||
max_failed_fraction=max_failed_fraction,
|
||||
|
||||
@@ -0,0 +1,48 @@
|
||||
# SPDX-License-Identifier: Apache-2.0
|
||||
# SPDX-FileCopyrightText: Copyright The LanceDB Authors
|
||||
|
||||
import re
|
||||
from typing import Any, Optional, Union
|
||||
|
||||
|
||||
def _validate_gpu_class_name(value: Any) -> str:
|
||||
if not isinstance(value, str) or not re.fullmatch(
|
||||
r"[a-z0-9](?:[a-z0-9-]{0,61}[a-z0-9])?", value
|
||||
):
|
||||
raise ValueError(
|
||||
"gpu_class must be a lowercase name of at most 63 letters, digits, or "
|
||||
"hyphens, and cannot start or end with a hyphen"
|
||||
)
|
||||
return value
|
||||
|
||||
|
||||
def _resource_options(
|
||||
cpu: Optional[int],
|
||||
memory: Optional[int],
|
||||
gpu: Optional[int],
|
||||
*,
|
||||
gpu_class: Optional[str] = None,
|
||||
gpu_count: Optional[int] = None,
|
||||
) -> dict[str, Union[int, str]]:
|
||||
result: dict[str, Union[int, str]] = {}
|
||||
for name, value, maximum, minimum in (
|
||||
("total_cpu_millis", cpu, 2**64 - 1, 1),
|
||||
("total_memory_bytes", memory, 2**64 - 1, 1),
|
||||
("total_gpu_count", gpu, 2**32 - 1, 0),
|
||||
("gpu_count", gpu_count, 2**32 - 1, 1),
|
||||
):
|
||||
if value is None:
|
||||
continue
|
||||
if isinstance(value, bool) or not isinstance(value, int):
|
||||
raise ValueError(f"{name} must be an integer")
|
||||
if not minimum <= value <= maximum:
|
||||
raise ValueError(f"{name} must be between {minimum} and {maximum}")
|
||||
result[name] = value
|
||||
if gpu_class is not None:
|
||||
result["gpu_class"] = _validate_gpu_class_name(gpu_class)
|
||||
if gpu is not None and (
|
||||
(gpu_count is not None and gpu_count > gpu)
|
||||
or (gpu_class is not None and gpu == 0)
|
||||
):
|
||||
raise ValueError("total_gpu_count cannot fit one Function worker")
|
||||
return result
|
||||
+153
-87
@@ -132,6 +132,7 @@ from .schema import (
|
||||
row_addressable_blob_v2_paths,
|
||||
schema_has_blob_field,
|
||||
)
|
||||
from .resources import _resource_options
|
||||
|
||||
|
||||
def _should_push_down_query_table(
|
||||
@@ -3456,7 +3457,11 @@ class Table(ABC):
|
||||
computed: Dict[str, str] | None = None,
|
||||
auto_refresh_enabled: bool | None = None,
|
||||
auto_refresh_interval_seconds: int | None = None,
|
||||
auto_refresh_resource_budget: Optional[Dict[str, int]] = None,
|
||||
total_cpu_millis: Optional[int] = None,
|
||||
total_memory_bytes: Optional[int] = None,
|
||||
total_gpu_count: Optional[int] = None,
|
||||
gpu_class: Optional[str] = None,
|
||||
gpu_count: Optional[int] = None,
|
||||
):
|
||||
"""
|
||||
Add new columns with defined values.
|
||||
@@ -3525,13 +3530,12 @@ class Table(ABC):
|
||||
When omitted, the server determines when to refresh. Applies to every
|
||||
computed output in this call.
|
||||
Scheduling options require computed or Function columns.
|
||||
auto_refresh_resource_budget: dict[str, int], optional
|
||||
Aggregate CPU, memory, and GPU budget for automatic refreshes of a
|
||||
registered Function declaration. ``cpu_millis`` and
|
||||
``memory_bytes`` are required; ``gpu_count`` defaults to zero.
|
||||
This option cannot be used with SQL-expression columns. LanceDB
|
||||
Enterprise only.
|
||||
|
||||
total_cpu_millis: int, optional
|
||||
Default total CPU budget for manual and automatic Function refreshes.
|
||||
total_memory_bytes: int, optional
|
||||
Default total memory budget for these refreshes, in bytes.
|
||||
total_gpu_count: int, optional
|
||||
Default total GPU budget across the Function workers.
|
||||
Returns
|
||||
-------
|
||||
AddColumnsResult
|
||||
@@ -3556,6 +3560,13 @@ class Table(ABC):
|
||||
>>> table.to_arrow()["score"].to_pylist()
|
||||
[0.25, 0.75]
|
||||
"""
|
||||
_resource_options(
|
||||
total_cpu_millis,
|
||||
total_memory_bytes,
|
||||
total_gpu_count,
|
||||
gpu_class=gpu_class,
|
||||
gpu_count=gpu_count,
|
||||
)
|
||||
|
||||
@abstractmethod
|
||||
def refresh_column(
|
||||
@@ -3566,11 +3577,13 @@ class Table(ABC):
|
||||
batch_size: Optional[int] = None,
|
||||
max_concurrency: Optional[int] = None,
|
||||
publication_interval_rows: Optional[int] = None,
|
||||
resource_budget: Optional[Dict[str, int]] = None,
|
||||
total_cpu_millis: Optional[int] = None,
|
||||
total_memory_bytes: Optional[int] = None,
|
||||
supervisor_resources: Optional[Dict[str, int]] = None,
|
||||
planning_workers: Optional[Dict[str, Any]] = None,
|
||||
gpu_class: Optional[str] = None,
|
||||
gpu_count: Optional[int] = None,
|
||||
total_gpu_count: Optional[int] = None,
|
||||
retry_policy: Optional[FunctionRetryPolicy] = None,
|
||||
error_policy: Optional[Literal["fail", "skip"]] = None,
|
||||
max_failed_fraction: Optional[float] = None,
|
||||
@@ -3625,13 +3638,10 @@ class Table(ABC):
|
||||
actual publication boundary can be larger than this threshold
|
||||
because it also depends on completed work and Function batching.
|
||||
LanceDB Enterprise only; local refreshes reject this option.
|
||||
resource_budget: dict[str, int], optional
|
||||
Aggregate resources for one registered Function refresh. The
|
||||
``cpu_millis`` and ``memory_bytes`` keys are required;
|
||||
``gpu_count`` is optional and defaults to zero, which requests a
|
||||
CPU-only budget. This budget cannot be combined with the top-level
|
||||
``gpu_count`` shorthand. LanceDB Enterprise only; local refreshes
|
||||
reject it.
|
||||
total_cpu_millis: int, optional
|
||||
Override the total CPU budget in millicores for this refresh.
|
||||
total_memory_bytes: int, optional
|
||||
Override the total memory budget in bytes for this refresh.
|
||||
supervisor_resources: dict[str, int], optional
|
||||
CPU, memory, and ephemeral-storage limits for the Function refresh
|
||||
supervisor pod. Keys are ``cpu_millis``, ``memory_bytes`` and
|
||||
@@ -3648,11 +3658,10 @@ class Table(ABC):
|
||||
letters, digits, or hyphens, without a leading or trailing hyphen.
|
||||
None keeps the Function's registered class or the deployment
|
||||
default. LanceDB Enterprise only.
|
||||
gpu_count: int, optional
|
||||
Positive aggregate GPU budget for Function workers without changing
|
||||
the deployment's CPU and memory defaults. None leaves the server's
|
||||
configured budget unchanged. For a complete CPU and memory budget,
|
||||
use ``resource_budget`` instead. LanceDB Enterprise only.
|
||||
total_gpu_count: int, optional
|
||||
Nonnegative total GPU budget for Function workers without changing
|
||||
the other resource limits. Unspecified resources inherit column defaults,
|
||||
then Function defaults, then deployment defaults. LanceDB Enterprise only.
|
||||
retry_policy: FunctionRetryPolicy, optional
|
||||
Override retries of failed user-code calls. Only use when repeating
|
||||
partial work is safe. Set max_attempts=1 to disable retries.
|
||||
@@ -3675,7 +3684,7 @@ class Table(ABC):
|
||||
Deadline for Function initialization. LanceDB Enterprise only.
|
||||
num_workers: int, optional
|
||||
Worker count for an expression column; registered Function
|
||||
columns reject it and use ``resource_budget`` instead. LanceDB
|
||||
columns reject it and set the corresponding ``total_*`` options. LanceDB
|
||||
Enterprise only.
|
||||
max_executor_processes_per_worker: int, optional
|
||||
Cap on executor processes per Function worker. LanceDB
|
||||
@@ -3714,11 +3723,13 @@ class Table(ABC):
|
||||
batch_size: Optional[int] = None,
|
||||
max_concurrency: Optional[int] = None,
|
||||
publication_interval_rows: Optional[int] = None,
|
||||
resource_budget: Optional[Dict[str, int]] = None,
|
||||
total_cpu_millis: Optional[int] = None,
|
||||
total_memory_bytes: Optional[int] = None,
|
||||
supervisor_resources: Optional[Dict[str, int]] = None,
|
||||
planning_workers: Optional[Dict[str, Any]] = None,
|
||||
gpu_class: Optional[str] = None,
|
||||
gpu_count: Optional[int] = None,
|
||||
total_gpu_count: Optional[int] = None,
|
||||
retry_policy: Optional[FunctionRetryPolicy] = None,
|
||||
error_policy: Optional[Literal["fail", "skip"]] = None,
|
||||
max_failed_fraction: Optional[float] = None,
|
||||
@@ -3772,13 +3783,10 @@ class Table(ABC):
|
||||
actual publication boundary can be larger than this threshold
|
||||
because it also depends on completed work and Function batching.
|
||||
LanceDB Enterprise only; local refreshes reject this option.
|
||||
resource_budget: dict[str, int], optional
|
||||
Aggregate resources for one registered Function refresh. The
|
||||
``cpu_millis`` and ``memory_bytes`` keys are required;
|
||||
``gpu_count`` is optional and defaults to zero, which requests a
|
||||
CPU-only budget. This budget cannot be combined with the top-level
|
||||
``gpu_count`` shorthand. LanceDB Enterprise only; local refreshes
|
||||
reject it.
|
||||
total_cpu_millis: int, optional
|
||||
Override the total CPU budget in millicores for this refresh.
|
||||
total_memory_bytes: int, optional
|
||||
Override the total memory budget in bytes for this refresh.
|
||||
supervisor_resources: dict[str, int], optional
|
||||
CPU, memory, and ephemeral-storage limits for the Function refresh
|
||||
supervisor pod. Keys are ``cpu_millis``, ``memory_bytes`` and
|
||||
@@ -3795,11 +3803,10 @@ class Table(ABC):
|
||||
letters, digits, or hyphens, without a leading or trailing hyphen.
|
||||
None keeps the Function's registered class or the deployment
|
||||
default. LanceDB Enterprise only.
|
||||
gpu_count: int, optional
|
||||
Positive aggregate GPU budget for Function workers without changing
|
||||
the deployment's CPU and memory defaults. None leaves the server's
|
||||
configured budget unchanged. For a complete CPU and memory budget,
|
||||
use ``resource_budget`` instead. LanceDB Enterprise only.
|
||||
total_gpu_count: int, optional
|
||||
Nonnegative total GPU budget for Function workers without changing
|
||||
the other resource limits. Unspecified resources inherit column defaults,
|
||||
then Function defaults, then deployment defaults. LanceDB Enterprise only.
|
||||
retry_policy: FunctionRetryPolicy, optional
|
||||
Override retries of failed user-code calls. Only use when repeating
|
||||
partial work is safe. Set max_attempts=1 to disable retries.
|
||||
@@ -3822,7 +3829,7 @@ class Table(ABC):
|
||||
Deadline for Function initialization. LanceDB Enterprise only.
|
||||
num_workers: int, optional
|
||||
Worker count for an expression column; registered Function
|
||||
columns reject it and use ``resource_budget`` instead. LanceDB
|
||||
columns reject it and set the corresponding ``total_*`` options. LanceDB
|
||||
Enterprise only.
|
||||
max_executor_processes_per_worker: int, optional
|
||||
Cap on executor processes per Function worker. LanceDB
|
||||
@@ -6485,15 +6492,30 @@ class LanceTable(Table):
|
||||
computed: Dict[str, str] | None = None,
|
||||
auto_refresh_enabled: bool | None = None,
|
||||
auto_refresh_interval_seconds: int | None = None,
|
||||
auto_refresh_resource_budget: Optional[Dict[str, int]] = None,
|
||||
total_cpu_millis: Optional[int] = None,
|
||||
total_memory_bytes: Optional[int] = None,
|
||||
total_gpu_count: Optional[int] = None,
|
||||
gpu_class: Optional[str] = None,
|
||||
gpu_count: Optional[int] = None,
|
||||
) -> AddColumnsResult:
|
||||
_resource_options(
|
||||
total_cpu_millis,
|
||||
total_memory_bytes,
|
||||
total_gpu_count,
|
||||
gpu_class=gpu_class,
|
||||
gpu_count=gpu_count,
|
||||
)
|
||||
return LOOP.run(
|
||||
self._table.add_columns(
|
||||
transforms,
|
||||
computed=computed,
|
||||
auto_refresh_enabled=auto_refresh_enabled,
|
||||
auto_refresh_interval_seconds=auto_refresh_interval_seconds,
|
||||
auto_refresh_resource_budget=auto_refresh_resource_budget,
|
||||
total_cpu_millis=total_cpu_millis,
|
||||
total_memory_bytes=total_memory_bytes,
|
||||
total_gpu_count=total_gpu_count,
|
||||
gpu_class=gpu_class,
|
||||
gpu_count=gpu_count,
|
||||
)
|
||||
)
|
||||
|
||||
@@ -6505,11 +6527,13 @@ class LanceTable(Table):
|
||||
batch_size: Optional[int] = None,
|
||||
max_concurrency: Optional[int] = None,
|
||||
publication_interval_rows: Optional[int] = None,
|
||||
resource_budget: Optional[Dict[str, int]] = None,
|
||||
total_cpu_millis: Optional[int] = None,
|
||||
total_memory_bytes: Optional[int] = None,
|
||||
supervisor_resources: Optional[Dict[str, int]] = None,
|
||||
planning_workers: Optional[Dict[str, Any]] = None,
|
||||
gpu_class: Optional[str] = None,
|
||||
gpu_count: Optional[int] = None,
|
||||
total_gpu_count: Optional[int] = None,
|
||||
retry_policy: Optional[FunctionRetryPolicy] = None,
|
||||
error_policy: Optional[Literal["fail", "skip"]] = None,
|
||||
max_failed_fraction: Optional[float] = None,
|
||||
@@ -6535,11 +6559,12 @@ class LanceTable(Table):
|
||||
batch_size=batch_size,
|
||||
max_concurrency=max_concurrency,
|
||||
publication_interval_rows=publication_interval_rows,
|
||||
resource_budget=resource_budget,
|
||||
total_cpu_millis=total_cpu_millis,
|
||||
total_memory_bytes=total_memory_bytes,
|
||||
supervisor_resources=supervisor_resources,
|
||||
planning_workers=planning_workers,
|
||||
gpu_class=gpu_class,
|
||||
gpu_count=gpu_count,
|
||||
total_gpu_count=total_gpu_count,
|
||||
retry_policy=retry_policy,
|
||||
error_policy=error_policy,
|
||||
max_failed_fraction=max_failed_fraction,
|
||||
@@ -6554,6 +6579,7 @@ class LanceTable(Table):
|
||||
include_quarantined=include_quarantined,
|
||||
function_version=function_version,
|
||||
recompute=recompute,
|
||||
gpu_count=gpu_count,
|
||||
)
|
||||
)
|
||||
|
||||
@@ -6565,11 +6591,13 @@ class LanceTable(Table):
|
||||
batch_size: Optional[int] = None,
|
||||
max_concurrency: Optional[int] = None,
|
||||
publication_interval_rows: Optional[int] = None,
|
||||
resource_budget: Optional[Dict[str, int]] = None,
|
||||
total_cpu_millis: Optional[int] = None,
|
||||
total_memory_bytes: Optional[int] = None,
|
||||
supervisor_resources: Optional[Dict[str, int]] = None,
|
||||
planning_workers: Optional[Dict[str, Any]] = None,
|
||||
gpu_class: Optional[str] = None,
|
||||
gpu_count: Optional[int] = None,
|
||||
total_gpu_count: Optional[int] = None,
|
||||
retry_policy: Optional[FunctionRetryPolicy] = None,
|
||||
error_policy: Optional[Literal["fail", "skip"]] = None,
|
||||
max_failed_fraction: Optional[float] = None,
|
||||
@@ -6597,11 +6625,12 @@ class LanceTable(Table):
|
||||
batch_size=batch_size,
|
||||
max_concurrency=max_concurrency,
|
||||
publication_interval_rows=publication_interval_rows,
|
||||
resource_budget=resource_budget,
|
||||
total_cpu_millis=total_cpu_millis,
|
||||
total_memory_bytes=total_memory_bytes,
|
||||
supervisor_resources=supervisor_resources,
|
||||
planning_workers=planning_workers,
|
||||
gpu_class=gpu_class,
|
||||
gpu_count=gpu_count,
|
||||
total_gpu_count=total_gpu_count,
|
||||
retry_policy=retry_policy,
|
||||
error_policy=error_policy,
|
||||
max_failed_fraction=max_failed_fraction,
|
||||
@@ -6616,6 +6645,7 @@ class LanceTable(Table):
|
||||
include_quarantined=include_quarantined,
|
||||
function_version=function_version,
|
||||
recompute=recompute,
|
||||
gpu_count=gpu_count,
|
||||
)
|
||||
)
|
||||
)
|
||||
@@ -9033,7 +9063,11 @@ class AsyncTable:
|
||||
computed: dict[str, str] | None = None,
|
||||
auto_refresh_enabled: bool | None = None,
|
||||
auto_refresh_interval_seconds: int | None = None,
|
||||
auto_refresh_resource_budget: Optional[Dict[str, int]] = None,
|
||||
total_cpu_millis: Optional[int] = None,
|
||||
total_memory_bytes: Optional[int] = None,
|
||||
total_gpu_count: Optional[int] = None,
|
||||
gpu_class: Optional[str] = None,
|
||||
gpu_count: Optional[int] = None,
|
||||
) -> AddColumnsResult:
|
||||
"""
|
||||
Add new columns with defined values.
|
||||
@@ -9100,13 +9134,12 @@ class AsyncTable:
|
||||
not force recomputation. Applies to every declared computed output.
|
||||
These options cannot be used with one-time transforms or ordinary
|
||||
all-null columns.
|
||||
auto_refresh_resource_budget: dict[str, int], optional
|
||||
Aggregate CPU, memory, and GPU budget for automatic refreshes of
|
||||
registered Function outputs. ``cpu_millis`` and ``memory_bytes``
|
||||
are required; ``gpu_count`` defaults to zero. SQL-expression
|
||||
columns do not use Function workers and reject this option.
|
||||
LanceDB Enterprise only.
|
||||
|
||||
total_cpu_millis: int, optional
|
||||
Default total CPU budget for manual and automatic Function refreshes.
|
||||
total_memory_bytes: int, optional
|
||||
Default total memory budget for these refreshes, in bytes.
|
||||
total_gpu_count: int, optional
|
||||
Default total GPU budget across the Function workers.
|
||||
Examples
|
||||
--------
|
||||
>>> await table.add_columns( # doctest: +SKIP
|
||||
@@ -9121,6 +9154,13 @@ class AsyncTable:
|
||||
version: the new version number of the table after adding columns.
|
||||
|
||||
"""
|
||||
_resource_options(
|
||||
total_cpu_millis,
|
||||
total_memory_bytes,
|
||||
total_gpu_count,
|
||||
gpu_class=gpu_class,
|
||||
gpu_count=gpu_count,
|
||||
)
|
||||
if auto_refresh_enabled is not None and type(auto_refresh_enabled) is not bool:
|
||||
raise ValueError("auto_refresh_enabled must be a boolean")
|
||||
if auto_refresh_interval_seconds is not None and (
|
||||
@@ -9134,7 +9174,11 @@ class AsyncTable:
|
||||
options_supplied = (
|
||||
auto_refresh_enabled is not None
|
||||
or auto_refresh_interval_seconds is not None
|
||||
or auto_refresh_resource_budget is not None
|
||||
or total_cpu_millis is not None
|
||||
or total_memory_bytes is not None
|
||||
or total_gpu_count is not None
|
||||
or gpu_class is not None
|
||||
or gpu_count is not None
|
||||
)
|
||||
function_application = None
|
||||
function_output_name = None
|
||||
@@ -9163,7 +9207,11 @@ class AsyncTable:
|
||||
function_output_name,
|
||||
auto_refresh_enabled,
|
||||
auto_refresh_interval_seconds,
|
||||
auto_refresh_resource_budget,
|
||||
total_cpu_millis,
|
||||
total_memory_bytes,
|
||||
total_gpu_count,
|
||||
gpu_class,
|
||||
gpu_count,
|
||||
)
|
||||
|
||||
if isinstance(transforms, pa.Field):
|
||||
@@ -9184,7 +9232,11 @@ class AsyncTable:
|
||||
list(computed.items()),
|
||||
auto_refresh_enabled,
|
||||
auto_refresh_interval_seconds,
|
||||
auto_refresh_resource_budget,
|
||||
total_cpu_millis,
|
||||
total_memory_bytes,
|
||||
total_gpu_count,
|
||||
gpu_class,
|
||||
gpu_count,
|
||||
)
|
||||
if options_supplied:
|
||||
raise ValueError(
|
||||
@@ -9208,11 +9260,13 @@ class AsyncTable:
|
||||
batch_size: Optional[int] = None,
|
||||
max_concurrency: Optional[int] = None,
|
||||
publication_interval_rows: Optional[int] = None,
|
||||
resource_budget: Optional[Dict[str, int]] = None,
|
||||
total_cpu_millis: Optional[int] = None,
|
||||
total_memory_bytes: Optional[int] = None,
|
||||
supervisor_resources: Optional[Dict[str, int]] = None,
|
||||
planning_workers: Optional[Dict[str, Any]] = None,
|
||||
gpu_class: Optional[str] = None,
|
||||
gpu_count: Optional[int] = None,
|
||||
total_gpu_count: Optional[int] = None,
|
||||
retry_policy: Optional[FunctionRetryPolicy] = None,
|
||||
error_policy: Optional[Literal["fail", "skip"]] = None,
|
||||
max_failed_fraction: Optional[float] = None,
|
||||
@@ -9267,13 +9321,10 @@ class AsyncTable:
|
||||
actual publication boundary can be larger than this threshold
|
||||
because it also depends on completed work and Function batching.
|
||||
LanceDB Enterprise only; local refreshes reject this option.
|
||||
resource_budget: dict[str, int], optional
|
||||
Aggregate resources for one registered Function refresh. The
|
||||
``cpu_millis`` and ``memory_bytes`` keys are required;
|
||||
``gpu_count`` is optional and defaults to zero, which requests a
|
||||
CPU-only budget. This budget cannot be combined with the top-level
|
||||
``gpu_count`` shorthand. LanceDB Enterprise only; local refreshes
|
||||
reject it.
|
||||
total_cpu_millis: int, optional
|
||||
Override the total CPU budget in millicores for this refresh.
|
||||
total_memory_bytes: int, optional
|
||||
Override the total memory budget in bytes for this refresh.
|
||||
supervisor_resources: dict[str, int], optional
|
||||
CPU, memory, and ephemeral-storage limits for the Function refresh
|
||||
supervisor pod. Keys are ``cpu_millis``, ``memory_bytes`` and
|
||||
@@ -9290,11 +9341,10 @@ class AsyncTable:
|
||||
letters, digits, or hyphens, without a leading or trailing hyphen.
|
||||
None keeps the Function's registered class or the deployment
|
||||
default. LanceDB Enterprise only.
|
||||
gpu_count: int, optional
|
||||
Positive aggregate GPU budget for Function workers without changing
|
||||
the deployment's CPU and memory defaults. None leaves the server's
|
||||
configured budget unchanged. For a complete CPU and memory budget,
|
||||
use ``resource_budget`` instead. LanceDB Enterprise only.
|
||||
total_gpu_count: int, optional
|
||||
Nonnegative total GPU budget for Function workers without changing
|
||||
the other resource limits. Unspecified resources inherit column defaults,
|
||||
then Function defaults, then deployment defaults. LanceDB Enterprise only.
|
||||
retry_policy: FunctionRetryPolicy, optional
|
||||
Override retries of failed user-code calls. Only use when repeating
|
||||
partial work is safe. Set max_attempts=1 to disable retries.
|
||||
@@ -9317,7 +9367,7 @@ class AsyncTable:
|
||||
Deadline for Function initialization. LanceDB Enterprise only.
|
||||
num_workers: int, optional
|
||||
Worker count for an expression column; registered Function
|
||||
columns reject it and use ``resource_budget`` instead. LanceDB
|
||||
columns reject it and set the corresponding ``total_*`` options. LanceDB
|
||||
Enterprise only.
|
||||
max_executor_processes_per_worker: int, optional
|
||||
Cap on executor processes per Function worker. LanceDB
|
||||
@@ -9345,17 +9395,25 @@ class AsyncTable:
|
||||
RefreshColumnResult
|
||||
The number of rows filled and the new version of the table.
|
||||
"""
|
||||
_resource_options(
|
||||
total_cpu_millis,
|
||||
total_memory_bytes,
|
||||
total_gpu_count,
|
||||
gpu_class=gpu_class,
|
||||
gpu_count=gpu_count,
|
||||
)
|
||||
return await self._inner.refresh_column(
|
||||
column,
|
||||
where=where,
|
||||
batch_size=batch_size,
|
||||
max_concurrency=max_concurrency,
|
||||
publication_interval_rows=publication_interval_rows,
|
||||
resource_budget=resource_budget,
|
||||
total_cpu_millis=total_cpu_millis,
|
||||
total_memory_bytes=total_memory_bytes,
|
||||
supervisor_resources=supervisor_resources,
|
||||
planning_workers=planning_workers,
|
||||
gpu_class=gpu_class,
|
||||
gpu_count=gpu_count,
|
||||
total_gpu_count=total_gpu_count,
|
||||
retry_policy=None
|
||||
if retry_policy is None
|
||||
else FunctionRetryPolicy.model_validate(retry_policy).model_dump_json(),
|
||||
@@ -9372,6 +9430,7 @@ class AsyncTable:
|
||||
include_quarantined=include_quarantined,
|
||||
function_version=function_version,
|
||||
recompute=recompute,
|
||||
gpu_count=gpu_count,
|
||||
)
|
||||
|
||||
async def retry_failed(
|
||||
@@ -9579,11 +9638,13 @@ class AsyncTable:
|
||||
batch_size: Optional[int] = None,
|
||||
max_concurrency: Optional[int] = None,
|
||||
publication_interval_rows: Optional[int] = None,
|
||||
resource_budget: Optional[Dict[str, int]] = None,
|
||||
total_cpu_millis: Optional[int] = None,
|
||||
total_memory_bytes: Optional[int] = None,
|
||||
supervisor_resources: Optional[Dict[str, int]] = None,
|
||||
planning_workers: Optional[Dict[str, Any]] = None,
|
||||
gpu_class: Optional[str] = None,
|
||||
gpu_count: Optional[int] = None,
|
||||
total_gpu_count: Optional[int] = None,
|
||||
retry_policy: Optional[FunctionRetryPolicy] = None,
|
||||
error_policy: Optional[Literal["fail", "skip"]] = None,
|
||||
max_failed_fraction: Optional[float] = None,
|
||||
@@ -9637,13 +9698,10 @@ class AsyncTable:
|
||||
actual publication boundary can be larger than this threshold
|
||||
because it also depends on completed work and Function batching.
|
||||
LanceDB Enterprise only; local refreshes reject this option.
|
||||
resource_budget: dict[str, int], optional
|
||||
Aggregate resources for one registered Function refresh. The
|
||||
``cpu_millis`` and ``memory_bytes`` keys are required;
|
||||
``gpu_count`` is optional and defaults to zero, which requests a
|
||||
CPU-only budget. This budget cannot be combined with the top-level
|
||||
``gpu_count`` shorthand. LanceDB Enterprise only; local refreshes
|
||||
reject it.
|
||||
total_cpu_millis: int, optional
|
||||
Override the total CPU budget in millicores for this refresh.
|
||||
total_memory_bytes: int, optional
|
||||
Override the total memory budget in bytes for this refresh.
|
||||
supervisor_resources: dict[str, int], optional
|
||||
CPU, memory, and ephemeral-storage limits for the Function refresh
|
||||
supervisor pod. Keys are ``cpu_millis``, ``memory_bytes`` and
|
||||
@@ -9660,11 +9718,10 @@ class AsyncTable:
|
||||
letters, digits, or hyphens, without a leading or trailing hyphen.
|
||||
None keeps the Function's registered class or the deployment
|
||||
default. LanceDB Enterprise only.
|
||||
gpu_count: int, optional
|
||||
Positive aggregate GPU budget for Function workers without changing
|
||||
the deployment's CPU and memory defaults. None leaves the server's
|
||||
configured budget unchanged. For a complete CPU and memory budget,
|
||||
use ``resource_budget`` instead. LanceDB Enterprise only.
|
||||
total_gpu_count: int, optional
|
||||
Nonnegative total GPU budget for Function workers without changing
|
||||
the other resource limits. Unspecified resources inherit column defaults,
|
||||
then Function defaults, then deployment defaults. LanceDB Enterprise only.
|
||||
retry_policy: FunctionRetryPolicy, optional
|
||||
Override retries of failed user-code calls. Only use when repeating
|
||||
partial work is safe. Set max_attempts=1 to disable retries.
|
||||
@@ -9687,7 +9744,7 @@ class AsyncTable:
|
||||
Deadline for Function initialization. LanceDB Enterprise only.
|
||||
num_workers: int, optional
|
||||
Worker count for an expression column; registered Function
|
||||
columns reject it and use ``resource_budget`` instead. LanceDB
|
||||
columns reject it and set the corresponding ``total_*`` options. LanceDB
|
||||
Enterprise only.
|
||||
max_executor_processes_per_worker: int, optional
|
||||
Cap on executor processes per Function worker. LanceDB
|
||||
@@ -9731,6 +9788,13 @@ class AsyncTable:
|
||||
>>> asyncio.run(refresh_in_background()) # doctest: +SKIP
|
||||
'finished'
|
||||
"""
|
||||
_resource_options(
|
||||
total_cpu_millis,
|
||||
total_memory_bytes,
|
||||
total_gpu_count,
|
||||
gpu_class=gpu_class,
|
||||
gpu_count=gpu_count,
|
||||
)
|
||||
return _typed_job(
|
||||
await self._inner.refresh_column_async(
|
||||
column,
|
||||
@@ -9738,11 +9802,12 @@ class AsyncTable:
|
||||
batch_size=batch_size,
|
||||
max_concurrency=max_concurrency,
|
||||
publication_interval_rows=publication_interval_rows,
|
||||
resource_budget=resource_budget,
|
||||
total_cpu_millis=total_cpu_millis,
|
||||
total_memory_bytes=total_memory_bytes,
|
||||
supervisor_resources=supervisor_resources,
|
||||
planning_workers=planning_workers,
|
||||
gpu_class=gpu_class,
|
||||
gpu_count=gpu_count,
|
||||
total_gpu_count=total_gpu_count,
|
||||
retry_policy=None
|
||||
if retry_policy is None
|
||||
else FunctionRetryPolicy.model_validate(retry_policy).model_dump_json(),
|
||||
@@ -9759,6 +9824,7 @@ class AsyncTable:
|
||||
include_quarantined=include_quarantined,
|
||||
function_version=function_version,
|
||||
recompute=recompute,
|
||||
gpu_count=gpu_count,
|
||||
),
|
||||
RefreshColumnJobResult.from_json,
|
||||
)
|
||||
|
||||
@@ -22,6 +22,7 @@ from lancedb.functions import (
|
||||
SecretReference,
|
||||
)
|
||||
from lancedb.table import AsyncTable
|
||||
from lancedb.resources import _resource_options
|
||||
|
||||
|
||||
FIXTURES = (
|
||||
@@ -614,7 +615,11 @@ class _FunctionDeclarationInner:
|
||||
output_name,
|
||||
auto_refresh_enabled,
|
||||
auto_refresh_interval_seconds,
|
||||
auto_refresh_resource_budget,
|
||||
total_cpu_millis,
|
||||
total_memory_bytes,
|
||||
total_gpu_count,
|
||||
gpu_class=None,
|
||||
gpu_count=None,
|
||||
):
|
||||
self.calls.append(
|
||||
(
|
||||
@@ -622,7 +627,9 @@ class _FunctionDeclarationInner:
|
||||
output_name,
|
||||
auto_refresh_enabled,
|
||||
auto_refresh_interval_seconds,
|
||||
auto_refresh_resource_budget,
|
||||
total_cpu_millis,
|
||||
total_memory_bytes,
|
||||
total_gpu_count,
|
||||
)
|
||||
)
|
||||
return "declared"
|
||||
@@ -648,18 +655,22 @@ async def test_add_columns_routes_struct_as_one_and_multi_output_binding_atomica
|
||||
)
|
||||
assert result == "declared"
|
||||
assert inner.calls[-1][1] == "features"
|
||||
assert inner.calls[-1][2:] == (None, None, None)
|
||||
assert inner.calls[-1][2:] == (None, None, None, None, None)
|
||||
|
||||
bare = application._copy(update={"columns": {}}).rename(
|
||||
columns={"normalized_text": "search_text"}
|
||||
)
|
||||
result = await table.add_columns(
|
||||
bare, auto_refresh_enabled=False, auto_refresh_interval_seconds=300
|
||||
bare,
|
||||
auto_refresh_enabled=False,
|
||||
auto_refresh_interval_seconds=300,
|
||||
total_cpu_millis=8000,
|
||||
total_gpu_count=0,
|
||||
)
|
||||
assert result == "declared"
|
||||
assert inner.calls[-1][1] is None
|
||||
assert inner.calls[-1][0]["columns"] == {"normalized_text": "search_text"}
|
||||
assert inner.calls[-1][2:] == (False, 300, None)
|
||||
assert inner.calls[-1][2:] == (False, 300, 8000, None, 0)
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
@@ -715,3 +726,20 @@ def test_rename_requires_named_struct_and_keeps_partial_mapping_immutable():
|
||||
renamed = application.rename(columns={"normalized_text": "search_text"})
|
||||
assert dict(application.columns) == {}
|
||||
assert dict(renamed.columns) == {"normalized_text": "search_text"}
|
||||
|
||||
|
||||
@pytest.mark.parametrize("gpu_count", [0, -1, True, 1.5, 2**32])
|
||||
def test_gpu_worker_count_rejects_invalid_values(gpu_count):
|
||||
with pytest.raises(ValueError, match="gpu_count"):
|
||||
_resource_options(None, None, None, gpu_count=gpu_count)
|
||||
|
||||
|
||||
def test_gpu_worker_settings_are_separate_from_execution_totals():
|
||||
assert _resource_options(8000, None, 8, gpu_class="any", gpu_count=2) == {
|
||||
"total_cpu_millis": 8000,
|
||||
"total_gpu_count": 8,
|
||||
"gpu_class": "any",
|
||||
"gpu_count": 2,
|
||||
}
|
||||
with pytest.raises(ValueError, match="cannot fit"):
|
||||
_resource_options(None, None, 1, gpu_count=2)
|
||||
|
||||
@@ -833,7 +833,7 @@ def test_function_image_requires_digest_reference(image):
|
||||
def test_function_gpu_marker_uses_gpu_runtime():
|
||||
with pytest.warns(UserWarning, match="uses a scalar callable"):
|
||||
|
||||
@function(pip=["cupy-cuda12x"], gpu=True, gpu_class="a10g")
|
||||
@function(pip=["cupy-cuda12x"], gpu=True, gpu_class="a10g", gpu_count=2)
|
||||
def double_on_gpu(value: int) -> int:
|
||||
return value * 2
|
||||
|
||||
@@ -841,6 +841,7 @@ def test_function_gpu_marker_uses_gpu_runtime():
|
||||
assert request["runtime"]["kind"] == "python_v2"
|
||||
assert request["runtime"]["gpu"] is True
|
||||
assert request["runtime"]["gpu_class"] == "a10g"
|
||||
assert request["runtime"]["gpus_per_worker"] == 2
|
||||
|
||||
@function(pip=["pyarrow"])
|
||||
def cpu_function(value: int) -> int:
|
||||
@@ -856,14 +857,29 @@ def test_function_gpu_marker_uses_gpu_runtime():
|
||||
def identity(value: int) -> int:
|
||||
return value
|
||||
|
||||
for invalid in [None, 0, 1, -1, 1.5, "", "true", "1", "H100"]:
|
||||
with pytest.raises(ValueError, match="gpu must be a boolean"):
|
||||
for invalid in [
|
||||
0,
|
||||
1,
|
||||
-1,
|
||||
1.5,
|
||||
"",
|
||||
"true",
|
||||
"1",
|
||||
"a_b",
|
||||
"-a10g",
|
||||
"a10g-",
|
||||
"a" * 64,
|
||||
]:
|
||||
with pytest.raises(ValueError, match="gpu"):
|
||||
function(name="invalid_gpu", gpu=invalid)(identity)
|
||||
for invalid in ["H100", "a_b", "-a10g", "a10g-", "a" * 64]:
|
||||
for enabled in (None, False):
|
||||
for options in ({"gpu_class": "h100"}, {"gpu_count": 2}):
|
||||
with pytest.raises(ValueError, match="require gpu=True"):
|
||||
function(gpu=enabled, **options)(identity)
|
||||
for invalid_class in ("H100", "a_b", "-h100", "h100-", "", "a" * 64):
|
||||
with pytest.raises(ValueError, match="gpu_class"):
|
||||
function(name="invalid_gpu_class", gpu=True, gpu_class=invalid)(identity)
|
||||
with pytest.raises(ValueError, match="requires gpu=True"):
|
||||
function(name="gpu_class_without_gpu", gpu_class="a10g")(identity)
|
||||
function(gpu=True, gpu_class=invalid_class)(identity)
|
||||
assert function(gpu=False)(identity).registration_request.runtime.gpu is None
|
||||
|
||||
base_runtime = {
|
||||
"kind": "python_v2",
|
||||
@@ -895,6 +911,66 @@ class _GpuArrayFunction:
|
||||
return value
|
||||
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
"name, count", [(None, 1), ("h100", 2), ("a10g", 4), ("any", 2)]
|
||||
)
|
||||
def test_gpu_count_is_part_of_runtime_identity(name, count):
|
||||
with pytest.warns(UserWarning):
|
||||
definition = function(gpu=True, gpu_class=name, gpu_count=count)(
|
||||
normalize_score.__wrapped__
|
||||
)
|
||||
runtime = definition.registration_request.runtime
|
||||
assert runtime.gpu is True
|
||||
assert runtime.gpu_class == name
|
||||
assert runtime.gpus_per_worker == count
|
||||
encoded = definition.registration_request.to_canonical_json()
|
||||
assert json.loads(encoded)["runtime"]["gpus_per_worker"] == count
|
||||
different = runtime._copy(update={"gpus_per_worker": count + 1})
|
||||
assert runtime.digest != different.digest
|
||||
|
||||
|
||||
@pytest.mark.parametrize("count", [0, -1, True, 1.5, "2", 2**32])
|
||||
def test_gpu_annotation_rejects_invalid_counts(count):
|
||||
with pytest.raises(ValueError, match="gpu_count"):
|
||||
function(gpu=True, gpu_count=count)(normalize_score.__wrapped__)
|
||||
|
||||
|
||||
@pytest.mark.parametrize("count", [0, -1, True, 1.5, "2", 2**32])
|
||||
def test_gpu_wire_count_is_a_strict_positive_uint32(count):
|
||||
with pytest.raises(ValueError):
|
||||
PythonRuntimeSpec.model_validate(
|
||||
{
|
||||
"kind": "python_v2",
|
||||
"python_version": "3.12",
|
||||
"environment": {"kind": "pip"},
|
||||
"gpu": True,
|
||||
"gpus_per_worker": count,
|
||||
}
|
||||
)
|
||||
|
||||
|
||||
def test_function_annotation_carries_independent_total_defaults():
|
||||
definition = function(
|
||||
total_cpu_millis=8000,
|
||||
total_memory_bytes=16 * 1024**3,
|
||||
total_gpu_count=0,
|
||||
)(normalize_score.__wrapped__)
|
||||
request = json.loads(definition.registration_request.to_canonical_json())
|
||||
assert request["total_cpu_millis"] == 8000
|
||||
assert request["total_memory_bytes"] == 16 * 1024**3
|
||||
assert request["total_gpu_count"] == 0
|
||||
assert "gpu" not in request["runtime"]
|
||||
for values in (
|
||||
{"total_cpu_millis": 0},
|
||||
{"total_memory_bytes": True},
|
||||
{"total_memory_bytes": 2**64},
|
||||
{"total_gpu_count": -1},
|
||||
{"total_gpu_count": 2**32},
|
||||
):
|
||||
with pytest.raises(ValueError):
|
||||
function(**values)(normalize_score.__wrapped__)
|
||||
|
||||
|
||||
def test_gpu_scalar_warning_names_the_vectorized_alternative():
|
||||
with pytest.warns(UserWarning, match="model batch is not inferred"):
|
||||
|
||||
|
||||
@@ -68,8 +68,12 @@ def mock_remote_materialized_view_refresh():
|
||||
"resources",
|
||||
[
|
||||
{},
|
||||
{"gpu_count": 2, "gpu_class": "h100"},
|
||||
{"cpu_millis": 8000, "memory_bytes": 16 * 1024**3, "gpu_count": 0},
|
||||
{"total_gpu_count": 2, "gpu_class": "h100"},
|
||||
{
|
||||
"total_cpu_millis": 8000,
|
||||
"total_memory_bytes": 16 * 1024**3,
|
||||
"total_gpu_count": 0,
|
||||
},
|
||||
],
|
||||
)
|
||||
async def test_remote_refresh_reports_unknown_metrics(
|
||||
@@ -159,13 +163,12 @@ async def test_remote_refresh_reports_unknown_metrics(
|
||||
assert expected.encode() in refresh
|
||||
previous = len(server.commands)
|
||||
for invalid in [
|
||||
{"cpu_millis": 0},
|
||||
{"memory_bytes": 1},
|
||||
{"gpu_count": -1},
|
||||
{"gpu_count": True},
|
||||
{"gpu_count": 2**32},
|
||||
{"total_cpu_millis": 0},
|
||||
{"total_gpu_count": -1},
|
||||
{"total_gpu_count": True},
|
||||
{"total_gpu_count": 2**32},
|
||||
{"gpu_class": "H200:8"},
|
||||
{"gpu_count": 0, "gpu_class": "h100"},
|
||||
{"total_gpu_count": 0, "gpu_class": "h100"},
|
||||
]:
|
||||
with pytest.raises(ValueError):
|
||||
if sync:
|
||||
@@ -200,6 +203,11 @@ def test_sync_remote_create_uses_public_async_connection(query):
|
||||
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,
|
||||
):
|
||||
calls.append(
|
||||
(
|
||||
@@ -709,6 +717,11 @@ class CapturingCreateConnection:
|
||||
{},
|
||||
{"auto_refresh_enabled": True},
|
||||
{"auto_refresh_enabled": False, "auto_refresh_interval_seconds": 0.5},
|
||||
{"total_cpu_millis": 8000, "total_gpu_count": 0},
|
||||
{"total_memory_bytes": 16 * 1024**3},
|
||||
{"gpu_class": "any"},
|
||||
{"gpu_count": 2},
|
||||
{"gpu_class": "h100", "gpu_count": 2, "total_gpu_count": 4},
|
||||
],
|
||||
)
|
||||
def test_remote_create_forwards_refresh_options_without_interval_default(options):
|
||||
@@ -731,6 +744,11 @@ def test_remote_create_forwards_refresh_options_without_interval_default(options
|
||||
"limit": None,
|
||||
"with_no_data": False,
|
||||
"exist_ok": False,
|
||||
"total_cpu_millis": options.get("total_cpu_millis"),
|
||||
"total_memory_bytes": options.get("total_memory_bytes"),
|
||||
"total_gpu_count": options.get("total_gpu_count"),
|
||||
"gpu_class": options.get("gpu_class"),
|
||||
"gpu_count": options.get("gpu_count"),
|
||||
"auto_refresh_enabled": options.get("auto_refresh_enabled"),
|
||||
"auto_refresh_interval_seconds": options.get(
|
||||
"auto_refresh_interval_seconds"
|
||||
@@ -783,18 +801,34 @@ def test_remote_create_rejects_invalid_interval_without_request(seconds):
|
||||
|
||||
|
||||
@pytest.mark.experimental_functions
|
||||
def test_namespace_forwards_automatic_refresh_request(tmp_path):
|
||||
@pytest.mark.parametrize(
|
||||
"options",
|
||||
[
|
||||
{"auto_refresh_enabled": True},
|
||||
{"total_cpu_millis": 8000, "total_gpu_count": 0},
|
||||
{"total_memory_bytes": 1024},
|
||||
],
|
||||
)
|
||||
def test_namespace_forwards_automatic_refresh_request(tmp_path, options):
|
||||
db = lancedb.connect_namespace("dir", {"root": str(tmp_path)})
|
||||
with pytest.raises(NotImplementedError, match="requires LanceDB Enterprise"):
|
||||
db.create_materialized_view("mv", "source", auto_refresh_enabled=True)
|
||||
db.create_materialized_view("mv", "source", **options)
|
||||
|
||||
|
||||
@pytest.mark.experimental_functions
|
||||
@pytest.mark.asyncio
|
||||
async def test_async_namespace_forwards_automatic_refresh_request(tmp_path):
|
||||
@pytest.mark.parametrize(
|
||||
"options",
|
||||
[
|
||||
{"auto_refresh_enabled": True},
|
||||
{"total_cpu_millis": 8000, "total_gpu_count": 0},
|
||||
{"total_memory_bytes": 1024},
|
||||
],
|
||||
)
|
||||
async def test_async_namespace_forwards_automatic_refresh_request(tmp_path, options):
|
||||
db = lancedb.connect_namespace_async("dir", {"root": str(tmp_path)})
|
||||
with pytest.raises(NotImplementedError, match="requires LanceDB Enterprise"):
|
||||
await db.create_materialized_view("mv", "source", auto_refresh_enabled=True)
|
||||
await db.create_materialized_view("mv", "source", **options)
|
||||
|
||||
|
||||
@pytest.mark.experimental_functions
|
||||
|
||||
@@ -2354,13 +2354,11 @@ def test_remote_create_index_async_returns_job():
|
||||
{"batch_size": 8},
|
||||
{"max_concurrency": 3},
|
||||
{"publication_interval_rows": 60},
|
||||
{"resource_budget": {"cpu_millis": 2000, "memory_bytes": 4 * 1024**3}},
|
||||
{"total_cpu_millis": 2000, "total_memory_bytes": 4 * 1024**3},
|
||||
{
|
||||
"resource_budget": {
|
||||
"cpu_millis": 8000,
|
||||
"memory_bytes": 16 * 1024**3,
|
||||
"gpu_count": 2,
|
||||
}
|
||||
"total_cpu_millis": 8000,
|
||||
"total_memory_bytes": 16 * 1024**3,
|
||||
"total_gpu_count": 2,
|
||||
},
|
||||
{
|
||||
"supervisor_resources": {
|
||||
@@ -2379,7 +2377,7 @@ def test_remote_create_index_async_returns_job():
|
||||
"fragments_per_worker": 8,
|
||||
},
|
||||
},
|
||||
{"gpu_class": "a10g", "gpu_count": 2},
|
||||
{"gpu_class": "a10g", "total_gpu_count": 2},
|
||||
{
|
||||
"retry_policy": {"transient": True, "max_attempts": 3},
|
||||
"error_policy": "skip",
|
||||
@@ -2417,14 +2415,11 @@ async def test_remote_refresh_async_returns_typed_terminal_result(
|
||||
expected["batch_size"] = refresh_kwargs["batch_size"]
|
||||
if refresh_kwargs.get("gpu_class") is not None:
|
||||
expected["gpu_class"] = refresh_kwargs["gpu_class"]
|
||||
if refresh_kwargs.get("gpu_count") is not None:
|
||||
expected["gpu_count"] = refresh_kwargs["gpu_count"]
|
||||
if refresh_kwargs.get("resource_budget") is not None:
|
||||
budget = refresh_kwargs["resource_budget"]
|
||||
expected["resource_budget"] = {
|
||||
**budget,
|
||||
"gpu_count": budget.get("gpu_count", 0),
|
||||
}
|
||||
if refresh_kwargs.get("total_gpu_count") is not None:
|
||||
expected["total_gpu_count"] = refresh_kwargs["total_gpu_count"]
|
||||
for key in ("total_cpu_millis", "total_memory_bytes"):
|
||||
if refresh_kwargs.get(key) is not None:
|
||||
expected[key] = refresh_kwargs[key]
|
||||
for key in ("supervisor_resources", "planning_workers"):
|
||||
if refresh_kwargs.get(key) is not None:
|
||||
expected[key] = refresh_kwargs[key]
|
||||
@@ -2606,8 +2601,7 @@ def test_remote_refresh_async_forwards_progress_from_submitted_handle():
|
||||
({"gpu_class": "H100"}, "gpu_class"),
|
||||
({"gpu_class": "-a10g"}, "gpu_class"),
|
||||
({"gpu_class": "a_b"}, "gpu_class"),
|
||||
({"gpu_count": 0}, "gpu_count"),
|
||||
({"gpu_count": -1}, "gpu_count"),
|
||||
({"total_gpu_count": -1}, "total_gpu_count"),
|
||||
({"retry_policy": {"transient": True, "max_attempts": 0}}, "retry_policy"),
|
||||
({"error_policy": "retry"}, "error_policy"),
|
||||
({"where": " "}, "where"),
|
||||
@@ -2624,37 +2618,8 @@ def test_remote_refresh_async_forwards_progress_from_submitted_handle():
|
||||
({"max_concurrency": 2**32}, "max_concurrency"),
|
||||
({"num_workers": 0}, "num_workers"),
|
||||
(
|
||||
{"resource_budget": {"cpu_millis": 1000}},
|
||||
"resource_budget.memory_bytes",
|
||||
),
|
||||
(
|
||||
{
|
||||
"resource_budget": {
|
||||
"cpu_millis": 0,
|
||||
"memory_bytes": 1,
|
||||
}
|
||||
},
|
||||
"resource_budget.cpu_millis",
|
||||
),
|
||||
(
|
||||
{
|
||||
"resource_budget": {
|
||||
"cpu_millis": 1000,
|
||||
"memory_bytes": 1,
|
||||
},
|
||||
"gpu_count": 1,
|
||||
},
|
||||
"gpu_count cannot be combined with resource_budget",
|
||||
),
|
||||
(
|
||||
{
|
||||
"resource_budget": {
|
||||
"cpu_millis": 1000,
|
||||
"memory_bytes": 1,
|
||||
"unknown": 1,
|
||||
}
|
||||
},
|
||||
"unsupported key 'unknown'",
|
||||
{"total_cpu_millis": 0, "total_memory_bytes": 1},
|
||||
"total_cpu_millis",
|
||||
),
|
||||
(
|
||||
{
|
||||
@@ -2675,17 +2640,6 @@ def test_remote_refresh_async_forwards_progress_from_submitted_handle():
|
||||
},
|
||||
"supervisor_resources.ephemeral_storage_bytes",
|
||||
),
|
||||
(
|
||||
{
|
||||
"supervisor_resources": {
|
||||
"cpu_millis": 1,
|
||||
"memory_bytes": 1,
|
||||
"ephemeral_storage_bytes": 1,
|
||||
"unknown": 1,
|
||||
}
|
||||
},
|
||||
"unsupported key 'unknown'",
|
||||
),
|
||||
(
|
||||
{
|
||||
"planning_workers": {
|
||||
@@ -7673,28 +7627,31 @@ async def test_remote_add_function_columns_forwards_auto_refresh_resource_budget
|
||||
request.send_response(404)
|
||||
request.end_headers()
|
||||
|
||||
budget = {"cpu_millis": 2_000, "memory_bytes": 4 * 1024**3}
|
||||
budget = {"total_cpu_millis": 2_000, "total_memory_bytes": 4 * 1024**3}
|
||||
with mock_lancedb_connection(handler) as db:
|
||||
table = db.open_table("test")
|
||||
table.add_columns(
|
||||
{"embedding": application},
|
||||
auto_refresh_resource_budget=budget,
|
||||
total_cpu_millis=(budget).get("total_cpu_millis"),
|
||||
total_memory_bytes=(budget).get("total_memory_bytes"),
|
||||
total_gpu_count=(budget).get("total_gpu_count"),
|
||||
)
|
||||
|
||||
async with mock_lancedb_connection_async(handler) as db:
|
||||
table = await db.open_table("test")
|
||||
await table.add_columns(
|
||||
{"embedding": application},
|
||||
auto_refresh_resource_budget=budget,
|
||||
total_cpu_millis=(budget).get("total_cpu_millis"),
|
||||
total_memory_bytes=(budget).get("total_memory_bytes"),
|
||||
total_gpu_count=(budget).get("total_gpu_count"),
|
||||
)
|
||||
|
||||
assert len(bodies) == 2
|
||||
for body in bodies:
|
||||
assert body["auto_refresh_enabled"] is True
|
||||
assert body["auto_refresh_resource_budget"] == {
|
||||
**budget,
|
||||
"gpu_count": 0,
|
||||
}
|
||||
for key, value in budget.items():
|
||||
assert body[key] == value
|
||||
assert "total_gpu_count" not in body
|
||||
assert body["new_columns"] == [{"name": "embedding", "all_null": True}]
|
||||
|
||||
|
||||
|
||||
@@ -6565,8 +6565,8 @@ def test_refresh_column_rejects_invalid_batch_size(tmp_path, method, batch_size)
|
||||
({"max_concurrency": 4}, "max_concurrency"),
|
||||
({"publication_interval_rows": 60}, "publication_interval_rows"),
|
||||
(
|
||||
{"resource_budget": {"cpu_millis": 1000, "memory_bytes": 1024}},
|
||||
"resource_budget",
|
||||
{"total_cpu_millis": 1000, "total_memory_bytes": 1024},
|
||||
"total_cpu_millis",
|
||||
),
|
||||
(
|
||||
{
|
||||
@@ -6864,10 +6864,8 @@ def test_auto_refresh_resource_budget_requires_a_function(tmp_path):
|
||||
with pytest.raises(ValueError, match="registered Function"):
|
||||
table.add_columns(
|
||||
computed={"doubled": "x * 2"},
|
||||
auto_refresh_resource_budget={
|
||||
"cpu_millis": 1_000,
|
||||
"memory_bytes": 1_024,
|
||||
},
|
||||
total_cpu_millis=1_000,
|
||||
total_memory_bytes=1_024,
|
||||
)
|
||||
assert table.version == before
|
||||
assert table.schema.names == ["x"]
|
||||
|
||||
Reference in New Issue
Block a user