Alinux3 AI增强镜像实践

本文重点介绍Alibaba Cloud Linux 3 AI Extension Edition如何配合阿里云AI容器镜像,实现性能提升。

  1. 开启keentune调优工具。

    Alibaba Cloud Linux 3 AI Extension Edition镜像预装了调优工具keentune,该工具提供了多种场景下的调优,通过如下步骤开启AI场景调优。

    systemctl stop tuned
    systemctl disable tuned
    systemctl start keentune-target
    systemctl enable keentune-target
    systemctl enable keentuned
    systemctl start keentuned
    keentune profile set ai_train.profile
keentune调优需要重启OS生效,如果想关闭keentune启用的调优,执行keentune profile rollback即可,同样需要重启生效。
  1. 安装docker。

    参考运行PyTorch GPU镜像训练模型 安装docker和相关组件。

  2. 获取测试镜像。

    docker pull ac2-registry.cn-hangzhou.cr.aliyuncs.com/ac2/openclip-bevformer:v0.1-torch2.6-cuda12.6-py3.10-ubuntu22.04
  3. 下载数据集。

    容器镜像中未预置数据集,下载容器镜像后,可参考以下命令下载对应模型数据集:

    OpenCLIP训练/推理数据集

    # 下载训练数据集
    mkdir -p /workspace/dataset && cd /workspace/dataset
    wget -O mscoco.parquet https://hf-mirror.com/datasets/ChristophSchuhmann/MS_COCO_2017_URL_TEXT/resolve/main/mscoco.parquet?download=true
    pip3 install img2dataset webdataset==0.2.86 numpy==1.23.5 --ignore-installed && NO_ALBUMENTATIONS_UPDATE=1 img2dataset --url_list mscoco.parquet --input_format "parquet" --url_col "URL" --caption_col "TEXT" --output_format webdataset --output_folder COCO_2017_Captions-webdataset-592k-256x256-296shards --processes_count 16 --thread_count 64 --image_size 256 --number_sample_per_shard 2000
    # 下载推理数据集
    mkdir -p /workspace/dataset && cd /workspace/dataset
    wget https://image-net.org/data/ILSVRC/2012/ILSVRC2012_img_val.tar --no-check-certificate
    mkdir -p ILSVRC2012_img_val
    tar xvf ILSVRC2012_img_val.tar -C ILSVRC2012_img_val
    cd ILSVRC2012_img_val/ && wget https://raw.githubusercontent.com/soumith/imagenetloader.torch/master/valprep.sh && bash valprep.sh
    可参考GitHub - mlfoundations/open_clip: An open source implementation of CLIP

    BEVFormer训练数据集

    mkdir -p /workspace/BEVFormer/data && cd /workspace/BEVFormer/data
    wget https://d36yt3mvayqw5m.cloudfront.net/public/v1.0/v1.0-mini.tgz
    mkdir -p nuscenes && tar -xzf v1.0-mini.tgz -C ./nuscenes/
    wget https://d36yt3mvayqw5m.cloudfront.net/public/v1.0/can_bus.zip
    unzip -q can_bus.zip
    cd /workspace/BEVFormer && python tools/create_data.py nuscenes --root-path ./data/nuscenes --out-dir ./data/nuscenes --extra-tag nuscenes --version v1.0-mini --canbus ./data
    可参考BEVFormer/docs/prepare_dataset.md at master · fundamentalvision/BEVFormer
  4. 在容器镜像中进行测试。

    OpenCLIP

    • 训练命令:

      cd /workspace/open_clip/src && torchrun --nproc_per_node 8 -m open_clip_train.main --model RN50 --train-data /workspace/dataset/COCO_2017_Captions-webdataset-592k-256x256-296shards/\{00000..00295\}.tar --train-num-samples 591753 --dataset-type webdataset --batch-size 1152 --precision amp --workers 8 --epochs 4 --log-every-n-steps 1 --torchcompile
    • 推理命令:

      cd /workspace/open_clip/src && torchrun --nproc_per_node 1 -m open_clip_train.main --imagenet-val /workspace/dataset/ILSVRC2012_img_val --model RN50 --batch-size 1152 --workers 8 --pretrained openai

    BEVFormer

    训练命令:

    cd /workspace/BEVFormer && TORCH_ALLOW_TF32_CUBLAS_OVERRIDE=1 tools/dist_train.sh projects/configs/bevformer/bevformer_base.py 8