Class: OCI::GenerativeAi::Models::TrainingConfig

Inherits:
Object
  • Object
show all
Defined in:
lib/oci/generative_ai/models/training_config.rb

Overview

The fine-tuning method and hyperparameters used for fine-tuning a custom model. This class has direct subclasses. If you are using this class as input to a service operations then you should favor using a subclass over the base class

Direct Known Subclasses

TFewTrainingConfig, VanillaTrainingConfig

Constant Summary collapse

TRAINING_CONFIG_TYPE_ENUM =
[
  TRAINING_CONFIG_TYPE_TFEW_TRAINING_CONFIG = 'TFEW_TRAINING_CONFIG'.freeze,
  TRAINING_CONFIG_TYPE_VANILLA_TRAINING_CONFIG = 'VANILLA_TRAINING_CONFIG'.freeze,
  TRAINING_CONFIG_TYPE_UNKNOWN_ENUM_VALUE = 'UNKNOWN_ENUM_VALUE'.freeze
].freeze

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(attributes = {}) ⇒ TrainingConfig

Initializes the object

Parameters:

  • attributes (Hash) (defaults to: {})

    Model attributes in the form of hash

Options Hash (attributes):



110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
# File 'lib/oci/generative_ai/models/training_config.rb', line 110

def initialize(attributes = {})
  return unless attributes.is_a?(Hash)

  # convert string to symbol for hash key
  attributes = attributes.each_with_object({}) { |(k, v), h| h[k.to_sym] = v }

  self.training_config_type = attributes[:'trainingConfigType'] if attributes[:'trainingConfigType']
  self.training_config_type = "TFEW_TRAINING_CONFIG" if training_config_type.nil? && !attributes.key?(:'trainingConfigType') # rubocop:disable Style/StringLiterals

  raise 'You cannot provide both :trainingConfigType and :training_config_type' if attributes.key?(:'trainingConfigType') && attributes.key?(:'training_config_type')

  self.training_config_type = attributes[:'training_config_type'] if attributes[:'training_config_type']
  self.training_config_type = "TFEW_TRAINING_CONFIG" if training_config_type.nil? && !attributes.key?(:'trainingConfigType') && !attributes.key?(:'training_config_type') # rubocop:disable Style/StringLiterals

  self.total_training_epochs = attributes[:'totalTrainingEpochs'] if attributes[:'totalTrainingEpochs']

  raise 'You cannot provide both :totalTrainingEpochs and :total_training_epochs' if attributes.key?(:'totalTrainingEpochs') && attributes.key?(:'total_training_epochs')

  self.total_training_epochs = attributes[:'total_training_epochs'] if attributes[:'total_training_epochs']

  self.learning_rate = attributes[:'learningRate'] if attributes[:'learningRate']

  raise 'You cannot provide both :learningRate and :learning_rate' if attributes.key?(:'learningRate') && attributes.key?(:'learning_rate')

  self.learning_rate = attributes[:'learning_rate'] if attributes[:'learning_rate']

  self.training_batch_size = attributes[:'trainingBatchSize'] if attributes[:'trainingBatchSize']

  raise 'You cannot provide both :trainingBatchSize and :training_batch_size' if attributes.key?(:'trainingBatchSize') && attributes.key?(:'training_batch_size')

  self.training_batch_size = attributes[:'training_batch_size'] if attributes[:'training_batch_size']

  self.early_stopping_patience = attributes[:'earlyStoppingPatience'] if attributes[:'earlyStoppingPatience']

  raise 'You cannot provide both :earlyStoppingPatience and :early_stopping_patience' if attributes.key?(:'earlyStoppingPatience') && attributes.key?(:'early_stopping_patience')

  self.early_stopping_patience = attributes[:'early_stopping_patience'] if attributes[:'early_stopping_patience']

  self.early_stopping_threshold = attributes[:'earlyStoppingThreshold'] if attributes[:'earlyStoppingThreshold']

  raise 'You cannot provide both :earlyStoppingThreshold and :early_stopping_threshold' if attributes.key?(:'earlyStoppingThreshold') && attributes.key?(:'early_stopping_threshold')

  self.early_stopping_threshold = attributes[:'early_stopping_threshold'] if attributes[:'early_stopping_threshold']

  self.log_model_metrics_interval_in_steps = attributes[:'logModelMetricsIntervalInSteps'] if attributes[:'logModelMetricsIntervalInSteps']

  raise 'You cannot provide both :logModelMetricsIntervalInSteps and :log_model_metrics_interval_in_steps' if attributes.key?(:'logModelMetricsIntervalInSteps') && attributes.key?(:'log_model_metrics_interval_in_steps')

  self.log_model_metrics_interval_in_steps = attributes[:'log_model_metrics_interval_in_steps'] if attributes[:'log_model_metrics_interval_in_steps']
end

Instance Attribute Details

#early_stopping_patienceInteger

Stop training if the loss metric does not improve beyond 'early_stopping_threshold' for this many times of evaluation.

Returns:

  • (Integer)


38
39
40
# File 'lib/oci/generative_ai/models/training_config.rb', line 38

def early_stopping_patience
  @early_stopping_patience
end

#early_stopping_thresholdFloat

How much the loss must improve to prevent early stopping.

Returns:

  • (Float)


42
43
44
# File 'lib/oci/generative_ai/models/training_config.rb', line 42

def early_stopping_threshold
  @early_stopping_threshold
end

#learning_rateFloat

The initial learning rate to be used during training

Returns:

  • (Float)


29
30
31
# File 'lib/oci/generative_ai/models/training_config.rb', line 29

def learning_rate
  @learning_rate
end

#log_model_metrics_interval_in_stepsInteger

Determines how frequently to log model metrics.

Every step is logged for the first 20 steps and then follows this parameter for log frequency. Set to 0 to disable logging the model metrics.

Returns:

  • (Integer)


49
50
51
# File 'lib/oci/generative_ai/models/training_config.rb', line 49

def log_model_metrics_interval_in_steps
  @log_model_metrics_interval_in_steps
end

#total_training_epochsInteger

The maximum number of training epochs to run for.

Returns:

  • (Integer)


25
26
27
# File 'lib/oci/generative_ai/models/training_config.rb', line 25

def total_training_epochs
  @total_training_epochs
end

#training_batch_sizeInteger

The batch size used during training.

Returns:

  • (Integer)


33
34
35
# File 'lib/oci/generative_ai/models/training_config.rb', line 33

def training_batch_size
  @training_batch_size
end

#training_config_typeString

[Required] The fine-tuning method for training a custom model.

Returns:

  • (String)


21
22
23
# File 'lib/oci/generative_ai/models/training_config.rb', line 21

def training_config_type
  @training_config_type
end

Class Method Details

.attribute_mapObject

Attribute mapping from ruby-style variable name to JSON key.



52
53
54
55
56
57
58
59
60
61
62
63
64
# File 'lib/oci/generative_ai/models/training_config.rb', line 52

def self.attribute_map
  {
    # rubocop:disable Style/SymbolLiteral
    'training_config_type': :'trainingConfigType',
    'total_training_epochs': :'totalTrainingEpochs',
    'learning_rate': :'learningRate',
    'training_batch_size': :'trainingBatchSize',
    'early_stopping_patience': :'earlyStoppingPatience',
    'early_stopping_threshold': :'earlyStoppingThreshold',
    'log_model_metrics_interval_in_steps': :'logModelMetricsIntervalInSteps'
    # rubocop:enable Style/SymbolLiteral
  }
end

.get_subtype(object_hash) ⇒ Object

Given the hash representation of a subtype of this class, use the info in the hash to return the class of the subtype.



86
87
88
89
90
91
92
93
94
# File 'lib/oci/generative_ai/models/training_config.rb', line 86

def self.get_subtype(object_hash)
  type = object_hash[:'trainingConfigType'] # rubocop:disable Style/SymbolLiteral

  return 'OCI::GenerativeAi::Models::VanillaTrainingConfig' if type == 'VANILLA_TRAINING_CONFIG'
  return 'OCI::GenerativeAi::Models::TFewTrainingConfig' if type == 'TFEW_TRAINING_CONFIG'

  # TODO: Log a warning when the subtype is not found.
  'OCI::GenerativeAi::Models::TrainingConfig'
end

.swagger_typesObject

Attribute type mapping.



67
68
69
70
71
72
73
74
75
76
77
78
79
# File 'lib/oci/generative_ai/models/training_config.rb', line 67

def self.swagger_types
  {
    # rubocop:disable Style/SymbolLiteral
    'training_config_type': :'String',
    'total_training_epochs': :'Integer',
    'learning_rate': :'Float',
    'training_batch_size': :'Integer',
    'early_stopping_patience': :'Integer',
    'early_stopping_threshold': :'Float',
    'log_model_metrics_interval_in_steps': :'Integer'
    # rubocop:enable Style/SymbolLiteral
  }
end

Instance Method Details

#==(other) ⇒ Object

Checks equality by comparing each attribute.

Parameters:

  • other (Object)

    the other object to be compared



181
182
183
184
185
186
187
188
189
190
191
192
# File 'lib/oci/generative_ai/models/training_config.rb', line 181

def ==(other)
  return true if equal?(other)

  self.class == other.class &&
    training_config_type == other.training_config_type &&
    total_training_epochs == other.total_training_epochs &&
    learning_rate == other.learning_rate &&
    training_batch_size == other.training_batch_size &&
    early_stopping_patience == other.early_stopping_patience &&
    early_stopping_threshold == other.early_stopping_threshold &&
    log_model_metrics_interval_in_steps == other.log_model_metrics_interval_in_steps
end

#build_from_hash(attributes) ⇒ Object

Builds the object from hash

Parameters:

  • attributes (Hash)

    Model attributes in the form of hash

Returns:

  • (Object)

    Returns the model itself



217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
# File 'lib/oci/generative_ai/models/training_config.rb', line 217

def build_from_hash(attributes)
  return nil unless attributes.is_a?(Hash)

  self.class.swagger_types.each_pair do |key, type|
    if type =~ /^Array<(.*)>/i
      # check to ensure the input is an array given that the the attribute
      # is documented as an array but the input is not
      if attributes[self.class.attribute_map[key]].is_a?(Array)
        public_method("#{key}=").call(
          attributes[self.class.attribute_map[key]]
            .map { |v| OCI::Internal::Util.convert_to_type(Regexp.last_match(1), v) }
        )
      end
    elsif !attributes[self.class.attribute_map[key]].nil?
      public_method("#{key}=").call(
        OCI::Internal::Util.convert_to_type(type, attributes[self.class.attribute_map[key]])
      )
    end
    # or else data not found in attributes(hash), not an issue as the data can be optional
  end

  self
end

#eql?(other) ⇒ Boolean

Parameters:

  • other (Object)

    the other object to be compared

Returns:

  • (Boolean)

See Also:

  • `==` method


197
198
199
# File 'lib/oci/generative_ai/models/training_config.rb', line 197

def eql?(other)
  self == other
end

#hashFixnum

Calculates hash code according to all attributes.

Returns:

  • (Fixnum)

    Hash code



206
207
208
# File 'lib/oci/generative_ai/models/training_config.rb', line 206

def hash
  [training_config_type, total_training_epochs, learning_rate, training_batch_size, early_stopping_patience, early_stopping_threshold, log_model_metrics_interval_in_steps].hash
end

#to_hashHash

Returns the object in the form of hash

Returns:

  • (Hash)

    Returns the object in the form of hash



250
251
252
253
254
255
256
257
258
259
# File 'lib/oci/generative_ai/models/training_config.rb', line 250

def to_hash
  hash = {}
  self.class.attribute_map.each_pair do |attr, param|
    value = public_method(attr).call
    next if value.nil? && !instance_variable_defined?("@#{attr}")

    hash[param] = _to_hash(value)
  end
  hash
end

#to_sString

Returns the string representation of the object

Returns:

  • (String)

    String presentation of the object



244
245
246
# File 'lib/oci/generative_ai/models/training_config.rb', line 244

def to_s
  to_hash.to_s
end