maitri01 commited on
Commit
5477669
·
verified ·
1 Parent(s): 6ef6fda

Upload 148 files

Browse files
This view is limited to 50 files because it contains too many changes.   See raw diff
Files changed (50) hide show
  1. RAR/1d-tokenizer/LICENSE +201 -0
  2. RAR/1d-tokenizer/README.md +125 -0
  3. RAR/1d-tokenizer/README_MaskGen.md +277 -0
  4. RAR/1d-tokenizer/README_RAR.md +236 -0
  5. RAR/1d-tokenizer/README_TiTok.md +215 -0
  6. RAR/1d-tokenizer/__pycache__/demo_util.cpython-312.pyc +0 -0
  7. RAR/1d-tokenizer/__pycache__/imagenet_classes.cpython-312.pyc +0 -0
  8. RAR/1d-tokenizer/assets/ILSVRC2012_val_00008636.png +3 -0
  9. RAR/1d-tokenizer/assets/ILSVRC2012_val_00010240.png +3 -0
  10. RAR/1d-tokenizer/assets/maskgen_overview.png +3 -0
  11. RAR/1d-tokenizer/assets/maskgen_vis1.png +3 -0
  12. RAR/1d-tokenizer/assets/maskgen_vis2.png +3 -0
  13. RAR/1d-tokenizer/assets/maskgen_vis3.png +3 -0
  14. RAR/1d-tokenizer/assets/perf_comp.png +3 -0
  15. RAR/1d-tokenizer/assets/random_vis_l32.png +3 -0
  16. RAR/1d-tokenizer/assets/rar_overview.png +3 -0
  17. RAR/1d-tokenizer/assets/recon_w_model_size_num_token.png +3 -0
  18. RAR/1d-tokenizer/assets/speed_vs_perf.png +3 -0
  19. RAR/1d-tokenizer/assets/tatitok_overview.png +3 -0
  20. RAR/1d-tokenizer/assets/titok_teaser.png +3 -0
  21. RAR/1d-tokenizer/assets/vis1.png +3 -0
  22. RAR/1d-tokenizer/assets/vis2.png +3 -0
  23. RAR/1d-tokenizer/assets/vis3.png +3 -0
  24. RAR/1d-tokenizer/configs/infer/MaskGen/maskgen_kl_l.yaml +36 -0
  25. RAR/1d-tokenizer/configs/infer/MaskGen/maskgen_kl_xl.yaml +36 -0
  26. RAR/1d-tokenizer/configs/infer/MaskGen/maskgen_vq_l.yaml +35 -0
  27. RAR/1d-tokenizer/configs/infer/MaskGen/maskgen_vq_xl.yaml +35 -0
  28. RAR/1d-tokenizer/configs/infer/TA-TiTok/tatitok_bl128_vq.yaml +24 -0
  29. RAR/1d-tokenizer/configs/infer/TA-TiTok/tatitok_bl32_vae.yaml +20 -0
  30. RAR/1d-tokenizer/configs/infer/TA-TiTok/tatitok_bl32_vq.yaml +24 -0
  31. RAR/1d-tokenizer/configs/infer/TA-TiTok/tatitok_bl64_vae.yaml +20 -0
  32. RAR/1d-tokenizer/configs/infer/TA-TiTok/tatitok_bl64_vq.yaml +24 -0
  33. RAR/1d-tokenizer/configs/infer/TA-TiTok/tatitok_sl128_vae.yaml +20 -0
  34. RAR/1d-tokenizer/configs/infer/TiTok/titok_b64.yaml +39 -0
  35. RAR/1d-tokenizer/configs/infer/TiTok/titok_bl128_vae_c16.yaml +19 -0
  36. RAR/1d-tokenizer/configs/infer/TiTok/titok_bl128_vq8k.yaml +21 -0
  37. RAR/1d-tokenizer/configs/infer/TiTok/titok_bl64_vae_c16.yaml +19 -0
  38. RAR/1d-tokenizer/configs/infer/TiTok/titok_bl64_vq8k.yaml +21 -0
  39. RAR/1d-tokenizer/configs/infer/TiTok/titok_l32.yaml +40 -0
  40. RAR/1d-tokenizer/configs/infer/TiTok/titok_ll32_vae_c16.yaml +19 -0
  41. RAR/1d-tokenizer/configs/infer/TiTok/titok_s128.yaml +39 -0
  42. RAR/1d-tokenizer/configs/infer/TiTok/titok_sl256_vq8k.yaml +21 -0
  43. RAR/1d-tokenizer/configs/training/MaskGen/maskgen_kl_l_stage1.yaml +82 -0
  44. RAR/1d-tokenizer/configs/training/MaskGen/maskgen_kl_l_stage2.yaml +83 -0
  45. RAR/1d-tokenizer/configs/training/MaskGen/maskgen_kl_xl_stage1.yaml +82 -0
  46. RAR/1d-tokenizer/configs/training/MaskGen/maskgen_kl_xl_stage2.yaml +83 -0
  47. RAR/1d-tokenizer/configs/training/MaskGen/maskgen_vq_l_stage1.yaml +86 -0
  48. RAR/1d-tokenizer/configs/training/MaskGen/maskgen_vq_l_stage2.yaml +87 -0
  49. RAR/1d-tokenizer/configs/training/MaskGen/maskgen_vq_xl_stage1.yaml +86 -0
  50. RAR/1d-tokenizer/configs/training/MaskGen/maskgen_vq_xl_stage2.yaml +87 -0
RAR/1d-tokenizer/LICENSE ADDED
@@ -0,0 +1,201 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ Apache License
2
+ Version 2.0, January 2004
3
+ http://www.apache.org/licenses/
4
+
5
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6
+
7
+ 1. Definitions.
8
+
9
+ "License" shall mean the terms and conditions for use, reproduction,
10
+ and distribution as defined by Sections 1 through 9 of this document.
11
+
12
+ "Licensor" shall mean the copyright owner or entity authorized by
13
+ the copyright owner that is granting the License.
14
+
15
+ "Legal Entity" shall mean the union of the acting entity and all
16
+ other entities that control, are controlled by, or are under common
17
+ control with that entity. For the purposes of this definition,
18
+ "control" means (i) the power, direct or indirect, to cause the
19
+ direction or management of such entity, whether by contract or
20
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
21
+ outstanding shares, or (iii) beneficial ownership of such entity.
22
+
23
+ "You" (or "Your") shall mean an individual or Legal Entity
24
+ exercising permissions granted by this License.
25
+
26
+ "Source" form shall mean the preferred form for making modifications,
27
+ including but not limited to software source code, documentation
28
+ source, and configuration files.
29
+
30
+ "Object" form shall mean any form resulting from mechanical
31
+ transformation or translation of a Source form, including but
32
+ not limited to compiled object code, generated documentation,
33
+ and conversions to other media types.
34
+
35
+ "Work" shall mean the work of authorship, whether in Source or
36
+ Object form, made available under the License, as indicated by a
37
+ copyright notice that is included in or attached to the work
38
+ (an example is provided in the Appendix below).
39
+
40
+ "Derivative Works" shall mean any work, whether in Source or Object
41
+ form, that is based on (or derived from) the Work and for which the
42
+ editorial revisions, annotations, elaborations, or other modifications
43
+ represent, as a whole, an original work of authorship. For the purposes
44
+ of this License, Derivative Works shall not include works that remain
45
+ separable from, or merely link (or bind by name) to the interfaces of,
46
+ the Work and Derivative Works thereof.
47
+
48
+ "Contribution" shall mean any work of authorship, including
49
+ the original version of the Work and any modifications or additions
50
+ to that Work or Derivative Works thereof, that is intentionally
51
+ submitted to Licensor for inclusion in the Work by the copyright owner
52
+ or by an individual or Legal Entity authorized to submit on behalf of
53
+ the copyright owner. For the purposes of this definition, "submitted"
54
+ means any form of electronic, verbal, or written communication sent
55
+ to the Licensor or its representatives, including but not limited to
56
+ communication on electronic mailing lists, source code control systems,
57
+ and issue tracking systems that are managed by, or on behalf of, the
58
+ Licensor for the purpose of discussing and improving the Work, but
59
+ excluding communication that is conspicuously marked or otherwise
60
+ designated in writing by the copyright owner as "Not a Contribution."
61
+
62
+ "Contributor" shall mean Licensor and any individual or Legal Entity
63
+ on behalf of whom a Contribution has been received by Licensor and
64
+ subsequently incorporated within the Work.
65
+
66
+ 2. Grant of Copyright License. Subject to the terms and conditions of
67
+ this License, each Contributor hereby grants to You a perpetual,
68
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
69
+ copyright license to reproduce, prepare Derivative Works of,
70
+ publicly display, publicly perform, sublicense, and distribute the
71
+ Work and such Derivative Works in Source or Object form.
72
+
73
+ 3. Grant of Patent License. Subject to the terms and conditions of
74
+ this License, each Contributor hereby grants to You a perpetual,
75
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
76
+ (except as stated in this section) patent license to make, have made,
77
+ use, offer to sell, sell, import, and otherwise transfer the Work,
78
+ where such license applies only to those patent claims licensable
79
+ by such Contributor that are necessarily infringed by their
80
+ Contribution(s) alone or by combination of their Contribution(s)
81
+ with the Work to which such Contribution(s) was submitted. If You
82
+ institute patent litigation against any entity (including a
83
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
84
+ or a Contribution incorporated within the Work constitutes direct
85
+ or contributory patent infringement, then any patent licenses
86
+ granted to You under this License for that Work shall terminate
87
+ as of the date such litigation is filed.
88
+
89
+ 4. Redistribution. You may reproduce and distribute copies of the
90
+ Work or Derivative Works thereof in any medium, with or without
91
+ modifications, and in Source or Object form, provided that You
92
+ meet the following conditions:
93
+
94
+ (a) You must give any other recipients of the Work or
95
+ Derivative Works a copy of this License; and
96
+
97
+ (b) You must cause any modified files to carry prominent notices
98
+ stating that You changed the files; and
99
+
100
+ (c) You must retain, in the Source form of any Derivative Works
101
+ that You distribute, all copyright, patent, trademark, and
102
+ attribution notices from the Source form of the Work,
103
+ excluding those notices that do not pertain to any part of
104
+ the Derivative Works; and
105
+
106
+ (d) If the Work includes a "NOTICE" text file as part of its
107
+ distribution, then any Derivative Works that You distribute must
108
+ include a readable copy of the attribution notices contained
109
+ within such NOTICE file, excluding those notices that do not
110
+ pertain to any part of the Derivative Works, in at least one
111
+ of the following places: within a NOTICE text file distributed
112
+ as part of the Derivative Works; within the Source form or
113
+ documentation, if provided along with the Derivative Works; or,
114
+ within a display generated by the Derivative Works, if and
115
+ wherever such third-party notices normally appear. The contents
116
+ of the NOTICE file are for informational purposes only and
117
+ do not modify the License. You may add Your own attribution
118
+ notices within Derivative Works that You distribute, alongside
119
+ or as an addendum to the NOTICE text from the Work, provided
120
+ that such additional attribution notices cannot be construed
121
+ as modifying the License.
122
+
123
+ You may add Your own copyright statement to Your modifications and
124
+ may provide additional or different license terms and conditions
125
+ for use, reproduction, or distribution of Your modifications, or
126
+ for any such Derivative Works as a whole, provided Your use,
127
+ reproduction, and distribution of the Work otherwise complies with
128
+ the conditions stated in this License.
129
+
130
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
131
+ any Contribution intentionally submitted for inclusion in the Work
132
+ by You to the Licensor shall be under the terms and conditions of
133
+ this License, without any additional terms or conditions.
134
+ Notwithstanding the above, nothing herein shall supersede or modify
135
+ the terms of any separate license agreement you may have executed
136
+ with Licensor regarding such Contributions.
137
+
138
+ 6. Trademarks. This License does not grant permission to use the trade
139
+ names, trademarks, service marks, or product names of the Licensor,
140
+ except as required for reasonable and customary use in describing the
141
+ origin of the Work and reproducing the content of the NOTICE file.
142
+
143
+ 7. Disclaimer of Warranty. Unless required by applicable law or
144
+ agreed to in writing, Licensor provides the Work (and each
145
+ Contributor provides its Contributions) on an "AS IS" BASIS,
146
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
147
+ implied, including, without limitation, any warranties or conditions
148
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
149
+ PARTICULAR PURPOSE. You are solely responsible for determining the
150
+ appropriateness of using or redistributing the Work and assume any
151
+ risks associated with Your exercise of permissions under this License.
152
+
153
+ 8. Limitation of Liability. In no event and under no legal theory,
154
+ whether in tort (including negligence), contract, or otherwise,
155
+ unless required by applicable law (such as deliberate and grossly
156
+ negligent acts) or agreed to in writing, shall any Contributor be
157
+ liable to You for damages, including any direct, indirect, special,
158
+ incidental, or consequential damages of any character arising as a
159
+ result of this License or out of the use or inability to use the
160
+ Work (including but not limited to damages for loss of goodwill,
161
+ work stoppage, computer failure or malfunction, or any and all
162
+ other commercial damages or losses), even if such Contributor
163
+ has been advised of the possibility of such damages.
164
+
165
+ 9. Accepting Warranty or Additional Liability. While redistributing
166
+ the Work or Derivative Works thereof, You may choose to offer,
167
+ and charge a fee for, acceptance of support, warranty, indemnity,
168
+ or other liability obligations and/or rights consistent with this
169
+ License. However, in accepting such obligations, You may act only
170
+ on Your own behalf and on Your sole responsibility, not on behalf
171
+ of any other Contributor, and only if You agree to indemnify,
172
+ defend, and hold each Contributor harmless for any liability
173
+ incurred by, or claims asserted against, such Contributor by reason
174
+ of your accepting any such warranty or additional liability.
175
+
176
+ END OF TERMS AND CONDITIONS
177
+
178
+ APPENDIX: How to apply the Apache License to your work.
179
+
180
+ To apply the Apache License to your work, attach the following
181
+ boilerplate notice, with the fields enclosed by brackets "[]"
182
+ replaced with your own identifying information. (Don't include
183
+ the brackets!) The text should be enclosed in the appropriate
184
+ comment syntax for the file format. We also recommend that a
185
+ file or class name and description of purpose be included on the
186
+ same "printed page" as the copyright notice for easier
187
+ identification within third-party archives.
188
+
189
+ Copyright [yyyy] [name of copyright owner]
190
+
191
+ Licensed under the Apache License, Version 2.0 (the "License");
192
+ you may not use this file except in compliance with the License.
193
+ You may obtain a copy of the License at
194
+
195
+ http://www.apache.org/licenses/LICENSE-2.0
196
+
197
+ Unless required by applicable law or agreed to in writing, software
198
+ distributed under the License is distributed on an "AS IS" BASIS,
199
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
200
+ See the License for the specific language governing permissions and
201
+ limitations under the License.
RAR/1d-tokenizer/README.md ADDED
@@ -0,0 +1,125 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # 1D Visual Tokenization and Generation
2
+
3
+ This repo hosts the code and models for the following projects:
4
+
5
+ - FlowTok: [FlowTok: Flowing Seamlessly Across Text and Image Tokens](https://tacju.github.io/projects/flowtok.html)
6
+
7
+ - TA-TiTok & MaskGen: [Democratizing Text-to-Image Masked Generative Models with Compact Text-Aware One-Dimensional Tokens](https://tacju.github.io/projects/maskgen.html)
8
+
9
+ - RAR: [Randomized Autoregressive Visual Generation](https://yucornetto.github.io/projects/rar.html)
10
+
11
+ - TiTok: [An Image is Worth 32 Tokens for Reconstruction and Generation](https://yucornetto.github.io/projects/titok.html)
12
+
13
+ ## Updates
14
+ - 03/16/2025: The [tech report](https://arxiv.org/abs/2503.10772) of FlowTok is available. FlowTok is a minimal yet powerful framework that seamlessly flows across text and images by encoding images into a compact 1D token representation. Code will be released soon.
15
+ - 02/24/2025: We release the training code, inference code and model weights of MaskGen.
16
+ - 01/17/2025: We release the training code, inference code and model weights of TA-TiTok.
17
+ - 01/14/2025: The [tech report](https://arxiv.org/abs/2501.07730) of TA-TiTok and MaskGen is available. TA-TiTok is an innovative text-aware transformer-based 1-dimensional tokenizer designed to handle both discrete and continuous tokens. MaskGen is a powerful and efficient text-to-image masked generative model trained exclusively on open-data. For more details, refer to the [README_MaskGen](README_MaskGen.md).
18
+ - 11/04/2024: We release the [tech report](https://arxiv.org/abs/2411.00776) and code for RAR models.
19
+ - 10/16/2024: We update a set of TiTok tokenizer weights trained with an updated single-stage recipe, leading to easier training and better performance. We release the weight of different model size for both VQ and VAE variants TiTok, which we hope could facilitate the research in this area. More details are available in the [tech report](https://arxiv.org/abs/2501.07730) of TA-TiTok.
20
+ - 09/25/2024: TiTok is accepted by NeurIPS 2024.
21
+ - 09/11/2024: Release the training codes of generator based on TiTok.
22
+ - 08/28/2024: Release the training codes of TiTok.
23
+ - 08/09/2024: Better support on loading pretrained weights from huggingface models, thanks for the help from [@NielsRogge](https://github.com/NielsRogge)!
24
+ - 07/03/2024: Evaluation scripts for reproducing the results reported in the paper, checkpoints of TiTok-B64 and TiTok-S128 are available.
25
+ - 06/21/2024: Demo code and TiTok-L-32 checkpoints release.
26
+ - 06/11/2024: The [tech report](https://arxiv.org/abs/2406.07550) of TiTok is available.
27
+
28
+ ## Short Intro on [Democratizing Text-to-Image Masked Generative Models with Compact Text-Aware One-Dimensional Tokens](https://arxiv.org/abs/2501.07730) ([README](README_MaskGen.md))
29
+
30
+ We introduce TA-TiTok, a novel text-aware transformer-based 1D tokenizer designed to handle both discrete and continuous tokens while effectively aligning reconstructions with textual descriptions.
31
+ Building on TA-TiTok, we present MaskGen, a versatile text-to-image masked generative model framework. Trained exclusively on open data, MaskGen demonstrates outstanding performance: with 32 continuous tokens, it achieves a FID score of 6.53 on MJHQ-30K, and with 128 discrete tokens, it attains an overall score of 0.57 on GenEval.
32
+
33
+ <p>
34
+ <img src="assets/tatitok_overview.png" alt="teaser" width=90% height=90%>
35
+ </p>
36
+ <p>
37
+ <img src="assets/maskgen_overview.png" alt="teaser" width=90% height=90%>
38
+ </p>
39
+
40
+ See more details at [README_MaskGen](README_MaskGen.md).
41
+
42
+ ## Short Intro on [Randomized Autoregressive Visual Generation](https://arxiv.org/abs/2411.00776) ([README](README_RAR.md))
43
+
44
+ RAR is a an autoregressive (AR) image generator with full compatibility to language modeling. It introduces a randomness annealing strategy with permuted objective at no additional cost, which enhances the model's ability to learn bidirectional contexts while leaving the autoregressive framework intact. RAR sets a FID score 1.48, demonstrating state-of-the-art performance on ImageNet-256 benchmark and significantly outperforming prior AR image generators.
45
+
46
+ <p>
47
+ <img src="assets/rar_overview.png" alt="teaser" width=90% height=90%>
48
+ </p>
49
+ <p>
50
+ <img src="assets/perf_comp.png" alt="teaser" width=90% height=90%>
51
+ </p>
52
+
53
+ See more details at [README_RAR](README_RAR.md).
54
+
55
+ ## Short Intro on [An Image is Worth 32 Tokens for Reconstruction and Generation](https://arxiv.org/abs/2406.07550) ([README](README_TiTok.md))
56
+
57
+ We present a compact 1D tokenizer which can represent an image with as few as 32 discrete tokens. As a result, it leads to a substantial speed-up on the sampling process (e.g., **410 × faster** than DiT-XL/2) while obtaining a competitive generation quality.
58
+
59
+ <p>
60
+ <img src="assets/titok_teaser.png" alt="teaser" width=90% height=90%>
61
+ </p>
62
+ <p>
63
+ <img src="assets/speed_vs_perf.png" alt="teaser" width=90% height=90%>
64
+ </p>
65
+
66
+ See more details at [README_TiTok](README_TiTok.md).
67
+
68
+
69
+ ## Installation
70
+ ```shell
71
+ pip3 install -r requirements.txt
72
+ ```
73
+
74
+ ## Citing
75
+ If you use our work in your research, please use the following BibTeX entry.
76
+
77
+ ```BibTeX
78
+ @article{he2025flowtok,
79
+ author = {Ju He and Qihang Yu and Qihao Liu and Liang-Chieh Chen},
80
+ title = {FlowTok: Flowing Seamlessly Across Text and Image Tokens},
81
+ journal = {arXiv preprint arXiv:2503.10772},
82
+ year = {2025}
83
+ }
84
+ ```
85
+
86
+ ```BibTeX
87
+ @article{kim2025democratizing,
88
+ author = {Dongwon Kim and Ju He and Qihang Yu and Chenglin Yang and Xiaohui Shen and Suha Kwak and Liang-Chieh Chen},
89
+ title = {Democratizing Text-to-Image Masked Generative Models with Compact Text-Aware One-Dimensional Tokens},
90
+ journal = {arXiv preprint arXiv:2501.07730},
91
+ year = {2025}
92
+ }
93
+ ```
94
+
95
+ ```BibTeX
96
+ @article{yu2024randomized,
97
+ author = {Qihang Yu and Ju He and Xueqing Deng and Xiaohui Shen and Liang-Chieh Chen},
98
+ title = {Randomized Autoregressive Visual Generation},
99
+ journal = {arXiv preprint arXiv:2411.00776},
100
+ year = {2024}
101
+ }
102
+ ```
103
+
104
+ ```BibTeX
105
+ @article{yu2024an,
106
+ author = {Qihang Yu and Mark Weber and Xueqing Deng and Xiaohui Shen and Daniel Cremers and Liang-Chieh Chen},
107
+ title = {An Image is Worth 32 Tokens for Reconstruction and Generation},
108
+ journal = {NeurIPS},
109
+ year = {2024}
110
+ }
111
+ ```
112
+
113
+ ## Acknowledgement
114
+
115
+ [CrossFlow](https://github.com/qihao067/CrossFlow)
116
+
117
+ [MAR](https://github.com/LTH14/mar)
118
+
119
+ [MaskGIT](https://github.com/google-research/maskgit)
120
+
121
+ [Taming-Transformers](https://github.com/CompVis/taming-transformers)
122
+
123
+ [Open-MUSE](https://github.com/huggingface/open-muse)
124
+
125
+ [MUSE-Pytorch](https://github.com/baaivision/MUSE-Pytorch)
RAR/1d-tokenizer/README_MaskGen.md ADDED
@@ -0,0 +1,277 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Democratizing Text-to-Image Masked Generative Models with Compact Text-Aware One-Dimensional Tokens
2
+
3
+
4
+ <div align="center">
5
+
6
+ [![Website](https://img.shields.io/badge/Project-Website-87CEEB)](https://tacju.github.io/projects/maskgen.html)&nbsp;&nbsp;
7
+ [![paper](https://img.shields.io/badge/arXiv-Paper-<COLOR>.svg)](http://arxiv.org/abs/2501.07730)&nbsp;&nbsp;
8
+
9
+ </div>
10
+
11
+ <!-- <p>
12
+ <img src="assets/maskgen_teaser.png" alt="teaser" width=90% height=90%>
13
+ </p> -->
14
+
15
+ We introduce TA-TiTok, a novel text-aware transformer-based 1D tokenizer designed to handle both discrete and continuous tokens while effectively aligning reconstructions with textual descriptions.
16
+ Building on TA-TiTok, we present MaskGen, a versatile text-to-image masked generative model framework. Trained exclusively on open data, MaskGen demonstrates outstanding performance: with 32 continuous tokens, it achieves a FID score of 6.53 on MJHQ-30K, and with 128 discrete tokens, it attains an overall score of 0.57 on GenEval.
17
+
18
+
19
+ <p>
20
+ <img src="assets/tatitok_overview.png" alt="teaser" width=90% height=90%>
21
+ </p>
22
+ <p>
23
+ <img src="assets/maskgen_overview.png" alt="teaser" width=90% height=90%>
24
+ </p>
25
+
26
+
27
+ ## 🚀 Contributions
28
+
29
+ #### We introduce TA-TiTok, an innovative text-aware transformer-based 1-dimensional tokenizer designed to handle both discrete and continuous tokens. TA-TiTok seamlessly integrates text information during the de-tokenization stage and offers scalability to efficiently handle large-scale datasets with a simple one-stage training recipe.
30
+
31
+ #### We propose MaskGen, a family of text-to-image masked generative models built upon TA-TiTok. The MaskGen VQ and MaskGen KL variants utilize compact sequences of 128 discrete tokens and 32 continuous tokens, respectively. Trained exclusively on open data, MaskGen achieves performance comparable to models trained on proprietary datasets, while offering significantly lower training cost and substantially faster inference speed.
32
+
33
+
34
+ ## TA-TiTok Model Zoo
35
+ | arch | #tokens | Link | rFID | IS |
36
+ | ------------- | ------------- | ------------- | ------------- | ------------- |
37
+ | VQ | 32 | [checkpoint](https://huggingface.co/turkeyju/tokenizer_tatitok_bl32_vq) | 3.95 | 219.6 |
38
+ | VQ | 64 | [checkpoint](https://huggingface.co/turkeyju/tokenizer_tatitok_bl64_vq) | 2.43 | 218.8 |
39
+ | VQ | 128 | [checkpoint](https://huggingface.co/turkeyju/tokenizer_tatitok_bl128_vq) | 1.53 | 222.8 |
40
+ | KL | 32 | [checkpoint](https://huggingface.co/turkeyju/tokenizer_tatitok_bl32_vae) | 1.53 | 222.0 |
41
+ | KL | 64 | [checkpoint](https://huggingface.co/turkeyju/tokenizer_tatitok_bl64_vae) | 1.47 | 220.7 |
42
+ | KL | 128 | [checkpoint](https://huggingface.co/turkeyju/tokenizer_tatitok_sl128_vae) | 0.90 | 227.7 |
43
+
44
+ Please note that these models are only for research purposes.
45
+
46
+ ## MaskGen Model Zoo
47
+ | Model | arch | Link | MJHQ-30K FID | GenEval Overall |
48
+ | ------------- | ------------- | ------------- | ------------- | ------------- |
49
+ | MaskGen-L | VQ | [checkpoint](https://huggingface.co/turkeyju/generator_maskgen_vq_l) | 7.74 | 0.53 |
50
+ | MaskGen-XL | VQ | [checkpoint](https://huggingface.co/turkeyju/generator_maskgen_vq_xl) | 7.51 | 0.57 |
51
+ | MaskGen-L | KL | [checkpoint](https://huggingface.co/turkeyju/generator_maskgen_kl_l) | 7.24 | 0.52 |
52
+ | MaskGen-XL | KL | [checkpoint](https://huggingface.co/turkeyju/generator_maskgen_kl_xl) | 6.53 | 0.55 |
53
+
54
+ Please note that these models are only for research purposes.
55
+
56
+ ## Installation
57
+ ```shell
58
+ pip3 install -r requirements.txt
59
+ ```
60
+
61
+ ## Get Started - TA-TiTok
62
+ ```python
63
+ import torch
64
+ from PIL import Image
65
+ import numpy as np
66
+ import open_clip
67
+ import demo_util
68
+ from huggingface_hub import hf_hub_download
69
+ from modeling.tatitok import TATiTok
70
+
71
+ # Choose one from ["tokenizer_tatitok_bl32_vq", "tokenizer_tatitok_bl64_vq, tokenizer_tatitok_bl128_vq", "tokenizer_tatitok_bl32_vae", "tokenizer_tatitok_bl64_vae, tokenizer_tatitok_sl128_vae"]
72
+ tatitok_tokenizer = TATiTok.from_pretrained("turkeyju/tokenizer_tatitok_bl32_vae")
73
+ tatitok_tokenizer.eval()
74
+ tatitok_tokenizer.requires_grad_(False)
75
+
76
+ # or alternatively, downloads from hf
77
+ # hf_hub_download(repo_id="fun-research/TA-TiTok", filename="tatitok_bl32_vae.bin", local_dir="./")
78
+
79
+ # load config
80
+ # config = demo_util.get_config("configs/infer/TA-TiTok/tatitok_bl32_vae.yaml")
81
+ # tatitok_tokenizer = demo_util.get_tatitok_tokenizer(config)
82
+
83
+ clip_encoder, _, _ = open_clip.create_model_and_transforms('ViT-L-14-336', pretrained='openai')
84
+ del clip_encoder.visual
85
+ clip_tokenizer = open_clip.get_tokenizer('ViT-L-14-336')
86
+ clip_encoder.transformer.batch_first = False
87
+ clip_encoder.eval()
88
+ clip_encoder.requires_grad_(False)
89
+
90
+ device = "cuda"
91
+ tatitok_tokenizer = tatitok_tokenizer.to(device)
92
+ clip_encoder = clip_encoder.to(device)
93
+
94
+ # reconstruct an image. I.e., image -> 32 tokens -> image
95
+ img_path = "assets/ILSVRC2012_val_00010240.png"
96
+ image = torch.from_numpy(np.array(Image.open(img_path)).astype(np.float32)).permute(2, 0, 1).unsqueeze(0) / 255.0
97
+ # tokenization
98
+ if tatitok_tokenizer.quantize_mode == "vq":
99
+ encoded_tokens = tatitok_tokenizer.encode(image.to(device))[1]["min_encoding_indices"]
100
+ elif tatitok_tokenizer.quantize_mode == "vae":
101
+ posteriors = tatitok_tokenizer.encode(image.to(device))[1]
102
+ encoded_tokens = posteriors.sample()
103
+ else:
104
+ raise NotImplementedError
105
+
106
+ text = ["A photo of a jay."]
107
+ text_guidance = clip_tokenizer(text).to(device)
108
+ cast_dtype = clip_encoder.transformer.get_cast_dtype()
109
+ text_guidance = clip_encoder.token_embedding(text_guidance).to(cast_dtype) # [batch_size, n_ctx, d_model]
110
+ text_guidance = text_guidance + clip_encoder.positional_embedding.to(cast_dtype)
111
+ text_guidance = text_guidance.permute(1, 0, 2) # NLD -> LND
112
+ text_guidance = clip_encoder.transformer(text_guidance, attn_mask=clip_encoder.attn_mask)
113
+ text_guidance = text_guidance.permute(1, 0, 2) # LND -> NLD
114
+ text_guidance = clip_encoder.ln_final(text_guidance) # [batch_size, n_ctx, transformer.width]
115
+
116
+ print(f"image {img_path} is encoded into tokens {encoded_tokens}, with shape {encoded_tokens.shape}")
117
+
118
+ # de-tokenization
119
+ reconstructed_image = tatitok_tokenizer.decode_tokens(encoded_tokens, text_guidance)
120
+ reconstructed_image = torch.clamp(reconstructed_image, 0.0, 1.0)
121
+ reconstructed_image = (reconstructed_image * 255.0).permute(0, 2, 3, 1).to("cpu", dtype=torch.uint8).numpy()[0]
122
+ reconstructed_image = Image.fromarray(reconstructed_image).save("assets/ILSVRC2012_val_00010240_recon.png")
123
+ ```
124
+
125
+ ## Get Started - MaskGen
126
+ ```python
127
+ import torch
128
+ from PIL import Image
129
+ import numpy as np
130
+ import open_clip
131
+ import demo_util
132
+ from huggingface_hub import hf_hub_download
133
+ from modeling.tatitok import TATiTok
134
+ from modeling.maskgen import MaskGen_VQ, MaskGen_KL
135
+
136
+ torch.manual_seed(42)
137
+ torch.cuda.manual_seed(42)
138
+ torch.backends.cudnn.deterministic = True
139
+ torch.backends.cudnn.benchmark = False
140
+
141
+ # VQ Tokenizer: load tokenizer tatitok_bl128_vq
142
+ tatitok_vq_tokenizer = TATiTok.from_pretrained("turkeyju/tokenizer_tatitok_bl128_vq")
143
+ tatitok_vq_tokenizer.eval()
144
+ tatitok_vq_tokenizer.requires_grad_(False)
145
+
146
+ # KL Tokenizer: load tokenizer tatitok_bl32_vae
147
+ tatitok_kl_tokenizer = TATiTok.from_pretrained("turkeyju/tokenizer_tatitok_bl32_vae")
148
+ tatitok_kl_tokenizer.eval()
149
+ tatitok_kl_tokenizer.requires_grad_(False)
150
+
151
+ # or alternatively, downloads from hf
152
+ # hf_hub_download(repo_id="fun-research/TA-TiTok", filename="tatitok_bl32_vae.bin", local_dir="./")
153
+
154
+ # load config
155
+ # config = demo_util.get_config("configs/infer/TA-TiTok/tatitok_bl32_vae.yaml")
156
+ # tatitok_tokenizer = demo_util.get_tatitok_tokenizer(config)
157
+
158
+ # VQ Generator: choose one from ["maskgen_vq_l", "maskgen_vq_xl"]
159
+ maskgen_vq_generator = MaskGen_VQ.from_pretrained("turkeyju/generator_maskgen_vq_xl")
160
+ maskgen_vq_generator.eval()
161
+ maskgen_vq_generator.requires_grad_(False)
162
+
163
+ # or alternatively, downloads from hf
164
+ # hf_hub_download(repo_id="fun-research/TA-TiTok", filename="maskgen_vq_xl.bin", local_dir="./")
165
+
166
+ # load config
167
+ # config = demo_util.get_config("configs/infer/MaskGen/maskgen_vq_xl.yaml")
168
+ # maskgen_vq_generator = demo_util.get_maskgen_vq_generator(config)
169
+
170
+ # KL Generator: choose one from ["maskgen_kl_l", "maskgen_kl_xl"]
171
+ maskgen_kl_generator = MaskGen_KL.from_pretrained("turkeyju/generator_maskgen_kl_xl")
172
+ maskgen_kl_generator.eval()
173
+ maskgen_kl_generator.requires_grad_(False)
174
+
175
+ # or alternatively, downloads from hf
176
+ # hf_hub_download(repo_id="fun-research/TA-TiTok", filename="maskgen_kl_xl.bin", local_dir="./")
177
+
178
+ # load config
179
+ # config = demo_util.get_config("configs/infer/MaskGen/maskgen_kl_xl.yaml")
180
+ # maskgen_kl_generator = demo_util.get_maskgen_kl_generator(config)
181
+
182
+ clip_encoder, _, _ = open_clip.create_model_and_transforms('ViT-L-14-336', pretrained='openai')
183
+ del clip_encoder.visual
184
+ clip_tokenizer = open_clip.get_tokenizer('ViT-L-14-336')
185
+ clip_encoder.transformer.batch_first = False
186
+ clip_encoder.eval()
187
+ clip_encoder.requires_grad_(False)
188
+
189
+ device = "cuda"
190
+ tatitok_vq_tokenizer = tatitok_vq_tokenizer.to(device)
191
+ tatitok_kl_tokenizer = tatitok_kl_tokenizer.to(device)
192
+ maskgen_vq_generator = maskgen_vq_generator.to(device)
193
+ maskgen_kl_generator = maskgen_kl_generator.to(device)
194
+ clip_encoder = clip_encoder.to(device)
195
+
196
+ # generate an image
197
+ text = ["A cozy cabin in the middle of a snowy forest, surrounded by tall trees with lights glowing through the windows, a northern lights display visible in the sky."]
198
+ text_guidance = clip_tokenizer(text).to(device)
199
+ cast_dtype = clip_encoder.transformer.get_cast_dtype()
200
+ text_guidance = clip_encoder.token_embedding(text_guidance).to(cast_dtype) # [batch_size, n_ctx, d_model]
201
+ text_guidance = text_guidance + clip_encoder.positional_embedding.to(cast_dtype)
202
+ text_guidance = text_guidance.permute(1, 0, 2) # NLD -> LND
203
+ text_guidance = clip_encoder.transformer(text_guidance, attn_mask=clip_encoder.attn_mask)
204
+ text_guidance = text_guidance.permute(1, 0, 2) # LND -> NLD
205
+ text_guidance = clip_encoder.ln_final(text_guidance) # [batch_size, n_ctx, transformer.width]
206
+
207
+ vq_generated_tokens = maskgen_vq_generator.generate(captions=text, guidance_scale=12.0, randomize_temperature=2.0, sample_aesthetic_score=6.5, clip_tokenizer=clip_tokenizer, clip_encoder=clip_encoder)
208
+ kl_generated_tokens = maskgen_kl_generator.sample_tokens(1, clip_tokenizer, clip_encoder, num_iter=32, cfg=3.0, aes_scores=6.5, captions=text)
209
+
210
+ # de-tokenization
211
+ vq_generated_image = tatitok_vq_tokenizer.decode_tokens(vq_generated_tokens, text_guidance)
212
+ kl_generated_image = tatitok_kl_tokenizer.decode_tokens(kl_generated_tokens, text_guidance)
213
+ vq_generated_image = torch.clamp(vq_generated_image, 0.0, 1.0)
214
+ kl_generated_image = torch.clamp(kl_generated_image, 0.0, 1.0)
215
+ vq_generated_image = (vq_generated_image * 255.0).permute(0, 2, 3, 1).to("cpu", dtype=torch.uint8).numpy()[0]
216
+ kl_generated_image = (kl_generated_image * 255.0).permute(0, 2, 3, 1).to("cpu", dtype=torch.uint8).numpy()[0]
217
+ vq_generated_image = Image.fromarray(vq_generated_image).save("assets/maskgen_vq_generator_generated.png")
218
+ kl_generated_image = Image.fromarray(kl_generated_image).save("assets/maskgen_kl_generator_generated.png")
219
+ ```
220
+
221
+ ## Training Preparation
222
+ We use [webdataset](https://github.com/webdataset/webdataset) format for data loading. To begin with, it is needed to convert the dataset into webdataset format.
223
+
224
+ ## Training
225
+ We provide example commands to train TA-TiTok as follows:
226
+ ```bash
227
+ # Training for TiTok-BL32-VQ
228
+ WANDB_MODE=offline accelerate launch --num_machines=4 --num_processes=8 --machine_rank=0 --main_process_ip=127.0.0.1 --main_process_port=9999 --same_network scripts/train_tatitok.py config=configs/training/TA-TiTok/tatitok_bl32_vq.yaml \
229
+ experiment.project="tatitok_bl32_vq" \
230
+ experiment.name="tatitok_bl32_vq_run1" \
231
+ experiment.output_dir="tatitok_bl32_vq_run1" \
232
+
233
+ # Training for TiTok-BL32-VAE
234
+ WANDB_MODE=offline accelerate launch --num_machines=4 --num_processes=8 --machine_rank=0 --main_process_ip=127.0.0.1 --main_process_port=9999 --same_network scripts/train_tatitok.py config=configs/training/TA-TiTok/tatitok_bl32_vae.yaml \
235
+ experiment.project="tatitok_bl32_vae" \
236
+ experiment.name="tatitok_bl32_vae_run1" \
237
+ experiment.output_dir="tatitok_bl32_vae_run1" \
238
+
239
+ # Training for MaskGen-{VQ/KL}-{L/XL} Stage1
240
+ WANDB_MODE=offline accelerate launch --num_machines=4 --num_processes=8 --machine_rank=0 --main_process_ip=127.0.0.1 --main_process_port=9999 --same_network scripts/train_maskgen.py config=configs/training/MaskGen/maskgen_{vq/kl}_{l/xl}_stage1.yaml \
241
+ experiment.project="maskgen_{vq/kl}_{l/xl}_stage1" \
242
+ experiment.name="maskgen_{vq/kl}_{l/xl}_stage1_run1" \
243
+ experiment.output_dir="maskgen_{vq/kl}_{l/xl}_stage1_run1" \
244
+
245
+ # Training for MaskGen-{VQ/KL}-{L/XL} Stage2
246
+ WANDB_MODE=offline accelerate launch --num_machines=4 --num_processes=8 --machine_rank=0 --main_process_ip=127.0.0.1 --main_process_port=9999 --same_network scripts/train_maskgen.py config=configs/training/MaskGen/maskgen_{vq/kl}_{l/xl}_stage2.yaml \
247
+ experiment.project="maskgen_{vq/kl}_{l/xl}_stage2" \
248
+ experiment.name="maskgen_{vq/kl}_{l/xl}_stage2_run1" \
249
+ experiment.output_dir="maskgen_{vq/kl}_{l/xl}_stage2_run1" \
250
+ ```
251
+ You may remove the flag "WANDB_MODE=offline" to support online wandb logging, if you have configured it.
252
+
253
+ The config can be replaced for other TA-TiTok variants.
254
+
255
+ ## Visualizations
256
+ <p>
257
+ <img src="assets/maskgen_vis1.png" alt="teaser" width=90% height=90%>
258
+ </p>
259
+ <p>
260
+ <img src="assets/maskgen_vis2.png" alt="teaser" width=90% height=90%>
261
+ </p>
262
+ <p>
263
+ <img src="assets/maskgen_vis3.png" alt="teaser" width=90% height=90%>
264
+ </p>
265
+
266
+
267
+ ## Citing
268
+ If you use our work in your research, please use the following BibTeX entry.
269
+
270
+ ```BibTeX
271
+ @article{kim2025democratizing,
272
+ author = {Kim, Dongwon and He, Ju and Yu, Qihang Yu and Yang, Chenglin and Shen, Xiaohui and Kwak, Suha and Chen Liang-Chieh},
273
+ title = {Democratizing Text-to-Image Masked Generative Models with Compact Text-Aware One-Dimensional Tokens},
274
+ journal = {arXiv preprint arXiv:2501.07730},
275
+ year = {2025}
276
+ }
277
+ ```
RAR/1d-tokenizer/README_RAR.md ADDED
@@ -0,0 +1,236 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Randomized Autoregressive Visual Generation
2
+
3
+
4
+ <div align="center">
5
+
6
+ [![demo](https://img.shields.io/badge/%F0%9F%A4%97%20Hugging%20Face-Online_Demo-blue)](https://huggingface.co/spaces/yucornetto/RAR)&nbsp;&nbsp;
7
+ [![Website](https://img.shields.io/badge/Project-Website-87CEEB)](https://yucornetto.github.io/projects/rar.html)&nbsp;&nbsp;
8
+ [![paper](https://img.shields.io/badge/arXiv-Paper-<COLOR>.svg)](https://arxiv.org/abs/2411.00776)&nbsp;&nbsp;
9
+ [![PWC](https://img.shields.io/endpoint.svg?url=https://paperswithcode.com/badge/randomized-autoregressive-visual-generation/image-generation-on-imagenet-256x256)](https://paperswithcode.com/sota/image-generation-on-imagenet-256x256?p=randomized-autoregressive-visual-generation)
10
+
11
+ </div>
12
+
13
+ RAR is a an autoregressive (AR) image generator with full compatibility to language modeling. It introduces a randomness annealing strategy with permuted objective at no additional cost, which enhances the model's ability to learn bidirectional contexts while leaving the autoregressive framework intact. RAR sets a FID score 1.48, demonstrating state-of-the-art performance on ImageNet-256 benchmark and significantly outperforming prior AR image generators.
14
+
15
+
16
+ <p>
17
+ <img src="assets/rar_overview.png" alt="teaser" width=90% height=90%>
18
+ </p>
19
+ <p>
20
+ <img src="assets/perf_comp.png" alt="teaser" width=90% height=90%>
21
+ </p>
22
+
23
+
24
+ ## 🚀 Contributions
25
+
26
+ #### We introduce RAR, an improved training strategy enabling standard autoregressive image generator to achieve state-of-the-art performance.
27
+
28
+ #### The proposed RAR is extremly simple yet effective: During training, we randomly permute the input token sequence with probability r, where r will starts at 1.0 and linearly decays to 0.0 over the course of training. This simple strategy enbales better bidirectional representation learning which is missing in standard raster-order-based AR image generator training.
29
+
30
+ #### RAR keeps the AR framework intact, and thus it is totally compatible to the LLM optimization techniques, such as KV-cache, leading to a significantly faster sampling speed compared to MAR-H or MaskBit while maintaining a better performance.
31
+
32
+ ## Model Zoo
33
+ | Model | Link | FID |
34
+ | ------------- | ------------- | ------------- |
35
+ | RAR-B | [checkpoint](https://huggingface.co/yucornetto/RAR/blob/main/rar_b.bin)| 1.95 (generation) |
36
+ | RAR-L | [checkpoint](https://huggingface.co/yucornetto/RAR/blob/main/rar_l.bin)| 1.70 (generation) |
37
+ | RAR-XL | [checkpoint](https://huggingface.co/yucornetto/RAR/blob/main/rar_xl.bin)| 1.50 (generation) |
38
+ | RAR-XXL | [checkpoint](https://huggingface.co/yucornetto/RAR/blob/main/rar_xxl.bin)| 1.48 (generation) |
39
+
40
+ Please note that these models are trained only on limited academic dataset ImageNet, and they are only for research purposes.
41
+
42
+ ## Installation
43
+ ```shell
44
+ pip3 install -r requirements.txt
45
+ ```
46
+
47
+ ## Get Started
48
+ ```python
49
+ import torch
50
+ from PIL import Image
51
+ import numpy as np
52
+ import demo_util
53
+ from huggingface_hub import hf_hub_download
54
+ from utils.train_utils import create_pretrained_tokenizer
55
+
56
+
57
+ # Choose one from ["rar_b_imagenet", "rar_l_imagenet", "rar_xl_imagenet", "rar_xxl_imagenet"]
58
+ rar_model_size = ["rar_b", "rar_l", "rar_xl", "rar_xxl"][3]
59
+
60
+ # download the maskgit-vq tokenizer
61
+ hf_hub_download(repo_id="fun-research/TiTok", filename=f"maskgit-vqgan-imagenet-f16-256.bin", local_dir="./")
62
+ # download the rar generator weight
63
+ hf_hub_download(repo_id="yucornetto/RAR", filename=f"{rar_model_size}.bin", local_dir="./")
64
+
65
+ # load config
66
+ config = demo_util.get_config("configs/training/generator/rar.yaml")
67
+ config.experiment.generator_checkpoint = f"{rar_model_size}.bin"
68
+ config.model.generator.hidden_size = {"rar_b": 768, "rar_l": 1024, "rar_xl": 1280, "rar_xxl": 1408}[rar_model_size]
69
+ config.model.generator.num_hidden_layers = {"rar_b": 24, "rar_l": 24, "rar_xl": 32, "rar_xxl": 40}[rar_model_size]
70
+ config.model.generator.num_attention_heads = 16
71
+ config.model.generator.intermediate_size = {"rar_b": 3072, "rar_l": 4096, "rar_xl": 5120, "rar_xxl": 6144}[rar_model_size]
72
+
73
+
74
+ device = "cuda"
75
+ # maskgit-vq as tokenizer
76
+ tokenizer = create_pretrained_tokenizer(config)
77
+ generator = demo_util.get_rar_generator(config)
78
+ tokenizer.to(device)
79
+ generator.to(device)
80
+
81
+ # generate an image
82
+ sample_labels = [torch.randint(0, 999, size=(1,)).item()] # random IN-1k class
83
+ generated_image = demo_util.sample_fn(
84
+ generator=generator,
85
+ tokenizer=tokenizer,
86
+ labels=sample_labels,
87
+ randomize_temperature=1.0,
88
+ guidance_scale=4.0,
89
+ guidance_scale_pow=0.0, # constant cfg
90
+ device=device
91
+ )
92
+ Image.fromarray(generated_image[0]).save(f"assets/rar_generated_{sample_labels[0]}.png")
93
+ ```
94
+
95
+ ## Testing on ImageNet-1K Benchmark
96
+
97
+ We provide a [sampling script](./sample_imagenet_rar.py) for reproducing the generation results on ImageNet-1K benchmark.
98
+ ```bash
99
+ # Prepare ADM evaluation script
100
+ git clone https://github.com/openai/guided-diffusion.git
101
+
102
+ wget https://openaipublic.blob.core.windows.net/diffusion/jul-2021/ref_batches/imagenet/256/VIRTUAL_imagenet256_labeled.npz
103
+ ```
104
+ ```python
105
+ # Reproducing RAR-B
106
+ torchrun --nnodes=1 --nproc_per_node=8 --rdzv-endpoint=localhost:9999 sample_imagenet_rar.py config=configs/training/generator/rar.yaml \
107
+ experiment.output_dir="rar_b" \
108
+ experiment.generator_checkpoint="rar_b.bin" \
109
+ model.generator.hidden_size=768 \
110
+ model.generator.num_hidden_layers=24 \
111
+ model.generator.num_attention_heads=16 \
112
+ model.generator.intermediate_size=3072 \
113
+ model.generator.randomize_temperature=1.0 \
114
+ model.generator.guidance_scale=16.0 \
115
+ model.generator.guidance_scale_pow=2.75
116
+ # Run eval script. The result FID should be ~1.95
117
+ python3 guided-diffusion/evaluations/evaluator.py VIRTUAL_imagenet256_labeled.npz rar_b.npz
118
+
119
+ # Reproducing RAR-L
120
+ torchrun --nnodes=1 --nproc_per_node=8 --rdzv-endpoint=localhost:9999 sample_imagenet_rar.py config=configs/training/generator/rar.yaml \
121
+ experiment.output_dir="rar_l" \
122
+ experiment.generator_checkpoint="rar_l.bin" \
123
+ model.generator.hidden_size=1024 \
124
+ model.generator.num_hidden_layers=24 \
125
+ model.generator.num_attention_heads=16 \
126
+ model.generator.intermediate_size=4096 \
127
+ model.generator.randomize_temperature=1.02 \
128
+ model.generator.guidance_scale=15.5 \
129
+ model.generator.guidance_scale_pow=2.5
130
+ # Run eval script. The result FID should be ~1.70
131
+ python3 guided-diffusion/evaluations/evaluator.py VIRTUAL_imagenet256_labeled.npz rar_l.npz
132
+
133
+ # Reproducing RAR-XL
134
+ torchrun --nnodes=1 --nproc_per_node=8 --rdzv-endpoint=localhost:9999 sample_imagenet_rar.py config=configs/training/generator/rar.yaml \
135
+ experiment.output_dir="rar_xl" \
136
+ experiment.generator_checkpoint="rar_xl.bin" \
137
+ model.generator.hidden_size=1280 \
138
+ model.generator.num_hidden_layers=32 \
139
+ model.generator.num_attention_heads=16 \
140
+ model.generator.intermediate_size=5120 \
141
+ model.generator.randomize_temperature=1.02 \
142
+ model.generator.guidance_scale=6.9 \
143
+ model.generator.guidance_scale_pow=1.5
144
+ # Run eval script. The result FID should be ~1.50
145
+ python3 guided-diffusion/evaluations/evaluator.py VIRTUAL_imagenet256_labeled.npz rar_xl.npz
146
+
147
+ # Reproducing RAR-XXL
148
+ torchrun --nnodes=1 --nproc_per_node=8 --rdzv-endpoint=localhost:9999 sample_imagenet_rar.py config=configs/training/generator/rar.yaml \
149
+ experiment.output_dir="rar_xxl" \
150
+ experiment.generator_checkpoint="rar_xxl.bin" \
151
+ model.generator.hidden_size=1408 \
152
+ model.generator.num_hidden_layers=40 \
153
+ model.generator.num_attention_heads=16 \
154
+ model.generator.intermediate_size=6144 \
155
+ model.generator.randomize_temperature=1.02 \
156
+ model.generator.guidance_scale=8.0 \
157
+ model.generator.guidance_scale_pow=1.2
158
+ # Run eval script. The result FID should be ~1.48
159
+ python3 guided-diffusion/evaluations/evaluator.py VIRTUAL_imagenet256_labeled.npz rar_xxl.npz
160
+ ```
161
+ ## Training Preparation
162
+ We pretokenize the whole dataset for speed-up the training process. We have uploaded [it](https://huggingface.co/yucornetto/RAR/blob/main/maskgitvq.jsonl) so you can train RAR directly. The training script will download the prerequisite checkpoints and dataset automatically.
163
+
164
+ For pretokenization on your own tokenizer or dataset, please refer to the [example pretokenization script](scripts/pretokenization.py).
165
+
166
+ ## Training
167
+ We provide example commands to train RAR as follows:
168
+ ```bash
169
+ # Training for RAR-B
170
+ WANDB_MODE=offline accelerate launch --num_machines=4 --num_processes=32 --machine_rank=${MACHINE_RANK} --main_process_ip=${ROOT_IP} --main_process_port=${ROOT_PORT} --same_network scripts/train_rar.py config=configs/training/generator/rar.yaml \
171
+ experiment.project="rar" \
172
+ experiment.name="rar_b" \
173
+ experiment.output_dir="rar_b" \
174
+ model.generator.hidden_size=768 \
175
+ model.generator.num_hidden_layers=24 \
176
+ model.generator.num_attention_heads=16 \
177
+ model.generator.intermediate_size=3072
178
+
179
+ # Training for RAR-L
180
+ WANDB_MODE=offline accelerate launch --num_machines=4 --num_processes=32 --machine_rank=${MACHINE_RANK} --main_process_ip=${ROOT_IP} --main_process_port=${ROOT_PORT} --same_network scripts/train_rar.py config=configs/training/generator/rar.yaml \
181
+ experiment.project="rar" \
182
+ experiment.name="rar_l" \
183
+ experiment.output_dir="rar_l" \
184
+ model.generator.hidden_size=1024 \
185
+ model.generator.num_hidden_layers=24 \
186
+ model.generator.num_attention_heads=16 \
187
+ model.generator.intermediate_size=4096
188
+
189
+ # Training for RAR-XL
190
+ WANDB_MODE=offline accelerate launch --num_machines=4 --num_processes=32 --machine_rank=${MACHINE_RANK} --main_process_ip=${ROOT_IP} --main_process_port=${ROOT_PORT} --same_network scripts/train_rar.py config=configs/training/generator/rar.yaml \
191
+ experiment.project="rar" \
192
+ experiment.name="rar_xl" \
193
+ experiment.output_dir="rar_xl" \
194
+ model.generator.hidden_size=1280 \
195
+ model.generator.num_hidden_layers=32 \
196
+ model.generator.num_attention_heads=16 \
197
+ model.generator.intermediate_size=5120
198
+
199
+ # Training for RAR-XXL
200
+ WANDB_MODE=offline accelerate launch --num_machines=4 --num_processes=32 --machine_rank=${MACHINE_RANK} --main_process_ip=${ROOT_IP} --main_process_port=${ROOT_PORT} --same_network scripts/train_rar.py config=configs/training/generator/rar.yaml \
201
+ experiment.project="rar" \
202
+ experiment.name="rar_xxl" \
203
+ experiment.output_dir="rar_xxl" \
204
+ model.generator.hidden_size=1408 \
205
+ model.generator.num_hidden_layers=40 \
206
+ model.generator.num_attention_heads=16 \
207
+ model.generator.intermediate_size=6144
208
+ ```
209
+ You may remove the flag "WANDB_MODE=offline" to support online wandb logging, if you have configured it.
210
+
211
+ Notably, you can enable grad checkpointing by adding the flag "model.generator.use_checkpoint=True" and adjust the machine number & GPU number based on your own need. All RAR checkpoints were trained with a global batchsize = 2048.
212
+
213
+
214
+ ## Visualizations
215
+ <p>
216
+ <img src="assets/vis1.png" alt="teaser" width=90% height=90%>
217
+ </p>
218
+ <p>
219
+ <img src="assets/vis2.png" alt="teaser" width=90% height=90%>
220
+ </p>
221
+ <p>
222
+ <img src="assets/vis3.png" alt="teaser" width=90% height=90%>
223
+ </p>
224
+
225
+
226
+ ## Citing
227
+ If you use our work in your research, please use the following BibTeX entry.
228
+
229
+ ```BibTeX
230
+ @inproceedings{yu2024randomized,
231
+ author = {Qihang Yu and Ju He and Xueqing Deng and Xiaohui Shen and Liang-Chieh Chen},
232
+ title = {Randomized Autoregressive Visual Generation},
233
+ journal = {arXiv preprint arXiv:2411.00776},
234
+ year = {2024}
235
+ }
236
+ ```
RAR/1d-tokenizer/README_TiTok.md ADDED
@@ -0,0 +1,215 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # (NeurIPS 2024) Compact and Mighty - Image Tokenization with Only 32 Tokens for both Reconstruction and Generation!
2
+
3
+ <div align="center">
4
+
5
+ [![demo](https://img.shields.io/badge/%F0%9F%A4%97%20Hugging%20Face-Online_Demo-blue)](https://huggingface.co/spaces/fun-research/TiTok)&nbsp;&nbsp;
6
+ [![Website](https://img.shields.io/badge/Project-Website-87CEEB)](https://yucornetto.github.io/projects/titok.html)&nbsp;&nbsp;
7
+ [![paper](https://img.shields.io/badge/arXiv-Paper-<COLOR>.svg)](https://arxiv.org/abs/2406.07550)&nbsp;&nbsp;
8
+
9
+ </div>
10
+
11
+ We present a compact 1D tokenizer which can represent an image with as few as 32 discrete tokens. As a result, it leads to a substantial speed-up on the sampling process (e.g., **410 × faster** than DiT-XL/2) while obtaining a competitive generation quality.
12
+
13
+
14
+ <p>
15
+ <img src="assets/titok_teaser.png" alt="teaser" width=90% height=90%>
16
+ </p>
17
+ <p>
18
+ <img src="assets/speed_vs_perf.png" alt="teaser" width=90% height=90%>
19
+ </p>
20
+
21
+
22
+ ## 🚀 Contributions
23
+
24
+ #### We introduce a novel 1D image tokenization framework that breaks grid constraints existing in 2D tokenization methods, leading to a much more flexible and compact image latent representation.
25
+
26
+ #### The proposed 1D tokenizer can tokenize a 256 × 256 image into as few as 32 discrete tokens, leading to a significant speed-up (hundreds times faster than diffusion models) in generation process, while maintaining state-of-the-art generation quality.
27
+
28
+ #### We conduct a series of experiments to probe the properties of rarely studied 1D image tokenization, paving the path towards compact latent space for efficient and effective image representation.
29
+
30
+ ## Model Zoo
31
+ | Model | Link | FID |
32
+ | ------------- | ------------- | ------------- |
33
+ | TiTok-L-32 Tokenizer | [checkpoint](https://huggingface.co/yucornetto/tokenizer_titok_l32_imagenet)| 2.21 (reconstruction) |
34
+ | TiTok-B-64 Tokenizer | [checkpoint](https://huggingface.co/yucornetto/tokenizer_titok_b64_imagenet) | 1.70 (reconstruction) |
35
+ | TiTok-S-128 Tokenizer | [checkpoint](https://huggingface.co/yucornetto/tokenizer_titok_s128_imagenet) | 1.71 (reconstruction) |
36
+ | TiTok-L-32 Generator | [checkpoint](https://huggingface.co/yucornetto/generator_titok_l32_imagenet) | 2.77 (generation) |
37
+ | TiTok-B-64 Generator | [checkpoint](https://huggingface.co/yucornetto/generator_titok_b64_imagenet) | 2.48 (generation) |
38
+ | TiTok-S-128 Generator | [checkpoint](https://huggingface.co/yucornetto/generator_titok_s128_imagenet) | 1.97 (generation) |
39
+ | TiTok-BL-64 VQ Tokenizer | [checkpoint](https://huggingface.co/yucornetto/tokenizer_titok_bl64_vq8k_imagenet)| 2.06 (reconstruction) |
40
+ | TiTok-BL-128 VQ Tokenizer | [checkpoint](https://huggingface.co/yucornetto/tokenizer_titok_bl128_vq8k_imagenet)| 1.49 (reconstruction) |
41
+ | TiTok-SL-256 VQ Tokenizer | [checkpoint](https://huggingface.co/yucornetto/tokenizer_titok_sl256_vq8k_imagenet)| 1.03 (reconstruction) |
42
+ | TiTok-LL-32 VAE Tokenizer | [checkpoint](https://huggingface.co/yucornetto/tokenizer_titok_ll32_vae_c16_imagenet)| 1.61 (reconstruction) |
43
+ | TiTok-BL-64 VAE Tokenizer | [checkpoint](https://huggingface.co/yucornetto/tokenizer_titok_bl64_vae_c16_imagenet)| 1.25 (reconstruction) |
44
+ | TiTok-BL-128 VAE Tokenizer | [checkpoint](https://huggingface.co/yucornetto/tokenizer_titok_bl128_vae_c16_imagenet)| 0.84 (reconstruction) |
45
+
46
+ Please note that these models are trained only on limited academic dataset ImageNet, and they are only for research purposes.
47
+
48
+ ## Installation
49
+ ```shell
50
+ pip3 install -r requirements.txt
51
+ ```
52
+
53
+ ## Get Started
54
+ ```python
55
+ import torch
56
+ from PIL import Image
57
+ import numpy as np
58
+ import demo_util
59
+ from huggingface_hub import hf_hub_download
60
+ from modeling.maskgit import ImageBert
61
+ from modeling.titok import TiTok
62
+
63
+ # Choose one from ["tokenizer_titok_l32_imagenet", "tokenizer_titok_b64_imagenet",
64
+ # "tokenizer_titok_s128_imagenet", "tokenizer_titok_bl128_vae_c16_imagenet", tokenizer_titok_bl64_vae_c16_imagenet",
65
+ # "tokenizer_titok_ll32_vae_c16_imagenet", "tokenizer_titok_sl256_vq8k_imagenet", "tokenizer_titok_bl128_vq8k_imagenet",
66
+ # "tokenizer_titok_bl64_vq8k_imagenet",]
67
+ titok_tokenizer = TiTok.from_pretrained("yucornetto/tokenizer_titok_l32_imagenet")
68
+ titok_tokenizer.eval()
69
+ titok_tokenizer.requires_grad_(False)
70
+ titok_generator = ImageBert.from_pretrained("yucornetto/generator_titok_l32_imagenet")
71
+ titok_generator.eval()
72
+ titok_generator.requires_grad_(False)
73
+
74
+ # or alternatively, downloads from hf
75
+ # hf_hub_download(repo_id="fun-research/TiTok", filename="tokenizer_titok_l32.bin", local_dir="./")
76
+ # hf_hub_download(repo_id="fun-research/TiTok", filename="generator_titok_l32.bin", local_dir="./")
77
+
78
+ # load config
79
+ # config = demo_util.get_config("configs/infer/TiTok/titok_l32.yaml")
80
+ # titok_tokenizer = demo_util.get_titok_tokenizer(config)
81
+ # titok_generator = demo_util.get_titok_generator(config)
82
+
83
+ device = "cuda"
84
+ titok_tokenizer = titok_tokenizer.to(device)
85
+ titok_generator = titok_generator.to(device)
86
+
87
+ # reconstruct an image. I.e., image -> 32 tokens -> image
88
+ img_path = "assets/ILSVRC2012_val_00010240.png"
89
+ image = torch.from_numpy(np.array(Image.open(img_path)).astype(np.float32)).permute(2, 0, 1).unsqueeze(0) / 255.0
90
+ # tokenization
91
+ if titok_tokenizer.quantize_mode == "vq":
92
+ encoded_tokens = titok_tokenizer.encode(image.to(device))[1]["min_encoding_indices"]
93
+ elif titok_tokenizer.quantize_mode == "vae":
94
+ posteriors = titok_tokenizer.encode(image.to(device))[1]
95
+ encoded_tokens = posteriors.sample()
96
+ else:
97
+ raise NotImplementedError
98
+ # image assets/ILSVRC2012_val_00010240.png is encoded into tokens tensor([[[ 887, 3979, 349, 720, 2809, 2743, 2101, 603, 2205, 1508, 1891, 4015, 1317, 2956, 3774, 2296, 484, 2612, 3472, 2330, 3140, 3113, 1056, 3779, 654, 2360, 1901, 2908, 2169, 953, 1326, 2598]]], device='cuda:0'), with shape torch.Size([1, 1, 32])
99
+ print(f"image {img_path} is encoded into tokens {encoded_tokens}, with shape {encoded_tokens.shape}")
100
+ # de-tokenization
101
+ reconstructed_image = titok_tokenizer.decode_tokens(encoded_tokens)
102
+ reconstructed_image = torch.clamp(reconstructed_image, 0.0, 1.0)
103
+ reconstructed_image = (reconstructed_image * 255.0).permute(0, 2, 3, 1).to("cpu", dtype=torch.uint8).numpy()[0]
104
+ reconstructed_image = Image.fromarray(reconstructed_image).save("assets/ILSVRC2012_val_00010240_recon.png")
105
+
106
+ # generate an image
107
+ sample_labels = [torch.randint(0, 999, size=(1,)).item()] # random IN-1k class
108
+ generated_image = demo_util.sample_fn(
109
+ generator=titok_generator,
110
+ tokenizer=titok_tokenizer,
111
+ labels=sample_labels,
112
+ guidance_scale=4.5,
113
+ randomize_temperature=1.0,
114
+ num_sample_steps=8,
115
+ device=device
116
+ )
117
+ Image.fromarray(generated_image[0]).save(f"assets/generated_{sample_labels[0]}.png")
118
+ ```
119
+
120
+ We also provide a [jupyter notebook](demo.ipynb) for a quick tutorial on reconstructing and generating images with TiTok-L-32.
121
+
122
+ We also support TiTok with [HuggingFace 🤗 Demo](https://huggingface.co/spaces/fun-research/TiTok)!
123
+
124
+ ## Testing on ImageNet-1K Benchmark
125
+
126
+ We provide a [sampling script](./sample_imagenet_titok.py) for reproducing the generation results on ImageNet-1K benchmark.
127
+ ```bash
128
+ # Prepare ADM evaluation script
129
+ git clone https://github.com/openai/guided-diffusion.git
130
+
131
+ wget https://openaipublic.blob.core.windows.net/diffusion/jul-2021/ref_batches/imagenet/256/VIRTUAL_imagenet256_labeled.npz
132
+ ```
133
+ ```python
134
+ # Reproducing TiTok-L-32
135
+ torchrun --nnodes=1 --nproc_per_node=8 --rdzv-endpoint=localhost:9999 sample_imagenet_titok.py config=configs/infer/TiTok/titok_l32.yaml experiment.output_dir="titok_l_32"
136
+ # Run eval script. The result FID should be ~2.77
137
+ python3 guided-diffusion/evaluations/evaluator.py VIRTUAL_imagenet256_labeled.npz titok_l_32.npz
138
+
139
+ # Reproducing TiTok-B-64
140
+ torchrun --nnodes=1 --nproc_per_node=8 --rdzv-endpoint=localhost:9999 sample_imagenet_titok.py config=configs/infer/TiTok/titok_b64.yaml experiment.output_dir="titok_b_64"
141
+ # Run eval script. The result FID should be ~2.48
142
+ python3 guided-diffusion/evaluations/evaluator.py VIRTUAL_imagenet256_labeled.npz titok_b_64.npz
143
+
144
+ # Reproducing TiTok-S-128
145
+ torchrun --nnodes=1 --nproc_per_node=8 --rdzv-endpoint=localhost:9999 sample_imagenet_titok.py config=configs/infer/TiTok/titok_s128.yaml experiment.output_dir="titok_s_128"
146
+ # Run eval script. The result FID should be ~1.97
147
+ python3 guided-diffusion/evaluations/evaluator.py VIRTUAL_imagenet256_labeled.npz titok_s_128.npz
148
+ ```
149
+ ## Training Preparation
150
+ We use [webdataset](https://github.com/webdataset/webdataset) format for data loading. To begin with, it is needed to convert the dataset into webdataset format. An example script to convert ImageNet to wds format is provided [here](./data/convert_imagenet_to_wds.py).
151
+
152
+ Furthermore, the stage1 training relies on a pre-trained MaskGIT-VQGAN to generate proxy codes as learning targets. You can convert the [official Jax weight](https://github.com/google-research/maskgit) to PyTorch version using [this script](https://github.com/huggingface/open-muse/blob/main/scripts/convert_maskgit_vqgan.py). Alternatively, we provided a converted version at [HuggingFace](https://huggingface.co/fun-research/TiTok/blob/main/maskgit-vqgan-imagenet-f16-256.bin) and [Google Drive](https://drive.google.com/file/d/1DjZqzJrUt2hwpmUPkjGSBTFEJcOkLY-Q/view?usp=sharing). The MaskGIT-VQGAN's weight will be automatically downloaded when you run the training script.
153
+
154
+ You may also pretokenize the dataset for a training speedup, please refer to the [example pretokenization script](scripts/pretokenization.py).
155
+
156
+ ## Training
157
+ We provide example commands to train TiTok as follows:
158
+ ```bash
159
+ # Training for TiTok-B64
160
+ # Stage 1
161
+ WANDB_MODE=offline accelerate launch --num_machines=1 --num_processes=8 --machine_rank=0 --main_process_ip=127.0.0.1 --main_process_port=9999 --same_network scripts/train_titok.py config=configs/training/TiTok/stage1/titok_b64.yaml \
162
+ experiment.project="titok_b64_stage1" \
163
+ experiment.name="titok_b64_stage1_run1" \
164
+ experiment.output_dir="titok_b64_stage1_run1" \
165
+ training.per_gpu_batch_size=32
166
+
167
+ # Stage 2
168
+ WANDB_MODE=offline accelerate launch --num_machines=1 --num_processes=8 --machine_rank=0 --main_process_ip=127.0.0.1 --main_process_port=9999 --same_network scripts/train_titok.py config=configs/training/TiTok/stage2/titok_b64.yaml \
169
+ experiment.project="titok_b64_stage2" \
170
+ experiment.name="titok_b64_stage2_run1" \
171
+ experiment.output_dir="titok_b64_stage2_run1" \
172
+ training.per_gpu_batch_size=32 \
173
+ experiment.init_weight=${PATH_TO_STAGE1_WEIGHT}
174
+
175
+ # Train Generator (TiTok-B64 as example)
176
+ WANDB_MODE=offline accelerate launch --num_machines=4 --num_processes=32 --machine_rank=${MACHINE_RANK} --main_process_ip=${ROOT_IP}--main_process_port=${ROOT_PORT} --same_network scripts/train_maskgit.py config=configs/training/generator/maskgit.yaml \
177
+ experiment.project="titok_generation" \
178
+ experiment.name="titok_b64_maskgit" \
179
+ experiment.output_dir="titok_b64_maskgit" \
180
+ experiment.tokenizer_checkpoint=${PATH_TO_STAGE1_or_STAGE2_WEIGHT}
181
+ ```
182
+ You may remove the flag "WANDB_MODE=offline" to support online wandb logging, if you have configured it.
183
+
184
+ The config _titok_b64.yaml_ can be replaced with _titok_s128.yaml_ or _titok_l32.yaml_ for other TiTok variants.
185
+
186
+ ## Visualizations
187
+ <p>
188
+ <img src="assets/recon_w_model_size_num_token.png" alt="teaser" width=90% height=90%>
189
+ </p>
190
+ <p>
191
+ <img src="assets/random_vis_l32.png" alt="teaser" width=90% height=90%>
192
+ </p>
193
+
194
+
195
+ ## Citing
196
+ If you use our work in your research, please use the following BibTeX entry.
197
+
198
+ ```BibTeX
199
+ @inproceedings{yu2024an,
200
+ author = {Qihang Yu and Mark Weber and Xueqing Deng and Xiaohui Shen and Daniel Cremers and Liang-Chieh Chen},
201
+ title = {An Image is Worth 32 Tokens for Reconstruction and Generation},
202
+ journal = {NeurIPS},
203
+ year = {2024}
204
+ }
205
+ ```
206
+
207
+ ## Acknowledgement
208
+
209
+ [MaskGIT](https://github.com/google-research/maskgit)
210
+
211
+ [Taming-Transformers](https://github.com/CompVis/taming-transformers)
212
+
213
+ [Open-MUSE](https://github.com/huggingface/open-muse)
214
+
215
+ [MUSE-Pytorch](https://github.com/baaivision/MUSE-Pytorch)
RAR/1d-tokenizer/__pycache__/demo_util.cpython-312.pyc ADDED
Binary file (7.07 kB). View file
 
RAR/1d-tokenizer/__pycache__/imagenet_classes.cpython-312.pyc ADDED
Binary file (52.8 kB). View file
 
RAR/1d-tokenizer/assets/ILSVRC2012_val_00008636.png ADDED

Git LFS Details

  • SHA256: dc9e100041f48fdd76e6a8f5813f501af68346616dfaec10c4dfaefb25485bce
  • Pointer size: 131 Bytes
  • Size of remote file: 162 kB
RAR/1d-tokenizer/assets/ILSVRC2012_val_00010240.png ADDED

Git LFS Details

  • SHA256: 75105b81fc706e977227c41ef2960b1aef84fe557d2c69e27ac8b3839539fbfa
  • Pointer size: 131 Bytes
  • Size of remote file: 107 kB
RAR/1d-tokenizer/assets/maskgen_overview.png ADDED

Git LFS Details

  • SHA256: 0c196f0c97c1b362f0779120bdadbf43d8da580687e0c95703e31fb90eb0a11c
  • Pointer size: 131 Bytes
  • Size of remote file: 231 kB
RAR/1d-tokenizer/assets/maskgen_vis1.png ADDED

Git LFS Details

  • SHA256: c1ba33801b5b572a6012387a6848fa90c131f638a9ccb4ba24a470641bcae7e1
  • Pointer size: 132 Bytes
  • Size of remote file: 3.81 MB
RAR/1d-tokenizer/assets/maskgen_vis2.png ADDED

Git LFS Details

  • SHA256: 87725625430558ef17d1e18b773d2d14fa8031b19e8335d968ca7801a48af871
  • Pointer size: 132 Bytes
  • Size of remote file: 4.55 MB
RAR/1d-tokenizer/assets/maskgen_vis3.png ADDED

Git LFS Details

  • SHA256: e63bb92c2b9674b20637255bb780d9ff6b90cf5f659fa50c189fcf092640f7f8
  • Pointer size: 132 Bytes
  • Size of remote file: 4.43 MB
RAR/1d-tokenizer/assets/perf_comp.png ADDED

Git LFS Details

  • SHA256: 9255f9ffffa70d129237062eebc9955424306b93d22db58adbeef9f6da95dde4
  • Pointer size: 131 Bytes
  • Size of remote file: 146 kB
RAR/1d-tokenizer/assets/random_vis_l32.png ADDED

Git LFS Details

  • SHA256: ff40d0274f7d6656791e4fc72afbf0d46b0a3975803d6184a46baac0ab80438e
  • Pointer size: 132 Bytes
  • Size of remote file: 2.27 MB
RAR/1d-tokenizer/assets/rar_overview.png ADDED

Git LFS Details

  • SHA256: 0ce147111f79db6f3dbc0190e861b5b6efea4c5965422147054ca31aebe25ec5
  • Pointer size: 132 Bytes
  • Size of remote file: 2.17 MB
RAR/1d-tokenizer/assets/recon_w_model_size_num_token.png ADDED

Git LFS Details

  • SHA256: 8e5fe53bb8aa64fe918a33de92ac2d965d46871298eeec6fcd2a4a00f1b75386
  • Pointer size: 132 Bytes
  • Size of remote file: 1.49 MB
RAR/1d-tokenizer/assets/speed_vs_perf.png ADDED

Git LFS Details

  • SHA256: c88536348c2b2fc95487dba305a080881e6bf7c830309d6630dd2ff2a324e21c
  • Pointer size: 131 Bytes
  • Size of remote file: 135 kB
RAR/1d-tokenizer/assets/tatitok_overview.png ADDED

Git LFS Details

  • SHA256: b4bc4d396e8a96735a3baf0f0fbc7a7b38347283c0c62ec4610bd3da05f169a7
  • Pointer size: 131 Bytes
  • Size of remote file: 417 kB
RAR/1d-tokenizer/assets/titok_teaser.png ADDED

Git LFS Details

  • SHA256: b086e98d69fe30a8c729af72c2a7219a4b002df36df442b55cae8e5b3e60eaae
  • Pointer size: 131 Bytes
  • Size of remote file: 844 kB
RAR/1d-tokenizer/assets/vis1.png ADDED

Git LFS Details

  • SHA256: f407322aa70ff4288db1ec8a3ddf6ab3e5d6149f33ce8e57e8493c8cb3ae7aca
  • Pointer size: 132 Bytes
  • Size of remote file: 3.54 MB
RAR/1d-tokenizer/assets/vis2.png ADDED

Git LFS Details

  • SHA256: f739117053cdbff67aebd95f0bf9cfdb3f2fdf900c030776fdc615a3b1672a69
  • Pointer size: 132 Bytes
  • Size of remote file: 3.32 MB
RAR/1d-tokenizer/assets/vis3.png ADDED

Git LFS Details

  • SHA256: 25914cd1bde3d34b6df46190ad77e046e6cfd57fdd58599cadd131f2ad92fb84
  • Pointer size: 132 Bytes
  • Size of remote file: 2.32 MB
RAR/1d-tokenizer/configs/infer/MaskGen/maskgen_kl_l.yaml ADDED
@@ -0,0 +1,36 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ experiment:
2
+ tokenizer_checkpoint: "tatitok_bl32_vae.bin"
3
+ generator_checkpoint: "maskgen_kl_l.bin"
4
+
5
+ model:
6
+ vq_model:
7
+ quantize_mode: vae
8
+ token_size: 16
9
+ vit_enc_model_size: base
10
+ vit_dec_model_size: large
11
+ vit_enc_patch_size: 16
12
+ vit_dec_patch_size: 16
13
+ num_latent_tokens: 32
14
+ scale_factor: 0.7525
15
+ finetune_decoder: False
16
+ is_legacy: False
17
+ maskgen:
18
+ decoder_embed_dim: 1024
19
+ decoder_depth: 16
20
+ decoder_num_heads: 16
21
+ micro_condition: true
22
+ micro_condition_embed_dim: 256
23
+ text_drop_prob: 0.1
24
+ cfg: 3.0
25
+ cfg_schedule: "linear"
26
+ num_iter: 32
27
+ temperature: 1.0
28
+ sample_aesthetic_score: 6.5
29
+
30
+ losses:
31
+ diffloss_d: 8
32
+ diffloss_w: 1024
33
+
34
+ dataset:
35
+ preprocessing:
36
+ crop_size: 256
RAR/1d-tokenizer/configs/infer/MaskGen/maskgen_kl_xl.yaml ADDED
@@ -0,0 +1,36 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ experiment:
2
+ tokenizer_checkpoint: "tatitok_bl32_vae.bin"
3
+ generator_checkpoint: "maskgen_kl_xl.bin"
4
+
5
+ model:
6
+ vq_model:
7
+ quantize_mode: vae
8
+ token_size: 16
9
+ vit_enc_model_size: base
10
+ vit_dec_model_size: large
11
+ vit_enc_patch_size: 16
12
+ vit_dec_patch_size: 16
13
+ num_latent_tokens: 32
14
+ scale_factor: 0.7525
15
+ finetune_decoder: False
16
+ is_legacy: False
17
+ maskgen:
18
+ decoder_embed_dim: 1280
19
+ decoder_depth: 20
20
+ decoder_num_heads: 16
21
+ micro_condition: true
22
+ micro_condition_embed_dim: 256
23
+ text_drop_prob: 0.1
24
+ cfg: 3.0
25
+ cfg_schedule: "linear"
26
+ num_iter: 32
27
+ temperature: 1.0
28
+ sample_aesthetic_score: 6.5
29
+
30
+ losses:
31
+ diffloss_d: 8
32
+ diffloss_w: 1280
33
+
34
+ dataset:
35
+ preprocessing:
36
+ crop_size: 256
RAR/1d-tokenizer/configs/infer/MaskGen/maskgen_vq_l.yaml ADDED
@@ -0,0 +1,35 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ experiment:
2
+ tokenizer_checkpoint: "tatitok_bl128_vq.bin"
3
+ generator_checkpoint: "maskgen_vq_l.bin"
4
+
5
+ model:
6
+ vq_model:
7
+ quantize_mode: vq
8
+ codebook_size: 8192
9
+ token_size: 64
10
+ use_l2_norm: False
11
+ commitment_cost: 0.25
12
+ clustering_vq: False
13
+ vit_enc_model_size: base
14
+ vit_dec_model_size: large
15
+ vit_enc_patch_size: 16
16
+ vit_dec_patch_size: 16
17
+ num_latent_tokens: 128
18
+ finetune_decoder: False
19
+ is_legacy: False
20
+ maskgen:
21
+ decoder_embed_dim: 1024
22
+ decoder_depth: 16
23
+ decoder_num_heads: 16
24
+ micro_condition: True
25
+ micro_condition_embed_dim: 256
26
+ text_drop_prob: 0.1
27
+ condition_num_classes: 1000
28
+ cfg: 12.0
29
+ num_iter: 16
30
+ temperature: 2.0
31
+ sample_aesthetic_score: 6.5
32
+
33
+ dataset:
34
+ preprocessing:
35
+ crop_size: 256
RAR/1d-tokenizer/configs/infer/MaskGen/maskgen_vq_xl.yaml ADDED
@@ -0,0 +1,35 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ experiment:
2
+ tokenizer_checkpoint: "tatitok_bl128_vq.bin"
3
+ generator_checkpoint: "maskgen_vq_xl.bin"
4
+
5
+ model:
6
+ vq_model:
7
+ quantize_mode: vq
8
+ codebook_size: 8192
9
+ token_size: 64
10
+ use_l2_norm: False
11
+ commitment_cost: 0.25
12
+ clustering_vq: False
13
+ vit_enc_model_size: base
14
+ vit_dec_model_size: large
15
+ vit_enc_patch_size: 16
16
+ vit_dec_patch_size: 16
17
+ num_latent_tokens: 128
18
+ finetune_decoder: False
19
+ is_legacy: False
20
+ maskgen:
21
+ decoder_embed_dim: 1280
22
+ decoder_depth: 20
23
+ decoder_num_heads: 16
24
+ micro_condition: True
25
+ micro_condition_embed_dim: 256
26
+ text_drop_prob: 0.1
27
+ condition_num_classes: 1000
28
+ cfg: 12.0
29
+ num_iter: 16
30
+ temperature: 2.0
31
+ sample_aesthetic_score: 6.5
32
+
33
+ dataset:
34
+ preprocessing:
35
+ crop_size: 256
RAR/1d-tokenizer/configs/infer/TA-TiTok/tatitok_bl128_vq.yaml ADDED
@@ -0,0 +1,24 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ experiment:
2
+ tokenizer_checkpoint: "tatitok_bl128_vq.bin"
3
+ output_dir: "tatitok_bl128_vq"
4
+
5
+ model:
6
+ vq_model:
7
+ quantize_mode: vq
8
+ codebook_size: 8192
9
+ token_size: 64
10
+ use_l2_norm: False
11
+ commitment_cost: 0.25
12
+ clustering_vq: False
13
+ # vit arch
14
+ vit_enc_model_size: "base"
15
+ vit_dec_model_size: "large"
16
+ vit_enc_patch_size: 16
17
+ vit_dec_patch_size: 16
18
+ num_latent_tokens: 128
19
+ finetune_decoder: False
20
+ is_legacy: False
21
+
22
+ dataset:
23
+ preprocessing:
24
+ crop_size: 256
RAR/1d-tokenizer/configs/infer/TA-TiTok/tatitok_bl32_vae.yaml ADDED
@@ -0,0 +1,20 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ experiment:
2
+ tokenizer_checkpoint: "tatitok_bl32_vae.bin"
3
+ output_dir: "tatitok_bl32_vae"
4
+
5
+ model:
6
+ vq_model:
7
+ quantize_mode: vae
8
+ token_size: 16
9
+ # vit arch
10
+ vit_enc_model_size: "base"
11
+ vit_dec_model_size: "large"
12
+ vit_enc_patch_size: 16
13
+ vit_dec_patch_size: 16
14
+ num_latent_tokens: 32
15
+ finetune_decoder: False
16
+ is_legacy: False
17
+
18
+ dataset:
19
+ preprocessing:
20
+ crop_size: 256
RAR/1d-tokenizer/configs/infer/TA-TiTok/tatitok_bl32_vq.yaml ADDED
@@ -0,0 +1,24 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ experiment:
2
+ tokenizer_checkpoint: "tatitok_bl32_vq.bin"
3
+ output_dir: "tatitok_bl32_vq"
4
+
5
+ model:
6
+ vq_model:
7
+ quantize_mode: vq
8
+ codebook_size: 8192
9
+ token_size: 64
10
+ use_l2_norm: False
11
+ commitment_cost: 0.25
12
+ clustering_vq: False
13
+ # vit arch
14
+ vit_enc_model_size: "base"
15
+ vit_dec_model_size: "large"
16
+ vit_enc_patch_size: 16
17
+ vit_dec_patch_size: 16
18
+ num_latent_tokens: 32
19
+ finetune_decoder: False
20
+ is_legacy: False
21
+
22
+ dataset:
23
+ preprocessing:
24
+ crop_size: 256
RAR/1d-tokenizer/configs/infer/TA-TiTok/tatitok_bl64_vae.yaml ADDED
@@ -0,0 +1,20 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ experiment:
2
+ tokenizer_checkpoint: "tatitok_bl64_vae.bin"
3
+ output_dir: "tatitok_bl64_vae"
4
+
5
+ model:
6
+ vq_model:
7
+ quantize_mode: vae
8
+ token_size: 16
9
+ # vit arch
10
+ vit_enc_model_size: "base"
11
+ vit_dec_model_size: "large"
12
+ vit_enc_patch_size: 16
13
+ vit_dec_patch_size: 16
14
+ num_latent_tokens: 64
15
+ finetune_decoder: False
16
+ is_legacy: False
17
+
18
+ dataset:
19
+ preprocessing:
20
+ crop_size: 256
RAR/1d-tokenizer/configs/infer/TA-TiTok/tatitok_bl64_vq.yaml ADDED
@@ -0,0 +1,24 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ experiment:
2
+ tokenizer_checkpoint: "tatitok_bl64_vq.bin"
3
+ output_dir: "tatitok_bl64_vq"
4
+
5
+ model:
6
+ vq_model:
7
+ quantize_mode: vq
8
+ codebook_size: 8192
9
+ token_size: 64
10
+ use_l2_norm: False
11
+ commitment_cost: 0.25
12
+ clustering_vq: False
13
+ # vit arch
14
+ vit_enc_model_size: "base"
15
+ vit_dec_model_size: "large"
16
+ vit_enc_patch_size: 16
17
+ vit_dec_patch_size: 16
18
+ num_latent_tokens: 64
19
+ finetune_decoder: False
20
+ is_legacy: False
21
+
22
+ dataset:
23
+ preprocessing:
24
+ crop_size: 256
RAR/1d-tokenizer/configs/infer/TA-TiTok/tatitok_sl128_vae.yaml ADDED
@@ -0,0 +1,20 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ experiment:
2
+ tokenizer_checkpoint: "tatitok_sl128_vae.bin"
3
+ output_dir: "tatitok_sl128_vae"
4
+
5
+ model:
6
+ vq_model:
7
+ quantize_mode: vae
8
+ token_size: 16
9
+ # vit arch
10
+ vit_enc_model_size: "small"
11
+ vit_dec_model_size: "large"
12
+ vit_enc_patch_size: 16
13
+ vit_dec_patch_size: 16
14
+ num_latent_tokens: 128
15
+ finetune_decoder: False
16
+ is_legacy: False
17
+
18
+ dataset:
19
+ preprocessing:
20
+ crop_size: 256
RAR/1d-tokenizer/configs/infer/TiTok/titok_b64.yaml ADDED
@@ -0,0 +1,39 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ experiment:
2
+ tokenizer_checkpoint: "tokenizer_titok_b64.bin"
3
+ generator_checkpoint: "generator_titok_b64.bin"
4
+ output_dir: "titok_b_64"
5
+ model:
6
+ vq_model:
7
+ codebook_size: 4096
8
+ token_size: 12
9
+ use_l2_norm: True
10
+ commitment_cost: 0.25
11
+ # vit arch
12
+ vit_enc_model_size: "base"
13
+ vit_dec_model_size: "base"
14
+ vit_enc_patch_size: 16
15
+ vit_dec_patch_size: 16
16
+ num_latent_tokens: 64
17
+ finetune_decoder: True
18
+
19
+ generator:
20
+ model_type: "ViT"
21
+ hidden_size: 768
22
+ num_hidden_layers: 24
23
+ num_attention_heads: 16
24
+ intermediate_size: 3072
25
+ dropout: 0.1
26
+ attn_drop: 0.1
27
+ num_steps: 8
28
+ class_label_dropout: 0.1
29
+ image_seq_len: ${model.vq_model.num_latent_tokens}
30
+ condition_num_classes: 1000
31
+
32
+ # sampling hyper-params
33
+ randomize_temperature: 11.0
34
+ guidance_scale: 3.0
35
+ guidance_decay: "linear"
36
+
37
+ dataset:
38
+ preprocessing:
39
+ crop_size: 256
RAR/1d-tokenizer/configs/infer/TiTok/titok_bl128_vae_c16.yaml ADDED
@@ -0,0 +1,19 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ experiment:
2
+ tokenizer_checkpoint: "titok_bl128_vae_c16.bin"
3
+ output_dir: "titok_bl128_vae_c16"
4
+ model:
5
+ vq_model:
6
+ quantize_mode: "vae"
7
+ token_size: 16
8
+ # vit arch
9
+ vit_enc_model_size: "base"
10
+ vit_dec_model_size: "large"
11
+ vit_enc_patch_size: 16
12
+ vit_dec_patch_size: 16
13
+ num_latent_tokens: 128
14
+ finetune_decoder: False
15
+ is_legacy: False
16
+
17
+ dataset:
18
+ preprocessing:
19
+ crop_size: 256
RAR/1d-tokenizer/configs/infer/TiTok/titok_bl128_vq8k.yaml ADDED
@@ -0,0 +1,21 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ experiment:
2
+ tokenizer_checkpoint: "tokenizer_titok_bl128_vq8k.bin"
3
+ output_dir: "titok_bl128_vq8k"
4
+ model:
5
+ vq_model:
6
+ codebook_size: 8192
7
+ token_size: 64
8
+ use_l2_norm: False
9
+ commitment_cost: 0.25
10
+ # vit arch
11
+ vit_enc_model_size: "base"
12
+ vit_dec_model_size: "large"
13
+ vit_enc_patch_size: 16
14
+ vit_dec_patch_size: 16
15
+ num_latent_tokens: 128
16
+ finetune_decoder: False
17
+ is_legacy: False
18
+
19
+ dataset:
20
+ preprocessing:
21
+ crop_size: 256
RAR/1d-tokenizer/configs/infer/TiTok/titok_bl64_vae_c16.yaml ADDED
@@ -0,0 +1,19 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ experiment:
2
+ tokenizer_checkpoint: "titok_bl64_vae_c16.bin"
3
+ output_dir: "titok_bl64_vae_c16"
4
+ model:
5
+ vq_model:
6
+ quantize_mode: "vae"
7
+ token_size: 16
8
+ # vit arch
9
+ vit_enc_model_size: "base"
10
+ vit_dec_model_size: "large"
11
+ vit_enc_patch_size: 16
12
+ vit_dec_patch_size: 16
13
+ num_latent_tokens: 64
14
+ finetune_decoder: False
15
+ is_legacy: False
16
+
17
+ dataset:
18
+ preprocessing:
19
+ crop_size: 256
RAR/1d-tokenizer/configs/infer/TiTok/titok_bl64_vq8k.yaml ADDED
@@ -0,0 +1,21 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ experiment:
2
+ tokenizer_checkpoint: "tokenizer_titok_bl64_vq8k.bin"
3
+ output_dir: "titok_bl64_vq8k"
4
+ model:
5
+ vq_model:
6
+ codebook_size: 8192
7
+ token_size: 64
8
+ use_l2_norm: False
9
+ commitment_cost: 0.25
10
+ # vit arch
11
+ vit_enc_model_size: "base"
12
+ vit_dec_model_size: "large"
13
+ vit_enc_patch_size: 16
14
+ vit_dec_patch_size: 16
15
+ num_latent_tokens: 64
16
+ finetune_decoder: False
17
+ is_legacy: False
18
+
19
+ dataset:
20
+ preprocessing:
21
+ crop_size: 256
RAR/1d-tokenizer/configs/infer/TiTok/titok_l32.yaml ADDED
@@ -0,0 +1,40 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ experiment:
2
+ tokenizer_checkpoint: "tokenizer_titok_l32.bin"
3
+ generator_checkpoint: "generator_titok_l32.bin"
4
+ output_dir: "titok_l_32"
5
+ model:
6
+ vq_model:
7
+ codebook_size: 4096
8
+ token_size: 12
9
+ use_l2_norm: True
10
+ commitment_cost: 0.25
11
+ # vit arch
12
+ vit_enc_model_size: "large"
13
+ vit_dec_model_size: "large"
14
+ vit_enc_patch_size: 16
15
+ vit_dec_patch_size: 16
16
+ num_latent_tokens: 32
17
+ finetune_decoder: True
18
+
19
+ generator:
20
+ model_type: "ViT"
21
+ hidden_size: 768
22
+ num_hidden_layers: 24
23
+ num_attention_heads: 16
24
+ intermediate_size: 3072
25
+ dropout: 0.1
26
+ attn_drop: 0.1
27
+ num_steps: 8
28
+ class_label_dropout: 0.1
29
+ image_seq_len: ${model.vq_model.num_latent_tokens}
30
+ condition_num_classes: 1000
31
+
32
+ # sampling hyper-params
33
+ randomize_temperature: 9.5
34
+ guidance_scale: 4.5
35
+ guidance_decay: "linear"
36
+
37
+
38
+ dataset:
39
+ preprocessing:
40
+ crop_size: 256
RAR/1d-tokenizer/configs/infer/TiTok/titok_ll32_vae_c16.yaml ADDED
@@ -0,0 +1,19 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ experiment:
2
+ tokenizer_checkpoint: "titok_ll32_vae_c16.bin"
3
+ output_dir: "titok_ll32_vae_c16"
4
+ model:
5
+ vq_model:
6
+ quantize_mode: "vae"
7
+ token_size: 16
8
+ # vit arch
9
+ vit_enc_model_size: "large"
10
+ vit_dec_model_size: "large"
11
+ vit_enc_patch_size: 16
12
+ vit_dec_patch_size: 16
13
+ num_latent_tokens: 32
14
+ finetune_decoder: False
15
+ is_legacy: False
16
+
17
+ dataset:
18
+ preprocessing:
19
+ crop_size: 256
RAR/1d-tokenizer/configs/infer/TiTok/titok_s128.yaml ADDED
@@ -0,0 +1,39 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ experiment:
2
+ tokenizer_checkpoint: "tokenizer_titok_s128.bin"
3
+ generator_checkpoint: "generator_titok_s128.bin"
4
+ output_dir: "titok_s_128"
5
+ model:
6
+ vq_model:
7
+ codebook_size: 4096
8
+ token_size: 12
9
+ use_l2_norm: True
10
+ commitment_cost: 0.25
11
+ # vit arch
12
+ vit_enc_model_size: "small"
13
+ vit_dec_model_size: "small"
14
+ vit_enc_patch_size: 16
15
+ vit_dec_patch_size: 16
16
+ num_latent_tokens: 128
17
+ finetune_decoder: True
18
+
19
+ generator:
20
+ model_type: "UViT"
21
+ hidden_size: 1024
22
+ num_hidden_layers: 20
23
+ num_attention_heads: 16
24
+ intermediate_size: 4096
25
+ dropout: 0.1
26
+ attn_drop: 0.1
27
+ num_steps: 64
28
+ class_label_dropout: 0.1
29
+ image_seq_len: ${model.vq_model.num_latent_tokens}
30
+ condition_num_classes: 1000
31
+
32
+ # sampling hyper-params
33
+ randomize_temperature: 2.8
34
+ guidance_scale: 6.9
35
+ guidance_decay: "power-cosine"
36
+
37
+ dataset:
38
+ preprocessing:
39
+ crop_size: 256
RAR/1d-tokenizer/configs/infer/TiTok/titok_sl256_vq8k.yaml ADDED
@@ -0,0 +1,21 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ experiment:
2
+ tokenizer_checkpoint: "tokenizer_titok_sl256_vq8k.bin"
3
+ output_dir: "titok_sl256_vq8k"
4
+ model:
5
+ vq_model:
6
+ codebook_size: 8192
7
+ token_size: 64
8
+ use_l2_norm: False
9
+ commitment_cost: 0.25
10
+ # vit arch
11
+ vit_enc_model_size: "small"
12
+ vit_dec_model_size: "large"
13
+ vit_enc_patch_size: 16
14
+ vit_dec_patch_size: 16
15
+ num_latent_tokens: 256
16
+ finetune_decoder: False
17
+ is_legacy: False
18
+
19
+ dataset:
20
+ preprocessing:
21
+ crop_size: 256
RAR/1d-tokenizer/configs/training/MaskGen/maskgen_kl_l_stage1.yaml ADDED
@@ -0,0 +1,82 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ experiment:
2
+ project: "maskgen_kl_l_stage1"
3
+ name: "maskgen_kl_l_stage1_run1"
4
+ output_dir: "maskgen_kl_l_stage1_run1"
5
+ max_train_examples: 250_000_000
6
+ save_every: 50_000
7
+ eval_every: 50_000
8
+ generate_every: 5_000
9
+ log_every: 50
10
+ log_grad_norm_every: 1_000
11
+ resume: True
12
+
13
+ model:
14
+ vq_model:
15
+ quantize_mode: vae
16
+ token_size: 16
17
+ vit_enc_model_size: base
18
+ vit_dec_model_size: large
19
+ vit_enc_patch_size: 16
20
+ vit_dec_patch_size: 16
21
+ num_latent_tokens: 32
22
+ scale_factor: 0.7525
23
+ finetune_decoder: False
24
+ is_legacy: False
25
+ maskgen:
26
+ decoder_embed_dim: 1024
27
+ decoder_depth: 16
28
+ decoder_num_heads: 16
29
+ micro_condition: True
30
+ micro_condition_embed_dim: 256
31
+ text_drop_prob: 0.1
32
+ cfg: 3.0
33
+ cfg_schedule: "linear"
34
+ num_iter: 32
35
+ temperature: 1.0
36
+ sample_aesthetic_score: 6.0
37
+
38
+ losses:
39
+ diffloss_d: 8
40
+ diffloss_w: 1024
41
+
42
+ dataset:
43
+ params:
44
+ train_shards_path_or_url: "datacomp5+::cc12m::laion-en-aesthetic"
45
+ eval_shards_path_or_url: "coco"
46
+ pretokenization: "true"
47
+ num_workers_per_gpu: 12
48
+ dataset_with_class_label: False
49
+ dataset_with_text_label: True
50
+ preprocessing:
51
+ resize_shorter_edge: 256
52
+ crop_size: 256
53
+ random_crop: True
54
+ random_flip: True
55
+ res_ratio_filtering: True
56
+
57
+ optimizer:
58
+ name: adamw
59
+ params:
60
+ learning_rate: 1e-4
61
+ beta1: 0.9
62
+ beta2: 0.95
63
+ weight_decay: 0.02
64
+
65
+ lr_scheduler:
66
+ scheduler: "constant"
67
+ params:
68
+ learning_rate: ${optimizer.params.learning_rate}
69
+ warmup_steps: 50_000
70
+ end_lr: 1e-5
71
+
72
+ training:
73
+ gradient_accumulation_steps: 1
74
+ per_gpu_batch_size: 32
75
+ mixed_precision: "fp16"
76
+ enable_tf32: True
77
+ enable_wandb: True
78
+ use_ema: True
79
+ seed: 42
80
+ max_train_steps: 1_000_000
81
+ num_generated_images: 2
82
+ max_grad_norm: 1.0
RAR/1d-tokenizer/configs/training/MaskGen/maskgen_kl_l_stage2.yaml ADDED
@@ -0,0 +1,83 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ experiment:
2
+ project: "maskgen_kl_l_stage2"
3
+ name: "maskgen_kl_l_stage2_run1"
4
+ output_dir: "maskgen_kl_l_stage2_run1"
5
+ init_weight: "maskgen_kl_l_stage1.bin"
6
+ max_train_examples: 13_000_000
7
+ save_every: 50_000
8
+ eval_every: 50_000
9
+ generate_every: 5_000
10
+ log_every: 50
11
+ log_grad_norm_every: 1_000
12
+ resume: True
13
+
14
+ model:
15
+ vq_model:
16
+ quantize_mode: vae
17
+ token_size: 16
18
+ vit_enc_model_size: base
19
+ vit_dec_model_size: large
20
+ vit_enc_patch_size: 16
21
+ vit_dec_patch_size: 16
22
+ num_latent_tokens: 32
23
+ scale_factor: 0.7525
24
+ finetune_decoder: False
25
+ is_legacy: False
26
+ maskgen:
27
+ decoder_embed_dim: 1024
28
+ decoder_depth: 16
29
+ decoder_num_heads: 16
30
+ micro_condition: True
31
+ micro_condition_embed_dim: 256
32
+ text_drop_prob: 0.1
33
+ cfg: 3.0
34
+ cfg_schedule: "linear"
35
+ num_iter: 32
36
+ temperature: 1.0
37
+ sample_aesthetic_score: 6.5
38
+
39
+ losses:
40
+ diffloss_d: 8
41
+ diffloss_w: 1024
42
+
43
+ dataset:
44
+ params:
45
+ train_shards_path_or_url: "datacomp6+::laion-art::laion-pop::journeydb::dalle3"
46
+ eval_shards_path_or_url: "coco"
47
+ pretokenization: "true"
48
+ num_workers_per_gpu: 12
49
+ dataset_with_class_label: False
50
+ dataset_with_text_label: True
51
+ preprocessing:
52
+ resize_shorter_edge: 256
53
+ crop_size: 256
54
+ random_crop: True
55
+ random_flip: True
56
+ res_ratio_filtering: True
57
+
58
+ optimizer:
59
+ name: adamw
60
+ params:
61
+ learning_rate: 1e-4
62
+ beta1: 0.9
63
+ beta2: 0.95
64
+ weight_decay: 0.02
65
+
66
+ lr_scheduler:
67
+ scheduler: "constant"
68
+ params:
69
+ learning_rate: ${optimizer.params.learning_rate}
70
+ warmup_steps: 50_000
71
+ end_lr: 1e-5
72
+
73
+ training:
74
+ gradient_accumulation_steps: 1
75
+ per_gpu_batch_size: 32
76
+ mixed_precision: "fp16"
77
+ enable_tf32: True
78
+ enable_wandb: True
79
+ use_ema: True
80
+ seed: 42
81
+ max_train_steps: 500_000
82
+ num_generated_images: 2
83
+ max_grad_norm: 1.0
RAR/1d-tokenizer/configs/training/MaskGen/maskgen_kl_xl_stage1.yaml ADDED
@@ -0,0 +1,82 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ experiment:
2
+ project: "maskgen_kl_xl_stage1"
3
+ name: "maskgen_kl_xl_stage1_run1"
4
+ output_dir: "maskgen_kl_xl_stage1_run1"
5
+ max_train_examples: 250_000_000
6
+ save_every: 50_000
7
+ eval_every: 50_000
8
+ generate_every: 5_000
9
+ log_every: 50
10
+ log_grad_norm_every: 1_000
11
+ resume: True
12
+
13
+ model:
14
+ vq_model:
15
+ quantize_mode: vae
16
+ token_size: 16
17
+ vit_enc_model_size: base
18
+ vit_dec_model_size: large
19
+ vit_enc_patch_size: 16
20
+ vit_dec_patch_size: 16
21
+ num_latent_tokens: 32
22
+ scale_factor: 0.7525
23
+ finetune_decoder: False
24
+ is_legacy: False
25
+ maskgen:
26
+ decoder_embed_dim: 1280
27
+ decoder_depth: 20
28
+ decoder_num_heads: 16
29
+ micro_condition: True
30
+ micro_condition_embed_dim: 256
31
+ text_drop_prob: 0.1
32
+ cfg: 3.0
33
+ cfg_schedule: "linear"
34
+ num_iter: 32
35
+ temperature: 1.0
36
+ sample_aesthetic_score: 6.0
37
+
38
+ losses:
39
+ diffloss_d: 8
40
+ diffloss_w: 1280
41
+
42
+ dataset:
43
+ params:
44
+ train_shards_path_or_url: "datacomp5+::cc12m::laion-en-aesthetic"
45
+ eval_shards_path_or_url: "coco"
46
+ pretokenization: "true"
47
+ num_workers_per_gpu: 12
48
+ dataset_with_class_label: False
49
+ dataset_with_text_label: True
50
+ preprocessing:
51
+ resize_shorter_edge: 256
52
+ crop_size: 256
53
+ random_crop: True
54
+ random_flip: True
55
+ res_ratio_filtering: True
56
+
57
+ optimizer:
58
+ name: adamw
59
+ params:
60
+ learning_rate: 1e-4
61
+ beta1: 0.9
62
+ beta2: 0.95
63
+ weight_decay: 0.02
64
+
65
+ lr_scheduler:
66
+ scheduler: "constant"
67
+ params:
68
+ learning_rate: ${optimizer.params.learning_rate}
69
+ warmup_steps: 50_000
70
+ end_lr: 1e-5
71
+
72
+ training:
73
+ gradient_accumulation_steps: 1
74
+ per_gpu_batch_size: 32
75
+ mixed_precision: "fp16"
76
+ enable_tf32: True
77
+ enable_wandb: True
78
+ use_ema: True
79
+ seed: 42
80
+ max_train_steps: 1_000_000
81
+ num_generated_images: 2
82
+ max_grad_norm: 1.0
RAR/1d-tokenizer/configs/training/MaskGen/maskgen_kl_xl_stage2.yaml ADDED
@@ -0,0 +1,83 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ experiment:
2
+ project: "maskgen_kl_xl_stage2"
3
+ name: "maskgen_kl_xl_stage2_run1"
4
+ output_dir: "maskgen_kl_xl_stage2_run1"
5
+ init_weight: "maskgen_kl_xl_stage1.bin"
6
+ max_train_examples: 13_000_000
7
+ save_every: 50_000
8
+ eval_every: 50_000
9
+ generate_every: 5_000
10
+ log_every: 50
11
+ log_grad_norm_every: 1_000
12
+ resume: True
13
+
14
+ model:
15
+ vq_model:
16
+ quantize_mode: vae
17
+ token_size: 16
18
+ vit_enc_model_size: base
19
+ vit_dec_model_size: large
20
+ vit_enc_patch_size: 16
21
+ vit_dec_patch_size: 16
22
+ num_latent_tokens: 32
23
+ scale_factor: 0.7525
24
+ finetune_decoder: False
25
+ is_legacy: False
26
+ maskgen:
27
+ decoder_embed_dim: 1280
28
+ decoder_depth: 20
29
+ decoder_num_heads: 16
30
+ micro_condition: True
31
+ micro_condition_embed_dim: 256
32
+ text_drop_prob: 0.1
33
+ cfg: 3.0
34
+ cfg_schedule: "linear"
35
+ num_iter: 32
36
+ temperature: 1.0
37
+ sample_aesthetic_score: 6.5
38
+
39
+ losses:
40
+ diffloss_d: 8
41
+ diffloss_w: 1280
42
+
43
+ dataset:
44
+ params:
45
+ train_shards_path_or_url: "datacomp6+::laion-art::laion-pop::journeydb::dalle3"
46
+ eval_shards_path_or_url: "coco"
47
+ pretokenization: "true"
48
+ num_workers_per_gpu: 12
49
+ dataset_with_class_label: False
50
+ dataset_with_text_label: True
51
+ preprocessing:
52
+ resize_shorter_edge: 256
53
+ crop_size: 256
54
+ random_crop: True
55
+ random_flip: True
56
+ res_ratio_filtering: True
57
+
58
+ optimizer:
59
+ name: adamw
60
+ params:
61
+ learning_rate: 1e-4
62
+ beta1: 0.9
63
+ beta2: 0.95
64
+ weight_decay: 0.02
65
+
66
+ lr_scheduler:
67
+ scheduler: "constant"
68
+ params:
69
+ learning_rate: ${optimizer.params.learning_rate}
70
+ warmup_steps: 50_000
71
+ end_lr: 1e-5
72
+
73
+ training:
74
+ gradient_accumulation_steps: 1
75
+ per_gpu_batch_size: 32
76
+ mixed_precision: "fp16"
77
+ enable_tf32: True
78
+ enable_wandb: True
79
+ use_ema: True
80
+ seed: 42
81
+ max_train_steps: 500_000
82
+ num_generated_images: 2
83
+ max_grad_norm: 1.0
RAR/1d-tokenizer/configs/training/MaskGen/maskgen_vq_l_stage1.yaml ADDED
@@ -0,0 +1,86 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ experiment:
2
+ project: "maskgen_vq_l_stage1"
3
+ name: "maskgen_vq_l_stage1_run1"
4
+ output_dir: "maskgen_vq_l_stage1_run1"
5
+ max_train_examples: 250_000_000
6
+ save_every: 50_000
7
+ eval_every: 50_000
8
+ generate_every: 5_000
9
+ log_every: 50
10
+ log_grad_norm_every: 1_000
11
+ resume: True
12
+
13
+ model:
14
+ vq_model:
15
+ quantize_mode: vq
16
+ codebook_size: 8192
17
+ token_size: 64
18
+ use_l2_norm: False
19
+ commitment_cost: 0.25
20
+ clustering_vq: True
21
+ # vit arch
22
+ vit_enc_model_size: "base"
23
+ vit_dec_model_size: "large"
24
+ vit_enc_patch_size: 16
25
+ vit_dec_patch_size: 16
26
+ num_latent_tokens: 128
27
+ finetune_decoder: False
28
+ is_legacy: False
29
+ maskgen:
30
+ decoder_embed_dim: 1024
31
+ decoder_depth: 16
32
+ decoder_num_heads: 16
33
+ micro_condition: True
34
+ micro_condition_embed_dim: 256
35
+ text_drop_prob: 0.1
36
+ condition_num_classes: 1000
37
+ cfg: 12.0
38
+ num_iter: 16
39
+ temperature: 2.0
40
+ sample_aesthetic_score: 6.0
41
+
42
+ losses:
43
+ label_smoothing: 0.1
44
+ loss_weight_unmasked_token: 0.1
45
+
46
+ dataset:
47
+ params:
48
+ train_shards_path_or_url: "datacomp5+::cc12m::laion-en-aesthetic"
49
+ eval_shards_path_or_url: "coco"
50
+ pretokenization: "true"
51
+ num_workers_per_gpu: 12
52
+ dataset_with_class_label: False
53
+ dataset_with_text_label: True
54
+ preprocessing:
55
+ resize_shorter_edge: 256
56
+ crop_size: 256
57
+ random_crop: True
58
+ random_flip: True
59
+ res_ratio_filtering: True
60
+
61
+ optimizer:
62
+ name: adamw
63
+ params:
64
+ learning_rate: 4e-4
65
+ beta1: 0.9
66
+ beta2: 0.96
67
+ weight_decay: 0.03
68
+
69
+ lr_scheduler:
70
+ scheduler: "cosine"
71
+ params:
72
+ learning_rate: ${optimizer.params.learning_rate}
73
+ warmup_steps: 10_000
74
+ end_lr: 1e-5
75
+
76
+ training:
77
+ gradient_accumulation_steps: 1
78
+ per_gpu_batch_size: 128
79
+ mixed_precision: "fp16"
80
+ enable_tf32: True
81
+ enable_wandb: True
82
+ use_ema: True
83
+ seed: 42
84
+ max_train_steps: 500_000
85
+ num_generated_images: 2
86
+ max_grad_norm: 1.0
RAR/1d-tokenizer/configs/training/MaskGen/maskgen_vq_l_stage2.yaml ADDED
@@ -0,0 +1,87 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ experiment:
2
+ project: "maskgen_vq_l_stage2"
3
+ name: "maskgen_vq_l_stage2_run1"
4
+ output_dir: "maskgen_vq_l_stage2_run1"
5
+ init_weight: "maskgen_vq_l_stage1.bin"
6
+ max_train_examples: 13_000_000
7
+ save_every: 50_000
8
+ eval_every: 50_000
9
+ generate_every: 5_000
10
+ log_every: 50
11
+ log_grad_norm_every: 1_000
12
+ resume: True
13
+
14
+ model:
15
+ vq_model:
16
+ quantize_mode: vq
17
+ codebook_size: 8192
18
+ token_size: 64
19
+ use_l2_norm: False
20
+ commitment_cost: 0.25
21
+ clustering_vq: True
22
+ # vit arch
23
+ vit_enc_model_size: "base"
24
+ vit_dec_model_size: "large"
25
+ vit_enc_patch_size: 16
26
+ vit_dec_patch_size: 16
27
+ num_latent_tokens: 128
28
+ finetune_decoder: False
29
+ is_legacy: False
30
+ maskgen:
31
+ decoder_embed_dim: 1024
32
+ decoder_depth: 16
33
+ decoder_num_heads: 16
34
+ micro_condition: True
35
+ micro_condition_embed_dim: 256
36
+ text_drop_prob: 0.1
37
+ condition_num_classes: 1000
38
+ cfg: 12.0
39
+ num_iter: 16
40
+ temperature: 2.0
41
+ sample_aesthetic_score: 6.5
42
+
43
+ losses:
44
+ label_smoothing: 0.1
45
+ loss_weight_unmasked_token: 0.1
46
+
47
+ dataset:
48
+ params:
49
+ train_shards_path_or_url: "datacomp6+::laion-art::laion-pop::journeydb::dalle3"
50
+ eval_shards_path_or_url: "coco"
51
+ pretokenization: "true"
52
+ num_workers_per_gpu: 12
53
+ dataset_with_class_label: False
54
+ dataset_with_text_label: True
55
+ preprocessing:
56
+ resize_shorter_edge: 256
57
+ crop_size: 256
58
+ random_crop: True
59
+ random_flip: True
60
+ res_ratio_filtering: True
61
+
62
+ optimizer:
63
+ name: adamw
64
+ params:
65
+ learning_rate: 1e-4
66
+ beta1: 0.9
67
+ beta2: 0.96
68
+ weight_decay: 0.03
69
+
70
+ lr_scheduler:
71
+ scheduler: "cosine"
72
+ params:
73
+ learning_rate: ${optimizer.params.learning_rate}
74
+ warmup_steps: 10_000
75
+ end_lr: 1e-5
76
+
77
+ training:
78
+ gradient_accumulation_steps: 1
79
+ per_gpu_batch_size: 128
80
+ mixed_precision: "fp16"
81
+ enable_tf32: True
82
+ enable_wandb: True
83
+ use_ema: True
84
+ seed: 42
85
+ max_train_steps: 250_000
86
+ num_generated_images: 2
87
+ max_grad_norm: 1.0
RAR/1d-tokenizer/configs/training/MaskGen/maskgen_vq_xl_stage1.yaml ADDED
@@ -0,0 +1,86 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ experiment:
2
+ project: "maskgen_vq_xl_stage1"
3
+ name: "maskgen_vq_xl_stage1_run1"
4
+ output_dir: "maskgen_vq_xl_stage1_run1"
5
+ max_train_examples: 250_000_000
6
+ save_every: 50_000
7
+ eval_every: 50_000
8
+ generate_every: 5_000
9
+ log_every: 50
10
+ log_grad_norm_every: 1_000
11
+ resume: True
12
+
13
+ model:
14
+ vq_model:
15
+ quantize_mode: vq
16
+ codebook_size: 8192
17
+ token_size: 64
18
+ use_l2_norm: False
19
+ commitment_cost: 0.25
20
+ clustering_vq: True
21
+ # vit arch
22
+ vit_enc_model_size: "base"
23
+ vit_dec_model_size: "large"
24
+ vit_enc_patch_size: 16
25
+ vit_dec_patch_size: 16
26
+ num_latent_tokens: 128
27
+ finetune_decoder: False
28
+ is_legacy: False
29
+ maskgen:
30
+ decoder_embed_dim: 1280
31
+ decoder_depth: 20
32
+ decoder_num_heads: 16
33
+ micro_condition: True
34
+ micro_condition_embed_dim: 256
35
+ text_drop_prob: 0.1
36
+ condition_num_classes: 1000
37
+ cfg: 12.0
38
+ num_iter: 16
39
+ temperature: 2.0
40
+ sample_aesthetic_score: 6.0
41
+
42
+ losses:
43
+ label_smoothing: 0.1
44
+ loss_weight_unmasked_token: 0.1
45
+
46
+ dataset:
47
+ params:
48
+ train_shards_path_or_url: "datacomp5+::cc12m::laion-en-aesthetic"
49
+ eval_shards_path_or_url: "coco"
50
+ pretokenization: "true"
51
+ num_workers_per_gpu: 12
52
+ dataset_with_class_label: False
53
+ dataset_with_text_label: True
54
+ preprocessing:
55
+ resize_shorter_edge: 256
56
+ crop_size: 256
57
+ random_crop: True
58
+ random_flip: True
59
+ res_ratio_filtering: True
60
+
61
+ optimizer:
62
+ name: adamw
63
+ params:
64
+ learning_rate: 4e-4
65
+ beta1: 0.9
66
+ beta2: 0.96
67
+ weight_decay: 0.03
68
+
69
+ lr_scheduler:
70
+ scheduler: "cosine"
71
+ params:
72
+ learning_rate: ${optimizer.params.learning_rate}
73
+ warmup_steps: 10_000
74
+ end_lr: 1e-5
75
+
76
+ training:
77
+ gradient_accumulation_steps: 1
78
+ per_gpu_batch_size: 128
79
+ mixed_precision: "fp16"
80
+ enable_tf32: True
81
+ enable_wandb: True
82
+ use_ema: True
83
+ seed: 42
84
+ max_train_steps: 500_000
85
+ num_generated_images: 2
86
+ max_grad_norm: 1.0
RAR/1d-tokenizer/configs/training/MaskGen/maskgen_vq_xl_stage2.yaml ADDED
@@ -0,0 +1,87 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ experiment:
2
+ project: "maskgen_vq_xl_stage2"
3
+ name: "maskgen_vq_xl_stage2_run1"
4
+ output_dir: "maskgen_vq_xl_stage2_run1"
5
+ init_weight: "maskgen_vq_xl_stage1.bin"
6
+ max_train_examples: 13_000_000
7
+ save_every: 50_000
8
+ eval_every: 50_000
9
+ generate_every: 5_000
10
+ log_every: 50
11
+ log_grad_norm_every: 1_000
12
+ resume: True
13
+
14
+ model:
15
+ vq_model:
16
+ quantize_mode: vq
17
+ codebook_size: 8192
18
+ token_size: 64
19
+ use_l2_norm: False
20
+ commitment_cost: 0.25
21
+ clustering_vq: True
22
+ # vit arch
23
+ vit_enc_model_size: "base"
24
+ vit_dec_model_size: "large"
25
+ vit_enc_patch_size: 16
26
+ vit_dec_patch_size: 16
27
+ num_latent_tokens: 128
28
+ finetune_decoder: False
29
+ is_legacy: False
30
+ maskgen:
31
+ decoder_embed_dim: 1280
32
+ decoder_depth: 20
33
+ decoder_num_heads: 16
34
+ micro_condition: True
35
+ micro_condition_embed_dim: 256
36
+ text_drop_prob: 0.1
37
+ condition_num_classes: 1000
38
+ cfg: 12.0
39
+ num_iter: 16
40
+ temperature: 2.0
41
+ sample_aesthetic_score: 6.5
42
+
43
+ losses:
44
+ label_smoothing: 0.1
45
+ loss_weight_unmasked_token: 0.1
46
+
47
+ dataset:
48
+ params:
49
+ train_shards_path_or_url: "datacomp6+::laion-art::laion-pop::journeydb::dalle3"
50
+ eval_shards_path_or_url: "coco"
51
+ pretokenization: "true"
52
+ num_workers_per_gpu: 12
53
+ dataset_with_class_label: False
54
+ dataset_with_text_label: True
55
+ preprocessing:
56
+ resize_shorter_edge: 256
57
+ crop_size: 256
58
+ random_crop: True
59
+ random_flip: True
60
+ res_ratio_filtering: True
61
+
62
+ optimizer:
63
+ name: adamw
64
+ params:
65
+ learning_rate: 1e-4
66
+ beta1: 0.9
67
+ beta2: 0.96
68
+ weight_decay: 0.03
69
+
70
+ lr_scheduler:
71
+ scheduler: "cosine"
72
+ params:
73
+ learning_rate: ${optimizer.params.learning_rate}
74
+ warmup_steps: 10_000
75
+ end_lr: 1e-5
76
+
77
+ training:
78
+ gradient_accumulation_steps: 1
79
+ per_gpu_batch_size: 128
80
+ mixed_precision: "fp16"
81
+ enable_tf32: True
82
+ enable_wandb: True
83
+ use_ema: True
84
+ seed: 42
85
+ max_train_steps: 250_000
86
+ num_generated_images: 2
87
+ max_grad_norm: 1.0