cnvrg 0.0.14254 → 0.0.14256

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: c569282c58ef4a5a88ba3f62190a2640bdf4e00f
4
- data.tar.gz: a9f9f19980dec4fa966f79a2116646f35571683d
3
+ metadata.gz: e16a2aac3b10ceece9436b1d704e614bf03fbec0
4
+ data.tar.gz: fcdb72eb0cd3da08bef8b8baa84e15ae74137a0e
5
5
  SHA512:
6
- metadata.gz: cfe491fa37c5830b7930afc840127ba45b223298fda50c975180422b3b41916004a87d600c7efde36bdd574ea3edafee7690240775c75074df4f87cf95ea30c3
7
- data.tar.gz: 70ef2d66fcee9c0f718b347b651ba7a066191910ddbf9f0028042949ee98d528630b005ca58919de2995baa079c07e8de0ceb171ce5ed7b0b6f271e255465977
6
+ metadata.gz: 71d7e5bfe772ff2265f84c25063323656e50e37c3357d531a9b0372ad3af05d4f6a3045f5d909d052f69dcc412957f3becddf83ec7d4acc5ff12693c29100108
7
+ data.tar.gz: 23cf4218ff64a183ca9da4c2e51c94c0cc0f3b17ebfd274c9663d286c03c6a1035b3d6eb5f2757ed5d6ad4624462a1a21fa30ec1e698de01ceefc2a100f801ae
data/lib/cnvrg/cli.rb CHANGED
@@ -35,7 +35,6 @@ require 'thor'
35
35
  require 'pathname'
36
36
  require 'enumerator'
37
37
 
38
-
39
38
  class Thor
40
39
  module Base
41
40
  def initialize(args = [], local_options = {}, config = {})
@@ -2194,6 +2193,8 @@ module Cnvrg
2194
2193
  method_option :data, :type => :string, :aliases => ["-d", "--data"], :default => ""
2195
2194
  method_option :data_commit, :type => :string, :aliases => ["-dc", "--data_commit"], :default => ""
2196
2195
  method_option :ignore, :type => :string, :aliases => ["-i", "--ignore"], :desc => "ignore following files", :default => ""
2196
+ method_option :remote, :type => :boolean, :aliases => ["--remote"], :default => false
2197
+ method_option :gpu, :type => :boolean, :aliases => ["--gpu"], :default => false
2197
2198
  def exec(*cmd)
2198
2199
 
2199
2200
  log = []
@@ -2260,6 +2261,12 @@ module Cnvrg
2260
2261
  exit(0)
2261
2262
  end
2262
2263
  end
2264
+ remote = options["remote"]
2265
+ if remote
2266
+ docker_id = `cat /etc/hostname`
2267
+ docker_id = docker_id.strip()
2268
+ end
2269
+ is_on_gpu = options["gpu"]
2263
2270
  start_commit = @project.last_local_commit
2264
2271
  cmd = cmd.join("\s")
2265
2272
 
@@ -2283,19 +2290,34 @@ module Cnvrg
2283
2290
  begin
2284
2291
  stdout.each do |line|
2285
2292
  cur_time = Time.now
2286
- monitor = %x{ps aux|awk '{print $2,$3,$4}'|grep #{pid} }
2287
- monitor_by = monitor.split(" ")
2288
- memory = monitor_by[2]
2289
- cpu = monitor_by[1]
2293
+ if remote
2294
+ stats = usage_metrics_in_docker(docker_id)
2295
+ cpu = stats[0]
2296
+ memory = stats[1]
2297
+ else
2298
+ memory = memory_usage()
2299
+ cpu = cpu_usage()
2300
+ end
2301
+
2290
2302
  memory_total << memory.to_f
2291
2303
  cpu_total << cpu.to_f
2292
2304
  real_time= Time.now-real
2293
2305
 
2294
- cur_log = {time: cur_time,
2306
+ cur_log = { time: cur_time,
2295
2307
  message: line,
2296
2308
  type: "stdout",
2297
- real: real_time}
2298
- if print_log
2309
+ real: real_time,
2310
+ cpu: cpu,
2311
+ memory: memory
2312
+ }
2313
+ if is_on_gpu
2314
+ gpu_stats = gpu_util
2315
+ gpu_utilization = gpu_stats[0]
2316
+ gpu_memory_util = gpu_stats[1]
2317
+ cur_log.merge!(gpu_util:gpu_utilization,gpu_memory_util:gpu_memory_util)
2318
+ end
2319
+
2320
+ if print_log
2299
2321
  puts cur_log
2300
2322
  end
2301
2323
  log << cur_log
@@ -2304,8 +2326,8 @@ module Cnvrg
2304
2326
  if time_to_upload !=0
2305
2327
  if time_to_upload <= Time.now - start_loop
2306
2328
  #upload current log
2307
- cpu_average = cpu_total.inject(0) { |sum, el| sum + el }.to_f / cpu_total.size
2308
- memory_average = memory_total.inject(0) { |sum, el| sum + el }.to_f / memory_total.size
2329
+ # cpu_average = cpu_total.inject(0) { |sum, el| sum + el }.to_f / cpu_total.size
2330
+ # memory_average = memory_total.inject(0) { |sum, el| sum + el }.to_f / memory_total.size
2309
2331
 
2310
2332
  @exp.upload_temp_log(log, cpu_average, memory_average)
2311
2333
  log = []
@@ -2621,8 +2643,7 @@ module Cnvrg
2621
2643
  method_option :data_commit, :type => :string, :aliases => ["--data_commit"], :default => ""
2622
2644
  method_option :ignore, :type => :string, :aliases => ["-i", "--ignore"], :desc => "ignore following files", :default => ""
2623
2645
 
2624
- def
2625
- exec_remote(*cmd)
2646
+ def exec_remote(*cmd)
2626
2647
  verify_logged_in(true)
2627
2648
  log_start(__method__, args, options)
2628
2649
  working_dir = is_cnvrg_dir
@@ -2661,10 +2682,15 @@ module Cnvrg
2661
2682
  else
2662
2683
  upload_output_option = "--upload_output=#{upload_output}"
2663
2684
  end
2685
+ remote = "--remote=true"
2686
+ if !instance_type.nil? and instance_type.include? "gpu"
2687
+ remote= "#{remote} --gpu=true"
2688
+ end
2689
+
2664
2690
  options_hash = Hash[options]
2665
2691
  options_hash.except!("schedule", "machine_type", "image", "upload_output", "grid", "data", "data_commit", "local", "small", "medium", "large", "gpu", "gpuxl", "gpuxxl")
2666
2692
  exec_options = options_hash.map { |x| "--#{x[0]}=#{x[1]}" }.flatten.join(" ")
2667
- command = "#{exec_options} #{upload_output_option} #{cmd.flatten.join(" ")}"
2693
+ command = "#{exec_options} #{remote} #{upload_output_option} #{cmd.flatten.join(" ")}"
2668
2694
  commit_to_run = options["commit"] || nil
2669
2695
  if !schedule.nil? and !schedule.empty?
2670
2696
 
@@ -3853,6 +3879,7 @@ module Cnvrg
3853
3879
  '8888/tcp' => {},
3854
3880
  },
3855
3881
  'HostConfig' => {
3882
+ 'Binds'=> ["/var/run/docker.sock:/var/run/docker.sock","/usr/bin/docker:/usr/bin/docker" ],
3856
3883
  'PortBindings' => {
3857
3884
  '8888/tcp' => [
3858
3885
  {'HostPort' => "#{port}", 'HostIp' => 'localhost'}
@@ -3877,6 +3904,7 @@ module Cnvrg
3877
3904
  container.exec(command, tty: true)
3878
3905
  say "#{container.id}:#{port}##{tensport}"
3879
3906
  rescue => e
3907
+ puts e
3880
3908
  if e.message.include? "is not running"
3881
3909
  return config_remote(image_name, port-1, tensport-1)
3882
3910
  end
@@ -3947,7 +3975,7 @@ module Cnvrg
3947
3975
  # },
3948
3976
  # }
3949
3977
 
3950
- container_id = `nvidia-docker run -itd -p #{port}:8888 -p #{tensport}:6006 -w #{app_dir} -v /usr/bin/nvidia-smi:/usr/bin/nvidia-smi #{image_name}:latest #{cmd} `
3978
+ container_id = `nvidia-docker run -itd -p #{port}:8888 -p #{tensport}:6006 -w #{app_dir} -v /usr/bin/nvidia-smi:/usr/bin/nvidia-smi -v /var/run/docker.sock:/var/run/docker.sock -v /usr/bin/docker:/usr/bin/docker #{image_name}:latest #{cmd} `
3951
3979
  container_id = container_id.gsub("\n", "")
3952
3980
  container = Docker::Container.get(container_id)
3953
3981
  # container.start()
@@ -4445,11 +4473,10 @@ module Cnvrg
4445
4473
  url = "https://cnvrg.io/api"
4446
4474
  end
4447
4475
  config = YAML.load_file(home_dir+"/.cnvrg/config.yml")
4448
-
4449
4476
  compression_path = "#{home_dir}/.cnvrg/tmp"
4450
- if config and !config.nil? and !config.empty? and !config.to_h[:compression_path].nil?
4451
- compression_path = config.to_h[:compression_path]
4452
- end
4477
+ if config and !config.nil? and !config.empty? and !config.to_h[:compression_path].nil?
4478
+ compression_path = config.to_h[:compression_path]
4479
+ end
4453
4480
  config = {owner: owner, username: username, version_last_check: get_start_day(), api: url,compression_path:compression_path}
4454
4481
 
4455
4482
  File.open(home_dir+"/.cnvrg/config.yml", "w+") { |f| f.write config.to_yaml }
@@ -4504,7 +4531,7 @@ module Cnvrg
4504
4531
 
4505
4532
  def log_end(exit_status=0, error=nil)
4506
4533
  begin
4507
- if exit_status==1
4534
+ if exit_status != 0
4508
4535
  $LOG.error exit_status: exit_status, error: error
4509
4536
  else
4510
4537
  $LOG.info exit_status: exit_status
@@ -4932,6 +4959,76 @@ module Cnvrg
4932
4959
  def extarct_tar(file_path, dir_path)
4933
4960
  `tar -xvf #{file_path} -C #{dir_path} > /dev/null 2>&1`
4934
4961
  return $?.success?
4962
+ end
4963
+ def cpu_usage
4964
+ cpu_usage = 0.0
4965
+ begin
4966
+ cpu = `top b -n 2 -d 2 |grep %Cpu |tail -1 |awk '{print $2+$3}'`
4967
+ if !cpu.nil?
4968
+ cpu_usage = cpu.to_f
4969
+ end
4970
+ rescue
4971
+ cpu_usage = 0.0
4972
+ end
4973
+
4974
+ return cpu_usage
4975
+ end
4976
+ def memory_usage
4977
+ prec = 0.0
4978
+ begin
4979
+ used = `free -mt |grep Mem: |awk '{print $3}'`
4980
+ total = `free -mt |grep Mem: |awk '{print $2}'`
4981
+
4982
+ used_f = used.to_f if !used.nil?
4983
+ total_f = total.to_f if !total.nil?
4984
+ prec = (used_f / total_f)*100
4985
+ prec = prec.round(2)
4986
+ rescue
4987
+ prec = 0.0
4988
+ end
4989
+ return prec
4990
+
4991
+
4992
+ end
4993
+ def gpu_util
4994
+ gpu = [0.0, 0.0]
4995
+ begin
4996
+ gpu_stats = `nvidia-smi --query-gpu=utilization.gpu,utilization.memory --format=csv |tail -1`
4997
+
4998
+ if !gpu_stats.nil?
4999
+ gpu = gpu_stats.strip
5000
+ gpu = gpu_stats.gsub!("%","").split(",")
5001
+ gpu[0] = gpu[0].to_f
5002
+ gpu[1] = gpu[1].to_f
5003
+ return gpu
5004
+ end
5005
+
5006
+ rescue
5007
+ return gpu
5008
+ end
5009
+
5010
+
5011
+ end
5012
+ def usage_metrics_in_docker(docker_id)
5013
+ begin
5014
+ if docker_id.nil?
5015
+ docker_id = `cat /etc/hostname`
5016
+ end
5017
+ stats = `sudo docker stats #{docker_id} --no-stream |tail -1 | awk '{print $2,$8}'`
5018
+ if !stats.nil?
5019
+ conv = stats.gsub!("%","").split(" ")
5020
+ cpu = conv[0].to_f
5021
+ memory = conv[1].to_f
5022
+ return [cpu,memory]
5023
+ end
5024
+
5025
+
5026
+ rescue
5027
+ return [0.0,0.0]
5028
+ end
5029
+
5030
+
5031
+
4935
5032
  end
4936
5033
 
4937
5034
  def with_progress_bar
@@ -92,8 +92,7 @@ module Cnvrg
92
92
 
93
93
  def upload_temp_log(temp_log, cpu_average, memory_average)
94
94
  response = Cnvrg::API.request(@base_resource + "experiment/upload_temp_log", 'POST', {output: temp_log,
95
- exp_slug: @slug, cpu_average: cpu_average,
96
- memory_average: memory_average})
95
+ exp_slug: @slug})
97
96
  Cnvrg::CLI.is_response_success(response,false)
98
97
  end
99
98
 
data/lib/cnvrg/version.rb CHANGED
@@ -1,4 +1,5 @@
1
1
  module Cnvrg
2
- VERSION = '0.0.14254'
2
+ VERSION = '0.0.14256'
3
+
3
4
  end
4
5
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: cnvrg
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.14254
4
+ version: 0.0.14256
5
5
  platform: ruby
6
6
  authors:
7
7
  - Yochay Ettun
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2017-07-03 00:00:00.000000000 Z
12
+ date: 2017-07-06 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: bundler
@@ -373,9 +373,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
373
373
  version: '0'
374
374
  requirements: []
375
375
  rubyforge_project:
376
- rubygems_version: 2.5.1
376
+ rubygems_version: 2.6.12
377
377
  signing_key:
378
378
  specification_version: 4
379
379
  summary: A CLI tool for interacting with cnvrg.io.
380
380
  test_files: []
381
- has_rdoc: