美文网首页
[python]调参自动机

[python]调参自动机

作者: VanJordan | 来源:发表于2019-02-26 11:17 被阅读1次

多卡并行调参美滋滋,以后终于可以大力调参了

import os
import threading

model_list = ['sst_adv_cnn','sst_adv_rnn','sst5_adv_cnn','sst5_adv_rnn']
action_list = ['no_up','no_down','no_same','no_updownsame']
run_list = []
for model in model_list:
    for action in action_list:
        run_list.append(model+'_'+action+'.sh')
command_list = []
for idx,run in enumerate(run_list):
    command = 'CUDA_VISIBLE_DEVICES='+str(idx%4)+' bash '+run
    print(command)
    command_list.append(command)


class myThread (threading.Thread):
    def __init__(self, command):
        threading.Thread.__init__(self)
        self.cmd = command

    def run(self):
        print("Starting " + self.cmd)
        os.system(self.cmd)
        print("Exiting " + self.cmd)

for idx,command in enumerate(command_list):
    myThread(command).start()

组间并行,组外串行,以16为一组,在4个GPU上执行,每隔三秒检查一次是否这一组的所有程序执行完,如果是的那么就执行下一组。

import os
import threading
import random
import time 
## {0} cnn rnn {1} un down same updownsame
set_num = 16
gpu_num = 4
sleep_time = 3 #second
command_raw = r"""
#!/usr/bin/env sh
set -e

NAME=sst5_adv_cnn_{1}_{2}_{3}_{4}
TRAIN_DIR=./tmp/$NAME
INPUT_DIR=./data/sst5
mkdir $TRAIN_DIR || true

python ./src/sst_action.py \
    --mode=train_adv \
    --action_type={4} \
    --model_type=cnn \
    --action={1} \
    --input_dir=$INPUT_DIR \
    --train_dir=$TRAIN_DIR \
    --save_steps=30 \
    --test_steps=50 \
    --least_freq=2 \
    --num_classes=2 \
    --every=1 \
    --dis_warm_up_step={2} \
    --gene_warm_up_step={3} \
    --max_vocab_size=100000 \
    --embedding_dims=300 \
    --rnn_cell_size=300 \
    --batch_size=64 \
    --learning_rate=0.0001 \
    --generator_learning_rate=0.001 \
    --max_steps=25000 \
    --max_grad_norm=1.0 \
    --num_timesteps=100 \
    --keep_prob_emb=0.6 \
    --keep_prob_dense=0.9 \

python ./src/sst_action.py \
    --mode=test \
    --model_type=cnn \
    --action_type={4} \
    --action={1} \
    --input_dir=$INPUT_DIR \
    --train_dir=$TRAIN_DIR \
    --save_steps=30 \
    --test_steps=50 \
    --least_freq=2 \
    --num_classes=2 \
    --every=1 \
    --dis_warm_up_step={2} \
    --gene_warm_up_step={3} \
    --max_vocab_size=100000 \
    --embedding_dims=300 \
    --rnn_cell_size=300 \
    --batch_size=64 \
    --learning_rate=0.0001 \
    --generator_learning_rate=0.001 \
    --max_steps=25000 \
    --max_grad_norm=1.0 \
    --num_timesteps=100 \
    --keep_prob_emb=0.6 \
    --keep_prob_dense=0.9 \
"""
dis_warm_up_list = [500,800,1000,1200]
gene_warm_up_list = [500,800,1000,1200]
model_list = ['cnn','rnn']
action_list = ['no_up','no_down','no_same','no_updownsame','all']
cuda_list = [0,1,2]
command_list = []

for dis_warm_up in dis_warm_up_list:
    for gene_warm_up in gene_warm_up_list:
            for action in action_list:
                action_type=5 if action=='all' else 4
                command = 'sst5_adv'+'_cnn'+'_'+str(action_type)+'_'+action+'_'+str(dis_warm_up)+'_'+str(gene_warm_up)+'.sh'
                with open(command,'w') as f:
                    f.write(command_raw.format('cnn',action,dis_warm_up,gene_warm_up,action_type))
                command_list.append(command)
run_list = []
print(command_list)
print(len(command_list))
input('check out!')
for idx,command in enumerate(command_list):
    cuda_idx = idx%gpu_num
    run = 'CUDA_VISIBLE_DEVICES='+str(cuda_idx)+' bash '+command
    run_list.append(run)

run_list = [run_list[i:i+set_num] for i in range(0,len(run_list),set_num)]

class myThread (threading.Thread):
    def __init__(self, command):
        threading.Thread.__init__(self)
        self.cmd = command

    def run(self):
        print("Starting " + self.cmd)
        os.system(self.cmd)
        print("Exiting " + self.cmd)
def alldown(thread_list):
    for thread in thread_list:
        if thread.isAlive():
            return False
    return True
for tmp_list in run_list:
    thread_list=[]
    for idx,run in enumerate(tmp_list):
        thread = myThread(run)
        thread_list.append(thread)
        thread.start()
    while True:
        if alldown(thread_list):
            break
        time.sleep(sleep_time)

相关文章

  • [python]调参自动机

    多卡并行调参美滋滋,以后终于可以大力调参了 组间并行,组外串行,以16为一组,在4个GPU上执行,每隔三秒检查一次...

  • [python]使用NNI调参

    overview pros: 内置多种调参算法可以选择,而不是无脑grid search。 可以方便的进行可视化,...

  • python机器学习模型调参

    1. 基于scikit-learn的RandomForestRegressor构建一个随机森林回归模型 sklea...

  • 调参

    1首先是数据增强,因为正常情况下,数据量往往不够,因此需要通过裁剪 2数据预处理,pca,normalizatio...

  • 调参

    参数更新 神经网络的学习目的是找到使损失函数尽可能小的参数,即解决一个最优化问题.但是由于神经网络参数空间过于复杂...

  • 调参

    死亡的神经元占的比例 RELU 文中给出了一种针对ReLU神经元的特殊初始化,并给出结论:网络中神经元的方差应该是...

  • 调参

    转载https://www.sohu.com/a/241208957_787107 基本原则:快速试错 一些大的注...

  • 调参

    1.lr用1e-2-1e-3结果较好。lr值小的话,上升test auc会比较慢,但最后结果说不定会比lr大要好。...

  • Python脚本传参(argparse模块)2022-08-23

    Python传参 简便版 进阶版 Python使用argparse模块传参 Python系统自带的传参用到sys模...

  • 自动机器学习工具NNI给xgboost模型调参

    基于Kaggle的Titanic入门赛,跑一个xgboost模型。使用NNI后,调参只需要3步,就可以自动搜索定义...

网友评论

      本文标题:[python]调参自动机

      本文链接:https://www.haomeiwen.com/subject/zxxayqtx.html