diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2022-12-20 17:22:11 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2022-12-20 17:22:11 +0300 |
commit | 0c872e02b2c822e3397515ec324051ff540f0cd5 (patch) | |
tree | ce2fb6ce7030e4dad0f4118d21ab6453e5938cdd /app/services/ml/experiment_tracking/candidate_repository.rb | |
parent | f7e05a6853b12f02911494c4b3fe53d9540d74fc (diff) |
Add latest changes from gitlab-org/gitlab@15-7-stable-eev15.7.0-rc42
Diffstat (limited to 'app/services/ml/experiment_tracking/candidate_repository.rb')
-rw-r--r-- | app/services/ml/experiment_tracking/candidate_repository.rb | 59 |
1 files changed, 32 insertions, 27 deletions
diff --git a/app/services/ml/experiment_tracking/candidate_repository.rb b/app/services/ml/experiment_tracking/candidate_repository.rb index b6f87995185..1dbeb30145b 100644 --- a/app/services/ml/experiment_tracking/candidate_repository.rb +++ b/app/services/ml/experiment_tracking/candidate_repository.rb @@ -14,11 +14,15 @@ module Ml ::Ml::Candidate.with_project_id_and_iid(project.id, iid) end - def create!(experiment, start_time) - experiment.candidates.create!( + def create!(experiment, start_time, tags = nil) + candidate = experiment.candidates.create!( user: user, start_time: start_time || 0 ) + + add_tags(candidate, tags) + + candidate end def update(candidate, status, end_time) @@ -41,36 +45,21 @@ module Ml candidate.params.create!(name: name, value: value) end - def add_metrics(candidate, metric_definitions) - return unless candidate.present? - - metrics = metric_definitions.map do |metric| - { - candidate_id: candidate.id, - name: metric[:key], - value: metric[:value], - tracked_at: metric[:timestamp], - step: metric[:step], - **timestamps - } - end + def add_tag!(candidate, name, value) + candidate.metadata.create!(name: name, value: value) + end - ::Ml::CandidateMetric.insert_all(metrics, returning: false) unless metrics.empty? + def add_metrics(candidate, metric_definitions) + extra_keys = { tracked_at: :timestamp, step: :step } + insert_many(candidate, metric_definitions, ::Ml::CandidateMetric, extra_keys) end def add_params(candidate, param_definitions) - return unless candidate.present? - - parameters = param_definitions.map do |p| - { - candidate_id: candidate.id, - name: p[:key], - value: p[:value], - **timestamps - } - end + insert_many(candidate, param_definitions, ::Ml::CandidateParam) + end - ::Ml::CandidateParam.insert_all(parameters, returning: false) unless parameters.empty? + def add_tags(candidate, tag_definitions) + insert_many(candidate, tag_definitions, ::Ml::CandidateMetadata) end private @@ -80,6 +69,22 @@ module Ml { created_at: current_time, updated_at: current_time } end + + def insert_many(candidate, definitions, entity_class, extra_keys = {}) + return unless candidate.present? && definitions.present? + + entities = definitions.map do |d| + { + candidate_id: candidate.id, + name: d[:key], + value: d[:value], + **extra_keys.transform_values { |old_key| d[old_key] }, + **timestamps + } + end + + entity_class.insert_all(entities, returning: false) unless entities.empty? + end end end end |