Guest User

Untitled

a guest
Nov 12th, 2015
119
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 7.59 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=BEGIN,FAIL,END # Type of email notification- BEGIN,END,FAIL,ALL
  55. #SBATCH [email protected] # 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=BEGIN,FAIL,END
  111.  
  112. source $HOME/a7dea06c655dcec82784/modules
  113. source $HOME/.env/ai/bin/activate
  114.  
  115. # run your script
  116. %s
  117.  
  118. deactivate
  119. """
  120.     slurm_text = slurm_text % (hour, minute, delay, task_name, log_path, log_path, nb_core, mem, running_script)
  121.     f = open('tmp_train_cpu.slurm', 'w')
  122.     f.write(slurm_text)
  123.     f.close()
  124.     os.system('sbatch tmp_train_cpu.slurm')
  125.     os.remove('tmp_train_cpu.slurm')
  126.     return slurm_text
  127.  
  128. # ======================================================================
  129. # model
  130. # ======================================================================
  131. def slurm_parser():
  132.     parser = argparse.ArgumentParser(
  133.         description='Science the sh*t out of Deep Learning!',
  134.         version='0.1',
  135.         formatter_class=argparse.RawDescriptionHelpFormatter,
  136.         add_help=True)
  137.     # ====== SLURM group ====== #
  138.     group = parser.add_argument_group('SLURM Configuration')
  139.  
  140.     group.add_argument('-t', action='store', type=str, default='AIgenJOB',
  141.             metavar='str',
  142.             help='Title for SLURM job')
  143.     group.add_argument('-d', action='store', type=int, required=True,
  144.             metavar='int',
  145.             help='Duration of running task in minute')
  146.     group.add_argument('-w', action='store', type=int, default=0,
  147.             metavar='int',
  148.             help='Run the task after minutes, default=0')
  149.  
  150.     group.add_argument('-p', action='store', choices=('gpu', 'cpu'), default = 'gpu',
  151.             metavar='cpu|gpu',
  152.             help='run the task on GPU or CPU, default=gpu')
  153.     group.add_argument('-m', action='store', type=int, default = 12000,
  154.             metavar='int',
  155.             help='memory for the job, default=12000 MB')
  156.     group.add_argument('-np', action='store', type=int, default = 8,
  157.             metavar='int',
  158.             help='Number of core for CPU task')
  159.  
  160.     group.add_argument('-f', action='append', required=True, nargs='+',
  161.             metavar='list',
  162.             help='path to python script & its arguments (e.g. script.py arg1 arg2 ...)')
  163.  
  164.     return parser
  165.  
  166. # python runner.py -t MFCC -d 30 -p cpu -m 16000 -np 8 -f feature_extract.py set01.dat 10 20 10 2500 8
  167. if __name__ == '__main__':
  168.     parser = slurm_parser()
  169.     if len(sys.argv) > 1:
  170.  
  171.         results = parser.parse_args()
  172.  
  173.         if results.p == 'gpu':
  174.             s = create_slurm_gpu(results.t, results.d, results.w, results.m, results.f)
  175.             print(s)
  176.         elif results.p == 'cpu':
  177.             s = create_slurm_cpu(results.t, results.d, results.w, results.np, results.m, results.f)
  178.             print(s)
  179.         else:
  180.             parser.print_help()
  181.     else:
  182.         parser.print_help()
  183.  
  184.  
  185. # python runner.py -t 3c52020mfcc  -d 4320 -m 15000 -f model_runner.py m3c 5_20_20_mfcc_set01
  186. # python runner.py -t 3c52010mfcc  -d 4320 -m 15000 -f model_runner.py m3c 5_20_10_mfcc_set01
  187. # python runner.py -t 3c52020attr  -d 4320 -m 15000 -f model_runner.py m3c 5_20_20_attr_set01
  188. # python runner.py -t 2b52010attr  -d 4320 -m 15000 -f model_runner.py m2b 5_20_10_attr_set01
  189.  
  190. # python runner.py -t 2e52020attr  -d 4320 -m 15000 -f model_runner.py m2e 5_20_20_attr_set01 train.yaml
  191. # python runner.py -t 2e52010attr  -d 4320 -m 15000 -f model_runner.py m2e 5_20_10_attr_set01 train.yaml
  192. # python runner.py -t 2e52020mfcc  -d 4320 -m 15000 -f model_runner.py m2e 5_20_20_mfcc_set01 train.yaml
  193.  
  194. # python runner.py -t 2f52020attr  -d 4320 -m 15000 -f model_runner.py m2f 5_20_20_attr_set01 train.yaml
  195. # python runner.py -t 2f52010attr  -d 4320 -m 15000 -f model_runner.py m2f 5_20_10_attr_set01 train.yaml
  196.  
  197. # python runner.py -t 2d52020attr  -d 4320 -m 15000 -f model_runner.py m2d 5_20_20_attr_set01 train.yaml
  198. # python runner.py -t 2d52010attr  -d 4320 -m 15000 -f model_runner.py m2d 5_20_10_attr_set01 train.yaml
  199. # python runner.py -t 2d52020mfcc  -d 4320 -m 15000 -f model_runner.py m2d 5_20_20_mfcc_set01 train.yaml
  200. # python runner.py -t 2d52010mfcc  -d 4320 -m 15000 -f model_runner.py m2d 5_20_10_mfcc_set01 train.yaml
  201.  
  202. # python runner.py -t 2c52020attr  -d 4320 -m 15000 -f model_runner.py m2c 5_20_20_attr_set01 train.yaml
  203. # python runner.py -t 2c52010attr  -d 4320 -m 15000 -f model_runner.py m2c 5_20_10_attr_set01 train.yaml
  204. # python runner.py -t 2c52020mfcc  -d 4320 -m 15000 -f model_runner.py m2c 5_20_20_mfcc_set01 train.yaml
  205. # python runner.py -t 2c52010mfcc  -d 4320 -m 15000 -f model_runner.py m2c 5_20_10_mfcc_set01 train.yaml
  206.  
  207. # python runner.py -t 2b52020mfcc  -d 4320 -m 15000 -f model_runner.py m2b 5_20_20_mfcc_set01 train.yaml
  208. # python runner.py -t 2b52010mfcc  -d 4320 -m 15000 -f model_runner.py m2b 5_20_10_mfcc_set01 train.yaml
  209. # 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