-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implementing
registered_model
service
- Loading branch information
Showing
10 changed files
with
257 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
# Registered model operations | ||
```@docs | ||
createregisteredmodel | ||
getregisteredmodel | ||
renameregisteredmodel | ||
updateregisteredmodel | ||
deleteregisteredmodel | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,91 @@ | ||
""" | ||
createregisteredmodel(instance::MLFlow, name::String; | ||
tags::MLFlowUpsertData{Tag}=Tag[], description::Union{String, Missing}=missing) | ||
Create a [`RegisteredModel`](@ref) with a name. Returns the newly created | ||
[`RegisteredModel`](@ref). Validates that another [`RegisteredModel`](@ref) with the same | ||
name does not already exist and fails if another [`RegisteredModel`](@ref) with the same | ||
name already exists. | ||
# Arguments | ||
- `instance`: [`MLFlow`](@ref) configuration. | ||
- `name`: Register models under this name. | ||
- `tags`: A collection of [`Tag`](@ref). | ||
- `description`: Optional description for [`RegisteredModel`](@ref). | ||
# Returns | ||
An instance of type [`RegisteredModel`](@ref). | ||
""" | ||
function createregisteredmodel(instance::MLFlow, name::String; | ||
tags::MLFlowUpsertData{Tag}=Tag[], | ||
description::Union{String, Missing}=missing)::RegisteredModel | ||
result = mlfpost(instance, "registered-models/create"; name=name, | ||
tags=parse(Tag, tags), description=description) | ||
return result["registered_model"] |> RegisteredModel | ||
end | ||
|
||
""" | ||
getregisteredmodel(instance::MLFlow, name::String) | ||
# Arguments | ||
- `instance`: [`MLFlow`](@ref) configuration. | ||
- `name`: [`RegisteredModel`](@ref) model unique name identifier. | ||
# Returns | ||
An instance of type [`RegisteredModel`](@ref). | ||
""" | ||
function getregisteredmodel(instance::MLFlow, name::String)::RegisteredModel | ||
result = mlfget(instance, "registered-models/get"; name=name) | ||
return result["registered_model"] |> RegisteredModel | ||
end | ||
|
||
""" | ||
renameregisteredmodel(instance::MLFlow, name::String, new_name::String) | ||
# Arguments | ||
- `instance`: [`MLFlow`](@ref) configuration. | ||
- `name`: [`RegisteredModel`](@ref) unique name identifier. | ||
- `new_name`: If provided, updates the name for this [`RegisteredModel`](@ref). | ||
# Returns | ||
An instance of type [`RegisteredModel`](@ref). | ||
""" | ||
function renameregisteredmodel(instance::MLFlow, name::String, | ||
new_name::String)::RegisteredModel | ||
result = mlfpost(instance, "registered-models/rename"; name=name, new_name=new_name) | ||
return result["registered_model"] |> RegisteredModel | ||
end | ||
|
||
""" | ||
updateregisteredmodel(instance::MLFlow, name::String; | ||
description::Union{String, Missing}=missing) | ||
# Arguments | ||
- `instance`: [`MLFlow`](@ref) configuration. | ||
- `name`: [`RegisteredModel`](@ref) unique name identifier. | ||
- `description`: If provided, updates the description for this [`RegisteredModel`](@ref). | ||
# Returns | ||
An instance of type [`RegisteredModel`](@ref). | ||
""" | ||
function updateregisteredmodel(instance::MLFlow, name::String; | ||
description::Union{String, Missing}=missing)::RegisteredModel | ||
result = mlfpatch(instance, "registered-models/update"; name=name, | ||
description=description) | ||
return result["registered_model"] |> RegisteredModel | ||
end | ||
|
||
""" | ||
deleteregisteredmodel(instance::MLFlow, name::String) | ||
# Arguments | ||
- `instance`: [`MLFlow`](@ref) configuration. | ||
- `name`: [`RegisteredModel`](@ref) unique name identifier. | ||
# Returns | ||
`true` if successful. Otherwise, raises exception. | ||
""" | ||
function deleteregisteredmodel(instance::MLFlow, name::String)::Bool | ||
mlfdelete(instance, "registered-models/delete"; name=name) | ||
return true | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,87 @@ | ||
@testset verbose = true "create registered model" begin | ||
@ensuremlf | ||
|
||
@testset "base" begin | ||
registered_model = createregisteredmodel(mlf, "missy"; description="gala") | ||
|
||
@test registered_model isa RegisteredModel | ||
@test registered_model.name == "missy" | ||
@test registered_model.description == "gala" | ||
end | ||
|
||
@testset "name exists" begin | ||
registered_model = getregisteredmodel(mlf, "missy") | ||
@test_throws ErrorException createregisteredmodel(mlf, registered_model.name) | ||
deleteregisteredmodel(mlf, "missy") | ||
end | ||
|
||
@testset "with tags as array of tags" begin | ||
createregisteredmodel(mlf, "missy"; tags=[Tag("test_key", "test_value")]) | ||
deleteregisteredmodel(mlf, "missy") | ||
end | ||
|
||
@testset "with tags as array of pairs" begin | ||
createregisteredmodel(mlf, "missy"; tags=["test_key" => "test_value"]) | ||
deleteregisteredmodel(mlf, "missy") | ||
end | ||
|
||
@testset "with tags as array of dicts" begin | ||
createregisteredmodel(mlf, "missy"; | ||
tags=[Dict("key" => "test_key", "value" => "test_value")]) | ||
deleteregisteredmodel(mlf, "missy") | ||
end | ||
|
||
@testset "with tags as dict" begin | ||
createregisteredmodel(mlf, "missy"; tags=Dict("test_key" => "test_value")) | ||
deleteregisteredmodel(mlf, "missy") | ||
end | ||
end | ||
|
||
@testset verbose = true "get registered model" begin | ||
@ensuremlf | ||
|
||
registered_model = createregisteredmodel(mlf, "missy"; description="gala") | ||
retrieved_registered_model = getregisteredmodel(mlf, registered_model.name) | ||
|
||
@test retrieved_registered_model isa RegisteredModel | ||
@test retrieved_registered_model.name == registered_model.name | ||
@test retrieved_registered_model.description == registered_model.description | ||
|
||
deleteregisteredmodel(mlf, "missy") | ||
end | ||
|
||
@testset verbose = true "rename registered model" begin | ||
@ensuremlf | ||
|
||
registered_model = createregisteredmodel(mlf, "missy"; description="gala") | ||
renamed_registered_model = renameregisteredmodel(mlf, registered_model.name, "mister") | ||
|
||
@test renamed_registered_model isa RegisteredModel | ||
@test renamed_registered_model.name == "mister" | ||
@test renamed_registered_model.description == registered_model.description | ||
|
||
deleteregisteredmodel(mlf, "mister") | ||
end | ||
|
||
@testset verbose = true "update registered model" begin | ||
@ensuremlf | ||
|
||
registered_model = createregisteredmodel(mlf, "missy"; description="gala") | ||
updated_registered_model = updateregisteredmodel(mlf, registered_model.name; | ||
description="ana") | ||
|
||
@test updated_registered_model isa RegisteredModel | ||
@test updated_registered_model.name == registered_model.name | ||
@test updated_registered_model.description == "ana" | ||
|
||
deleteregisteredmodel(mlf, "missy") | ||
end | ||
|
||
@testset verbose = true "delete registered model" begin | ||
@ensuremlf | ||
|
||
registered_model = createregisteredmodel(mlf, "missy"; description="gala") | ||
deleteregisteredmodel(mlf, "missy") | ||
|
||
@test_throws ErrorException getregisteredmodel(mlf, "missy") | ||
end |