Advertisement
Guest User

Untitled

a guest
Oct 28th, 2015
132
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 7.58 KB | None | 0 0
  1. # ======================================================================
  2. # Library:
  3. # ======================================================================
  4.  
  5. from __future__ import print_function, division
  6.  
  7. import os
  8. import sys
  9.  
  10. import argparse
  11. import math
  12.  
  13. # ======================================================================
  14. # SLURM creator
  15. # ======================================================================
  16. def create_slurm_gpu(task_name, duration, delay, mem, script):
  17.     '''
  18.     THEANO_FLAGS=mode=FAST_RUN,device=gpu,floatX=float32 python $HOME/appl_taito/src/nist_lre15/models1.py model3 set03
  19.     script = [[path, params ...], [path, params ...]]
  20.     '''
  21.     hour = int(math.floor(duration / 60))
  22.     minute = duration - hour * 60
  23.     log_path = task_name + '.out'
  24.     task_name = task_name
  25.     mem = int(mem)
  26.  
  27.     if not (isinstance(script[0], list) or isinstance(script[0], tuple)):
  28.         script = [script]
  29.     running_prefix = 'THEANO_FLAGS=mode=FAST_RUN,device=gpu,floatX=float32 python '
  30.     running_script = ''
  31.     for s in script:
  32.         running_script += running_prefix
  33.         running_script += s[0] + ' ' # path to script
  34.         running_script += ' '.join([str(p) for p in s[1:]])
  35.         running_script += ';'
  36.     running_script = running_script[:-1]
  37.  
  38.     arch = 'gpu'
  39.     if hour == 0 and minute <= 15:
  40.         arch = 'gputest'
  41.  
  42.     slurm_text = \
  43. """#!/bin/bash
  44. # author: trungnt
  45. #SBATCH -N 1
  46. #SBATCH -p %s
  47. #SBATCH -t %02d:%02d:00
  48. #SBATCH --begin=now+%dminute
  49. #SBATCH -J %s
  50. #SBATCH -o log/%s
  51. #SBATCH -e log/%s
  52. #SBATCH --mem=%d
  53. #SBATCH --gres=gpu:1
  54. #SBATCH --mail-type=FAIL,END # Type of email notification- BEGIN,END,FAIL,ALL
  55. #SBATCH --mail-user=anonymouswork90@gmail.com # Email to which notifications will be sent
  56. #SBATCH
  57.  
  58. source $HOME/a7dea06c655dcec82784/modules
  59. source $HOME/.env/ai/bin/activate
  60.  
  61. # run your script
  62. %s
  63.  
  64. deactivate
  65. """
  66.     # SBATCH --exclusive
  67.     slurm_text = slurm_text % (arch, hour, minute, delay, task_name, log_path, log_path, mem, running_script)
  68.     f = open('tmp_train_gpu.slurm', 'w')
  69.     f.write(slurm_text)
  70.     f.close()
  71.     os.system('sbatch tmp_train_gpu.slurm')
  72.     os.remove('tmp_train_gpu.slurm')
  73.     return slurm_text
  74.  
  75. def create_slurm_cpu(task_name, duration, delay, nb_core, mem, script):
  76.     '''
  77.     THEANO_FLAGS=mode=FAST_RUN,device=gpu,floatX=float32 python $HOME/appl_taito/src/nist_lre15/models1.py model3 set03
  78.     '''
  79.     hour = int(math.floor(duration / 60))
  80.     minute = duration - hour * 60
  81.     log_path = task_name + '.out'
  82.     task_name = task_name
  83.     nb_core = int(nb_core)
  84.     mem = int(mem / float(nb_core))
  85.  
  86.     if not (isinstance(script[0], list) or isinstance(script[0], tuple)):
  87.         script = [script]
  88.     running_prefix = 'python '
  89.     running_script = ''
  90.     for s in script:
  91.         running_script += running_prefix
  92.         running_script += s[0] + ' ' # path to script
  93.         running_script += ' '.join([str(p) for p in s[1:]])
  94.         running_script += ';'
  95.     running_script = running_script[:-1]
  96.  
  97.     slurm_text = \
  98. """#!/bin/bash
  99. # author: trungnt
  100. #SBATCH -N 1
  101. #SBATCH -t %02d:%02d:00
  102. #SBATCH --begin=now+%dminute
  103. #SBATCH -J %s
  104. #SBATCH -o log/%s
  105. #SBATCH -e log/%s
  106. #SBATCH --constraint="snb|hsw"
  107. #SBATCH -p parallel
  108. #SBATCH -n %d
  109. #SBATCH --mem-per-cpu=%d
  110. #SBATCH --mail-type=FAIL,END
  111. #SBATCH --mail-user=anonymouswork90@gmail.com
  112.  
  113. source $HOME/a7dea06c655dcec82784/modules
  114. source $HOME/.env/ai/bin/activate
  115.  
  116. # run your script
  117. %s
  118.  
  119. deactivate
  120. """
  121.     slurm_text = slurm_text % (hour, minute, delay, task_name, log_path, log_path, nb_core, mem, running_script)
  122.     f = open('tmp_train_cpu.slurm', 'w')
  123.     f.write(slurm_text)
  124.     f.close()
  125.     os.system('sbatch tmp_train_cpu.slurm')
  126.     os.remove('tmp_train_cpu.slurm')
  127.     return slurm_text
  128.  
  129. # ======================================================================
  130. # model
  131. # ======================================================================
  132. def slurm_parser():
  133.     parser = argparse.ArgumentParser(
  134.         description='Science the sh*t out of Deep Learning!',
  135.         version='0.1',
  136.         formatter_class=argparse.RawDescriptionHelpFormatter,
  137.         add_help=True)
  138.     # ====== SLURM group ====== #
  139.     group = parser.add_argument_group('SLURM Configuration')
  140.  
  141.     group.add_argument('-t', action='store', type=str, default='AIgenJOB',
  142.             metavar='str',
  143.             help='Title for SLURM job')
  144.     group.add_argument('-d', action='store', type=int, required=True,
  145.             metavar='int',
  146.             help='Duration of running task in minute')
  147.     group.add_argument('-w', action='store', type=int, default=0,
  148.             metavar='int',
  149.             help='Run the task after minutes, default=0')
  150.  
  151.     group.add_argument('-p', action='store', choices=('gpu', 'cpu'), default = 'gpu',
  152.             metavar='cpu|gpu',
  153.             help='run the task on GPU or CPU, default=gpu')
  154.     group.add_argument('-m', action='store', type=int, default = 12000,
  155.             metavar='int',
  156.             help='memory for the job, default=12000 MB')
  157.     group.add_argument('-np', action='store', type=int, default = 8,
  158.             metavar='int',
  159.             help='Number of core for CPU task')
  160.  
  161.     group.add_argument('-f', action='append', required=True, nargs='+',
  162.             metavar='list',
  163.             help='path to python script & its arguments (e.g. script.py arg1 arg2 ...)')
  164.  
  165.     return parser
  166.  
  167. # python runner.py -t MFCC -d 30 -p cpu -m 16000 -np 8 -f feature_extract.py set01.dat 10 20 10 2500 8
  168. if __name__ == '__main__':
  169.     parser = slurm_parser()
  170.     if len(sys.argv) > 1:
  171.  
  172.         results = parser.parse_args()
  173.  
  174.         if results.p == 'gpu':
  175.             s = create_slurm_gpu(results.t, results.d, results.w, results.m, results.f)
  176.             print(s)
  177.         elif results.p == 'cpu':
  178.             s = create_slurm_cpu(results.t, results.d, results.w, results.np, results.m, results.f)
  179.             print(s)
  180.         else:
  181.             parser.print_help()
  182.     else:
  183.         parser.print_help()
  184.  
  185.  
  186. # python runner.py -t 3c52020mfcc  -d 4320 -m 15000 -f model_runner.py m3c 5_20_20_mfcc_set01
  187. # python runner.py -t 3c52010mfcc  -d 4320 -m 15000 -f model_runner.py m3c 5_20_10_mfcc_set01
  188. # python runner.py -t 3c52020attr  -d 4320 -m 15000 -f model_runner.py m3c 5_20_20_attr_set01
  189. # python runner.py -t 2b52010attr  -d 4320 -m 15000 -f model_runner.py m2b 5_20_10_attr_set01
  190.  
  191. # python runner.py -t 2e52020attr  -d 4320 -m 15000 -f model_runner.py m2e 5_20_20_attr_set01 train.yaml
  192. # python runner.py -t 2e52010attr  -d 4320 -m 15000 -f model_runner.py m2e 5_20_10_attr_set01 train.yaml
  193. # python runner.py -t 2e52020mfcc  -d 4320 -m 15000 -f model_runner.py m2e 5_20_20_mfcc_set01 train.yaml
  194.  
  195. # python runner.py -t 2f52020attr  -d 4320 -m 15000 -f model_runner.py m2f 5_20_20_attr_set01 train.yaml
  196. # python runner.py -t 2f52010attr  -d 4320 -m 15000 -f model_runner.py m2f 5_20_10_attr_set01 train.yaml
  197.  
  198. # python runner.py -t 2d52020attr  -d 4320 -m 15000 -f model_runner.py m2d 5_20_20_attr_set01 train.yaml
  199. # python runner.py -t 2d52010attr  -d 4320 -m 15000 -f model_runner.py m2d 5_20_10_attr_set01 train.yaml
  200. # python runner.py -t 2d52020mfcc  -d 4320 -m 15000 -f model_runner.py m2d 5_20_20_mfcc_set01 train.yaml
  201. # python runner.py -t 2d52010mfcc  -d 4320 -m 15000 -f model_runner.py m2d 5_20_10_mfcc_set01 train.yaml
  202.  
  203. # python runner.py -t 2c52020attr  -d 4320 -m 15000 -f model_runner.py m2c 5_20_20_attr_set01 train.yaml
  204. # python runner.py -t 2c52010attr  -d 4320 -m 15000 -f model_runner.py m2c 5_20_10_attr_set01 train.yaml
  205. # python runner.py -t 2c52020mfcc  -d 4320 -m 15000 -f model_runner.py m2c 5_20_20_mfcc_set01 train.yaml
  206. # python runner.py -t 2c52010mfcc  -d 4320 -m 15000 -f model_runner.py m2c 5_20_10_mfcc_set01 train.yaml
  207.  
  208. # python runner.py -t 2b52020mfcc  -d 4320 -m 15000 -f model_runner.py m2b 5_20_20_mfcc_set01 train.yaml
  209. # python runner.py -t 2b52010mfcc  -d 4320 -m 15000 -f model_runner.py m2b 5_20_10_mfcc_set01 train.yaml
  210. # python runner.py -t 2b52010attr  -d 4320 -m 15000 -f model_runner.py m2b 5_20_10_attr_set01 train.yaml
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement