mcpField
T
tao-train-mask-auto-encoder

tao-train-mask-auto-encoder

github.com/promptingcompany数据与数据库039 次安装17 周前更新
代码仓库

关于 tao-train-mask-auto-encoder

TAO 的 MAE 模型技能,支持通过遮蔽图像块并重建来进行自监督预训练,也支持分类微调。它包含预训练和微调阶段的配置说明,以及用于 TensorRT 引擎生成的部署流程。

主要功能

  1. 01遮蔽图像块并重建
  2. 02自监督预训练
  3. 03分类微调
  4. 04预训练权重加载
  5. 05TensorRT 引擎部署流程

适用场景

  1. 01从图像数据进行自监督预训练
  2. 02使用预训练权重微调分类模型
  3. 03将模型导出并生成 TensorRT 引擎

安装

复制下面的命令,在终端中运行。

$npx skills add https://github.com/promptingcompany/nv-skills --skill tao-train-mask-auto-encoder

安装后在 Claude Code 中输入/tao-train-mask-auto-encoder确认已加载。

包含的文件

除 SKILL.md 外,安装时一起下载的参考资料和脚本。

BENCHMARK.md
skill-card.md
skill.oms.sig
evals/
evals.json
references/
skill_info.yaml
spec_template_deploy_gen_trt_engine.yaml
spec_template_evaluate.yaml
spec_template_export.yaml
spec_template_gen_trt_engine.yaml
spec_template_inference.yaml
spec_template_train.yaml
tao-deploy-mask-auto-encoder.md
tao-deploy-mask-auto-encoder.skill_info.yaml
schemas/
evaluate.schema.json
export.schema.json
gen_trt_engine.schema.json
inference.schema.json
manifest.json
train.schema.json

详细介绍

MAE

用于自监督预训练和微调的 MAE(掩码自编码器)。随机遮蔽图像块并重建,以学习视觉表示。支持预训练和微调阶段。

微调时,将预训练的 MAE 权重设置为 train.pretrained_model_path。

对于 TAO Deploy TensorRT 操作(gen_trt_engine),请先阅读 references/tao-deploy-mask-auto-encoder.md。部署规范模板位于此技能的 references/ 文件夹中,文件名前缀为 spec_template_deploy_*.yaml。

Dataclass 架构

生成的 TAO Core 架构打包在 schemas/<action>.schema.json 中,schemas/manifest.json 列出了可用操作。每个生成的架构还会根据架构顶层的 default 字段生成 references/spec_template_<action>.yaml。AutoML 是否启用由模型层的 references/skill_info.yaml 中的 automl_enabled 声明。要运行 AutoML,还必须存在并且能够解析 schemas/train.schema.json 和 references/spec_template_train.yaml。使用打包的 train 架构获取 automl_default_parameters、automl_disabled_parameters、默认值、最小值/最大值范围、枚举、选项权重、数学条件、依赖项和常用参数。不要期望运行时存在 ~/tao-core;维护者会在打包技能库之前重新生成架构/模板。

训练操作策略

此模型在模型层启用了 AutoML。处理任何训练阶段请求之前,请先阅读 references/skill_info.yaml,并根据明确指定的 automl_policy 值或用户的工作流请求确定本次运行的策略。将“关闭 AutoML”“禁用 AutoML”“不进行 HPO”或“普通训练”等表述视为仅对本次运行设置 automl_policy: off;否则默认为 auto。当 automl_policy: auto、automl_enabled: true,且已打包 schemas/train.schema.json 和 references/spec_template_train.yaml 时,默认通过 tao-skill-bank:tao-run-automl 执行训练操作,并传入此模型的 skill_dir。保留工作流/应用覆盖项,包括数据集、规范、输出目录、GPU/平台设置、父检查点和 automl_policy。仅在 automl_policy: off 或缺少打包的训练架构/模板时,才直接训练模型;如果缺少架构,请说明此模型已启用 AutoML,但在生成架构之前无法运行 AutoML。

evaluate、inference、export 和部署流程等非训练操作仍由此模型技能处理。每次运行的 automl_policy 覆盖项不会更改模型元数据。

训练要求

  • 数据集类型: image_classification
  • 格式: ssl
  • 接受的数据集用途: 训练、评估、测试
  • 监控指标: train_loss
各操作的数据集要求
操作规范键来源文件列表?
traindataset.train_data_sourcestrain_datasetsimages_train.tar.gz否
traindataset.val_data_sourceseval_datasetimages_val.tar.gz否
evaluatedataset.val_data_sourceseval_datasetimages_val.tar.gz否
inferencedataset.test_data_sourcesinference_datasetimages_test.tar.gz否
典型规范覆盖项

每个操作都必须覆盖数据源——Agent 必须根据上方“各操作的数据集要求”表构造数据源路径,并将其包含在 spec_overrides 中。

S3_TRAIN = "s3://bucket/data/train"
S3_EVAL = "s3://bucket/data/eval"

train(必须指定数据源):

{
    "dataset.train_data_sources": f"{S3_TRAIN}/images_train.tar.gz",
    "dataset.val_data_sources": f"{S3_EVAL}/images_val.tar.gz",
    "train.num_epochs": 10,
    "train.optim.lr": 2e-4,
}

evaluate(必须指定数据源):

{
    "dataset.val_data_sources": f"{S3_EVAL}/images_val.tar.gz",
}

inference(必须指定数据源):

{
    "dataset.test_data_sources": f"{S3_EVAL}/images_test.tar.gz",
}

评估数据集

可选。预训练不需要评估数据。微调可选择使用验证集。

重要参数

  • train.stage:训练阶段。可选项:pretrain、finetune。Pretrain 通过掩码学习表征。Finetune 添加分类头。
  • model.arch:架构。默认值为 convnextv2_base。选项丰富,包括 ConvNeXt、Hiera、ViT 的各种变体。
  • model.num_classes:微调的类别数。默认值为 1000(ImageNet)。仅适用于 finetune 阶段。
  • model.mask_ratio:预训练期间需要掩码的图块比例。通常为 0.75。
  • model.norm_pix_loss:是否在重建损失中对像素值进行归一化。
  • train.optim.lr:学习率。默认值为 2e-4。
  • dataset.augmentation:数据增强设置,包括微调时使用的 mixup、cutmix。

多 GPU / 多节点

**启动方式:**由 Lightning 管理(单个 python 进程,Lightning 会生成工作进程)。

Spec Key描述默认值
train.num_gpusGPU 数量1
train.gpu_idsGPU 设备索引[0]
train.num_nodes节点数量1
train.distributed_strategyddp 或 fsdpddp
  • ddp 使用 find_unused_parameters=True
  • fsdp 强制使用 FP16
  • 强烈建议使用多 GPU 进行预训练(需要较大的批次大小)

多节点环境变量(由编排器设置):WORLD_SIZE、NODE_RANK、MASTER_ADDR、MASTER_PORT、NUM_GPU_PER_NODE。

硬件

至少需要 2 个 GPU,建议使用 8 个 GPU。每个 GPU 需要 24GB 以上显存(建议使用 A100)。MAE 预训练得益于在多 GPU 上使用较大的批次大小。微调的资源需求则相对较低。

错误模式

阶段不匹配:确保 train.stage 符合你的意图(pretrain 或 finetune)。如果没有指定 pretrained_model_path,微调将从头开始训练。

num_classes 不匹配(仅 finetune):微调时,确保 model.num_classes 与数据集的类别数一致。

Spec 参数 / 父模型推断

特定于模型的推断映射应放在此 MD 文件中,而不是 config.json 中。生成的运行器应读取此部分,并在 create_job() 之前使用 SDK 辅助函数应用这些映射。这与旧版微服务的 infer_params.py 流程相同。

来自 TAO Core mae.config.json 的推断映射:

ActionSpec FieldInference FunctionMeaning
evaluateencryption_keykey加密密钥
evaluateevaluate.checkpointparent_model从父作业结果文件夹推断的模型文件
evaluateevaluate.trt_engineparent_model从父作业结果文件夹推断的模型文件
evaluateresults_diroutput_dir当前作业结果目录
exportencryption_keykey加密密钥
exportexport.checkpointparent_model从父作业结果文件夹推断的模型文件
exportexport.onnx_filecreate_onnx_file输出 ONNX 路径
exportresults_diroutput_dir当前作业结果目录
gen_trt_engineencryption_keykey加密密钥
gen_trt_enginegen_trt_engine.onnx_fileparent_model从父作业结果文件夹推断的模型文件
gen_trt_enginegen_trt_engine.trt_enginecreate_engine_file输出 TensorRT 引擎路径
gen_trt_engineresults_diroutput_dir当前作业结果目录
inferenceencryption_keykey加密密钥
inferenceinference.checkpointparent_model从父作业结果文件夹推断的模型文件
inferenceinference.trt_engineparent_model从父作业结果文件夹推断的模型文件
inferenceresults_diroutput_dir当前作业结果目录
trainencryption_keykey加密密钥
trainresults_diroutput_dir当前作业结果目录
traintrain.pretrained_model_pathptm_if_no_resume_model不存在恢复检查点时使用的 PTM
traintrain.resume_training_checkpoint_pathresume_model从当前作业结果文件夹推断的模型文件

对于 parent_model 或 parent_model_folder,请将上游 train/export/AutoML 子作业 ID 作为 parent_job_id 传入。SDK 会列出父结果文件夹、筛选检查点产物,并返回选定的模型文件或文件夹。不要将这些映射重新添加到 config.json 中,也不要修改生成的运行器脚本来猜测检查点路径。

部署

评论

支持 Markdown