Skip to content

[Example] NdLinear + LoRA Fine-Tuning on SmallViT (MNIST)Add files via upload #1

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Apr 30, 2025

Conversation

aryanator
Copy link
Owner

This notebook demonstrates an efficient fine-tuning strategy for vision transformers by combining:

  • NdLinear: A compressed linear layer that introduces tensor factorization to reduce parameter redundancy.
  • LoRA (Low-Rank Adaptation): Lightweight fine-tuning via trainable low-rank matrices.

🧠 What’s included:

  • A wrapper (NdLinearAdapter) to replace nn.Linear with NdLinear across ViT blocks.
  • LoRA injection into NdLinear using pre-forward hooks.
  • Training loop for three model variants:
    • Standard SmallViT
    • SmallViT with NdLinear
    • SmallViT with NdLinear + LoRA
  • Visualization of loss, accuracy, and singular value distribution
  • Final comparison of parameter counts, file size, and accuracy

📊 Results Summary

Model Parameters Accuracy Model Size
Standard ViT 5.52M 95.01% 22.11 MB
NdLinear ViT 5.52M 95.81% 22.11 MB
NdLinear + LoRA 5.67M 94.86% 22.70 MB

📍 Notes:

  • Dataset: MNIST
  • Architecture: SmallViT from timm
  • Self-contained, Colab-compatible, and easy to follow

This notebook is intended as a research-style educational example for the examples/ directory.

@aryanator aryanator merged commit f290e69 into main Apr 30, 2025
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