You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 

5.5 KiB

1资源准备

根据模型规模,合理安排每个容器使用的资源额度,计算所需要的总资源数目

如100个学生,每个容器需要1C,4G

那么总资源需要100C,400G

在K8S系统中添加工作节点,满足资源总需求*115%,其中15%为余量,可以多一点。

考试的节点手动添加标签cal_type:cpu/gpu ntype:exam

对于exam的镜像会全部调度到这些节点中,普通教学的镜像只会被调度在ntype:study的节点上,以此实现考试和教学的分离,保障考试稳定性

对于gpu的镜像只会被调度到cal_type:gpu的节点上,cpu的镜像同理。

2环境准备

根据考试实际需要,build一个镜像

打包过程:

文件在jupyter-image-mladder文件夹中

其中base是基镜像,先本地build该镜像

​ cd base

​ sudo docker build -t mld:v1 .

其它几个镜像中的FROM字段内容要修改为刚刚build的mld:v1

安装包只需要仿照下面代码,用conda或者pip3安装即可,推荐使用一些镜像源,速度较快

cudnn等一些包不能用pip安装,可以用conda,自行google搜索

FROM mld:v1     #这个要对应自己build的镜像

ARG NB_USER="jupyter"
ARG NB_UID="1000"
ARG NB_GID="100"
ARG NB_PORT=8888

USER root

###### 以下是装包:
RUN conda install pytorch torchvision torchaudio cpuonly -c pytorch \
    && conda install tensorflow

RUN pip3 install numpy seaborn sklearn h5py matplotlib pandas future imageio -i https://pypi.mirrors.ustc.edu.cn/simple/ 

RUN pip3 install lightgbm xgboost imblearn mindspore -i https://pypi.mirrors.ustc.edu.cn/simple/ 

RUN pip3 install keras -i https://pypi.mirrors.ustc.edu.cn/simple/ 
######

ENV HOME="/home/${NB_USER}"
USER ${NB_UID}
ENTRYPOINT [ "/enterpoint.sh" ]

不同环境,只需要修改######之间的内容即可,别的代码一般不需要修改

打包好镜像后,需要上传到dockerhub

dasetalent账户密码查阅 dassetalent_host.md文件

docker push 到dockerhub后,进入考试专用的节点(可以直接ssh,也可以在阿里云k8s管理模块workbench远程连接功能),手动ctr images pull docker.io/dasetalent/xxxxxx,其中xxxxxx为上传的镜像,要带版本号

之后在服务器nfs上添加节点ip

在服务器/etc/exports文件下添加节点ip

随后重启nfs服务,重启命令:

service nfs-kernel-server restart

重启完后可使用service nfs-kernel-server status命令查看nfs是否正常运行

下面步骤为暂时性:

进入天梯服务器

目录/home/lwttest

修改/home/lwttest/config.json文件

{"version": "v1.2.1", "images": {
  "old": {"image": "bnc1010/old_notebook:v1", "use_gpu": false, "workdir": "/home/public/", "node_select":{"ntype":"study"}}, 
  "torch-gpu": {"image": "bnc1010/mladder_notebook_torchgpu:v0.3", "use_gpu": true, "workdir": "/home/jupyter/", "node_select":{"ntype":"study"}}, 
  "tensorflow-gpu": {"image": "bnc1010/mladder_notebook_tensorflowgpu:v0.2", "use_gpu": true, "workdir": "/home/jupyter/", "node_select":{"ntype":"study"}},
  "tensorflow-pytorch-cpu(exam)": {"image": "bnc1010/mladder_notebook_torch_tf_sk:v1.6", "use_gpu": false, "workdir": "/home/jupyter/", "node_select":{"ntype":"exam"}}
  }, 
  "node_ips": ["47.100.69.138", "139.224.216.129"], 
  "gpu_maxn": 0, 
  "gpu_notebook": {}}

这里以tensorflow-pytorch-cpu(exam)为例,这是一个考试专用镜像,它有四个参数:

{
	"image": "bnc1010/mladder_notebook_torch_tf_sk:v1.6", 
	"use_gpu": false, 
	"workdir": "/home/jupyter/", 
	"node_select":{"ntype":"exam"}
}

image: dockerhub中能直接pull的镜像名

use_gpu: 是否是需要GPU的

workdir: notebook的工作地址

node_select: 节点标签选择

这里node_select中有一个ntype:exam,表明该镜像起的容器只会在考试专用节点上

其它几个镜像起的容器只会在带有ntype:study标签的节点上

在该配置文件添加好新镜像后,重启脚本/home/lwttest/workServer.py

目前是使用screen挂载 screen -x notebook即可进入, ctrl c 终端,然后python3 /home/lwttest/workServer.py即可重启

3比赛准备

准备好考试需要的比赛

详见天梯助教手册

设置考试的环境为上述准备好的考试专用环境

暂时不要publish,测试作业可以使用私密链接,账号可以让测试人员直接从水杉账号,从水杉跳转过来

4考试过程

4.1 快开始时

清空k8s考试节点中已打开的容器

配置资源容器资源额度:

        resources:
          requests:
            memory: 2Gi
            cpu: 800m
          limits:
            memory: 4Gi
            cpu: 2000m

4.2 开始

将比赛正式publish

4.3 考试中

检测k8s集群,掌握资源实时状态,如果不足,则需要临时加入新节点

如果有其它节点可用时,一个简单有效的补救:手动修改没有成功开启的deployment的yml,修改其ntype调度到非考试节点上去。

考试内容相关:

如果有文件错误、说明有误等需要修改、增加文件的情况时,手动上传至对应比赛的input文件中。

4.4 考试结束

应该向考生说明保存notebook,避免关闭容器后,代码没有保存而丢失。

在天梯中,点击code按钮下载考生代码、leaderboader排名CSV文件。

保存完毕后,删除考试节点所有的deployment。

设置比赛的环境为空,让考生无法从比赛页面再次进入notebook。

数据盘创建快照。

删除临时work节点。