Implementation:Bentoml BentoML Models Delete
Appearance
| Implementation Metadata | |
|---|---|
| Implementation Name | Models Delete |
| API | bentoml.models.delete()
|
| Source | src/bentoml/models.py:L53-58 (public), src/bentoml/_internal/store.py:L183-207 (Store.delete)
|
| Workflow | Model_Store_Management |
| Domain | ML_Serving, Model_Management |
| Implements | Principle:Bentoml_BentoML_Model_Cleanup |
| Last Updated | 2026-02-13 15:00 GMT |
Overview
The bentoml.models.delete() function removes a specific model version from the local BentoML model store. It deletes the model's directory and all contained artifact files, and updates the "latest" symlink if the deleted version was the most recent.
Import
import bentoml
Signature
def delete(tag: Tag | str) -> None
Parameters
| Parameter | Type | Default | Description |
|---|---|---|---|
tag |
str | required | The model tag to delete from the local store. Can be "name:version" for a specific version or "name:latest" to delete the latest version.
|
Inputs and Outputs
Inputs:
- Model tag to remove from the local store
Outputs:
None— the model directory is removed from<bentoml_home>/models/as a side effect- The
"latest"symlink is updated if the deleted version was the latest - Raises
NotFoundif the specified model does not exist
Usage Examples
import bentoml
# Delete a specific model version
bentoml.models.delete("text_classifier:abc123")
# Delete the latest version of a model
bentoml.models.delete("text_classifier:latest")
# Bulk cleanup: keep only the 3 most recent versions
models = bentoml.models.list("text_classifier")
for model in models[3:]:
bentoml.models.delete(model.tag)
# Delete all versions of a model
for model in bentoml.models.list("text_classifier"):
bentoml.models.delete(model.tag)
Behavior Details
Deletion Process
The delete operation (implemented in Store.delete() at src/bentoml/_internal/store.py:L183-207) performs the following steps:
- Resolve the tag: If the tag uses
"latest", resolve it to the actual version. - Validate existence: Verify the model exists in the store. Raise
NotFoundif not. - Remove directory: Delete the model version directory at
<bentoml_home>/models/<name>/<version>/. - Update "latest" symlink: If the deleted version was the one pointed to by the
"latest"symlink:- If other versions remain, update the symlink to point to the next most recent version.
- If no versions remain, remove the symlink and the model name directory.
Error Handling
| Scenario | Behavior |
|---|---|
| Model tag does not exist | Raises NotFound error
|
| Delete the latest version | "latest" symlink updated to previous version
|
| Delete the only remaining version | Model name directory and symlink removed entirely |
| Delete a non-latest version | Only that version's directory removed; "latest" unchanged
|
Filesystem Effects
Deletion removes the entire version directory, including:
- Serialized model artifact files (e.g.,
.pkl,.pt,.onnx) - The
model.yamldescriptor file - Any custom objects stored alongside the model
- Any framework-specific auxiliary files
Important Notes
- Irreversible: Deletion is permanent. There is no trash or undo mechanism.
- Local Only: This operation only affects the local store. Models pushed to BentoCloud are not affected.
- No Cascade: Deleting a model does not affect any bentos or services that reference it. Those references will fail at resolution time if the model is needed.
Source Reference
- Public API:
src/bentoml/models.py, lines 53-58 - Store implementation:
src/bentoml/_internal/store.py, lines 183-207
Knowledge Sources
Page Connections
Double-click a node to navigate. Hold to expand connections.
Principle
Implementation
Heuristic
Environment