Hi everyone,
I'm currently working on a project where I'm migrating models and artifacts from a source Databricks workspace to a target one. I've written a script to upload the model artifacts from my local system to DBFS in the target workspace (using the /api/2.0/dbfs/put API). The upload part works perfectly, and the files are successfully transferred to DBFS.
However, I'm struggling to register the models in the target workspace after the upload. I’ve tried using the mlflow.register_model method, but it doesn’t seem to work.
Here’s a summary of what I’ve done so far:
- I’ve uploaded the model artifacts using the code below.
- After the upload, I tried registering the models in the target workspace using mlflow.register_model or mlflow.models.Model.register, but I don’t see the model appearing in the Model Registry.
Here’s my upload script for reference:
python
import os import requests # Databricks host and token (directly in the script) databricks_host = "<databricks_host>" token = "<token>" # Define the local directory and DBFS destination path local_directory = r"C:\Users\offerings_admin\Downloads\artifacts" dbfs_directory = "dbfs:/artifacts2/" # Function to upload a file to DBFS using REST API def upload_to_dbfs(local_path, dbfs_path): with open(local_path, "rb") as f: file_data = f.read() url = f"{databricks_host}/api/2.0/dbfs/put" headers = { "Authorization": f"Bearer {token}" } data = { "path": dbfs_path, "overwrite": "true" } # Sending the POST request to upload the file response = requests.post(url, headers=headers, data=data, files={"file": file_data}) if response.status_code == 200: print(f"File {local_path} uploaded successfully!") else: print(f"Failed to upload file {local_path}: {response.text}") # Iterate through the artifacts directory and upload files while preserving the folder structure for root, dirs, files in os.walk(local_directory): for file in files: local_file_path = os.path.join(root, file) relative_path = os.path.relpath(local_file_path, local_directory) dbfs_file_path = os.path.join(dbfs_directory, relative_path).replace("\\", "/") upload_to_dbfs(local_file_path, dbfs_file_path)
Could anyone suggest why the models aren't being registered, or what I might be missing in the process?
Thanks in advance for your help!