cancel
Showing results for 
Search instead for 
Did you mean: 
Community Platform Discussions
Connect with fellow community members to discuss general topics related to the Databricks platform, industry trends, and best practices. Share experiences, ask questions, and foster collaboration within the community.
cancel
Showing results for 
Search instead for 
Did you mean: 

Unable to Register Models After Uploading Artifacts to DBFS in Databricks

Sudheer2
New Contributor III

 

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:

  1. I’ve uploaded the model artifacts using the code below.
  2. 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!

1 REPLY 1

Alberto_Umana
Databricks Employee
Databricks Employee

Hi @Sudheer2,

Does it give you any error while trying to register the model?

Connect with Databricks Users in Your Area

Join a Regional User Group to connect with local Databricks users. Events will be happening in your city, and you won’t want to miss the chance to attend and share knowledge.

If there isn’t a group near you, start one and help create a community that brings people together.

Request a New Group