The error message "RestException: NOT_FOUND: The directory being accessed is not found" typically indicates that the model or its version cannot be located in the specified directory. Here are a few steps you can take to troubleshoot and resolve this issue:
- Verify Model URI: Ensure that the model URI is correctly specified. The model URI should follow the format models:/<model_name>/<model_version>. Double-check for any typos in the model name or version.
- Check Model Registration: Confirm that the model and its version are registered in the MLflow Model Registry. You can do this by navigating to the Model Registry in the Databricks workspace and verifying that the model and version exist.
- Permissions: Ensure that you have the necessary permissions to access the model and its version. Lack of permissions can sometimes result in a "not found" error.
- Model Serving Endpoint: If you are using Unity Catalog, ensure that the model serving endpoint is correctly set up and that there are no issues with the endpoint configuration.
Here is an example of how to verify the model URI and check the model registration
import mlflow
# Set the registry URI to Databricks
mlflow.set_registry_uri("databricks-uc")
# Define the model URI
model_uri = f"models:/{model_name}/{model_version}"
# Check if the model exists
try:
model_info = mlflow.models.get_model_info(model_uri)
print(f"Model {model_name} version {model_version} exists.")
except mlflow.exceptions.MlflowException as e:
print(f"Error: {e}")