Image Feature Extraction
Transformers
Safetensors
vit_nepa
sihanxu commited on
Commit
241e9ff
·
verified ·
1 Parent(s): f34710c

Update README.md

Browse files
Files changed (1) hide show
  1. README.md +138 -132
README.md CHANGED
@@ -1,199 +1,205 @@
1
  ---
2
  library_name: transformers
3
- tags: []
 
 
4
  ---
 
5
 
6
- # Model Card for Model ID
 
 
7
 
8
- <!-- Provide a quick summary of what the model is/does. -->
9
 
 
 
 
10
 
 
11
 
12
- ## Model Details
 
 
 
 
 
 
13
 
14
- ### Model Description
15
 
16
- <!-- Provide a longer summary of what this model is. -->
17
 
18
- This is the model card of a 🤗 transformers model that has been pushed on the Hub. This model card has been automatically generated.
19
 
20
- - **Developed by:** [More Information Needed]
21
- - **Funded by [optional]:** [More Information Needed]
22
- - **Shared by [optional]:** [More Information Needed]
23
- - **Model type:** [More Information Needed]
24
- - **Language(s) (NLP):** [More Information Needed]
25
- - **License:** [More Information Needed]
26
- - **Finetuned from model [optional]:** [More Information Needed]
27
 
28
- ### Model Sources [optional]
 
 
29
 
30
- <!-- Provide the basic links for the model. -->
31
 
32
- - **Repository:** [More Information Needed]
33
- - **Paper [optional]:** [More Information Needed]
34
- - **Demo [optional]:** [More Information Needed]
35
 
36
- ## Uses
 
 
 
37
 
38
- <!-- Address questions around how the model is intended to be used, including the foreseeable users of the model and those affected by the model. -->
39
 
40
- ### Direct Use
 
 
 
41
 
42
- <!-- This section is for the model use without fine-tuning or plugging into a larger ecosystem/app. -->
43
 
44
- [More Information Needed]
 
 
45
 
46
- ### Downstream Use [optional]
47
 
48
- <!-- This section is for the model use when fine-tuned for a task, or when plugged into a larger ecosystem/app -->
49
 
50
- [More Information Needed]
 
 
 
 
51
 
52
- ### Out-of-Scope Use
 
53
 
54
- <!-- This section addresses misuse, malicious use, and uses that the model will not work well for. -->
 
55
 
56
- [More Information Needed]
 
 
 
 
 
 
57
 
58
- ## Bias, Risks, and Limitations
59
 
60
- <!-- This section is meant to convey both technical and sociotechnical limitations. -->
61
 
62
- [More Information Needed]
 
 
63
 
64
- ### Recommendations
65
 
66
- <!-- This section is meant to convey recommendations with respect to the bias, risk, and technical limitations. -->
67
 
68
- Users (both direct and downstream) should be made aware of the risks, biases and limitations of the model. More information needed for further recommendations.
69
 
70
- ## How to Get Started with the Model
 
 
 
71
 
72
- Use the code below to get started with the model.
73
 
74
- [More Information Needed]
75
 
76
- ## Training Details
 
 
77
 
78
- ### Training Data
79
 
80
- <!-- This should link to a Dataset Card, perhaps with a short stub of information on what the training data is all about as well as documentation related to data pre-processing or additional filtering. -->
81
 
82
- [More Information Needed]
83
 
84
- ### Training Procedure
 
 
 
85
 
86
- <!-- This relates heavily to the Technical Specifications. Content here should link to that section when it is relevant to the training procedure. -->
87
 
88
- #### Preprocessing [optional]
 
 
89
 
90
- [More Information Needed]
 
 
 
 
 
91
 
 
92
 
93
- #### Training Hyperparameters
 
 
94
 
95
- - **Training regime:** [More Information Needed] <!--fp32, fp16 mixed precision, bf16 mixed precision, bf16 non-mixed precision, fp16 non-mixed precision, fp8 mixed precision -->
 
 
 
 
 
96
 
97
- #### Speeds, Sizes, Times [optional]
98
 
99
- <!-- This section provides information about throughput, start/end time, checkpoint size if relevant, etc. -->
100
 
101
- [More Information Needed]
102
 
103
- ## Evaluation
 
 
104
 
105
- <!-- This section describes the evaluation protocols and provides the results. -->
106
 
107
- ### Testing Data, Factors & Metrics
 
 
108
 
109
- #### Testing Data
110
 
111
- <!-- This should link to a Dataset Card if possible. -->
112
 
113
- [More Information Needed]
114
 
115
- #### Factors
116
 
117
- <!-- These are the things the evaluation is disaggregating by, e.g., subpopulations or domains. -->
 
 
118
 
119
- [More Information Needed]
120
 
121
- #### Metrics
 
 
122
 
123
- <!-- These are the evaluation metrics being used, ideally with a description of why. -->
124
 
125
- [More Information Needed]
126
 
127
- ### Results
128
 
129
- [More Information Needed]
 
 
 
 
 
 
 
 
130
 
131
- #### Summary
132
 
 
133
 
 
134
 
135
- ## Model Examination [optional]
136
-
137
- <!-- Relevant interpretability work for the model goes here -->
138
-
139
- [More Information Needed]
140
-
141
- ## Environmental Impact
142
-
143
- <!-- Total emissions (in grams of CO2eq) and additional considerations, such as electricity usage, go here. Edit the suggested text below accordingly -->
144
-
145
- Carbon emissions can be estimated using the [Machine Learning Impact calculator](https://mlco2.github.io/impact#compute) presented in [Lacoste et al. (2019)](https://arxiv.org/abs/1910.09700).
146
-
147
- - **Hardware Type:** [More Information Needed]
148
- - **Hours used:** [More Information Needed]
149
- - **Cloud Provider:** [More Information Needed]
150
- - **Compute Region:** [More Information Needed]
151
- - **Carbon Emitted:** [More Information Needed]
152
-
153
- ## Technical Specifications [optional]
154
-
155
- ### Model Architecture and Objective
156
-
157
- [More Information Needed]
158
-
159
- ### Compute Infrastructure
160
-
161
- [More Information Needed]
162
-
163
- #### Hardware
164
-
165
- [More Information Needed]
166
-
167
- #### Software
168
-
169
- [More Information Needed]
170
-
171
- ## Citation [optional]
172
-
173
- <!-- If there is a paper or blog post introducing the model, the APA and Bibtex information for that should go in this section. -->
174
-
175
- **BibTeX:**
176
-
177
- [More Information Needed]
178
-
179
- **APA:**
180
-
181
- [More Information Needed]
182
-
183
- ## Glossary [optional]
184
-
185
- <!-- If relevant, include terms and calculations in this section that can help readers understand the model or model card. -->
186
-
187
- [More Information Needed]
188
-
189
- ## More Information [optional]
190
-
191
- [More Information Needed]
192
-
193
- ## Model Card Authors [optional]
194
-
195
- [More Information Needed]
196
-
197
- ## Model Card Contact
198
-
199
- [More Information Needed]
 
1
  ---
2
  library_name: transformers
3
+ license: apache-2.0
4
+ datasets:
5
+ - ILSVRC/imagenet-1k
6
  ---
7
+ # NEPA: Next-Embedding Predictive Architectures Are Strong Vision Learners
8
 
9
+ [![Paper](https://img.shields.io/badge/arXiv-Paper-b31b1b?logo=arxiv&logoColor=b31b1b)]()
10
+ [![Project Page](https://img.shields.io/badge/Project-Website-5B7493?logo=googlechrome&logoColor=5B7493)]()
11
+ [![Hugging Model Card](https://img.shields.io/badge/huggingface-model:NEPA-lightblue)]()
12
 
13
+ This is a PyTorch/GPU re-implementation of Next-Embedding Predictive Architectures Are Strong Vision Learners.
14
 
15
+ <p align="center">
16
+ <img src="https://github.com/user-attachments/assets/760a7ca4-1aa4-43d9-8731-ab8b33e463d5" width="350">
17
+ </p>
18
 
19
+ The Next-Embedding Predictive Architecture. An image is split into patches and embedded into a sequence. An autoregressive model predicts the next embedding from previous ones.
20
 
21
+ ```
22
+ @article{six2025nepa,
23
+ title={Next-Embedding Predictive Architectures Are Strong Vision Learners},
24
+ author = {Sihan Xu and Ziqiao Ma and Wenhao Chai and Xuweiyi Chen and Weiyang Jin and Joyce Chai and Saining Xie and Stella X. Yu},
25
+ journal={arXiv preprint arXiv:},
26
+ year={2025}
27
+ }
28
 
29
+ ```
30
 
 
31
 
32
+ ## Environment
33
 
34
+ The codebase has been tested with the following environment:
 
 
 
 
 
 
35
 
36
+ - Python 3.10
37
+ - PyTorch 2.8.0
38
+ - Transformers 4.56.2
39
 
40
+ ### Installation
41
 
42
+ First, clone the repository:
 
 
43
 
44
+ ```bash
45
+ git clone https://github.com/SihanXU/nepa
46
+ cd nepa
47
+ ```
48
 
49
+ Then, create a conda environment and install dependencies:
50
 
51
+ ```bash
52
+ conda env create -f environment.yml
53
+ conda activate nepa
54
+ ```
55
 
56
+ Alternatively, you can install the dependencies manually:
57
 
58
+ ```bash
59
+ pip install -r requirements.txt
60
+ ```
61
 
62
+ ## Quick Start
63
 
64
+ Here's a simple example to run inference with a pretrained NEPA model:
65
 
66
+ ```python
67
+ from transformers import AutoImageProcessor
68
+ from models.vit_nepa import ViTNepaForImageClassification
69
+ from PIL import Image
70
+ import requests
71
 
72
+ url = 'https://raw.githubusercontent.com/pytorch/hub/master/images/dog.jpg'
73
+ image = Image.open(requests.get(url, stream=True).raw)
74
 
75
+ processor = AutoImageProcessor.from_pretrained('SixAILab/nepa-large-patch14-224-sft')
76
+ model = ViTNepaForImageClassification.from_pretrained('SixAILab/nepa-large-patch14-224-sft')
77
 
78
+ inputs = processor(images=image, return_tensors="pt")
79
+ outputs = model(**inputs)
80
+ logits = outputs.logits
81
+ # model predicts one of the 1000 ImageNet classes
82
+ predicted_class_idx = logits.argmax(-1).item()
83
+ print("Predicted class:", model.config.id2label[predicted_class_idx])
84
+ ```
85
 
86
+ ## Setup Huggingface Token
87
 
88
+ To download pretrained models from Hugging Face Hub, you need to authenticate with your Hugging Face account:
89
 
90
+ ```bash
91
+ hf auth login
92
+ ```
93
 
 
94
 
95
+ ## [Optional] Setup Wandb Token
96
 
97
+ We use Wandb to track experiments. You may want to use [Weights & Biases](https://wandb.ai/) to log and track your experiments:
98
 
99
+ ```bash
100
+ pip install wandb
101
+ wandb login
102
+ ```
103
 
104
+ ## Prepare ImageNet-1k Dataset
105
 
106
+ We use the ImageNet-1k dataset for training and evaluation. To download the dataset via Hugging Face Datasets:
107
 
108
+ ```bash
109
+ python download_dataset.py
110
+ ```
111
 
112
+ This script will download and prepare the ImageNet-1k dataset. Note that this requires approximately 150GB of disk space. You may need to accept the dataset terms on [Hugging Face](https://huggingface.co/datasets/ILSVRC/imagenet-1k) before downloading.
113
 
114
+ ## Evaluate Nepa for Image Classification
115
 
116
+ We provide pretrained checkpoints for NEPA models. The following table compares our reproduced results with the paper:
117
 
118
+ | Model | SwiGLU (paper) | GeLU (reproduce) |
119
+ |--------|---------------:|-----------------:|
120
+ | Nepa-B | 83.8 | 83.75 |
121
+ | Nepa-L | 85.3 | 85.40 |
122
 
123
+ To evaluate the base model on ImageNet-1k validation set:
124
 
125
+ ```bash
126
+ bash scripts/eval/nepa_b_sft_eval.sh
127
+ ```
128
 
129
+ This should give:
130
+ ```
131
+ ***** eval metrics *****
132
+ eval_accuracy = 0.8375
133
+ eval_loss = 0.7169
134
+ ```
135
 
136
+ To evaluate the large model:
137
 
138
+ ```bash
139
+ bash scripts/eval/nepa_l_sft_eval.sh
140
+ ```
141
 
142
+ This should give:
143
+ ```
144
+ ***** eval metrics *****
145
+ eval_accuracy = 0.854
146
+ eval_loss = 0.6371
147
+ ```
148
 
149
+ ## Fine-tune
150
 
151
+ To fine-tune a pretrained NEPA model on ImageNet-1k for image classification:
152
 
153
+ For the base model:
154
 
155
+ ```bash
156
+ bash scripts/finetune/nepa_b_sft.sh
157
+ ```
158
 
159
+ For the large model:
160
 
161
+ ```bash
162
+ bash scripts/finetune/nepa_l_sft.sh
163
+ ```
164
 
165
+ You can modify the training hyperparameters (learning rate, batch size, epochs, etc.) in the corresponding script files.
166
 
167
+ ## Pretrain
168
 
169
+ To pretrain NEPA from scratch on ImageNet-1k:
170
 
171
+ For the base model:
172
 
173
+ ```bash
174
+ bash scripts/pretrain/nepa_b.sh
175
+ ```
176
 
177
+ For the large model:
178
 
179
+ ```bash
180
+ bash scripts/pretrain/nepa_l.sh
181
+ ```
182
 
183
+ Pretraining typically requires multiple GPUs. We recommend using at least 8 A100 GPUs for the large model.
184
 
185
+ ## Convert a Pretrained Model to Classification Model
186
 
187
+ After pretraining, you can convert the pretrained model to a classification model by initializing a classification head. Use the `init_nepa_cls_from_pretrain.py` script:
188
 
189
+ Here is an example:
190
+ ```
191
+ python init_nepa_cls_from_pretrain.py \
192
+ --pretrained_model_id SixAILab/nepa-base-patch14-224 \
193
+ --config_model_id configs/finetune/nepa-base-patch14-224-sft \
194
+ --pretrained_revision main \
195
+ --save_local \
196
+ --local_dir ./nepa-base-patch14-224-sft
197
+ ```
198
 
199
+ ## Acknowledgements
200
 
201
+ We gratefully acknowledge the developers of [Transformers](https://github.com/huggingface/transformers), [Evaluate](https://github.com/huggingface/evaluate), and [timm](https://github.com/huggingface/pytorch-image-models) for their excellent open-source contributions.
202
 
203
+ ## Contact
204
 
205
+ Feel free to contact me through email (sihanxu@umich.edu). Enjoy!