Skip to content

Commit 052d255

Browse files
committed
Implementing logmodel function
1 parent a2a797a commit 052d255

File tree

4 files changed

+57
-4
lines changed

4 files changed

+57
-4
lines changed

.github/workflows/CI.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ jobs:
2626
if: hashFiles('**/requirements.txt', '**/pyproject.toml') == ''
2727
run: |
2828
touch ./requirements.txt
29-
echo "mlflow==3.1.2" > ./requirements.txt
29+
echo "mlflow[auth]==3.1.2" > ./requirements.txt
3030
- uses: actions/setup-python@v4
3131
with:
3232
python-version: '3.12.3'

src/MLFlowClient.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ export getrun, createrun, deleterun, setruntag, updaterun, restorerun, searchrun
6565
deleteruntag
6666

6767
include("services/logger.jl")
68-
export logbatch, loginputs, logmetric, logparam
68+
export logbatch, loginputs, logmetric, logmodel, logparam
6969

7070
include("services/artifact.jl")
7171
export listartifacts

src/services/logger.jl

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,8 +57,9 @@ For more information about this function, check [MLFlow official documentation](
5757
- `params`: A collection of [`Param`](@ref) to log.
5858
- `tags`: A collection of [`Tag`](@ref) to log.
5959
60-
**Note**: A single request can contain up to 1000 metrics, and up to 1000 metrics, params,
61-
and tags in total.
60+
!!! note
61+
A single request can contain up to 1000 metrics, and up to 1000 metrics, params, and
62+
tags in total.
6263
6364
# Returns
6465
`true` if successful. Otherwise, raises exception.
@@ -123,3 +124,18 @@ logparam(instance::MLFlow, run_id::String, param::Param)::Bool =
123124
logparam(instance, run_id, param.key, param.value)
124125
logparam(instance::MLFlow, run::Run, param::Param)::Bool =
125126
logparam(instance, run.info.run_id, param.key, param.value)
127+
128+
"""
129+
logmodel(instance::MLFlow, run_id::String, model_json::String)
130+
131+
# Arguments
132+
- `instance`: [`MLFlow`](@ref) configuration.
133+
- `run_id`: ID of the [`Run`](@ref) to log under.
134+
- `model_json`: MLmodel file in json format.
135+
"""
136+
function logmodel(instance::MLFlow, run_id::String, model_json::String)::Bool
137+
mlfpost(instance, "runs/log-model"; run_id=run_id, model_json=model_json)
138+
return true
139+
end
140+
logmodel(instance::MLFlow, run::Run, model_json::String)::Bool =
141+
logmodel(instance, run.info.run_id, model_json)

test/services/logger.jl

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -298,3 +298,40 @@ end
298298

299299
deleteexperiment(mlf, experiment_id)
300300
end
301+
302+
@testset verbose = true "log model" begin
303+
@ensuremlf
304+
305+
experiment_id = createexperiment(mlf, UUIDs.uuid4() |> string)
306+
mlmodel_json_string = """
307+
{
308+
"time_created": "2018-05-25T17:28:53.35",
309+
"flavors": {
310+
"sklearn": {
311+
"sklearn_version": "0.19.1",
312+
"pickled_model": "model.pkl"
313+
},
314+
"python_function": {
315+
"loader_module": "mlflow.sklearn"
316+
}
317+
},
318+
"utc_time_created": "2025-08-16T16:50:00.00Z",
319+
"artifact_path": "mlflowclientjl-test",
320+
"run_id": "<RUN_ID>"
321+
}
322+
"""
323+
324+
@testset "with run id as string" begin
325+
run = createrun(mlf, experiment_id)
326+
@assert logmodel(mlf, run.info.run_id, replace(mlmodel_json_string, "<RUN_ID>" => run.info.run_id))
327+
deleterun(mlf, run)
328+
end
329+
330+
@testset "with run" begin
331+
run = createrun(mlf, experiment_id)
332+
@assert logmodel(mlf, run, replace(mlmodel_json_string, "<RUN_ID>" => run.info.run_id))
333+
deleterun(mlf, run)
334+
end
335+
336+
deleteexperiment(mlf, experiment_id)
337+
end

0 commit comments

Comments
 (0)