Module: Torch::NN::Utils

Included in:
Functional, Module
Defined in:
lib/torch/nn/utils.rb

Instance Method Summary collapse

Instance Method Details

#_activation_fn(activation) ⇒ Object



28
29
30
31
32
33
34
# File 'lib/torch/nn/utils.rb', line 28

def _activation_fn(activation)
  case activation.to_sym
  when :relu then F.method(:relu)
  when :gelu then F.method(:gelu)
  else raise ArgumentError, "Activation should be relu/gelu, not `#{activation}`"
  end
end

#_clones(mod, n) ⇒ Object



24
25
26
# File 'lib/torch/nn/utils.rb', line 24

def _clones(mod, n)
  ModuleList.new(n.times.map { mod.deep_dup })
end

#_ntuple(n, value) ⇒ Object



20
21
22
# File 'lib/torch/nn/utils.rb', line 20

def _ntuple(n, value)
  value.is_a?(Array) ? value : [value] * n
end

#_pair(value) ⇒ Object



8
9
10
# File 'lib/torch/nn/utils.rb', line 8

def _pair(value)
  _ntuple(2, value)
end

#_quadrupal(value) ⇒ Object



16
17
18
# File 'lib/torch/nn/utils.rb', line 16

def _quadrupal(value)
  _ntuple(4, value)
end

#_single(value) ⇒ Object



4
5
6
# File 'lib/torch/nn/utils.rb', line 4

def _single(value)
  _ntuple(1, value)
end

#_triple(value) ⇒ Object



12
13
14
# File 'lib/torch/nn/utils.rb', line 12

def _triple(value)
  _ntuple(3, value)
end