Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Deleting experiments #60501

Closed
jcpayne opened this issue Aug 7, 2020 · 12 comments
Closed

Deleting experiments #60501

jcpayne opened this issue Aug 7, 2020 · 12 comments

Comments

@jcpayne
Copy link

jcpayne commented Aug 7, 2020

I have recently started using Machine Learning services quite regularly and my costs on Azure have gone way up, in part (I think) because so much data is stored from every run. It is annoying that it appears to be so hard to delete experiments. The experiment is the unit at which deletion should be easiest. For example, I don't want to junk my whole workspace because I'm still working on the same problem, but I do want to get rid of gigabytes of data from 35 failed runs or whatever, so that I don't pay for them.

Document Details

Do not edit this section. It is required for docs.microsoft.com ➟ GitHub issue linking.

@BhargaviAnnadevara
Copy link
Contributor

@jcpayne Thanks for reaching out. We're investigating this and will get back to you shortly.

@GiftA-MSFT
Copy link
Contributor

@jcpayne thanks for reaching out. A default storage account is created along with your AML workspace and you can manage the data accordingly. Your experiment data is stored in a blob container in the default storage account and you can access it directly from your resource group or view your credentials in AML Studio > Datastores > workspaceblobstore (Default).

@jcpayne
Copy link
Author

jcpayne commented Aug 10, 2020

Yes thanks, I was aware of that. So is just deleting the blobstore folders for a run going to cause any problem? I.e., does the workspace somehow index those folders in a way that would cause problems if they were deleted?

Also, there are two folders and two files created for every run (a 'setup' folder; a main folder, a .zip file, and another non-zipped file), so deleting "Experiment 2, Run 4" requires locating and deleting 4 different things, which is made more awkward by the obscure file and folder names that are auto-generated; for example, AML Studio named my Experiment 2, Run 4 folder "expt2_1593466198_5ee83437." It would be nicer if it was just possible to click on an experiment in Studio and have all of the pieces found and deleted at once.

@GiftA-MSFT
Copy link
Contributor

@jcpayne currently, AML doesn't support deleting experiments but this feature is on our roadmap. It is also not recommended to delete files in blob storage (you can but I just confirmed that it is not recommended as it could cause inconsistencies). However, you can use the following python code sample to delete runs and its artifcats (note- snapshot dir won't be deleted). Let me know if the below suggestion helps. Thanks.

import uuid
import requests
from azureml._base_sdk_common.user_agent import get_user_agent
from azureml._base_sdk_common import _ClientSessionId
from azureml.core.experiment import Experiment
from azureml._common.exceptions import AzureMLException
from azureml._restclient.clientbase import ClientBase

def delete_run(workspace, experiment_name, run_id):
    """
    :param workspace:
    :type workspace: azureml.core.workspace.Workspace
    :param experiment_name: experiment name.
    :type experiment_name: str
    :param run_id: run id
    :type run_id: str
    :return:
    """
    
    headers = {
        "User-Agent": get_user_agent(),
        "x-ms-client-session-id": _ClientSessionId,
        "x-ms-client-request-id": str(uuid.uuid4())
    }

    # Merging the auth header.
    headers.update(workspace._auth_object.get_authentication_header())
    experiment = Experiment(workspace, experiment_name)
    rh_workspace_scope = workspace.service_context._get_run_history_url() + "/history/v1.0/private" + workspace.service_context._get_workspace_scope()
    delete_url = rh_workspace_scope + "/" + "experimentids/{}/runs/{}".format(experiment.id, run_id)
    response = ClientBase._execute_func(requests.delete, delete_url, headers=headers)
    
    if response.status_code >= 400:
        from azureml._base_sdk_common.common import get_http_exception_response_string
        # response.text is a JSON from execution service.
        response_message = get_http_exception_response_string(response)
        raise AzureMLException(response_message)
    result = response.json()
    print(result)

@jcpayne
Copy link
Author

jcpayne commented Aug 13, 2020 via email

@jcpayne
Copy link
Author

jcpayne commented Aug 18, 2020

For other users: this snippet deletes all of the runs in a given experiment. Afterwards, the experiment name and the 'latest run' are still visible in Studio, but all of the associated storage has been cleared.

experiment_name = 'my_experiment'  
exp = ws.experiments[experiment_name]  
for run in exp.get_runs():  
    #print(run.id) #might want to check before deleting!
    delete_run(ws, experiment_name, run.id)

@jcpayne
Copy link
Author

jcpayne commented Aug 18, 2020

Oddly enough, the script you suggested worked for the first experiment, but I tried it on 3 more experiments and while the printed message indicates that the files were removed, the Microsoft Azure Storage Explorer shows that they are still there (and not deleted).

@GiftA-MSFT
Copy link
Contributor

Hi @jcpayne thanks for following up. Using the above code, I was able to delete the experiment runs of multiple experiments successfully. What folder are you looking at? Did you try to refresh Containers > azureml > ExperimentRun folder?

@jcpayne
Copy link
Author

jcpayne commented Aug 26, 2020 via email

@GiftA-MSFT
Copy link
Contributor

Hi, thanks for following up. Unfortunately, we currently don't have an option to automatically identify and delete all data associated with an experiment run in the default blobstore. The code I provided above only deletes data in the azureml container. You can try to manually identify/delete the data in default blobstore, however, it is not recommended as you may no longer be able to use old snapshots or see old logs/models and this can cause weird errors. The product team are aware of this feature request, and plans to enable the option for deleting runs is on their roadmap. So sorry for the inconvenience. Thanks.

@jcpayne
Copy link
Author

jcpayne commented Aug 27, 2020 via email

@nikhilweee
Copy link

Has there been progress on this issue? Is there a way to delete storage information associated with an experiment yet?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

6 participants