10-08-2024 03:39 PM
Hi everyone,
I’m looking for accessing Unity Catalog (UC) Volumes from a Databricks Serving Endpoint. Here’s my current setup:
Since the Serving Endpoint runs in an isolated environment, how can I access Unity Catalog Volumes from within my custom model class during inference?
Any guidance on solving this issue or alternative methods to access UC Volumes from a Serving Endpoint would be greatly appreciated.
Thanks in advance
10-08-2024 03:39 PM
Additionally, I log the model as shown below, with MicrosoftResnet50Model being my custom inference class with load_context and predict methods:
with mlflow.start_run():
model_info = mlflow.pyfunc.log_model(
REGISTERED_MODEL_NAME,
python_model=MicrosoftResnet50Model(),
input_example=api_input_example,
artifacts={"model_path": MODEL_PATH},
pip_requirements=[
f"transformers=={transformers.__version__}",
"torch==2.0.1"
],
signature=signature,
registered_model_name=f"{CATALOG}.{SCHEMA}.{REGISTERED_MODEL_NAME}"
)
04-22-2025 11:36 PM
Hey VELU1122,
did you find a solution for it. We are struggling with the same problem currently.
Thanks
a month ago
Greetings @VELU1122 , you’re correct that the Databricks Model Serving container is isolated, so you can’t rely on cluster-only affordances like mounts or executor-distributed file utilities. The reliable way to read from Unity Catalog (UC) Volumes in a serving endpoint is to use the Databricks Files API / SDK with an endpoint-injected credential, and address files by their UC Volumes path, for example /Volumes/<catalog>/<schema>/<volume>/<relative_path>.
/Volumes/<catalog>/<schema>/<volume>/.... This is supported for managing and reading files directly from Volumes, and avoids the need for dbutils or mounts inside the serving container.DATABRICKS_HOST as plain text and DATABRICKS_TOKEN (or use OAuth for a service principal) as a secret in the endpoint config; then use the SDK to call the Files API at inference time.dbutils.fs.mount or relying on FUSE-style local paths in serving containers; use Files API / SDK instead. Model Serving doesn’t run notebook executors and doesn’t support the same dbutils semantics; Volumes are intended for path-based governance and programmatic access via APIs and POSIX-like paths, not runtime mounts in serving.DATABRICKS_HOST: https://<your-workspace-url> (plain text). * DATABRICKS_TOKEN: {{secrets/<scope>/<key>}} (secret). * Alternatively, use OAuth M2M for a service principal and inject DATABRICKS_CLIENT_ID / DATABRICKS_CLIENT_SECRET and fetch short-lived tokens at runtime, then call the Files API. This avoids PATs and is recommended for unattended endpoints.python_model class, read files with the SDK: ```python import os import io from databricks.sdk import WorkspaceClientdef _read_volume_file(self, path: str) -> bytes:
# path like "/Volumes/<catalog>/<schema>/<volume>/images/cat.jpg"
resp = self.w.files.download(path) # returns a response with .contents (bytes)
return resp.contents
/Volumes/... path at runtime.dbutils is notebook/cluster-bound; Model Serving supports environment variables and secrets injection for external access, not dbutils mounts. Use the Files API / SDK instead of dbutils in serving.context.artifacts rather than reaching out to Volumes during inference. This reduces I/O and removes external dependencies at serving time.json
{
"name": "uc-model-endpoint",
"config": {
"served_entities": [
{
"entity_name": "myCatalog.mySchema.myModel",
"entity_version": "1",
"workload_size": "Small",
"scale_to_zero_enabled": true,
"environment_vars": {
"DATABRICKS_HOST": "https://<workspace-url>",
"DATABRICKS_TOKEN": "{{secrets/my_scope/my_token_key}}"
}
}
]
}
}
/api/2.0/fs/files/Volumes/... and SDK usage in WorkspaceClient.files.yesterday
Serverless Model Serving does not mount the UC Volumes FUSE path (/Volumes), so references to “/Volumes/…” inside a custom pyfunc’s model code will fail at container build or runtime. The correct pattern is to package any required files (like your GGUF) into the model artifact at log time and then load them from context.artifacts[...] in load_context() during serving.
Ref Doc - https://docs.databricks.com/aws/en/machine-learning/model-serving/model-serving-custom-artifacts
Passionate about hosting events and connecting people? Help us grow a vibrant local community—sign up today to get started!
Sign Up Now