Class: Trainers::LoraConfig

Inherits:
Object
  • Object
show all
Defined in:
lib/trainers/lora/lora_config.rb

Constant Summary collapse

DEFAULTS =
{
  r:              8,
  lora_alpha:     16,
  lora_dropout:   0.0,
  target_modules: ["query", "value"],  # or :all_linear
  bias:           :none,               # :none, :all, :lora_only
  task_type:      :sequence_classification
}.freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(**kwargs) ⇒ LoraConfig

Returns a new instance of LoraConfig.



17
18
19
20
21
22
# File 'lib/trainers/lora/lora_config.rb', line 17

def initialize(**kwargs)
  DEFAULTS.each do |key, default|
    value = kwargs.fetch(key, default)
    instance_variable_set(:"@#{key}", value)
  end
end

Instance Attribute Details

#biasObject

Returns the value of attribute bias.



5
6
7
# File 'lib/trainers/lora/lora_config.rb', line 5

def bias
  @bias
end

#lora_alphaObject

Returns the value of attribute lora_alpha.



5
6
7
# File 'lib/trainers/lora/lora_config.rb', line 5

def lora_alpha
  @lora_alpha
end

#lora_dropoutObject

Returns the value of attribute lora_dropout.



5
6
7
# File 'lib/trainers/lora/lora_config.rb', line 5

def lora_dropout
  @lora_dropout
end

#rObject

Returns the value of attribute r.



5
6
7
# File 'lib/trainers/lora/lora_config.rb', line 5

def r
  @r
end

#target_modulesObject

Returns the value of attribute target_modules.



5
6
7
# File 'lib/trainers/lora/lora_config.rb', line 5

def target_modules
  @target_modules
end

#task_typeObject

Returns the value of attribute task_type.



5
6
7
# File 'lib/trainers/lora/lora_config.rb', line 5

def task_type
  @task_type
end

Instance Method Details

#scalingObject



24
25
26
# File 'lib/trainers/lora/lora_config.rb', line 24

def scaling
  @lora_alpha.to_f / @r
end

#to_hObject



28
29
30
31
32
# File 'lib/trainers/lora/lora_config.rb', line 28

def to_h
  DEFAULTS.keys.each_with_object({}) do |key, hash|
    hash[key] = send(key)
  end
end