Naflexvit模型复现#3411
Open
yicycyc wants to merge 5 commits into
Open
Conversation
|
Thanks for your contribution! |
DP1212158
reviewed
Jun 17, 2026
Comment on lines
+268
to
+274
| use_antialias = paddle.get_device().startswith("gpu") | ||
| pos = F.interpolate( | ||
| self.pos_embed.transpose([0, 3, 1, 2]).astype("float64"), | ||
| size=interp_size, | ||
| mode=self.pos_embed_interp_mode, | ||
| align_corners=False, | ||
| antialias=use_antialias, |
There was a problem hiding this comment.
F.interpolate(..., antialias=use_antialias) 是 PaConvert 从 PyTorch 转换的残留——paddle.nn.functional.interpolate 不支持 antialias 参数,eval/export 阶段会报 unexpected keyword argument 'antialias'。
删掉use_antialias = paddle.get_device().startswith("gpu")这一行就可以跑通
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
本 PR 在 PaddleClas 中补充 NaFlexViT`分类主干实现,目标是完成与timm 参考实现的前向对齐,并补齐基础训练配置、文档、导出支持和小数据收敛验证。
本次提交聚焦以下内容:
NaFlexViT主干复现timm官方预训练权重前向对齐不包含全量 ImageNet 精度实验
主要改动
NaFlexViT主干实现,支持:naflexvit_base_patch16_gapnaflexvit_base_patch16_par_gapnaflexvit_base_patch16_parfac_gapppcls/configs/ImageNet/NaFlexViT/naflexvit_base_patch16_gap.yamlppcls/configs/ImageNet/NaFlexViT/naflexvit_base_patch16_par_gap.yamlppcls/configs/ImageNet/NaFlexViT/naflexvit_base_patch16_parfac_gap.yamlppcls/configs/ImageNet/NaFlexViT/naflexvit_base_patch16_gap_lite_imagenet.yamltest_tipc/configs/NaFlexViT/naflexvit_base_patch16_gap_train_infer_python.txttools/verify_naflexvit_alignment.pydocs/zh_CN/models/ImageNet1k/NaFlexViT.mddocs/zh_CN/models/ImageNet1k/README.md对齐与兼容性说明
完成了与本地
timm官方预训练权重的同权重前向对齐,forward_features和最终out的绝对误差均小于1e-4。此外,
NaFlexViT支持变分辨率输入;本次对齐分别覆盖了:256 x 256224 x 320实验结果
1. 官方预训练权重前向对齐
实验环境:A100 40G
naflexvit_base_patch16_gap256 x 256forward_features6.48e-051.40e-06naflexvit_base_patch16_gap256 x 256out4.29e-065.60e-07naflexvit_base_patch16_par_gap224 x 320forward_features7.82e-051.61e-06naflexvit_base_patch16_par_gap224 x 320out6.91e-067.98e-07naflexvit_base_patch16_parfac_gap224 x 320forward_features8.77e-051.33e-06naflexvit_base_patch16_parfac_gap224 x 320out8.58e-066.37e-072. 随机初始化权重验证
随机初始化场景也完成了前向对齐验证,3 个基础变体的
forward_features max abs diff均在1e-6量级。该部分主要用于验证结构实现、参数映射和权重转换逻辑正确性。
3. 小数据收敛实验
使用 TIPC
lite_train_lite_infer小数据集,在 GPU 上对naflexvit_base_patch16_gap进行了 5 epoch 短周期训练,用于证明训练链路能够正常收敛。naflexvit_base_patch16_gap_lite_imagenet.yamllite_train_lite_infergpu:07.208650.000000.00000naflexvit_base_patch16_gap_lite_imagenet.yamllite_train_lite_infergpu:03.463030.206900.58621从训练集指标看,loss 明显下降,Top-1 / Top-5 持续上升,可以作为“训练链路可正常收敛”的快速验证。
4. 导出验证
以下 3 个基础变体均已完成静态图导出验证,可成功生成
inference.pdmodel和inference.pdiparams:naflexvit_base_patch16_gapnaflexvit_base_patch16_par_gapnaflexvit_base_patch16_parfac_gap验证命令
前向对齐