diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2023-10-27 03:12:17 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2023-10-27 03:12:17 +0300 |
commit | dfc8a99695e16feffcc811a536e58e2c9be75ce2 (patch) | |
tree | 34307394a3bde02dc1e8a18f94c5958a24cc91d5 /app | |
parent | 277496b843d3c14cfd48286b1718b03775d83bbc (diff) |
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'app')
-rw-r--r-- | app/models/commit_status.rb | 12 | ||||
-rw-r--r-- | app/models/ml/candidate.rb | 2 | ||||
-rw-r--r-- | app/models/ml/model_version.rb | 1 | ||||
-rw-r--r-- | app/services/ml/create_candidate_service.rb | 37 | ||||
-rw-r--r-- | app/services/ml/experiment_tracking/candidate_repository.rb | 18 | ||||
-rw-r--r-- | app/services/ml/find_or_create_model_version_service.rb | 10 |
6 files changed, 68 insertions, 12 deletions
diff --git a/app/models/commit_status.rb b/app/models/commit_status.rb index 6109ead9865..1695b407daf 100644 --- a/app/models/commit_status.rb +++ b/app/models/commit_status.rb @@ -8,6 +8,18 @@ class CommitStatus < Ci::ApplicationRecord include Presentable include BulkInsertableAssociations include TaggableQueries + include IgnorableColumns + + ignore_columns %i[ + auto_canceled_by_id_convert_to_bigint + commit_id_convert_to_bigint + erased_by_id_convert_to_bigint + project_id_convert_to_bigint + runner_id_convert_to_bigint + trigger_request_id_convert_to_bigint + upstream_pipeline_id_convert_to_bigint + user_id_convert_to_bigint + ], remove_with: '17.0', remove_after: '2024-04-22' self.table_name = :p_ci_builds self.sequence_name = :ci_builds_id_seq diff --git a/app/models/ml/candidate.rb b/app/models/ml/candidate.rb index 6f4728a1d98..70eaab8c0ab 100644 --- a/app/models/ml/candidate.rb +++ b/app/models/ml/candidate.rb @@ -12,12 +12,14 @@ module Ml validates :eid, :experiment, presence: true validates :status, inclusion: { in: statuses.keys } + validates :model_version_id, uniqueness: { allow_nil: true } belongs_to :experiment, class_name: 'Ml::Experiment' belongs_to :user belongs_to :package, class_name: 'Packages::Package' belongs_to :project belongs_to :ci_build, class_name: 'Ci::Build', optional: true + belongs_to :model_version, class_name: 'Ml::ModelVersion', optional: true, inverse_of: :candidate has_many :metrics, class_name: 'Ml::CandidateMetric' has_many :params, class_name: 'Ml::CandidateParam' has_many :metadata, class_name: 'Ml::CandidateMetadata' diff --git a/app/models/ml/model_version.rb b/app/models/ml/model_version.rb index 36272cb33de..ec55fa9e2ed 100644 --- a/app/models/ml/model_version.rb +++ b/app/models/ml/model_version.rb @@ -20,6 +20,7 @@ module Ml belongs_to :model, class_name: 'Ml::Model' belongs_to :project belongs_to :package, class_name: 'Packages::MlModel::Package', optional: true + has_one :candidate, class_name: 'Ml::Candidate' delegate :name, to: :model diff --git a/app/services/ml/create_candidate_service.rb b/app/services/ml/create_candidate_service.rb new file mode 100644 index 00000000000..53913c3fb19 --- /dev/null +++ b/app/services/ml/create_candidate_service.rb @@ -0,0 +1,37 @@ +# frozen_string_literal: true + +module Ml + class CreateCandidateService + def initialize(experiment, params = {}) + @experiment = experiment + @name = params[:name] + @user = params[:user] + @start_time = params[:start_time] + @model_version = params[:model_version] + end + + def execute + Ml::Candidate.create!( + experiment: experiment, + project: experiment.project, + name: candidate_name, + start_time: start_time || 0, + user: user, + model_version: model_version + ) + end + + private + + def candidate_name + name.presence || random_candidate_name + end + + def random_candidate_name + parts = Array.new(3).map { FFaker::Animal.common_name.downcase.delete(' ') } << rand(10000) + parts.join('-').truncate(255) + end + + attr_reader :name, :user, :experiment, :start_time, :model_version + end +end diff --git a/app/services/ml/experiment_tracking/candidate_repository.rb b/app/services/ml/experiment_tracking/candidate_repository.rb index 436f06e3ca5..8739379912a 100644 --- a/app/services/ml/experiment_tracking/candidate_repository.rb +++ b/app/services/ml/experiment_tracking/candidate_repository.rb @@ -15,12 +15,13 @@ module Ml end def create!(experiment, start_time, tags = nil, name = nil) - candidate = experiment.candidates.create!( + create_params = { + start_time: start_time, user: user, - name: candidate_name(name, tags), - project: project, - start_time: start_time || 0 - ) + name: candidate_name(name, tags) + } + + candidate = Ml::CreateCandidateService.new(experiment, create_params).execute add_tags(candidate, tags) @@ -103,17 +104,12 @@ module Ml end def candidate_name(name, tags) - name.presence || candidate_name_from_tags(tags) || random_candidate_name + name.presence || candidate_name_from_tags(tags) end def candidate_name_from_tags(tags) tags&.detect { |t| t[:key] == 'mlflow.runName' }&.dig(:value) end - - def random_candidate_name - parts = Array.new(3).map { FFaker::Animal.common_name.downcase.delete(' ') } << rand(10000) - parts.join('-').truncate(255) - end end 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 index b84c1cec073..cccbe37dbb1 100644 --- a/app/services/ml/find_or_create_model_version_service.rb +++ b/app/services/ml/find_or_create_model_version_service.rb @@ -12,7 +12,15 @@ module Ml def execute model = Ml::FindOrCreateModelService.new(project, name).execute - Ml::ModelVersion.find_or_create!(model, version, package, description) + + model_version = Ml::ModelVersion.find_or_create!(model, version, package, description) + + model_version.candidate = ::Ml::CreateCandidateService.new( + model.default_experiment, + { model_version: model_version } + ).execute + + model_version end private |