determined机器学习平台使用说明

本文介绍了如何搭建Determined机器学习平台来解决GPU资源管理和批量任务调度问题,包括环境设置、多节点添加、docker镜像使用、账户管理以及任务模板。同时指出了平台的不足之处和非Determined任务的兼容性问题。

determined机器学习平台

背景

为了方便批量提交GPU任务,防止资源冲突导致任务异常中断,搭建了determined机器学习平台,选择这一框架的原因是一方面它提供GPU资源管理和深度学习任务的调度功能,另一方面它实现了超参搜索功能方便调参。

目前,determined主要解决了个人两个痛点

  1. GPU资源管理问题,多用户和多任务时容易抢占GPU资源导致CUDA OOM。

  2. 批量GPU任务调度,大量项目视频数据需要分别训练NeRF/3DGS模型,超出了GPU数量,在命令行里手动管理任务非常低效。

环境

pip install determined

det deploy local cluster-up

添加节点

如果有多台机器,需要将其加入到determined集群。已经运行det deploy local cluster-up作为master节点,其他机器作为agent节点,mater和agent。
先运行命令:

docker pull determinedai/determined-agent
pip install determined

在本地创建配置文件agent-config.yaml,写入mater节点determined服务的ip和port。

master_host: 192.168.0.12
master_port: 8080

然后启动服务

# 在子节点中运行
docker run --gpus all -v /var/run/docker.sock:/var/run/docker.sock -v "$PWD"/agent-config.yaml:/etc/determined/agent.yaml determinedai/determined-agent

docker镜像

determined使用docker运行任务,所用docker镜像中必须安装determined,否则任务会卡住。

可以用determined提供的镜像作为基础镜像。

https://hub.docker.com/r/determinedai/environments/tags?page=1&name=gpu

建议以determined或者pytorch的镜像作为基础镜像。

账户

账号为名字拼音,默认密码为空。
管理员用户名为admin,建议搭建好环境后,立刻修改其密码。
修改密码:

det user login  # 登录,后续命令将以此用户为默认用户

det -u {username} user change-password  # 修改密码

模板

提前构建好docker镜像

参考配置模板创建config文件:配置

name: test_pytorch_determined  # 实验名称
workspace: Test
project: init

resources:
  slots_per_trial: 1  # 显卡数量
entrypoint: python3 test.py  # 任务命令

# 挂载
bind_mounts:
  - host_path: /data/lambda
    container_path: /mnt/lambda


# Use the single-searcher to run just one instance of the training script
searcher:
   name: single
   # metric is required but it shouldn't hurt to ignore it at this point.
   metric: none
   # max_length is ignored if the training script ignores it.
   max_length: 1

max_restarts: 3 # 任务运行失败会重跑

environment:
  image: determinedai/environments:cuda-11.3-pytorch-1.12-tf-2.11-gpu-622d512  # 镜像
  environment_variables:  # container环境变量
  - USERNAME=lambda


cd {workspace}
det experiment create config.yaml ./  # 会上传当前目录到master节点

省事起见,也可以将个人home挂载,然后从container_path里的代码启动任务

任务管理

http://localhost:8080/

不足

  1. 非determined任务无法监测,所以如果存在从命令行运行的训练任务,还是会发生资源抢占的现象。需要大家都迁移到determined平台运行GPU任务才能发挥最大作用。

  2. 权限管理可能不够完善。

参考

https://docs.determined.ai/latest/index.html#

### 绘制机器学习模型的学习曲线 绘制学习曲线有助于理解模型的表现以及是否存在过拟合或欠拟合的情况。良好的学习曲线应显示训练集与验证集之间的差距较小,并且两条曲线都趋于稳定[^2]。 为了实现这一目标,Python 的 `scikit-learn` 库提供了便捷的方法来创建这样的图表。下面是一个具体的例子: #### 使用 Scikit-Learn 创建学习曲线 ```python import numpy as np import matplotlib.pyplot as plt from sklearn.model_selection import learning_curve from sklearn.datasets import load_iris from sklearn.linear_model import LogisticRegression def plot_learning_curve(estimator, title, X, y, ylim=None, cv=None, n_jobs=-1, train_sizes=np.linspace(.1, 1.0, 5)): """ Generate a simple plot of the test and training learning curve. Parameters: estimator : object type that implements the "fit" and "predict" methods An object of that type which is cloned for each validation. title : string Title for the chart. X : array-like, shape (n_samples, n_features) Training vector, where n_samples is the number of samples and n_features is the number of features. y : array-like, shape (n_samples) or (n_samples, n_features), optional Target relative to X for classification or regression; None for unsupervised learning. ylim : tuple, shape (ymin, ymax), optional Defines minimum and maximum yvalues plotted. cv : int, cross-validation generator or an iterable, optional Determines the cross-validation splitting strategy. n_jobs : integer, optional Number of jobs to run in parallel. train_sizes : array-like, shape (n_ticks,), dtype float or int Relative or absolute numbers of training examples that will be used to generate the learning curve. If the dtype is float, it is regarded as a fraction of the maximum size of the training set (that is determined by the selected validation method), i.e. it has to be within (0, 1]. Otherwise it is interpreted as absolute sizes of the training sets. """ plt.figure() plt.title(title) if ylim is not None: plt.ylim(*ylim) plt.xlabel("Training examples") plt.ylabel("Score") train_sizes, train_scores, test_scores = learning_curve( estimator, X, y, cv=cv, n_jobs=n_jobs, train_sizes=train_sizes) train_scores_mean = np.mean(train_scores, axis=1) train_scores_std = np.std(train_scores, axis=1) test_scores_mean = np.mean(test_scores, axis=1) test_scores_std = np.std(test_scores, axis=1) plt.grid() plt.fill_between(train_sizes, train_scores_mean - train_scores_std, train_scores_mean + train_scores_std, alpha=0.1, color="r") plt.fill_between(train_sizes, test_scores_mean - test_scores_std, test_scores_mean + test_scores_std, alpha=0.1, color="g") plt.plot(train_sizes, train_scores_mean, 'o-', color="r", label="Training score") plt.plot(train_sizes, test_scores_mean, 'o-', color="g", label="Cross-validation score") plt.legend(loc="best") return plt # 加载数据并准备绘图 data = load_iris() X, y = data.data, data.target title = "Learning Curves (Logistic Regression)" estimator = LogisticRegression(max_iter=200) plot_learning_curve(estimator, title, X, y, cv=5) plt.show() ``` 此代码片段定义了一个名为 `plot_learning_curve()` 函数用于生成给定估计器(在此例中为逻辑回归)的学习曲线。通过调整输入参数如 `train_sizes`, 可以控制所使用的不同规模的数据子集来进行训练和评估。最终的结果会展示两个分数随样本数量变化的趋势——一个是训练得分,另一个则是交叉验证得分。理想情况下,这两个分数应该接近并且随着更多的数据加入而逐渐平稳下来。
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值