diff options
Diffstat (limited to 'app/services/ml')
4 files changed, 73 insertions, 4 deletions
diff --git a/app/services/ml/experiment_tracking/candidate_repository.rb b/app/services/ml/experiment_tracking/candidate_repository.rb index 2399da3e182..436f06e3ca5 100644 --- a/app/services/ml/experiment_tracking/candidate_repository.rb +++ b/app/services/ml/experiment_tracking/candidate_repository.rb @@ -5,7 +5,7 @@ module Ml class CandidateRepository attr_accessor :project, :user, :experiment, :candidate - def initialize(project, user) + def initialize(project, user = nil) @project = project @user = user end @@ -103,10 +103,16 @@ module Ml end def candidate_name(name, tags) - return name if name.present? - return unless tags.present? + name.presence || candidate_name_from_tags(tags) || random_candidate_name + end + + def candidate_name_from_tags(tags) + tags&.detect { |t| t[:key] == 'mlflow.runName' }&.dig(:value) + end - tags.detect { |t| t[:key] == 'mlflow.runName' }&.dig(:value) + def random_candidate_name + parts = Array.new(3).map { FFaker::Animal.common_name.downcase.delete(' ') } << rand(10000) + parts.join('-').truncate(255) end end end diff --git a/app/services/ml/find_or_create_experiment_service.rb b/app/services/ml/find_or_create_experiment_service.rb new file mode 100644 index 00000000000..1fe10c7f856 --- /dev/null +++ b/app/services/ml/find_or_create_experiment_service.rb @@ -0,0 +1,19 @@ +# frozen_string_literal: true + +module Ml + class FindOrCreateExperimentService + def initialize(project, experiment_name, user = nil) + @project = project + @name = experiment_name + @user = user + end + + def execute + Ml::Experiment.find_or_create(project, name, user) + end + + private + + attr_reader :project, :name, :user + end +end diff --git a/app/services/ml/find_or_create_model_service.rb b/app/services/ml/find_or_create_model_service.rb new file mode 100644 index 00000000000..66dec7a6234 --- /dev/null +++ b/app/services/ml/find_or_create_model_service.rb @@ -0,0 +1,22 @@ +# frozen_string_literal: true + +module Ml + class FindOrCreateModelService + def initialize(project, model_name) + @project = project + @name = model_name + end + + def execute + Ml::Model.find_or_create( + project, + name, + Ml::FindOrCreateExperimentService.new(project, name).execute + ) + end + + private + + attr_reader :name, :project + end +end diff --git a/app/services/ml/find_or_create_model_version_service.rb b/app/services/ml/find_or_create_model_version_service.rb new file mode 100644 index 00000000000..1316b2546b9 --- /dev/null +++ b/app/services/ml/find_or_create_model_version_service.rb @@ -0,0 +1,22 @@ +# frozen_string_literal: true + +module Ml + class FindOrCreateModelVersionService + def initialize(project, params = {}) + @project = project + @name = params[:model_name] + @version = params[:version] + @package = params[:package] + end + + def execute + model = Ml::FindOrCreateModelService.new(project, name).execute + + Ml::ModelVersion.find_or_create!(model, version, package) + end + + private + + attr_reader :version, :name, :project, :package + end +end |