栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 软件开发 > 后端开发 > Python

NNI 超参调优

Python 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

NNI 超参调优

安装

pip install nni

例子:求 x 2 + y 2 x^2+y^2 x2+y2最大值

model.py

import nni

# Get optimized hyperparameters
params = {'x': 0, 'y': 0} #待优化的参数
optimized_params = nni.get_next_parameter()
params.update(optimized_params)

def test(x,y):
    return x*x+y*y

epochs = 5
for t in range(epochs):
    out = test(params['x'],params['y'])
    nni.report_intermediate_result(out) 
nni.report_final_result(out)

main.py

from pathlib import Path
import signal

from nni.experiment import Experiment

# Define search space
search_space = {
    'x': {'_type': 'randint', '_value': [0, 10]},
    'y': {'_type': 'randint', '_value': [0, 10]},
}

# Configure experiment
experiment = Experiment('local')
experiment.config.trial_command = 'python model.py'
experiment.config.trial_code_directory = Path(__file__).parent
experiment.config.search_space = search_space

# Custom define
experiment.config.max_trial_number = 100 # 最大实验次数
experiment.config.trial_concurrency = 2 # 并发实验数
experiment.config.tuner.name = 'GridSearch' # 调优方法

# Run it!
experiment.run(port=8080, wait_completion=False)

print('Experiment is running. Press Ctrl-C to quit.')
signal.pause()

执行python main.py,可以在网页端监控进度

复现

使用nni.experiment.Experiment.view(experiment_id=Experiment ID)可重新启动历史实验的网页控制台

更多内容参考官方文档 NNI

转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/876033.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号