Skip to content

[2026-Fall T2-2-2] feat(cv): add vision operators, ResNet-18 & MobileNetV2 CIFAR-10 training - #278

Draft
yanchaomei wants to merge 2 commits into
InfiniTensor:masterfrom
yanchaomei:2026-fall-yanchaomei-T2-2-2
Draft

yanchaomei wants to merge 2 commits into
InfiniTensor:masterfrom
yanchaomei:2026-fall-yanchaomei-T2-2-2

Conversation

@yanchaomei

Copy link
Copy Markdown

Summary

Implements Track 2 Problem 2 (InfiniTrain Small Vision Model Training Support) for the 2026 Autumn InfiniTensor AI Contest (Team: 启忆智存, GitHub: @yanchaomei).

Framework & Operator Additions (CPU + CUDA, Forward + Backward, FP32)

  • Conv2d (stride, padding, bias, groups including depthwise groups == in_channels):
    • Zero-dependency custom CUDA backend (USE_CUDNN=OFF): specialized depthwise kernel, zero-im2col 1x1 strided-batched GEMM, chunked batched im2col + cuBLAS SGEMM, deterministic gather col2im, 32-bit indexing, per-thread/per-device reusable workspace.
    • Optional cuDNN backend (USE_CUDNN=ON, -DCUDNN_ROOT=...): strict FP32 (CUDNN_FMA_MATH), cached descriptors/plans, deterministic algorithm selection by default.
  • BatchNorm2d (train/eval mode separation, unbiased running_var update, FP64 statistics accumulation on CPU & CUDA).
  • ReLU, ReLU6, MaxPool2d, AdaptiveAvgPool2d (general + 1x1 fast path), nn::Flatten.
  • Module & Optimizer: recursive Module::Train(bool) / Eval() / is_training(), buffer accessors, nn::init::KaimingNormal, optimizers::SGD with PyTorch-exact momentum & weight_decay + fused SGDAccumulateGrad kernel + StateDict()/LoadStateDict() (preserving empty state when momentum == 0), and save_planner.cc support for SGD optimizer keys.
  • Build: CMakeLists.txt respects external -DCMAKE_CUDA_ARCHITECTURES (including sm_86 / sm_120) and adds optional USE_CUDNN + cifar10 executable.

CIFAR-10 End-to-End Suite (example/cifar10/)

  • ResNet18 (CIFAR 3x3 stride-1 stem) & MobileNetV2 (width_mult=1.0, CIFAR strides), matching PyTorch state_dict keys 1:1.
  • Official CIFAR-10 binary dataset loader, OpenMP batch builder, RandomCrop(pad=4)+RandomHorizontalFlip, deterministic non-overlapping DDP sharding.
  • Portable full checkpoint save/resume (model + BN buffers + SGD momentum buffers + epoch/step/LR).
  • Automated verifier example/cifar10/verify_pytorch_alignment.py and weight exporter example/cifar10/export_alignment_weights.py.
  • Includes signed example/cifar10/HONOR_CODE.md and example/cifar10/REFERENCE.md.

Verified Results (NVIDIA A40 46GB, FP32, TF32=OFF)

  • 20-Epoch CIFAR-10 Test Acc (bs=128, baseline augment):
    • ResNet-18: 91.94% (1-GPU, peak 92.02%) | 91.12% (2-GPU DDP) (threshold >= 80%)
    • MobileNetV2: 91.38% (1-GPU) | 90.44% (2-GPU DDP bonus) (threshold >= 70%)
  • Numerical Alignment & Determinism: 14/14 CPU/CUDA alignment cases PASS (5-step loss rel diff: ResNet-18 3.78e-3, MobileNetV2 5.92e-3 <= 1e-2); Checkpoint resume 0-bit identical; 2-GPU DDP gradient allreduce max diff 0.00e+00.
  • Throughput vs PyTorch FP32 (bs=128):
    • USE_CUDNN=OFF: ResNet-18 1,828 img/s (50.1%), MobileNetV2 2,130 img/s (62.7%); 2-GPU DDP 1.90x / 1.95x.
    • USE_CUDNN=ON (det.): ResNet-18 2,817 img/s (77.1%), MobileNetV2 2,166 img/s (63.8%); 2-GPU DDP 1.93x / 1.89x (5,378 / 4,095 img/s).
  • Regression: CPU-only ctest 316/316 PASS; CUDA suite 25/25 PASS (including AutogradCVTest 6/6, test_checkpoint_cuda 36/36, test_optimizer_cuda 26/26); repo-wide clang-format-16 & black PASS.

(Draft PR submitted ahead of midterm to validate official CI; final RTX 5090 sm_120 verification numbers will be appended once compute vouchers are redeemed.)

@yanchaomei

yanchaomei commented Nov 27, 2026 •

Copy link
Copy Markdown
Author

Verified all 3 official CI workflows on fork (yanchaomei/InfiniTrain, commit f0df15c):

  • Format Check (clang-format-16 + black 26.10.1): PASS (37s)
  • IWYU (clang-17 + iwyu_tool): PASS (3m50s)
  • clang-tidy (clang-tidy-18 + InfiniTrainTidy.so): PASS (4m41s)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant