Class: Torch::TorchRun::Parser
- Inherits:
-
Object
- Object
- Torch::TorchRun::Parser
- Defined in:
- lib/torch/torchrun.rb
Instance Attribute Summary collapse
-
#parser ⇒ Object
readonly
Returns the value of attribute parser.
Instance Method Summary collapse
-
#initialize ⇒ Parser
constructor
A new instance of Parser.
- #parse(argv) ⇒ Object
- #to_s ⇒ Object
Constructor Details
#initialize ⇒ Parser
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
#parser ⇒ Object (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
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) = parser. = "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: #{[:nnodes]})") do |value| [:nnodes] = value end parser.on("--nproc-per-node VALUE", String, "Processes per node (int, gpu, cpu, auto). Default: #{[:nproc_per_node]}") do |value| [:nproc_per_node] = value end parser.on("--node-rank VALUE", Integer, "Rank of the node for multi-node jobs. Default: #{[:node_rank]}") do |value| [:node_rank] = value end parser.on("--rdzv-backend NAME", String, "Rendezvous backend (static or c10d). Default: #{[:rdzv_backend]}") do |value| [:rdzv_backend] = value end parser.on("--rdzv-endpoint HOST[:PORT]", String, "Rendezvous endpoint. Default: use --master-addr/--master-port") do |value| [:rdzv_endpoint] = value end parser.on("--rdzv-id ID", String, "User defined job id. Default: #{[:rdzv_id]}") do |value| [:rdzv_id] = value end parser.on("--rdzv-conf CONF", String, "Additional rendezvous config (k=v,k2=v2)") do |value| [:rdzv_conf] = parse_kv_pairs(value) end parser.on("--standalone", "Start a local rendezvous store on a free port") do [:standalone] = true end parser.on("--max-restarts VALUE", Integer, "Restarts before failing. Default: #{[:max_restarts]}") do |value| [:max_restarts] = value end parser.on("--monitor-interval SECONDS", Float, "Delay between restart attempts. Default: #{[:monitor_interval]}") do |value| [:monitor_interval] = value end parser.on("--role NAME", String, "Role for the worker group. Default: #{[:role]}") do |value| [:role] = value end parser.on("--master-addr HOST", String, "Master address for static rendezvous. Default: #{[:master_addr]}") do |value| [:master_addr] = value end parser.on("--master-port PORT", Integer, "Master port for static rendezvous. Default: #{[:master_port]}") do |value| [:master_port] = value end parser.on("--pass-local-rank-arg", "Append --local-rank to the training script invocation") do [:pass_local_rank_arg] = true end parser.on("--no-ruby", "Execute the training script directly instead of `#{RbConfig.ruby}`") do [: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 [, training_script, rest] end |
#to_s ⇒ Object
104 105 106 |
# File 'lib/torch/torchrun.rb', line 104 def to_s parser.to_s end |