Class: Torch::TorchRun::Parser

Inherits:
Object
  • Object
show all
Defined in:
lib/torch/torchrun.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeParser

Returns a new instance of Parser.



21
22
23
# File 'lib/torch/torchrun.rb', line 21

def initialize
  @parser = OptionParser.new
end

Instance Attribute Details

#parserObject (readonly)

Returns the value of attribute parser.



19
20
21
# File 'lib/torch/torchrun.rb', line 19

def parser
  @parser
end

Instance Method Details

#parse(argv) ⇒ Object

Raises:

  • (OptionParser::MissingArgument)


25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
# File 'lib/torch/torchrun.rb', line 25

def parse(argv)
  options = default_options

  parser.banner = "Usage: torchrun [options] TRAINING_SCRIPT [script args]"
  parser.separator ""
  parser.separator "Launch parameters:"

  parser.on("--nnodes MIN[:MAX]", String, "Number of nodes or range (default: #{options[:nnodes]})") do |value|
    options[:nnodes] = value
  end

  parser.on("--nproc-per-node VALUE", String, "Processes per node (int, gpu, cpu, auto). Default: #{options[:nproc_per_node]}") do |value|
    options[:nproc_per_node] = value
  end

  parser.on("--node-rank VALUE", Integer, "Rank of the node for multi-node jobs. Default: #{options[:node_rank]}") do |value|
    options[:node_rank] = value
  end

  parser.on("--rdzv-backend NAME", String, "Rendezvous backend (static or c10d). Default: #{options[:rdzv_backend]}") do |value|
    options[:rdzv_backend] = value
  end

  parser.on("--rdzv-endpoint HOST[:PORT]", String, "Rendezvous endpoint. Default: use --master-addr/--master-port") do |value|
    options[:rdzv_endpoint] = value
  end

  parser.on("--rdzv-id ID", String, "User defined job id. Default: #{options[:rdzv_id]}") do |value|
    options[:rdzv_id] = value
  end

  parser.on("--rdzv-conf CONF", String, "Additional rendezvous config (k=v,k2=v2)") do |value|
    options[:rdzv_conf] = parse_kv_pairs(value)
  end

  parser.on("--standalone", "Start a local rendezvous store on a free port") do
    options[:standalone] = true
  end

  parser.on("--max-restarts VALUE", Integer, "Restarts before failing. Default: #{options[:max_restarts]}") do |value|
    options[:max_restarts] = value
  end

  parser.on("--monitor-interval SECONDS", Float, "Delay between restart attempts. Default: #{options[:monitor_interval]}") do |value|
    options[:monitor_interval] = value
  end

  parser.on("--role NAME", String, "Role for the worker group. Default: #{options[:role]}") do |value|
    options[:role] = value
  end

  parser.on("--master-addr HOST", String, "Master address for static rendezvous. Default: #{options[:master_addr]}") do |value|
    options[:master_addr] = value
  end

  parser.on("--master-port PORT", Integer, "Master port for static rendezvous. Default: #{options[:master_port]}") do |value|
    options[:master_port] = value
  end

  parser.on("--pass-local-rank-arg", "Append --local-rank to the training script invocation") do
    options[:pass_local_rank_arg] = true
  end

  parser.on("--no-ruby", "Execute the training script directly instead of `#{RbConfig.ruby}`") do
    options[:no_ruby] = true
  end

  parser.on("-h", "--help", "Prints this help") do
    puts parser
    exit
  end

  rest = parser.parse!(argv)
  raise OptionParser::MissingArgument, "training_script" if rest.empty?

  training_script = rest.shift
  [options, training_script, rest]
end

#to_sObject



104
105
106
# File 'lib/torch/torchrun.rb', line 104

def to_s
  parser.to_s
end