Upload code from /mnt/43.oT_eV
Browse filesThis view is limited to 50 files because it contains too many changes.
See raw diff
- .gitattributes +0 -0
- Meissonic/.github/FUNDING.yml +15 -0
- Meissonic/.gitignore +166 -0
- Meissonic/LICENSE +201 -0
- Meissonic/README.md +222 -0
- Meissonic/app.py +149 -0
- Meissonic/app_Monetico.py +151 -0
- Meissonic/app_fp8.py +223 -0
- Meissonic/assets/architecture.png +3 -0
- Meissonic/assets/demos.pdf +3 -0
- Meissonic/assets/demos.png +3 -0
- Meissonic/assets/inpaint/0eKR4M2uuL8.jpg +3 -0
- Meissonic/assets/inpaint/0eKR4M2uuL8.png +0 -0
- Meissonic/assets/inpaint/_Rh_zxIUWXA.jpg +0 -0
- Meissonic/assets/inpaint/_Rh_zxIUWXA.png +0 -0
- Meissonic/assets/inpaint/__Owak0IgJk.jpg +3 -0
- Meissonic/assets/inpaint/__Owak0IgJk.png +0 -0
- Meissonic/assets/inpaint/cases.json +20 -0
- Meissonic/assets/outpaint/__G2yFuW7jQ.jpg +3 -0
- Meissonic/assets/outpaint/__G2yFuW7jQ.png +0 -0
- Meissonic/assets/outpaint/cases.json +20 -0
- Meissonic/cog.yaml +29 -0
- Meissonic/cosmos_test_output/comparison_grid_video_0.png +3 -0
- Meissonic/cosmos_test_output/comparison_grid_video_1.png +3 -0
- Meissonic/cosmos_test_output/comparison_grid_video_2.png +3 -0
- Meissonic/cosmos_test_output/comparison_grid_video_3.png +3 -0
- Meissonic/cosmos_test_output/metrics_video_0.txt +12 -0
- Meissonic/cosmos_test_output/metrics_video_1.txt +12 -0
- Meissonic/cosmos_test_output/metrics_video_2.txt +12 -0
- Meissonic/cosmos_test_output/metrics_video_3.txt +12 -0
- Meissonic/inference.py +65 -0
- Meissonic/inference_fp16.py +64 -0
- Meissonic/inference_fp16_Monetico.py +64 -0
- Meissonic/inference_fp8.py +103 -0
- Meissonic/inpaint.py +55 -0
- Meissonic/predict.py +105 -0
- Meissonic/pretrained_ckpts/Cosmos-0.1-Tokenizer-DV4x8x8/.gitattributes +38 -0
- Meissonic/pretrained_ckpts/Cosmos-0.1-Tokenizer-DV4x8x8/README.md +326 -0
- Meissonic/pretrained_ckpts/Cosmos-0.1-Tokenizer-DV4x8x8/autoencoder.jit +3 -0
- Meissonic/pretrained_ckpts/Cosmos-0.1-Tokenizer-DV4x8x8/config.json +6 -0
- Meissonic/pretrained_ckpts/Cosmos-0.1-Tokenizer-DV4x8x8/decoder.jit +3 -0
- Meissonic/pretrained_ckpts/Cosmos-0.1-Tokenizer-DV4x8x8/encoder.jit +3 -0
- Meissonic/pretrained_ckpts/Cosmos-0.1-Tokenizer-DV4x8x8/model_config.yaml +1 -0
- Meissonic/pretrained_ckpts/Cosmos-0.1-Tokenizer-DV8x8x8/.gitattributes +38 -0
- Meissonic/pretrained_ckpts/Cosmos-0.1-Tokenizer-DV8x8x8/README.md +325 -0
- Meissonic/pretrained_ckpts/Cosmos-0.1-Tokenizer-DV8x8x8/autoencoder.jit +3 -0
- Meissonic/pretrained_ckpts/Cosmos-0.1-Tokenizer-DV8x8x8/config.json +6 -0
- Meissonic/pretrained_ckpts/Cosmos-0.1-Tokenizer-DV8x8x8/decoder.jit +3 -0
- Meissonic/pretrained_ckpts/Cosmos-0.1-Tokenizer-DV8x8x8/encoder.jit +3 -0
- Meissonic/pretrained_ckpts/Cosmos-0.1-Tokenizer-DV8x8x8/model_config.yaml +1 -0
.gitattributes
CHANGED
|
The diff for this file is too large to render.
See raw diff
|
|
|
Meissonic/.github/FUNDING.yml
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# These are supported funding model platforms
|
| 2 |
+
|
| 3 |
+
github: viiika
|
| 4 |
+
patreon: # Replace with a single Patreon username
|
| 5 |
+
open_collective: # Replace with a single Open Collective username
|
| 6 |
+
ko_fi: # Replace with a single Ko-fi username
|
| 7 |
+
tidelift: # Replace with a single Tidelift platform-name/package-name e.g., npm/babel
|
| 8 |
+
community_bridge: # Replace with a single Community Bridge project-name e.g., cloud-foundry
|
| 9 |
+
liberapay: # Replace with a single Liberapay username
|
| 10 |
+
issuehunt: # Replace with a single IssueHunt username
|
| 11 |
+
lfx_crowdfunding: # Replace with a single LFX Crowdfunding project-name e.g., cloud-foundry
|
| 12 |
+
polar: # Replace with a single Polar username
|
| 13 |
+
buy_me_a_coffee: # Replace with a single Buy Me a Coffee username
|
| 14 |
+
thanks_dev: # Replace with a single thanks.dev username
|
| 15 |
+
custom: # Replace with up to 4 custom sponsorship URLs e.g., ['link1', 'link2']
|
Meissonic/.gitignore
ADDED
|
@@ -0,0 +1,166 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# Byte-compiled / optimized / DLL files
|
| 2 |
+
__pycache__/
|
| 3 |
+
*.py[cod]
|
| 4 |
+
*$py.class
|
| 5 |
+
|
| 6 |
+
# C extensions
|
| 7 |
+
*.so
|
| 8 |
+
|
| 9 |
+
# Distribution / packaging
|
| 10 |
+
.Python
|
| 11 |
+
build/
|
| 12 |
+
develop-eggs/
|
| 13 |
+
dist/
|
| 14 |
+
downloads/
|
| 15 |
+
eggs/
|
| 16 |
+
.eggs/
|
| 17 |
+
lib/
|
| 18 |
+
lib64/
|
| 19 |
+
parts/
|
| 20 |
+
sdist/
|
| 21 |
+
var/
|
| 22 |
+
wheels/
|
| 23 |
+
share/python-wheels/
|
| 24 |
+
*.egg-info/
|
| 25 |
+
.installed.cfg
|
| 26 |
+
*.egg
|
| 27 |
+
MANIFEST
|
| 28 |
+
|
| 29 |
+
# PyInstaller
|
| 30 |
+
# Usually these files are written by a python script from a template
|
| 31 |
+
# before PyInstaller builds the exe, so as to inject date/other infos into it.
|
| 32 |
+
*.manifest
|
| 33 |
+
*.spec
|
| 34 |
+
|
| 35 |
+
# Installer logs
|
| 36 |
+
pip-log.txt
|
| 37 |
+
pip-delete-this-directory.txt
|
| 38 |
+
|
| 39 |
+
# Mac OS related
|
| 40 |
+
.DS_Store
|
| 41 |
+
*.DS_Store
|
| 42 |
+
|
| 43 |
+
# Unit test / coverage reports
|
| 44 |
+
htmlcov/
|
| 45 |
+
.tox/
|
| 46 |
+
.nox/
|
| 47 |
+
.coverage
|
| 48 |
+
.coverage.*
|
| 49 |
+
.cache
|
| 50 |
+
nosetests.xml
|
| 51 |
+
coverage.xml
|
| 52 |
+
*.cover
|
| 53 |
+
*.py,cover
|
| 54 |
+
.hypothesis/
|
| 55 |
+
.pytest_cache/
|
| 56 |
+
cover/
|
| 57 |
+
|
| 58 |
+
# Translations
|
| 59 |
+
*.mo
|
| 60 |
+
*.pot
|
| 61 |
+
|
| 62 |
+
# Django stuff:
|
| 63 |
+
*.log
|
| 64 |
+
local_settings.py
|
| 65 |
+
db.sqlite3
|
| 66 |
+
db.sqlite3-journal
|
| 67 |
+
|
| 68 |
+
# Flask stuff:
|
| 69 |
+
instance/
|
| 70 |
+
.webassets-cache
|
| 71 |
+
|
| 72 |
+
# Scrapy stuff:
|
| 73 |
+
.scrapy
|
| 74 |
+
|
| 75 |
+
# Sphinx documentation
|
| 76 |
+
docs/_build/
|
| 77 |
+
|
| 78 |
+
# PyBuilder
|
| 79 |
+
.pybuilder/
|
| 80 |
+
target/
|
| 81 |
+
|
| 82 |
+
# Jupyter Notebook
|
| 83 |
+
.ipynb_checkpoints
|
| 84 |
+
|
| 85 |
+
# IPython
|
| 86 |
+
profile_default/
|
| 87 |
+
ipython_config.py
|
| 88 |
+
|
| 89 |
+
# pyenv
|
| 90 |
+
# For a library or package, you might want to ignore these files since the code is
|
| 91 |
+
# intended to run in multiple environments; otherwise, check them in:
|
| 92 |
+
# .python-version
|
| 93 |
+
|
| 94 |
+
# pipenv
|
| 95 |
+
# According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control.
|
| 96 |
+
# However, in case of collaboration, if having platform-specific dependencies or dependencies
|
| 97 |
+
# having no cross-platform support, pipenv may install dependencies that don't work, or not
|
| 98 |
+
# install all needed dependencies.
|
| 99 |
+
#Pipfile.lock
|
| 100 |
+
|
| 101 |
+
# poetry
|
| 102 |
+
# Similar to Pipfile.lock, it is generally recommended to include poetry.lock in version control.
|
| 103 |
+
# This is especially recommended for binary packages to ensure reproducibility, and is more
|
| 104 |
+
# commonly ignored for libraries.
|
| 105 |
+
# https://python-poetry.org/docs/basic-usage/#commit-your-poetrylock-file-to-version-control
|
| 106 |
+
#poetry.lock
|
| 107 |
+
|
| 108 |
+
# pdm
|
| 109 |
+
# Similar to Pipfile.lock, it is generally recommended to include pdm.lock in version control.
|
| 110 |
+
#pdm.lock
|
| 111 |
+
# pdm stores project-wide configurations in .pdm.toml, but it is recommended to not include it
|
| 112 |
+
# in version control.
|
| 113 |
+
# https://pdm.fming.dev/latest/usage/project/#working-with-version-control
|
| 114 |
+
.pdm.toml
|
| 115 |
+
.pdm-python
|
| 116 |
+
.pdm-build/
|
| 117 |
+
|
| 118 |
+
# PEP 582; used by e.g. github.com/David-OConnor/pyflow and github.com/pdm-project/pdm
|
| 119 |
+
__pypackages__/
|
| 120 |
+
|
| 121 |
+
# Celery stuff
|
| 122 |
+
celerybeat-schedule
|
| 123 |
+
celerybeat.pid
|
| 124 |
+
|
| 125 |
+
# SageMath parsed files
|
| 126 |
+
*.sage.py
|
| 127 |
+
|
| 128 |
+
# Environments
|
| 129 |
+
.env
|
| 130 |
+
.venv
|
| 131 |
+
env/
|
| 132 |
+
venv/
|
| 133 |
+
ENV/
|
| 134 |
+
env.bak/
|
| 135 |
+
venv.bak/
|
| 136 |
+
|
| 137 |
+
# Spyder project settings
|
| 138 |
+
.spyderproject
|
| 139 |
+
.spyproject
|
| 140 |
+
|
| 141 |
+
# Rope project settings
|
| 142 |
+
.ropeproject
|
| 143 |
+
|
| 144 |
+
# mkdocs documentation
|
| 145 |
+
/site
|
| 146 |
+
|
| 147 |
+
# mypy
|
| 148 |
+
.mypy_cache/
|
| 149 |
+
.dmypy.json
|
| 150 |
+
dmypy.json
|
| 151 |
+
|
| 152 |
+
# Pyre type checker
|
| 153 |
+
.pyre/
|
| 154 |
+
|
| 155 |
+
# pytype static type analyzer
|
| 156 |
+
.pytype/
|
| 157 |
+
|
| 158 |
+
# Cython debug symbols
|
| 159 |
+
cython_debug/
|
| 160 |
+
|
| 161 |
+
# PyCharm
|
| 162 |
+
# JetBrains specific template is maintained in a separate JetBrains.gitignore that can
|
| 163 |
+
# be found at https://github.com/github/gitignore/blob/main/Global/JetBrains.gitignore
|
| 164 |
+
# and can be added to the global gitignore or merged into this file. For a more nuclear
|
| 165 |
+
# option (not recommended) you can uncomment the following to ignore the entire idea folder.
|
| 166 |
+
#.idea/
|
Meissonic/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.
|
Meissonic/README.md
ADDED
|
@@ -0,0 +1,222 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# Meissonic: Revitalizing Masked Generative Transformers for Efficient High-Resolution Text-to-Image Synthesis
|
| 2 |
+
|
| 3 |
+
<div align="center">
|
| 4 |
+
<img width="1421" alt="Meissonic Banner" src="https://github.com/user-attachments/assets/703f6882-163a-42d0-8da8-3680231ca75e">
|
| 5 |
+
|
| 6 |
+
[](https://arxiv.org/abs/2410.08261)
|
| 7 |
+
[](https://huggingface.co/MeissonFlow/Meissonic)
|
| 8 |
+
[](https://github.com/viiika/Meissonic)
|
| 9 |
+
[](https://www.youtube.com/watch?v=PlmifElhr6M)
|
| 10 |
+
[](https://www.youtube.com/watch?v=rJDrf49wF64)
|
| 11 |
+
[](https://huggingface.co/spaces/MeissonFlow/meissonic)
|
| 12 |
+
[](https://replicate.com/chenxwh/meissonic)
|
| 13 |
+
|
| 14 |
+
[](https://huggingface.co/Collov-Labs/Monetico)
|
| 15 |
+
[](https://huggingface.co/spaces/Collov-Labs/Monetico)
|
| 16 |
+
|
| 17 |
+
[](https://arxiv.org/abs/2411.10781)
|
| 18 |
+
|
| 19 |
+
[](https://arxiv.org/abs/2503.15457)
|
| 20 |
+
[](https://huggingface.co/Yuanzhi/DiMO)
|
| 21 |
+
[](https://github.com/yuanzhi-zhu/DiMO)
|
| 22 |
+
|
| 23 |
+
|
| 24 |
+
[](https://arxiv.org/abs/2505.23606)
|
| 25 |
+
[](https://huggingface.co/MeissonFlow/Muddit)
|
| 26 |
+
[](https://github.com/M-E-AGI-Lab/Muddit)
|
| 27 |
+
[](https://huggingface.co/spaces/MeissonFlow/muddit)
|
| 28 |
+
|
| 29 |
+
[](https://arxiv.org/abs/2507.04947)
|
| 30 |
+
|
| 31 |
+
[](https://arxiv.org/abs/2508.10684)
|
| 32 |
+
|
| 33 |
+
[](https://arxiv.org/abs/2509.19244)
|
| 34 |
+
[](https://arxiv.org/abs/2509.23919)
|
| 35 |
+
[](https://arxiv.org/abs/2509.25171)
|
| 36 |
+
|
| 37 |
+
[](https://arxiv.org/abs/2510.06308)
|
| 38 |
+
|
| 39 |
+
[](https://arxiv.org/abs/2510.20668) [](https://github.com/M-E-AGI-Lab/Awesome-World-Models)
|
| 40 |
+
|
| 41 |
+
</div>
|
| 42 |
+
|
| 43 |
+
## 📝 Meissonic Updates and Family Papers
|
| 44 |
+
|
| 45 |
+
- [MaskGIT: Masked Generative Image Transformer](https://arxiv.org/abs/2202.04200) [CVPR 2022]
|
| 46 |
+
- [Muse: Text-To-Image Generation via Masked Generative Transformers](https://arxiv.org/abs/2301.00704) [ICML 2023]
|
| 47 |
+
- [🌟][Meissonic: Revitalizing Masked Generative Transformers for Efficient High-Resolution Text-to-Image Synthesis](https://arxiv.org/abs/2410.08261) [ICLR 2025]
|
| 48 |
+
- [Bag of Design Choices for Inference of High-Resolution Masked Generative Transformer](https://arxiv.org/abs/2411.10781)
|
| 49 |
+
- [Di[𝙼]O: Distilling Masked Diffusion Models into One-step Generator](https://arxiv.org/abs/2503.15457) [ICCV 2025]
|
| 50 |
+
- [🌟][Muddit: Liberating Generation Beyond Text-to-Image with a Unified Discrete Diffusion Model](https://arxiv.org/abs/2505.23606)
|
| 51 |
+
- [DC-AR: Efficient Masked Autoregressive Image Generation with Deep Compression Hybrid Tokenizer](https://arxiv.org/pdf/2507.04947) [ICCV 2025]
|
| 52 |
+
- [MDNS: Masked Diffusion Neural Sampler via Stochastic Optimal Control](https://arxiv.org/abs/2508.10684)
|
| 53 |
+
- [Lavida-O: Elastic Large Masked Diffusion Models for Unified Multimodal Understanding and Generation](https://arxiv.org/abs/2509.19244)
|
| 54 |
+
- [🌟][Lumina-DiMOO: An Omni Diffusion Large Language Model for Multi-Modal Generation and Understanding](https://arxiv.org/abs/2510.06308)
|
| 55 |
+
- [Token Painter: Training-Free Text-Guided Image Inpainting via Mask Autoregressive Models](https://arxiv.org/abs/2509.23919)
|
| 56 |
+
- [TR2-D2: Tree Search Guided Trajectory-Aware Fine-Tuning for Discrete Diffusion](https://arxiv.org/abs/2509.25171)
|
| 57 |
+
- [OneFlow: Concurrent Mixed-Modal and Interleaved Generation with Edit Flows](https://arxiv.org/abs/2510.03506)
|
| 58 |
+
- [Diffuse Everything: Multimodal Diffusion Models on Arbitrary State Spaces](https://arxiv.org/abs/2506.07903) [ICML 2025]
|
| 59 |
+
- [Towards Better & Faster Autoregressive Image Generation: From the Perspective of Entropy](https://arxiv.org/abs/2510.09012) [NeurIPS 2025]
|
| 60 |
+
- [🌟][From Masks to Worlds: A Hitchhiker's Guide to World Models](https://arxiv.org/abs/2510.20668)
|
| 61 |
+
- [Soft-Di[M]O: Improving One-Step Discrete Image Generation with Soft Embeddings](https://arxiv.org/abs/2509.22925)
|
| 62 |
+
|
| 63 |
+
- More papers are coming soon!
|
| 64 |
+
See [MeissonFlow Research](https://huggingface.co/MeissonFlow) (Organization Card) for more about our vision.
|
| 65 |
+
|
| 66 |
+
|
| 67 |
+

|
| 68 |
+
|
| 69 |
+
## 🚀 Introduction
|
| 70 |
+
|
| 71 |
+
Meissonic is a non-autoregressive mask image modeling text-to-image synthesis model that can generate high-resolution images. It is designed to run on consumer graphics cards.
|
| 72 |
+
|
| 73 |
+

|
| 74 |
+
|
| 75 |
+
**Key Features:**
|
| 76 |
+
- 🖼️ High-resolution image generation (up to 1024x1024)
|
| 77 |
+
- 💻 Designed to run on consumer GPUs
|
| 78 |
+
- 🎨 Versatile applications: text-to-image, image-to-image
|
| 79 |
+
|
| 80 |
+
## 🛠️ Prerequisites
|
| 81 |
+
|
| 82 |
+
### Step 1: Clone the repository
|
| 83 |
+
```bash
|
| 84 |
+
git clone https://github.com/viiika/Meissonic/
|
| 85 |
+
cd Meissonic
|
| 86 |
+
```
|
| 87 |
+
|
| 88 |
+
### Step 2: Create virtual environment
|
| 89 |
+
```bash
|
| 90 |
+
conda create --name meissonic python
|
| 91 |
+
conda activate meissonic
|
| 92 |
+
pip install -r requirements.txt
|
| 93 |
+
```
|
| 94 |
+
|
| 95 |
+
### Step 3: Install diffusers
|
| 96 |
+
```bash
|
| 97 |
+
git clone https://github.com/huggingface/diffusers.git
|
| 98 |
+
cd diffusers
|
| 99 |
+
pip install -e .
|
| 100 |
+
```
|
| 101 |
+
|
| 102 |
+
## 💡 Inference Usage
|
| 103 |
+
|
| 104 |
+
### Gradio Web UI
|
| 105 |
+
|
| 106 |
+
```bash
|
| 107 |
+
python app.py
|
| 108 |
+
```
|
| 109 |
+
|
| 110 |
+
### Command-line Interface
|
| 111 |
+
|
| 112 |
+
#### Text-to-Image Generation
|
| 113 |
+
|
| 114 |
+
```bash
|
| 115 |
+
python inference.py --prompt "Your creative prompt here"
|
| 116 |
+
```
|
| 117 |
+
|
| 118 |
+
#### Inpainting and Outpainting
|
| 119 |
+
|
| 120 |
+
```bash
|
| 121 |
+
python inpaint.py --mode inpaint --input_image path/to/image.jpg
|
| 122 |
+
python inpaint.py --mode outpaint --input_image path/to/image.jpg
|
| 123 |
+
```
|
| 124 |
+
|
| 125 |
+
### Advanced: FP8 Quantization
|
| 126 |
+
|
| 127 |
+
Optimize performance with FP8 quantization:
|
| 128 |
+
|
| 129 |
+
Requirements:
|
| 130 |
+
- CUDA 12.4
|
| 131 |
+
- PyTorch 2.4.1
|
| 132 |
+
- TorchAO
|
| 133 |
+
|
| 134 |
+
Note: Windows users install TorchAO using
|
| 135 |
+
```shell
|
| 136 |
+
pip install --pre torchao --index-url https://download.pytorch.org/whl/nightly/cpu
|
| 137 |
+
```
|
| 138 |
+
|
| 139 |
+
Command-line inference
|
| 140 |
+
```shell
|
| 141 |
+
python inference_fp8.py --quantization fp8
|
| 142 |
+
```
|
| 143 |
+
|
| 144 |
+
Gradio for FP8 (Select Quantization Method in Advanced settings)
|
| 145 |
+
```shell
|
| 146 |
+
python app_fp8.py
|
| 147 |
+
```
|
| 148 |
+
|
| 149 |
+
#### Performance Benchmarks
|
| 150 |
+
|
| 151 |
+
| Precision (Steps=64, Resolution=1024x1024) | Batch Size=1 (Avg. Time) | Memory Usage |
|
| 152 |
+
|-------------------------------------------|--------------------------|--------------|
|
| 153 |
+
| FP32 | 13.32s | 12GB |
|
| 154 |
+
| FP16 | 12.35s | 9.5GB |
|
| 155 |
+
| FP8 | 12.93s | 8.7GB |
|
| 156 |
+
|
| 157 |
+
## 🎨 Showcase
|
| 158 |
+
|
| 159 |
+
<div align="center">
|
| 160 |
+
<img src="https://github.com/user-attachments/assets/b30a7912-5453-48ba-aff4-bfb547bbe626" width="320" alt="A pillow with a picture of a Husky on it.">
|
| 161 |
+
<p><i>"A pillow with a picture of a Husky on it."</i></p>
|
| 162 |
+
</div>
|
| 163 |
+
|
| 164 |
+
<div align="center">
|
| 165 |
+
<img src="https://github.com/user-attachments/assets/b23a1603-399d-40d6-8e16-c077d3d12a08" width="320" alt="A white coffee mug, a solid black background">
|
| 166 |
+
<p><i>"A white coffee mug, a solid black background"</i></p>
|
| 167 |
+
</div>
|
| 168 |
+
|
| 169 |
+
## 🎓 Training
|
| 170 |
+
|
| 171 |
+
To train Meissonic, follow these steps:
|
| 172 |
+
|
| 173 |
+
1. Install dependencies:
|
| 174 |
+
```bash
|
| 175 |
+
cd train
|
| 176 |
+
pip install -r requirements.txt
|
| 177 |
+
```
|
| 178 |
+
|
| 179 |
+
2. Download the [Meissonic](https://huggingface.co/MeissonFlow/Meissonic) base model from Hugging Face.
|
| 180 |
+
|
| 181 |
+
3. Prepare your dataset:
|
| 182 |
+
- Use the sample dataset: [MeissonFlow/splash](https://huggingface.co/datasets/MeissonFlow/lemon/resolve/main/0000.parquet)
|
| 183 |
+
- Or prepare your own dataset and dataset class following the format in line 100 in [dataset_utils.py](./train/dataset_utils.py) and line 656-680 in [train_meissonic.py](./train/train_meissonic.py)
|
| 184 |
+
- Modify [train.sh](./train/train.sh) with your dataset path
|
| 185 |
+
|
| 186 |
+
4. Start training:
|
| 187 |
+
```bash
|
| 188 |
+
bash train/train.sh
|
| 189 |
+
```
|
| 190 |
+
|
| 191 |
+
Note: For custom datasets, you'll likely need to implement your own dataset class.
|
| 192 |
+
|
| 193 |
+
|
| 194 |
+
## 📚 Citation
|
| 195 |
+
|
| 196 |
+
If you find this work helpful, please consider citing:
|
| 197 |
+
|
| 198 |
+
```bibtex
|
| 199 |
+
@article{bai2024meissonic,
|
| 200 |
+
title={Meissonic: Revitalizing Masked Generative Transformers for Efficient High-Resolution Text-to-Image Synthesis},
|
| 201 |
+
author={Bai, Jinbin and Ye, Tian and Chow, Wei and Song, Enxin and Chen, Qing-Guo and Li, Xiangtai and Dong, Zhen and Zhu, Lei and Yan, Shuicheng},
|
| 202 |
+
journal={arXiv preprint arXiv:2410.08261},
|
| 203 |
+
year={2024}
|
| 204 |
+
}
|
| 205 |
+
```
|
| 206 |
+
|
| 207 |
+
## 🙏 Acknowledgements
|
| 208 |
+
|
| 209 |
+
We thank the community and contributors for their invaluable support in developing Meissonic. We thank apolinario@multimodal.art for making Meissonic [Demo](https://huggingface.co/spaces/MeissonFlow/meissonic). We thank @NewGenAI and @飛鷹しずか@自称文系プログラマの勉強 for making YouTube tutorials. We thank @pprp for making fp8 and int4 quantization. We thank @camenduru for making [jupyter tutorial](https://github.com/camenduru/Meissonic-jupyter). We thank @chenxwh for making Replicate demo and api. We thank Collov Labs for reproducing [Monetico](https://huggingface.co/Collov-Labs/Monetico). We thank [Shitong et al.](https://arxiv.org/abs/2411.10781) for identifying effective design choices for enhancing visual quality.
|
| 210 |
+
|
| 211 |
+
|
| 212 |
+
---
|
| 213 |
+
|
| 214 |
+
<p align="center">
|
| 215 |
+
<a href="https://star-history.com/#viiika/Meissonic&Date">
|
| 216 |
+
<img src="https://api.star-history.com/svg?repos=viiika/Meissonic&type=Date" alt="Star History Chart">
|
| 217 |
+
</a>
|
| 218 |
+
</p>
|
| 219 |
+
|
| 220 |
+
<p align="center">
|
| 221 |
+
Made with ❤️ by the MeissonFlow Research
|
| 222 |
+
</p>
|
Meissonic/app.py
ADDED
|
@@ -0,0 +1,149 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import os
|
| 2 |
+
import sys
|
| 3 |
+
sys.path.append("./")
|
| 4 |
+
|
| 5 |
+
import torch
|
| 6 |
+
from torchvision import transforms
|
| 7 |
+
from src.transformer import Transformer2DModel
|
| 8 |
+
from src.pipeline import Pipeline
|
| 9 |
+
from src.scheduler import Scheduler
|
| 10 |
+
from transformers import (
|
| 11 |
+
CLIPTextModelWithProjection,
|
| 12 |
+
CLIPTokenizer,
|
| 13 |
+
)
|
| 14 |
+
from diffusers import VQModel
|
| 15 |
+
import gradio as gr
|
| 16 |
+
|
| 17 |
+
|
| 18 |
+
device = 'cuda' if torch.cuda.is_available() else 'cpu'
|
| 19 |
+
|
| 20 |
+
model_path = "MeissonFlow/Meissonic"
|
| 21 |
+
model = Transformer2DModel.from_pretrained(model_path, subfolder="transformer")
|
| 22 |
+
vq_model = VQModel.from_pretrained(model_path, subfolder="vqvae")
|
| 23 |
+
# text_encoder = CLIPTextModelWithProjection.from_pretrained(model_path, subfolder="text_encoder")
|
| 24 |
+
text_encoder = CLIPTextModelWithProjection.from_pretrained( #more stable sampling for some cases
|
| 25 |
+
"laion/CLIP-ViT-H-14-laion2B-s32B-b79K"
|
| 26 |
+
)
|
| 27 |
+
tokenizer = CLIPTokenizer.from_pretrained(model_path, subfolder="tokenizer")
|
| 28 |
+
scheduler = Scheduler.from_pretrained(model_path, subfolder="scheduler")
|
| 29 |
+
pipe = Pipeline(vq_model, tokenizer=tokenizer, text_encoder=text_encoder, transformer=model, scheduler=scheduler)
|
| 30 |
+
pipe.to(device)
|
| 31 |
+
|
| 32 |
+
MAX_SEED = 2**32 - 1
|
| 33 |
+
MAX_IMAGE_SIZE = 1024
|
| 34 |
+
|
| 35 |
+
|
| 36 |
+
def generate_image(prompt, negative_prompt, seed, randomize_seed, width, height, guidance_scale, num_inference_steps, progress=gr.Progress(track_tqdm=True)):
|
| 37 |
+
if randomize_seed or seed == 0:
|
| 38 |
+
seed = torch.randint(0, MAX_SEED, (1,)).item()
|
| 39 |
+
torch.manual_seed(seed)
|
| 40 |
+
|
| 41 |
+
image = pipe(
|
| 42 |
+
prompt=prompt,
|
| 43 |
+
negative_prompt=negative_prompt,
|
| 44 |
+
height=height,
|
| 45 |
+
width=width,
|
| 46 |
+
guidance_scale=guidance_scale,
|
| 47 |
+
num_inference_steps=num_inference_steps
|
| 48 |
+
).images[0]
|
| 49 |
+
|
| 50 |
+
return image, seed
|
| 51 |
+
|
| 52 |
+
# Default negative prompt
|
| 53 |
+
default_negative_prompt = "worst quality, low quality, low res, blurry, distortion, watermark, logo, signature, text, jpeg artifacts, signature, sketch, duplicate, ugly, identifying mark"
|
| 54 |
+
css = """
|
| 55 |
+
#col-container {
|
| 56 |
+
margin: 0 auto;
|
| 57 |
+
max-width: 640px;
|
| 58 |
+
}
|
| 59 |
+
"""
|
| 60 |
+
|
| 61 |
+
examples = [
|
| 62 |
+
"Modern Architecture render with pleasing aesthetics.",
|
| 63 |
+
"An image of a Pikachu wearing a birthday hat and playing guitar.",
|
| 64 |
+
"A statue of a lion stands in front of a building.",
|
| 65 |
+
"A white and blue coffee mug with a picture of a man on it.",
|
| 66 |
+
"A metal sculpture of a deer with antlers.",
|
| 67 |
+
"A bronze statue of an owl with its wings spread.",
|
| 68 |
+
"A white table with a vase of flowers and a cup of coffee on top of it.",
|
| 69 |
+
"A woman stands on a dock in the fog.",
|
| 70 |
+
"A lion's head is shown in a grayscale image.",
|
| 71 |
+
"A sculpture of a Greek woman head with a headband and a head of hair."
|
| 72 |
+
]
|
| 73 |
+
|
| 74 |
+
with gr.Blocks(css=css) as demo:
|
| 75 |
+
with gr.Column(elem_id="col-container"):
|
| 76 |
+
gr.Markdown("# Meissonic Text-to-Image Generator")
|
| 77 |
+
with gr.Row():
|
| 78 |
+
prompt = gr.Text(
|
| 79 |
+
label="Prompt",
|
| 80 |
+
show_label=False,
|
| 81 |
+
max_lines=1,
|
| 82 |
+
placeholder="Enter your prompt",
|
| 83 |
+
container=False,
|
| 84 |
+
)
|
| 85 |
+
run_button = gr.Button("Run", scale=0, variant="primary")
|
| 86 |
+
result = gr.Image(label="Result", show_label=False)
|
| 87 |
+
with gr.Accordion("Advanced Settings", open=False):
|
| 88 |
+
negative_prompt = gr.Text(
|
| 89 |
+
label="Negative prompt",
|
| 90 |
+
max_lines=1,
|
| 91 |
+
placeholder="Enter a negative prompt",
|
| 92 |
+
value=default_negative_prompt,
|
| 93 |
+
)
|
| 94 |
+
seed = gr.Slider(
|
| 95 |
+
label="Seed",
|
| 96 |
+
minimum=0,
|
| 97 |
+
maximum=MAX_SEED,
|
| 98 |
+
step=1,
|
| 99 |
+
value=0,
|
| 100 |
+
)
|
| 101 |
+
randomize_seed = gr.Checkbox(label="Randomize seed", value=True)
|
| 102 |
+
with gr.Row():
|
| 103 |
+
width = gr.Slider(
|
| 104 |
+
label="Width",
|
| 105 |
+
minimum=256,
|
| 106 |
+
maximum=MAX_IMAGE_SIZE,
|
| 107 |
+
step=32,
|
| 108 |
+
value=1024,
|
| 109 |
+
)
|
| 110 |
+
height = gr.Slider(
|
| 111 |
+
label="Height",
|
| 112 |
+
minimum=256,
|
| 113 |
+
maximum=MAX_IMAGE_SIZE,
|
| 114 |
+
step=32,
|
| 115 |
+
value=1024,
|
| 116 |
+
)
|
| 117 |
+
with gr.Row():
|
| 118 |
+
guidance_scale = gr.Slider(
|
| 119 |
+
label="Guidance scale",
|
| 120 |
+
minimum=0.0,
|
| 121 |
+
maximum=20.0,
|
| 122 |
+
step=0.1,
|
| 123 |
+
value=9.0,
|
| 124 |
+
)
|
| 125 |
+
num_inference_steps = gr.Slider(
|
| 126 |
+
label="Number of inference steps",
|
| 127 |
+
minimum=1,
|
| 128 |
+
maximum=100,
|
| 129 |
+
step=1,
|
| 130 |
+
value=64,
|
| 131 |
+
)
|
| 132 |
+
gr.Examples(examples=examples, inputs=[prompt])
|
| 133 |
+
gr.on(
|
| 134 |
+
triggers=[run_button.click, prompt.submit],
|
| 135 |
+
fn=generate_image,
|
| 136 |
+
inputs=[
|
| 137 |
+
prompt,
|
| 138 |
+
negative_prompt,
|
| 139 |
+
seed,
|
| 140 |
+
randomize_seed,
|
| 141 |
+
width,
|
| 142 |
+
height,
|
| 143 |
+
guidance_scale,
|
| 144 |
+
num_inference_steps,
|
| 145 |
+
],
|
| 146 |
+
outputs=[result, seed],
|
| 147 |
+
)
|
| 148 |
+
|
| 149 |
+
demo.launch()
|
Meissonic/app_Monetico.py
ADDED
|
@@ -0,0 +1,151 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import os
|
| 2 |
+
import sys
|
| 3 |
+
sys.path.append("./")
|
| 4 |
+
|
| 5 |
+
import torch
|
| 6 |
+
from torchvision import transforms
|
| 7 |
+
from src.transformer import Transformer2DModel
|
| 8 |
+
from src.pipeline import Pipeline
|
| 9 |
+
from src.scheduler import Scheduler
|
| 10 |
+
from transformers import (
|
| 11 |
+
CLIPTextModelWithProjection,
|
| 12 |
+
CLIPTokenizer,
|
| 13 |
+
)
|
| 14 |
+
from diffusers import VQModel
|
| 15 |
+
import gradio as gr
|
| 16 |
+
import spaces
|
| 17 |
+
|
| 18 |
+
device = 'cuda' if torch.cuda.is_available() else 'cpu'
|
| 19 |
+
dtype = torch.bfloat16
|
| 20 |
+
|
| 21 |
+
model_path = "Collov-Labs/Monetico"
|
| 22 |
+
|
| 23 |
+
model = Transformer2DModel.from_pretrained(model_path, subfolder="transformer", torch_dtype=dtype)
|
| 24 |
+
vq_model = VQModel.from_pretrained(model_path, subfolder="vqvae", torch_dtype=dtype)
|
| 25 |
+
text_encoder = CLIPTextModelWithProjection.from_pretrained(model_path, subfolder="text_encoder", torch_dtype=dtype) # better for Monetico
|
| 26 |
+
# text_encoder = CLIPTextModelWithProjection.from_pretrained( #more stable sampling for some cases
|
| 27 |
+
# "laion/CLIP-ViT-H-14-laion2B-s32B-b79K", torch_dtype=dtype
|
| 28 |
+
# )
|
| 29 |
+
tokenizer = CLIPTokenizer.from_pretrained(model_path, subfolder="tokenizer", torch_dtype=dtype)
|
| 30 |
+
scheduler = Scheduler.from_pretrained(model_path, subfolder="scheduler", torch_dtype=dtype)
|
| 31 |
+
pipe = Pipeline(vq_model, tokenizer=tokenizer, text_encoder=text_encoder, transformer=model, scheduler=scheduler)
|
| 32 |
+
pipe.to(device)
|
| 33 |
+
|
| 34 |
+
MAX_SEED = 2**32 - 1
|
| 35 |
+
MAX_IMAGE_SIZE = 512
|
| 36 |
+
|
| 37 |
+
@spaces.GPU
|
| 38 |
+
def generate_image(prompt, negative_prompt, seed, randomize_seed, width, height, guidance_scale, num_inference_steps, progress=gr.Progress(track_tqdm=True)):
|
| 39 |
+
if randomize_seed or seed == 0:
|
| 40 |
+
seed = torch.randint(0, MAX_SEED, (1,)).item()
|
| 41 |
+
torch.manual_seed(seed)
|
| 42 |
+
|
| 43 |
+
image = pipe(
|
| 44 |
+
prompt=prompt,
|
| 45 |
+
negative_prompt=negative_prompt,
|
| 46 |
+
height=height,
|
| 47 |
+
width=width,
|
| 48 |
+
guidance_scale=guidance_scale,
|
| 49 |
+
num_inference_steps=num_inference_steps
|
| 50 |
+
).images[0]
|
| 51 |
+
|
| 52 |
+
return image, seed
|
| 53 |
+
|
| 54 |
+
# Default negative prompt
|
| 55 |
+
default_negative_prompt = "worst quality, low quality, low res, blurry, distortion, watermark, logo, signature, text, jpeg artifacts, signature, sketch, duplicate, ugly, identifying mark"
|
| 56 |
+
css = """
|
| 57 |
+
#col-container {
|
| 58 |
+
margin: 0 auto;
|
| 59 |
+
max-width: 640px;
|
| 60 |
+
}
|
| 61 |
+
"""
|
| 62 |
+
|
| 63 |
+
examples = [
|
| 64 |
+
"Modern Architecture render with pleasing aesthetics.",
|
| 65 |
+
"An image of a Pikachu wearing a birthday hat and playing guitar.",
|
| 66 |
+
"A statue of a lion stands in front of a building.",
|
| 67 |
+
"A white and blue coffee mug with a picture of a man on it.",
|
| 68 |
+
"A metal sculpture of a deer with antlers.",
|
| 69 |
+
"A bronze statue of an owl with its wings spread.",
|
| 70 |
+
"A white table with a vase of flowers and a cup of coffee on top of it.",
|
| 71 |
+
"A woman stands on a dock in the fog.",
|
| 72 |
+
"A lion's head is shown in a grayscale image.",
|
| 73 |
+
"A sculpture of a Greek woman head with a headband and a head of hair."
|
| 74 |
+
]
|
| 75 |
+
|
| 76 |
+
with gr.Blocks(css=css) as demo:
|
| 77 |
+
with gr.Column(elem_id="col-container"):
|
| 78 |
+
gr.Markdown("# Monetico Text-to-Image Generator")
|
| 79 |
+
with gr.Row():
|
| 80 |
+
prompt = gr.Text(
|
| 81 |
+
label="Prompt",
|
| 82 |
+
show_label=False,
|
| 83 |
+
max_lines=1,
|
| 84 |
+
placeholder="Enter your prompt",
|
| 85 |
+
container=False,
|
| 86 |
+
)
|
| 87 |
+
run_button = gr.Button("Run", scale=0, variant="primary")
|
| 88 |
+
result = gr.Image(label="Result", show_label=False)
|
| 89 |
+
with gr.Accordion("Advanced Settings", open=False):
|
| 90 |
+
negative_prompt = gr.Text(
|
| 91 |
+
label="Negative prompt",
|
| 92 |
+
max_lines=1,
|
| 93 |
+
placeholder="Enter a negative prompt",
|
| 94 |
+
value=default_negative_prompt,
|
| 95 |
+
)
|
| 96 |
+
seed = gr.Slider(
|
| 97 |
+
label="Seed",
|
| 98 |
+
minimum=0,
|
| 99 |
+
maximum=MAX_SEED,
|
| 100 |
+
step=1,
|
| 101 |
+
value=0,
|
| 102 |
+
)
|
| 103 |
+
randomize_seed = gr.Checkbox(label="Randomize seed", value=True)
|
| 104 |
+
with gr.Row():
|
| 105 |
+
width = gr.Slider(
|
| 106 |
+
label="Width",
|
| 107 |
+
minimum=256,
|
| 108 |
+
maximum=MAX_IMAGE_SIZE,
|
| 109 |
+
step=32,
|
| 110 |
+
value=512,
|
| 111 |
+
)
|
| 112 |
+
height = gr.Slider(
|
| 113 |
+
label="Height",
|
| 114 |
+
minimum=256,
|
| 115 |
+
maximum=MAX_IMAGE_SIZE,
|
| 116 |
+
step=32,
|
| 117 |
+
value=512,
|
| 118 |
+
)
|
| 119 |
+
with gr.Row():
|
| 120 |
+
guidance_scale = gr.Slider(
|
| 121 |
+
label="Guidance scale",
|
| 122 |
+
minimum=0.0,
|
| 123 |
+
maximum=20.0,
|
| 124 |
+
step=0.1,
|
| 125 |
+
value=9.0,
|
| 126 |
+
)
|
| 127 |
+
num_inference_steps = gr.Slider(
|
| 128 |
+
label="Number of inference steps",
|
| 129 |
+
minimum=1,
|
| 130 |
+
maximum=100,
|
| 131 |
+
step=1,
|
| 132 |
+
value=48,
|
| 133 |
+
)
|
| 134 |
+
gr.Examples(examples=examples, inputs=[prompt])
|
| 135 |
+
gr.on(
|
| 136 |
+
triggers=[run_button.click, prompt.submit],
|
| 137 |
+
fn=generate_image,
|
| 138 |
+
inputs=[
|
| 139 |
+
prompt,
|
| 140 |
+
negative_prompt,
|
| 141 |
+
seed,
|
| 142 |
+
randomize_seed,
|
| 143 |
+
width,
|
| 144 |
+
height,
|
| 145 |
+
guidance_scale,
|
| 146 |
+
num_inference_steps,
|
| 147 |
+
],
|
| 148 |
+
outputs=[result, seed],
|
| 149 |
+
)
|
| 150 |
+
|
| 151 |
+
demo.launch()
|
Meissonic/app_fp8.py
ADDED
|
@@ -0,0 +1,223 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import os
|
| 2 |
+
import sys
|
| 3 |
+
sys.path.append("./")
|
| 4 |
+
|
| 5 |
+
import torch
|
| 6 |
+
from src.transformer import Transformer2DModel
|
| 7 |
+
from src.pipeline import Pipeline
|
| 8 |
+
from src.scheduler import Scheduler
|
| 9 |
+
from transformers import (
|
| 10 |
+
CLIPTextModelWithProjection,
|
| 11 |
+
CLIPTokenizer,
|
| 12 |
+
)
|
| 13 |
+
from diffusers import VQModel
|
| 14 |
+
import gradio as gr
|
| 15 |
+
import time
|
| 16 |
+
from torchao.quantization.quant_api import (
|
| 17 |
+
quantize_,
|
| 18 |
+
float8_weight_only,
|
| 19 |
+
)
|
| 20 |
+
|
| 21 |
+
device = 'cuda'
|
| 22 |
+
|
| 23 |
+
def get_quantization_method(method):
|
| 24 |
+
quantization_methods = {
|
| 25 |
+
'fp8': lambda: float8_weight_only(),
|
| 26 |
+
'none': None
|
| 27 |
+
}
|
| 28 |
+
return quantization_methods.get(method, None)
|
| 29 |
+
|
| 30 |
+
def load_models(quantization_method='none'):
|
| 31 |
+
model_path = "MeissonFlow/Meissonic"
|
| 32 |
+
dtype = torch.float16
|
| 33 |
+
model = Transformer2DModel.from_pretrained(model_path, subfolder="transformer", torch_dtype=dtype)
|
| 34 |
+
vq_model = VQModel.from_pretrained(model_path, subfolder="vqvae", torch_dtype=dtype)
|
| 35 |
+
text_encoder = CLIPTextModelWithProjection.from_pretrained(
|
| 36 |
+
"laion/CLIP-ViT-H-14-laion2B-s32B-b79K",
|
| 37 |
+
torch_dtype=dtype
|
| 38 |
+
)
|
| 39 |
+
tokenizer = CLIPTokenizer.from_pretrained(model_path, subfolder="tokenizer")
|
| 40 |
+
scheduler = Scheduler.from_pretrained(model_path, subfolder="scheduler")
|
| 41 |
+
|
| 42 |
+
if quantization_method != 'none':
|
| 43 |
+
quant_method = get_quantization_method(quantization_method)
|
| 44 |
+
if quant_method:
|
| 45 |
+
quantize_(model, quant_method())
|
| 46 |
+
|
| 47 |
+
pipe = Pipeline(vq_model, tokenizer=tokenizer, text_encoder=text_encoder, transformer=model, scheduler=scheduler)
|
| 48 |
+
return pipe.to(device)
|
| 49 |
+
|
| 50 |
+
# Global variable to store the pipeline
|
| 51 |
+
global_pipe = None
|
| 52 |
+
current_quantization = 'none'
|
| 53 |
+
|
| 54 |
+
def initialize_pipeline(quantization):
|
| 55 |
+
global global_pipe, current_quantization
|
| 56 |
+
if global_pipe is None or current_quantization != quantization:
|
| 57 |
+
global_pipe = load_models(quantization)
|
| 58 |
+
current_quantization = quantization
|
| 59 |
+
return global_pipe
|
| 60 |
+
|
| 61 |
+
def generate_images(prompt, negative_prompt, seed, randomize_seed, width, height,
|
| 62 |
+
guidance_scale, num_inference_steps, quantization_method, batch_size=1,
|
| 63 |
+
progress=gr.Progress(track_tqdm=True)):
|
| 64 |
+
if randomize_seed or seed == 0:
|
| 65 |
+
seed = torch.randint(0, MAX_SEED, (1,)).item()
|
| 66 |
+
torch.manual_seed(seed)
|
| 67 |
+
|
| 68 |
+
# Initialize or update pipeline if needed
|
| 69 |
+
pipe = initialize_pipeline(quantization_method)
|
| 70 |
+
|
| 71 |
+
# Reset CUDA memory stats
|
| 72 |
+
torch.cuda.reset_peak_memory_stats()
|
| 73 |
+
start_time = time.time()
|
| 74 |
+
|
| 75 |
+
# Handle batch generation
|
| 76 |
+
if isinstance(prompt, str):
|
| 77 |
+
prompts = [prompt] * batch_size
|
| 78 |
+
else:
|
| 79 |
+
prompts = prompt[:batch_size]
|
| 80 |
+
|
| 81 |
+
images = pipe(
|
| 82 |
+
prompt=prompts,
|
| 83 |
+
negative_prompt=[negative_prompt] * batch_size,
|
| 84 |
+
height=height,
|
| 85 |
+
width=width,
|
| 86 |
+
guidance_scale=guidance_scale,
|
| 87 |
+
num_inference_steps=num_inference_steps
|
| 88 |
+
).images
|
| 89 |
+
|
| 90 |
+
# Calculate performance metrics
|
| 91 |
+
inference_time = time.time() - start_time
|
| 92 |
+
memory_used = torch.cuda.max_memory_reserved() / (1024 ** 3) # Convert to GB
|
| 93 |
+
|
| 94 |
+
performance_info = f"""
|
| 95 |
+
Inference Time: {inference_time:.2f} seconds
|
| 96 |
+
Memory Used: {memory_used:.2f} GB
|
| 97 |
+
Quantization: {quantization_method}
|
| 98 |
+
"""
|
| 99 |
+
|
| 100 |
+
return images[0] if batch_size == 1 else images, seed, performance_info
|
| 101 |
+
|
| 102 |
+
MAX_SEED = 2**32 - 1
|
| 103 |
+
MAX_IMAGE_SIZE = 1024
|
| 104 |
+
default_negative_prompt = "worst quality, low quality, low res, blurry, distortion, watermark, logo, signature, text, jpeg artifacts, signature, sketch, duplicate, ugly, identifying mark"
|
| 105 |
+
|
| 106 |
+
examples = [
|
| 107 |
+
"Two actors are posing for a pictur with one wearing a black and white face paint.",
|
| 108 |
+
"A large body of water with a rock in the middle and mountains in the background.",
|
| 109 |
+
"A white and blue coffee mug with a picture of a man on it.",
|
| 110 |
+
"The sun is setting over a city skyline with a river in the foreground.",
|
| 111 |
+
"A black and white cat with blue eyes.",
|
| 112 |
+
"Three boats in the ocean with a rainbow in the sky.",
|
| 113 |
+
"A robot playing the piano.",
|
| 114 |
+
"A cat wearing a hat.",
|
| 115 |
+
"A dog in a jungle."
|
| 116 |
+
]
|
| 117 |
+
|
| 118 |
+
css = """
|
| 119 |
+
#col-container {
|
| 120 |
+
margin: 0 auto;
|
| 121 |
+
max-width: 640px;
|
| 122 |
+
}
|
| 123 |
+
"""
|
| 124 |
+
|
| 125 |
+
with gr.Blocks(css=css) as demo:
|
| 126 |
+
with gr.Column(elem_id="col-container"):
|
| 127 |
+
gr.Markdown("# Meissonic Text-to-Image Generator (with FP8 Support)")
|
| 128 |
+
|
| 129 |
+
with gr.Row():
|
| 130 |
+
prompt = gr.Text(
|
| 131 |
+
label="Prompt",
|
| 132 |
+
show_label=False,
|
| 133 |
+
max_lines=1,
|
| 134 |
+
placeholder="Enter your prompt",
|
| 135 |
+
container=False,
|
| 136 |
+
)
|
| 137 |
+
run_button = gr.Button("Run", scale=0, variant="primary")
|
| 138 |
+
|
| 139 |
+
result = gr.Image(label="Result", show_label=False)
|
| 140 |
+
performance_info = gr.Textbox(label="Performance Metrics", lines=4)
|
| 141 |
+
|
| 142 |
+
with gr.Accordion("Advanced Settings", open=False):
|
| 143 |
+
quantization = gr.Radio(
|
| 144 |
+
choices=['none', 'fp8'],
|
| 145 |
+
value='none',
|
| 146 |
+
label="Quantization Method",
|
| 147 |
+
)
|
| 148 |
+
negative_prompt = gr.Text(
|
| 149 |
+
label="Negative prompt",
|
| 150 |
+
max_lines=1,
|
| 151 |
+
placeholder="Enter a negative prompt",
|
| 152 |
+
value=default_negative_prompt,
|
| 153 |
+
)
|
| 154 |
+
seed = gr.Slider(
|
| 155 |
+
label="Seed",
|
| 156 |
+
minimum=0,
|
| 157 |
+
maximum=MAX_SEED,
|
| 158 |
+
step=1,
|
| 159 |
+
value=0,
|
| 160 |
+
)
|
| 161 |
+
randomize_seed = gr.Checkbox(label="Randomize seed", value=True)
|
| 162 |
+
|
| 163 |
+
with gr.Row():
|
| 164 |
+
width = gr.Slider(
|
| 165 |
+
label="Width",
|
| 166 |
+
minimum=256,
|
| 167 |
+
maximum=MAX_IMAGE_SIZE,
|
| 168 |
+
step=32,
|
| 169 |
+
value=1024,
|
| 170 |
+
)
|
| 171 |
+
height = gr.Slider(
|
| 172 |
+
label="Height",
|
| 173 |
+
minimum=256,
|
| 174 |
+
maximum=MAX_IMAGE_SIZE,
|
| 175 |
+
step=32,
|
| 176 |
+
value=1024,
|
| 177 |
+
)
|
| 178 |
+
|
| 179 |
+
with gr.Row():
|
| 180 |
+
guidance_scale = gr.Slider(
|
| 181 |
+
label="Guidance scale",
|
| 182 |
+
minimum=0.0,
|
| 183 |
+
maximum=20.0,
|
| 184 |
+
step=0.1,
|
| 185 |
+
value=9.0,
|
| 186 |
+
)
|
| 187 |
+
num_inference_steps = gr.Slider(
|
| 188 |
+
label="Number of inference steps",
|
| 189 |
+
minimum=1,
|
| 190 |
+
maximum=100,
|
| 191 |
+
step=1,
|
| 192 |
+
value=64,
|
| 193 |
+
)
|
| 194 |
+
|
| 195 |
+
batch_size = gr.Slider(
|
| 196 |
+
label="Batch Size",
|
| 197 |
+
minimum=1,
|
| 198 |
+
maximum=8,
|
| 199 |
+
step=1,
|
| 200 |
+
value=1,
|
| 201 |
+
)
|
| 202 |
+
|
| 203 |
+
gr.Examples(examples=examples, inputs=[prompt])
|
| 204 |
+
|
| 205 |
+
gr.on(
|
| 206 |
+
triggers=[run_button.click, prompt.submit],
|
| 207 |
+
fn=generate_images,
|
| 208 |
+
inputs=[
|
| 209 |
+
prompt,
|
| 210 |
+
negative_prompt,
|
| 211 |
+
seed,
|
| 212 |
+
randomize_seed,
|
| 213 |
+
width,
|
| 214 |
+
height,
|
| 215 |
+
guidance_scale,
|
| 216 |
+
num_inference_steps,
|
| 217 |
+
quantization,
|
| 218 |
+
batch_size,
|
| 219 |
+
],
|
| 220 |
+
outputs=[result, seed, performance_info],
|
| 221 |
+
)
|
| 222 |
+
|
| 223 |
+
demo.launch()
|
Meissonic/assets/architecture.png
ADDED
|
Git LFS Details
|
Meissonic/assets/demos.pdf
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:1d14191e0b8e9fdf4cb3a7199cf36554e60e456cdeba11509d305a8201e6b131
|
| 3 |
+
size 2476203
|
Meissonic/assets/demos.png
ADDED
|
Git LFS Details
|
Meissonic/assets/inpaint/0eKR4M2uuL8.jpg
ADDED
|
Git LFS Details
|
Meissonic/assets/inpaint/0eKR4M2uuL8.png
ADDED
|
Meissonic/assets/inpaint/_Rh_zxIUWXA.jpg
ADDED
|
Meissonic/assets/inpaint/_Rh_zxIUWXA.png
ADDED
|
Meissonic/assets/inpaint/__Owak0IgJk.jpg
ADDED
|
Git LFS Details
|
Meissonic/assets/inpaint/__Owak0IgJk.png
ADDED
|
Meissonic/assets/inpaint/cases.json
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
[
|
| 2 |
+
{
|
| 3 |
+
"input":"./assets/inpaint/_Rh_zxIUWXA.jpg",
|
| 4 |
+
"mask": "./assets/inpaint/_Rh_zxIUWXA.png",
|
| 5 |
+
"prompt": "A woman with short hair wears a silver gas mask.",
|
| 6 |
+
"negative_prompts": null
|
| 7 |
+
},
|
| 8 |
+
{
|
| 9 |
+
"input":"./assets/inpaint/0eKR4M2uuL8.jpg",
|
| 10 |
+
"mask": "./assets/inpaint/0eKR4M2uuL8.png",
|
| 11 |
+
"prompt": "A stylish dog wearing sunglasses.",
|
| 12 |
+
"negative_prompts": null
|
| 13 |
+
},
|
| 14 |
+
{
|
| 15 |
+
"input":"./assets/inpaint/__Owak0IgJk.jpg",
|
| 16 |
+
"mask": "./assets/inpaint/__Owak0IgJk.png",
|
| 17 |
+
"prompt": "A woman wearing a white suspender skirt is sitting",
|
| 18 |
+
"negative_prompts": null
|
| 19 |
+
}
|
| 20 |
+
]
|
Meissonic/assets/outpaint/__G2yFuW7jQ.jpg
ADDED
|
Git LFS Details
|
Meissonic/assets/outpaint/__G2yFuW7jQ.png
ADDED
|
Meissonic/assets/outpaint/cases.json
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
[
|
| 2 |
+
{
|
| 3 |
+
"input":"./assets/outpaint/__G2yFuW7jQ.jpg",
|
| 4 |
+
"mask": "./assets/outpaint/__G2yFuW7jQ.png",
|
| 5 |
+
"prompt": "fall mountains",
|
| 6 |
+
"negative_prompts": "The artwork avoids the pitfalls of bad art, such as ugly and deformed eyes and faces, poorly drawn, blurry, and disfigured bodies with extra limbs and close-ups that look weird. It also avoids other common issues such as watermarking, text errors, missing fingers or digits, cropping, poor quality, and JPEG artifacts. The artwork is free of signature or watermark and avoids framing issues.The hands are not deformed, the eyes are not disfigured, and there areno extra bodies or limbs. The artwork is not blurry, out of focus, or poorly drawn, and the proportions are not bad or deformed. There are no mutations, missing limbs, or floating or disconnected limbs. The hands and neck are not malformed, and there are no extra heads or out-of-frame elements. The artwork is not low-res or disgusting and is a well-drawn, highly detailed, and beautiful rendering."
|
| 7 |
+
},
|
| 8 |
+
{
|
| 9 |
+
"input":"./assets/outpaint/__G2yFuW7jQ.jpg",
|
| 10 |
+
"mask": "./assets/outpaint/__G2yFuW7jQ.png",
|
| 11 |
+
"prompt": "Rocket launch site",
|
| 12 |
+
"negative_prompts": "The artwork avoids the pitfalls of bad art, such as ugly and deformed eyes and faces, poorly drawn, blurry, and disfigured bodies with extra limbs and close-ups that look weird. It also avoids other common issues such as watermarking, text errors, missing fingers or digits, cropping, poor quality, and JPEG artifacts. The artwork is free of signature or watermark and avoids framing issues.The hands are not deformed, the eyes are not disfigured, and there areno extra bodies or limbs. The artwork is not blurry, out of focus, or poorly drawn, and the proportions are not bad or deformed. There are no mutations, missing limbs, or floating or disconnected limbs. The hands and neck are not malformed, and there are no extra heads or out-of-frame elements. The artwork is not low-res or disgusting and is a well-drawn, highly detailed, and beautiful rendering."
|
| 13 |
+
},
|
| 14 |
+
{
|
| 15 |
+
"input":"./assets/outpaint/__G2yFuW7jQ.jpg",
|
| 16 |
+
"mask": "./assets/outpaint/__G2yFuW7jQ.png",
|
| 17 |
+
"prompt": "Volcano",
|
| 18 |
+
"negative_prompts": "The artwork avoids the pitfalls of bad art, such as ugly and deformed eyes and faces, poorly drawn, blurry, and disfigured bodies with extra limbs and close-ups that look weird. It also avoids other common issues such as watermarking, text errors, missing fingers or digits, cropping, poor quality, and JPEG artifacts. The artwork is free of signature or watermark and avoids framing issues.The hands are not deformed, the eyes are not disfigured, and there areno extra bodies or limbs. The artwork is not blurry, out of focus, or poorly drawn, and the proportions are not bad or deformed. There are no mutations, missing limbs, or floating or disconnected limbs. The hands and neck are not malformed, and there are no extra heads or out-of-frame elements. The artwork is not low-res or disgusting and is a well-drawn, highly detailed, and beautiful rendering."
|
| 19 |
+
}
|
| 20 |
+
]
|
Meissonic/cog.yaml
ADDED
|
@@ -0,0 +1,29 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# Configuration for Cog ⚙️
|
| 2 |
+
# Reference: https://cog.run/yaml
|
| 3 |
+
|
| 4 |
+
build:
|
| 5 |
+
# set to true if your model requires a GPU
|
| 6 |
+
gpu: true
|
| 7 |
+
|
| 8 |
+
# a list of ubuntu apt packages to install
|
| 9 |
+
system_packages:
|
| 10 |
+
- "libgl1-mesa-glx"
|
| 11 |
+
- "libglib2.0-0"
|
| 12 |
+
|
| 13 |
+
# python version in the form '3.11' or '3.11.4'
|
| 14 |
+
python_version: "3.11"
|
| 15 |
+
|
| 16 |
+
# a list of packages in the format <package-name>==<version>
|
| 17 |
+
python_packages:
|
| 18 |
+
- torch
|
| 19 |
+
- torchvision
|
| 20 |
+
- git+https://github.com/huggingface/diffusers.git
|
| 21 |
+
- accelerate
|
| 22 |
+
- transformers
|
| 23 |
+
|
| 24 |
+
# commands run after the environment is setup
|
| 25 |
+
run:
|
| 26 |
+
- curl -o /usr/local/bin/pget -L "https://github.com/replicate/pget/releases/download/v0.8.2/pget_linux_x86_64" && chmod +x /usr/local/bin/pget
|
| 27 |
+
|
| 28 |
+
# predict.py defines how predictions are run on your model
|
| 29 |
+
predict: "predict.py:Predictor"
|
Meissonic/cosmos_test_output/comparison_grid_video_0.png
ADDED
|
Git LFS Details
|
Meissonic/cosmos_test_output/comparison_grid_video_1.png
ADDED
|
Git LFS Details
|
Meissonic/cosmos_test_output/comparison_grid_video_2.png
ADDED
|
Git LFS Details
|
Meissonic/cosmos_test_output/comparison_grid_video_3.png
ADDED
|
Git LFS Details
|
Meissonic/cosmos_test_output/metrics_video_0.txt
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
Video Index: 0
|
| 2 |
+
Video Path: 000/000/000/0.mp4
|
| 3 |
+
Caption: In the video, a man is seen in a living room setting, standing in front of a window with blinds. He is wearing a black sweater and appears to be in the middle of a conversation. The room is dimly lit, with a lamp providing a soft glow in the background. The man's expression is serious, suggesting that the conversation is of importance. The overall style of the video is realistic and naturalistic, capturing a candid moment in the man's life.
|
| 4 |
+
|
| 5 |
+
=== Metrics ===
|
| 6 |
+
Average PSNR: 27.54 dB
|
| 7 |
+
Average MSE: 0.001764
|
| 8 |
+
Average SSIM: 0.9779
|
| 9 |
+
|
| 10 |
+
Per-frame PSNR: [26.747089385986328, 27.265975952148438, 27.32347297668457, 27.352922439575195, 27.334339141845703, 27.782726287841797, 27.661243438720703, 27.803525924682617, 27.705425262451172, 27.679603576660156, 27.297304153442383, 27.51146125793457, 27.4649658203125, 27.89719581604004, 27.753822326660156, 27.86109161376953, 27.80060577392578]
|
| 11 |
+
Per-frame MSE: [0.002114907605573535, 0.0018767336150631309, 0.0018520501907914877, 0.001839534263126552, 0.001847422681748867, 0.001666200696490705, 0.0017134671797975898, 0.0016582406824454665, 0.0016961240908131003, 0.0017062382539734244, 0.0018632437568157911, 0.001773593365214765, 0.001792682334780693, 0.0016228572931140661, 0.0016773275565356016, 0.0016364054754376411, 0.0016593559412285686]
|
| 12 |
+
Per-frame SSIM: [0.9738484025001526, 0.9765720963478088, 0.9768512845039368, 0.9769563674926758, 0.9766926765441895, 0.9789631962776184, 0.9783727526664734, 0.9790931344032288, 0.9786423444747925, 0.9784184694290161, 0.9765286445617676, 0.9777430295944214, 0.9775411486625671, 0.9799171090126038, 0.9794126749038696, 0.9798620343208313, 0.9795750379562378]
|
Meissonic/cosmos_test_output/metrics_video_1.txt
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
Video Index: 1
|
| 2 |
+
Video Path: 000/000/001/1.mp4
|
| 3 |
+
Caption: The video shows a man standing next to a purple van with a floral design on the side. The man is wearing a black t-shirt and jeans, and he is smiling and waving his hands in the air. The van has pink rims and a black roof rack. The van is parked in front of a building with a glass door. The man appears to be happy and excited about the van. The video is likely a short clip of a man showing off his van.
|
| 4 |
+
|
| 5 |
+
=== Metrics ===
|
| 6 |
+
Average PSNR: 25.14 dB
|
| 7 |
+
Average MSE: 0.003232
|
| 8 |
+
Average SSIM: 0.9700
|
| 9 |
+
|
| 10 |
+
Per-frame PSNR: [29.570905685424805, 25.845619201660156, 24.151002883911133, 24.53882598876953, 26.607555389404297, 23.609159469604492, 23.5848445892334, 24.532224655151367, 26.290340423583984, 23.606443405151367, 23.633737564086914, 24.562894821166992, 26.255611419677734, 24.259323120117188, 25.643463134765625, 25.491649627685547]
|
| 11 |
+
Per-frame MSE: [0.0011038482189178467, 0.002602784661576152, 0.003845029277727008, 0.0035165559966117144, 0.0021839593537151814, 0.004355963785201311, 0.004380417056381702, 0.003521904582157731, 0.0023494488559663296, 0.004358689300715923, 0.004331381060183048, 0.0034971192944794893, 0.0023683111649006605, 0.0037503137718886137, 0.0027268033009022474, 0.002823807764798403]
|
| 12 |
+
Per-frame SSIM: [0.9893906712532043, 0.974087119102478, 0.9622812867164612, 0.9658014178276062, 0.9791845083236694, 0.957465648651123, 0.957618772983551, 0.9664595127105713, 0.977811872959137, 0.9590921998023987, 0.960818350315094, 0.9692971110343933, 0.9799112677574158, 0.9681466817855835, 0.9765862822532654, 0.9759609699249268]
|
Meissonic/cosmos_test_output/metrics_video_2.txt
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
Video Index: 2
|
| 2 |
+
Video Path: 000/000/002/2.mp4
|
| 3 |
+
Caption: The video is a news segment featuring a man in a red baseball cap and a blue vest, standing in front of a statue of a soldier and two children. The man appears to be a veteran, as indicated by the cap and the context of the event. The event is an honorary ceremony for lost submarines and submarine veterans, taking place near the World Peace Bell in Newport. The news segment is titled "Connected to the Community" and is scheduled to air at 11:10 PM on ABC 9. The style of the video is informative and respectful, focusing on the man and the event, with a clear and concise presentation of the details.
|
| 4 |
+
|
| 5 |
+
=== Metrics ===
|
| 6 |
+
Average PSNR: 22.09 dB
|
| 7 |
+
Average MSE: 0.006399
|
| 8 |
+
Average SSIM: 0.9607
|
| 9 |
+
|
| 10 |
+
Per-frame PSNR: [24.496965408325195, 22.367679595947266, 22.21709442138672, 22.679195404052734, 23.883594512939453, 22.220516204833984, 22.20623207092285, 21.4675350189209, 22.316797256469727, 19.425098419189453, 21.102333068847656, 21.321147918701172, 23.025981903076172, 21.053565979003906, 21.95743179321289, 21.684494018554688]
|
| 11 |
+
Per-frame MSE: [0.0035506151616573334, 0.005797383841127157, 0.006001925095915794, 0.005396105814725161, 0.0040892185643315315, 0.00599720049649477, 0.006016954779624939, 0.007132581900805235, 0.005865707993507385, 0.011415375396609306, 0.007758304942399263, 0.007377093657851219, 0.00498197739943862, 0.007845907472074032, 0.006371723022311926, 0.0067850141786038876]
|
| 12 |
+
Per-frame SSIM: [0.9770643711090088, 0.9623730778694153, 0.9605475068092346, 0.9618802070617676, 0.9713600277900696, 0.9565339088439941, 0.9568989872932434, 0.9560506939888, 0.9673117399215698, 0.9364117383956909, 0.9567262530326843, 0.9589394927024841, 0.9706904888153076, 0.9546973705291748, 0.9623250365257263, 0.9610125422477722]
|
Meissonic/cosmos_test_output/metrics_video_3.txt
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
Video Index: 3
|
| 2 |
+
Video Path: 000/000/003/3.mp4
|
| 3 |
+
Caption: The video features a man in a pink shirt and a black bucket hat, wearing glasses and a necklace. He is holding a spoon and making a playful face, as if he is about to eat something. The background shows a lush garden with trees and a wooden structure. The man's expression and the spoon suggest that he is about to taste something, possibly food. The overall style of the video is casual and fun, with a focus on the man's reaction to the food.
|
| 4 |
+
|
| 5 |
+
=== Metrics ===
|
| 6 |
+
Average PSNR: 26.22 dB
|
| 7 |
+
Average MSE: 0.002459
|
| 8 |
+
Average SSIM: 0.9856
|
| 9 |
+
|
| 10 |
+
Per-frame PSNR: [27.509328842163086, 26.409242630004883, 25.4619140625, 25.407241821289062, 26.446935653686523, 23.73136329650879, 25.60137176513672, 26.993793487548828, 28.306987762451172, 25.729787826538086, 25.27326774597168, 26.266807556152344, 27.462078094482422, 25.950550079345703, 26.63888168334961, 26.327953338623047]
|
| 11 |
+
Per-frame MSE: [0.001774463220499456, 0.0022859980817884207, 0.002843207446858287, 0.0028792270459234715, 0.0022662426345050335, 0.004235099535435438, 0.002753359731286764, 0.0019981153309345245, 0.0014767315005883574, 0.002673137467354536, 0.00296943006105721, 0.0023622140288352966, 0.0017938758246600628, 0.0025406500790268183, 0.0021682626102119684, 0.002329188399016857]
|
| 12 |
+
Per-frame SSIM: [0.9894547462463379, 0.9864593744277954, 0.983065664768219, 0.9832437634468079, 0.9867878556251526, 0.9748696088790894, 0.9840085506439209, 0.9884393215179443, 0.991378664970398, 0.9843630194664001, 0.9830930829048157, 0.986225962638855, 0.989523708820343, 0.9850807189941406, 0.9871661067008972, 0.9861734509468079]
|
Meissonic/inference.py
ADDED
|
@@ -0,0 +1,65 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import os
|
| 2 |
+
import sys
|
| 3 |
+
sys.path.append("./")
|
| 4 |
+
|
| 5 |
+
import torch
|
| 6 |
+
from torchvision import transforms
|
| 7 |
+
from src.transformer import Transformer2DModel
|
| 8 |
+
from src.pipeline import Pipeline
|
| 9 |
+
from src.scheduler import Scheduler
|
| 10 |
+
from transformers import (
|
| 11 |
+
CLIPTextModelWithProjection,
|
| 12 |
+
CLIPTokenizer,
|
| 13 |
+
)
|
| 14 |
+
from diffusers import VQModel
|
| 15 |
+
|
| 16 |
+
device = 'cuda'
|
| 17 |
+
|
| 18 |
+
model_path = "MeissonFlow/Meissonic"
|
| 19 |
+
model = Transformer2DModel.from_pretrained(model_path,subfolder="transformer",)
|
| 20 |
+
vq_model = VQModel.from_pretrained(model_path, subfolder="vqvae", )
|
| 21 |
+
# text_encoder = CLIPTextModelWithProjection.from_pretrained(model_path,subfolder="text_encoder",)
|
| 22 |
+
text_encoder = CLIPTextModelWithProjection.from_pretrained( #using original text enc for stable sampling
|
| 23 |
+
"laion/CLIP-ViT-H-14-laion2B-s32B-b79K"
|
| 24 |
+
)
|
| 25 |
+
tokenizer = CLIPTokenizer.from_pretrained(model_path,subfolder="tokenizer",)
|
| 26 |
+
scheduler = Scheduler.from_pretrained(model_path,subfolder="scheduler",)
|
| 27 |
+
pipe=Pipeline(vq_model, tokenizer=tokenizer,text_encoder=text_encoder,transformer=model,scheduler=scheduler)
|
| 28 |
+
|
| 29 |
+
pipe = pipe.to(device)
|
| 30 |
+
|
| 31 |
+
steps = 64
|
| 32 |
+
CFG = 9
|
| 33 |
+
resolution = 1024
|
| 34 |
+
negative_prompt = "worst quality, low quality, low res, blurry, distortion, watermark, logo, signature, text, jpeg artifacts, signature, sketch, duplicate, ugly, identifying mark"
|
| 35 |
+
|
| 36 |
+
prompts = [
|
| 37 |
+
"Two actors are posing for a pictur with one wearing a black and white face paint.",
|
| 38 |
+
"A large body of water with a rock in the middle and mountains in the background.",
|
| 39 |
+
"A white and blue coffee mug with a picture of a man on it.",
|
| 40 |
+
"A statue of a man with a crown on his head.",
|
| 41 |
+
"A man in a yellow wet suit is holding a big black dog in the water.",
|
| 42 |
+
"A white table with a vase of flowers and a cup of coffee on top of it.",
|
| 43 |
+
"A woman stands on a dock in the fog.",
|
| 44 |
+
"A woman is standing next to a picture of another woman."
|
| 45 |
+
]
|
| 46 |
+
|
| 47 |
+
batched_generation = False
|
| 48 |
+
num_images = len(prompts) if batched_generation else 1
|
| 49 |
+
|
| 50 |
+
images = pipe(
|
| 51 |
+
prompt=prompts[:num_images],
|
| 52 |
+
negative_prompt=[negative_prompt] * num_images,
|
| 53 |
+
height=resolution,
|
| 54 |
+
width=resolution,
|
| 55 |
+
guidance_scale=CFG,
|
| 56 |
+
num_inference_steps=steps
|
| 57 |
+
).images
|
| 58 |
+
|
| 59 |
+
output_dir = "./output"
|
| 60 |
+
os.makedirs(output_dir, exist_ok=True)
|
| 61 |
+
for i, prompt in enumerate(prompts[:num_images]):
|
| 62 |
+
sanitized_prompt = prompt.replace(" ", "_")
|
| 63 |
+
file_path = os.path.join(output_dir, f"{sanitized_prompt}_{resolution}_{steps}_{CFG}.png")
|
| 64 |
+
images[i].save(file_path)
|
| 65 |
+
print(f"The {i+1}/{num_images} image is saved to {file_path}")
|
Meissonic/inference_fp16.py
ADDED
|
@@ -0,0 +1,64 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import os
|
| 2 |
+
import sys
|
| 3 |
+
sys.path.append("./")
|
| 4 |
+
|
| 5 |
+
import torch
|
| 6 |
+
from torchvision import transforms
|
| 7 |
+
from src.transformer import Transformer2DModel
|
| 8 |
+
from src.pipeline import Pipeline
|
| 9 |
+
from src.scheduler import Scheduler
|
| 10 |
+
from transformers import (
|
| 11 |
+
CLIPTextModelWithProjection,
|
| 12 |
+
CLIPTokenizer,
|
| 13 |
+
)
|
| 14 |
+
from diffusers import VQModel
|
| 15 |
+
|
| 16 |
+
device = 'cuda'
|
| 17 |
+
dtype = torch.bfloat16
|
| 18 |
+
model_path = "MeissonFlow/Meissonic"
|
| 19 |
+
model = Transformer2DModel.from_pretrained(model_path, subfolder="transformer", torch_dtype=dtype)
|
| 20 |
+
vq_model = VQModel.from_pretrained(model_path, subfolder="vqvae", torch_dtype=dtype)
|
| 21 |
+
# text_encoder = CLIPTextModelWithProjection.from_pretrained(model_path,subfolder="text_encoder", torch_dtype=dtype)
|
| 22 |
+
text_encoder = CLIPTextModelWithProjection.from_pretrained( #using original text enc for stable sampling
|
| 23 |
+
"laion/CLIP-ViT-H-14-laion2B-s32B-b79K",torch_dtype=dtype)
|
| 24 |
+
tokenizer = CLIPTokenizer.from_pretrained(model_path, subfolder="tokenizer", torch_dtype=dtype)
|
| 25 |
+
scheduler = Scheduler.from_pretrained(model_path, subfolder="scheduler")
|
| 26 |
+
pipe=Pipeline(vq_model, tokenizer=tokenizer,text_encoder=text_encoder,transformer=model,scheduler=scheduler)
|
| 27 |
+
|
| 28 |
+
pipe = pipe.to(device)
|
| 29 |
+
|
| 30 |
+
steps = 64
|
| 31 |
+
CFG = 9
|
| 32 |
+
resolution = 1024
|
| 33 |
+
negative_prompt = "worst quality, low quality, low res, blurry, distortion, watermark, logo, signature, text, jpeg artifacts, signature, sketch, duplicate, ugly, identifying mark"
|
| 34 |
+
|
| 35 |
+
prompts = [
|
| 36 |
+
"Two actors are posing for a pictur with one wearing a black and white face paint.",
|
| 37 |
+
"A large body of water with a rock in the middle and mountains in the background.",
|
| 38 |
+
"A white and blue coffee mug with a picture of a man on it.",
|
| 39 |
+
"A statue of a man with a crown on his head.",
|
| 40 |
+
"A man in a yellow wet suit is holding a big black dog in the water.",
|
| 41 |
+
"A white table with a vase of flowers and a cup of coffee on top of it.",
|
| 42 |
+
"A woman stands on a dock in the fog.",
|
| 43 |
+
"A woman is standing next to a picture of another woman."
|
| 44 |
+
]
|
| 45 |
+
|
| 46 |
+
batched_generation = False
|
| 47 |
+
num_images = len(prompts) if batched_generation else 1
|
| 48 |
+
|
| 49 |
+
images = pipe(
|
| 50 |
+
prompt=prompts[:num_images],
|
| 51 |
+
negative_prompt=[negative_prompt] * num_images,
|
| 52 |
+
height=resolution,
|
| 53 |
+
width=resolution,
|
| 54 |
+
guidance_scale=CFG,
|
| 55 |
+
num_inference_steps=steps
|
| 56 |
+
).images
|
| 57 |
+
|
| 58 |
+
output_dir = "./output"
|
| 59 |
+
os.makedirs(output_dir, exist_ok=True)
|
| 60 |
+
for i, prompt in enumerate(prompts[:num_images]):
|
| 61 |
+
sanitized_prompt = prompt.replace(" ", "_")
|
| 62 |
+
file_path = os.path.join(output_dir, f"{sanitized_prompt}_{resolution}_{steps}_{CFG}.png")
|
| 63 |
+
images[i].save(file_path)
|
| 64 |
+
print(f"The {i+1}/{num_images} image is saved to {file_path}")
|
Meissonic/inference_fp16_Monetico.py
ADDED
|
@@ -0,0 +1,64 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import os
|
| 2 |
+
import sys
|
| 3 |
+
sys.path.append("./")
|
| 4 |
+
|
| 5 |
+
import torch
|
| 6 |
+
from torchvision import transforms
|
| 7 |
+
from src.transformer import Transformer2DModel
|
| 8 |
+
from src.pipeline import Pipeline
|
| 9 |
+
from src.scheduler import Scheduler
|
| 10 |
+
from transformers import (
|
| 11 |
+
CLIPTextModelWithProjection,
|
| 12 |
+
CLIPTokenizer,
|
| 13 |
+
)
|
| 14 |
+
from diffusers import VQModel
|
| 15 |
+
|
| 16 |
+
device = 'cuda'
|
| 17 |
+
dtype = torch.bfloat16
|
| 18 |
+
model_path = "Collov-Labs/Monetico"
|
| 19 |
+
model = Transformer2DModel.from_pretrained(model_path, subfolder="transformer", torch_dtype=dtype)
|
| 20 |
+
vq_model = VQModel.from_pretrained(model_path, subfolder="vqvae", torch_dtype=dtype)
|
| 21 |
+
text_encoder = CLIPTextModelWithProjection.from_pretrained(model_path, subfolder="text_encoder", torch_dtype=dtype) # better for Monetico
|
| 22 |
+
# text_encoder = CLIPTextModelWithProjection.from_pretrained( #more stable sampling for some cases
|
| 23 |
+
# "laion/CLIP-ViT-H-14-laion2B-s32B-b79K", torch_dtype=dtype
|
| 24 |
+
# )
|
| 25 |
+
tokenizer = CLIPTokenizer.from_pretrained(model_path, subfolder="tokenizer", torch_dtype=dtype)
|
| 26 |
+
scheduler = Scheduler.from_pretrained(model_path, subfolder="scheduler", torch_dtype=dtype)
|
| 27 |
+
pipe = Pipeline(vq_model, tokenizer=tokenizer, text_encoder=text_encoder, transformer=model, scheduler=scheduler)
|
| 28 |
+
pipe.to(device)
|
| 29 |
+
|
| 30 |
+
steps = 48
|
| 31 |
+
CFG = 9
|
| 32 |
+
resolution = 512
|
| 33 |
+
negative_prompt = "worst quality, low quality, low res, blurry, distortion, watermark, logo, signature, text, jpeg artifacts, signature, sketch, duplicate, ugly, identifying mark"
|
| 34 |
+
|
| 35 |
+
prompts = [
|
| 36 |
+
"Two actors are posing for a pictur with one wearing a black and white face paint.",
|
| 37 |
+
"A large body of water with a rock in the middle and mountains in the background.",
|
| 38 |
+
"A white and blue coffee mug with a picture of a man on it.",
|
| 39 |
+
"A statue of a man with a crown on his head.",
|
| 40 |
+
"A man in a yellow wet suit is holding a big black dog in the water.",
|
| 41 |
+
"A white table with a vase of flowers and a cup of coffee on top of it.",
|
| 42 |
+
"A woman stands on a dock in the fog.",
|
| 43 |
+
"A woman is standing next to a picture of another woman."
|
| 44 |
+
]
|
| 45 |
+
|
| 46 |
+
batched_generation = False
|
| 47 |
+
num_images = len(prompts) if batched_generation else 1
|
| 48 |
+
|
| 49 |
+
images = pipe(
|
| 50 |
+
prompt=prompts[:num_images],
|
| 51 |
+
negative_prompt=[negative_prompt] * num_images,
|
| 52 |
+
height=resolution,
|
| 53 |
+
width=resolution,
|
| 54 |
+
guidance_scale=CFG,
|
| 55 |
+
num_inference_steps=steps
|
| 56 |
+
).images
|
| 57 |
+
|
| 58 |
+
output_dir = "./output"
|
| 59 |
+
os.makedirs(output_dir, exist_ok=True)
|
| 60 |
+
for i, prompt in enumerate(prompts[:num_images]):
|
| 61 |
+
sanitized_prompt = prompt.replace(" ", "_")
|
| 62 |
+
file_path = os.path.join(output_dir, f"{sanitized_prompt}_{resolution}_{steps}_{CFG}.png")
|
| 63 |
+
images[i].save(file_path)
|
| 64 |
+
print(f"The {i+1}/{num_images} image is saved to {file_path}")
|
Meissonic/inference_fp8.py
ADDED
|
@@ -0,0 +1,103 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import os
|
| 2 |
+
import sys
|
| 3 |
+
sys.path.append("./")
|
| 4 |
+
|
| 5 |
+
import torch
|
| 6 |
+
from src.transformer import Transformer2DModel
|
| 7 |
+
from src.pipeline import Pipeline
|
| 8 |
+
from src.scheduler import Scheduler
|
| 9 |
+
from transformers import (
|
| 10 |
+
CLIPTextModelWithProjection,
|
| 11 |
+
CLIPTokenizer,
|
| 12 |
+
)
|
| 13 |
+
from diffusers import VQModel
|
| 14 |
+
import time
|
| 15 |
+
import argparse
|
| 16 |
+
|
| 17 |
+
from torchao.quantization.quant_api import (
|
| 18 |
+
quantize_,
|
| 19 |
+
float8_weight_only, # A8W8 FP8
|
| 20 |
+
)
|
| 21 |
+
|
| 22 |
+
device = 'cuda'
|
| 23 |
+
|
| 24 |
+
def get_quantization_method(method):
|
| 25 |
+
quantization_methods = {
|
| 26 |
+
'fp8': lambda: float8_weight_only(),
|
| 27 |
+
}
|
| 28 |
+
return quantization_methods.get(method, None)
|
| 29 |
+
|
| 30 |
+
def load_models(quantization_method=None):
|
| 31 |
+
model_path = "MeissonFlow/Meissonic"
|
| 32 |
+
dtype = torch.float16
|
| 33 |
+
model = Transformer2DModel.from_pretrained(model_path, subfolder="transformer", torch_dtype=dtype)
|
| 34 |
+
vq_model = VQModel.from_pretrained(model_path, subfolder="vqvae", torch_dtype=dtype)
|
| 35 |
+
text_encoder = CLIPTextModelWithProjection.from_pretrained(
|
| 36 |
+
"laion/CLIP-ViT-H-14-laion2B-s32B-b79K",
|
| 37 |
+
torch_dtype=dtype
|
| 38 |
+
)
|
| 39 |
+
tokenizer = CLIPTokenizer.from_pretrained(model_path, subfolder="tokenizer")
|
| 40 |
+
scheduler = Scheduler.from_pretrained(model_path, subfolder="scheduler")
|
| 41 |
+
|
| 42 |
+
if quantization_method:
|
| 43 |
+
quant_method = get_quantization_method(quantization_method)
|
| 44 |
+
if quant_method:
|
| 45 |
+
quantize_(model, quant_method())
|
| 46 |
+
else:
|
| 47 |
+
print(f"Unsupported quantization method: {quantization_method}")
|
| 48 |
+
|
| 49 |
+
|
| 50 |
+
pipe = Pipeline(vq_model, tokenizer=tokenizer, text_encoder=text_encoder, transformer=model, scheduler=scheduler)
|
| 51 |
+
return pipe.to(device)
|
| 52 |
+
|
| 53 |
+
def run_inference(pipe, prompt, negative_prompt, resolution, cfg, steps):
|
| 54 |
+
return pipe(prompt=prompt, negative_prompt=negative_prompt, height=resolution, width=resolution, guidance_scale=cfg, num_inference_steps=steps).images[0]
|
| 55 |
+
|
| 56 |
+
def main(quantization_method):
|
| 57 |
+
steps = 64
|
| 58 |
+
CFG = 9
|
| 59 |
+
resolution = 1024
|
| 60 |
+
negative_prompts = "worst quality, low quality, low res, blurry, distortion, watermark, logo, signature, text, jpeg artifacts, signature, sketch, duplicate, ugly, identifying mark"
|
| 61 |
+
|
| 62 |
+
prompts = [
|
| 63 |
+
"Two actors are posing for a pictur with one wearing a black and white face paint.",
|
| 64 |
+
"A large body of water with a rock in the middle and mountains in the background.",
|
| 65 |
+
"A white and blue coffee mug with a picture of a man on it.",
|
| 66 |
+
"The sun is setting over a city skyline with a river in the foreground.",
|
| 67 |
+
"A black and white cat with blue eyes.",
|
| 68 |
+
"Three boats in the ocean with a rainbow in the sky.",
|
| 69 |
+
"A robot playing the piano.",
|
| 70 |
+
"A cat wearing a hat.",
|
| 71 |
+
"A dog in a jungle.",
|
| 72 |
+
]
|
| 73 |
+
|
| 74 |
+
output_dir = "./output"
|
| 75 |
+
os.makedirs(output_dir, exist_ok=True)
|
| 76 |
+
|
| 77 |
+
pipe = load_models(quantization_method)
|
| 78 |
+
start_time = time.time()
|
| 79 |
+
total_memory_used = 0
|
| 80 |
+
for i, prompt in enumerate(prompts):
|
| 81 |
+
torch.cuda.reset_peak_memory_stats()
|
| 82 |
+
image_start_time = time.time()
|
| 83 |
+
image = run_inference(pipe, prompt, negative_prompts, resolution, CFG, steps)
|
| 84 |
+
image_end_time = time.time()
|
| 85 |
+
image.save(os.path.join(output_dir, f"{prompt[:10]}_{resolution}_{steps}_{CFG}_{quantization_method}.png"))
|
| 86 |
+
|
| 87 |
+
memory_used = torch.cuda.max_memory_reserved() / (1024 ** 3) # Convert to GB
|
| 88 |
+
total_memory_used += memory_used
|
| 89 |
+
|
| 90 |
+
print(f"Image {i+1} time: {image_end_time - image_start_time:.2f} seconds")
|
| 91 |
+
print(f"Image {i+1} max memory used: {memory_used:.2f} GB")
|
| 92 |
+
|
| 93 |
+
total_time = time.time() - start_time
|
| 94 |
+
avg_memory_used = total_memory_used / len(prompts)
|
| 95 |
+
print(f"Total inference time ({quantization_method}): {total_time:.2f} seconds")
|
| 96 |
+
print(f"Average memory used per image: {avg_memory_used:.2f} GB")
|
| 97 |
+
|
| 98 |
+
if __name__ == "__main__":
|
| 99 |
+
parser = argparse.ArgumentParser(description="Run inference with specified quantization method.")
|
| 100 |
+
parser.add_argument("--quantization", type=str, choices=['fp8'],
|
| 101 |
+
help="Quantization method to use")
|
| 102 |
+
args = parser.parse_args()
|
| 103 |
+
main(args.quantization)
|
Meissonic/inpaint.py
ADDED
|
@@ -0,0 +1,55 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import os
|
| 2 |
+
import sys
|
| 3 |
+
sys.path.append("./")
|
| 4 |
+
|
| 5 |
+
import argparse
|
| 6 |
+
import json
|
| 7 |
+
from PIL import Image
|
| 8 |
+
from src.transformer import Transformer2DModel
|
| 9 |
+
from src.pipeline_inpaint import InpaintPipeline
|
| 10 |
+
from src.scheduler import Scheduler
|
| 11 |
+
from transformers import (
|
| 12 |
+
CLIPTextModelWithProjection,
|
| 13 |
+
CLIPTokenizer,
|
| 14 |
+
)
|
| 15 |
+
from diffusers import VQModel
|
| 16 |
+
|
| 17 |
+
def get_parse_args():
|
| 18 |
+
parser = argparse.ArgumentParser(description="Meissonic Inpaint and Outpaint")
|
| 19 |
+
parser.add_argument("--mode", type=str,default="inpaint", choices=["inpaint", "outpaint"], help="Inpaint or Outpaint")
|
| 20 |
+
return parser.parse_args()
|
| 21 |
+
|
| 22 |
+
if __name__ == "__main__":
|
| 23 |
+
args = get_parse_args()
|
| 24 |
+
device = 'cuda'
|
| 25 |
+
|
| 26 |
+
model_path = "MeissonFlow/Meissonic"
|
| 27 |
+
model = Transformer2DModel.from_pretrained(model_path, subfolder="transformer", )
|
| 28 |
+
vq_model = VQModel.from_pretrained(model_path, subfolder="vqvae", )
|
| 29 |
+
# text_encoder = CLIPTextModelWithProjection.from_pretrained(model_path,subfolder="text_encoder",)
|
| 30 |
+
text_encoder = CLIPTextModelWithProjection.from_pretrained( # using original text enc for stable sampling
|
| 31 |
+
"laion/CLIP-ViT-H-14-laion2B-s32B-b79K"
|
| 32 |
+
)
|
| 33 |
+
tokenizer = CLIPTokenizer.from_pretrained(model_path, subfolder="tokenizer", )
|
| 34 |
+
scheduler = Scheduler.from_pretrained(model_path, subfolder="scheduler", )
|
| 35 |
+
|
| 36 |
+
pipe=InpaintPipeline(vq_model, tokenizer=tokenizer,text_encoder=text_encoder,transformer=model,scheduler=scheduler)
|
| 37 |
+
pipe = pipe.to(device)
|
| 38 |
+
|
| 39 |
+
with open(f"./assets/{args.mode}/cases.json", 'r', encoding='utf-8') as file:
|
| 40 |
+
cases = json.load(file)
|
| 41 |
+
item = cases[0]
|
| 42 |
+
|
| 43 |
+
steps = 64
|
| 44 |
+
CFG = 9
|
| 45 |
+
resolution = 1024
|
| 46 |
+
negative_prompts = item["negative_prompts"] if "negative_prompts" in item.keys() else "worst quality, low quality, low res, blurry, distortion, watermark, logo, signature, text, jpeg artifacts, signature, sketch, duplicate, ugly, identifying mark"
|
| 47 |
+
|
| 48 |
+
image = Image.open(item["input"]).resize((resolution, resolution)).convert("RGB")
|
| 49 |
+
mask = Image.open(item["mask"]).resize((resolution, resolution)).convert("RGB")
|
| 50 |
+
|
| 51 |
+
image = pipe(prompt=item["prompt"],negative_prompt=negative_prompts,image =image, mask_image =mask, guidance_scale=CFG, num_inference_steps=steps).images[0]
|
| 52 |
+
|
| 53 |
+
output_dir = "./output"
|
| 54 |
+
os.makedirs(output_dir, exist_ok=True)
|
| 55 |
+
image.save(os.path.join(output_dir, f"{item['prompt'][:10]}_{resolution}_{steps}_{CFG}.png"))
|
Meissonic/predict.py
ADDED
|
@@ -0,0 +1,105 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# Prediction interface for Cog ⚙️
|
| 2 |
+
# https://cog.run/python
|
| 3 |
+
|
| 4 |
+
import os
|
| 5 |
+
import subprocess
|
| 6 |
+
import time
|
| 7 |
+
import torch
|
| 8 |
+
from transformers import (
|
| 9 |
+
CLIPTextModelWithProjection,
|
| 10 |
+
CLIPTokenizer,
|
| 11 |
+
)
|
| 12 |
+
from diffusers import VQModel
|
| 13 |
+
from cog import BasePredictor, Input, Path
|
| 14 |
+
|
| 15 |
+
from src.transformer import Transformer2DModel
|
| 16 |
+
from src.pipeline import Pipeline
|
| 17 |
+
from src.scheduler import Scheduler
|
| 18 |
+
|
| 19 |
+
|
| 20 |
+
MODEL_CACHE = "model_cache"
|
| 21 |
+
MODEL_URL = (
|
| 22 |
+
f"https://weights.replicate.delivery/default/viiika/Meissonic/{MODEL_CACHE}.tar"
|
| 23 |
+
)
|
| 24 |
+
|
| 25 |
+
os.environ.update(
|
| 26 |
+
{
|
| 27 |
+
"HF_DATASETS_OFFLINE": "1",
|
| 28 |
+
"TRANSFORMERS_OFFLINE": "1",
|
| 29 |
+
"HF_HOME": MODEL_CACHE,
|
| 30 |
+
"TORCH_HOME": MODEL_CACHE,
|
| 31 |
+
"HF_DATASETS_CACHE": MODEL_CACHE,
|
| 32 |
+
"TRANSFORMERS_CACHE": MODEL_CACHE,
|
| 33 |
+
"HUGGINGFACE_HUB_CACHE": MODEL_CACHE,
|
| 34 |
+
}
|
| 35 |
+
)
|
| 36 |
+
|
| 37 |
+
|
| 38 |
+
def download_weights(url, dest):
|
| 39 |
+
start = time.time()
|
| 40 |
+
print("downloading url: ", url)
|
| 41 |
+
print("downloading to: ", dest)
|
| 42 |
+
subprocess.check_call(["pget", "-x", url, dest], close_fds=False)
|
| 43 |
+
print("downloading took: ", time.time() - start)
|
| 44 |
+
|
| 45 |
+
|
| 46 |
+
class Predictor(BasePredictor):
|
| 47 |
+
def setup(self) -> None:
|
| 48 |
+
"""Load the model into memory to make running multiple predictions efficient"""
|
| 49 |
+
|
| 50 |
+
if not os.path.exists(MODEL_CACHE):
|
| 51 |
+
download_weights(MODEL_URL, MODEL_CACHE)
|
| 52 |
+
|
| 53 |
+
model_path = f"{MODEL_CACHE}/MeissonFlow/Meissonic"
|
| 54 |
+
model = Transformer2DModel.from_pretrained(model_path, subfolder="transformer")
|
| 55 |
+
vq_model = VQModel.from_pretrained(model_path, subfolder="vqvae")
|
| 56 |
+
text_encoder = CLIPTextModelWithProjection.from_pretrained( # more stable sampling for some cases
|
| 57 |
+
f"{MODEL_CACHE}/laion/CLIP-ViT-H-14-laion2B-s32B-b79K"
|
| 58 |
+
)
|
| 59 |
+
tokenizer = CLIPTokenizer.from_pretrained(model_path, subfolder="tokenizer")
|
| 60 |
+
scheduler = Scheduler.from_pretrained(model_path, subfolder="scheduler")
|
| 61 |
+
self.pipe = Pipeline(
|
| 62 |
+
vq_model,
|
| 63 |
+
tokenizer=tokenizer,
|
| 64 |
+
text_encoder=text_encoder,
|
| 65 |
+
transformer=model,
|
| 66 |
+
scheduler=scheduler,
|
| 67 |
+
).to("cuda")
|
| 68 |
+
|
| 69 |
+
def predict(
|
| 70 |
+
self,
|
| 71 |
+
prompt: str = Input(
|
| 72 |
+
description="Input prompt",
|
| 73 |
+
default="a photo of an astronaut riding a horse on mars",
|
| 74 |
+
),
|
| 75 |
+
negative_prompt: str = Input(
|
| 76 |
+
description="Specify things to not see in the output",
|
| 77 |
+
default="worst quality, low quality, low res, blurry, distortion, watermark, logo, signature, text, jpeg artifacts, signature, sketch, duplicate, ugly, identifying mark",
|
| 78 |
+
),
|
| 79 |
+
num_inference_steps: int = Input(
|
| 80 |
+
description="Number of denoising steps", ge=1, le=100, default=64
|
| 81 |
+
),
|
| 82 |
+
guidance_scale: float = Input(
|
| 83 |
+
description="Scale for classifier-free guidance", ge=0, le=20, default=9
|
| 84 |
+
),
|
| 85 |
+
seed: int = Input(
|
| 86 |
+
description="Random seed. Leave blank to randomize the seed", default=None
|
| 87 |
+
),
|
| 88 |
+
) -> Path:
|
| 89 |
+
"""Run a single prediction on the model"""
|
| 90 |
+
if seed is None:
|
| 91 |
+
seed = int.from_bytes(os.urandom(2), "big")
|
| 92 |
+
print(f"Using seed: {seed}")
|
| 93 |
+
torch.manual_seed(seed)
|
| 94 |
+
|
| 95 |
+
image = self.pipe(
|
| 96 |
+
prompt=prompt,
|
| 97 |
+
negative_prompt=negative_prompt,
|
| 98 |
+
height=1024,
|
| 99 |
+
width=1024,
|
| 100 |
+
guidance_scale=guidance_scale,
|
| 101 |
+
num_inference_steps=num_inference_steps,
|
| 102 |
+
).images[0]
|
| 103 |
+
output_path = f"/tmp/out.png"
|
| 104 |
+
image.save(output_path)
|
| 105 |
+
return Path(output_path)
|
Meissonic/pretrained_ckpts/Cosmos-0.1-Tokenizer-DV4x8x8/.gitattributes
ADDED
|
@@ -0,0 +1,38 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
*.7z filter=lfs diff=lfs merge=lfs -text
|
| 2 |
+
*.arrow filter=lfs diff=lfs merge=lfs -text
|
| 3 |
+
*.bin filter=lfs diff=lfs merge=lfs -text
|
| 4 |
+
*.bz2 filter=lfs diff=lfs merge=lfs -text
|
| 5 |
+
*.ckpt filter=lfs diff=lfs merge=lfs -text
|
| 6 |
+
*.ftz filter=lfs diff=lfs merge=lfs -text
|
| 7 |
+
*.gz filter=lfs diff=lfs merge=lfs -text
|
| 8 |
+
*.h5 filter=lfs diff=lfs merge=lfs -text
|
| 9 |
+
*.joblib filter=lfs diff=lfs merge=lfs -text
|
| 10 |
+
*.lfs.* filter=lfs diff=lfs merge=lfs -text
|
| 11 |
+
*.mlmodel filter=lfs diff=lfs merge=lfs -text
|
| 12 |
+
*.model filter=lfs diff=lfs merge=lfs -text
|
| 13 |
+
*.msgpack filter=lfs diff=lfs merge=lfs -text
|
| 14 |
+
*.npy filter=lfs diff=lfs merge=lfs -text
|
| 15 |
+
*.npz filter=lfs diff=lfs merge=lfs -text
|
| 16 |
+
*.onnx filter=lfs diff=lfs merge=lfs -text
|
| 17 |
+
*.ot filter=lfs diff=lfs merge=lfs -text
|
| 18 |
+
*.parquet filter=lfs diff=lfs merge=lfs -text
|
| 19 |
+
*.pb filter=lfs diff=lfs merge=lfs -text
|
| 20 |
+
*.pickle filter=lfs diff=lfs merge=lfs -text
|
| 21 |
+
*.pkl filter=lfs diff=lfs merge=lfs -text
|
| 22 |
+
*.pt filter=lfs diff=lfs merge=lfs -text
|
| 23 |
+
*.pth filter=lfs diff=lfs merge=lfs -text
|
| 24 |
+
*.rar filter=lfs diff=lfs merge=lfs -text
|
| 25 |
+
*.safetensors filter=lfs diff=lfs merge=lfs -text
|
| 26 |
+
saved_model/**/* filter=lfs diff=lfs merge=lfs -text
|
| 27 |
+
*.tar.* filter=lfs diff=lfs merge=lfs -text
|
| 28 |
+
*.tar filter=lfs diff=lfs merge=lfs -text
|
| 29 |
+
*.tflite filter=lfs diff=lfs merge=lfs -text
|
| 30 |
+
*.tgz filter=lfs diff=lfs merge=lfs -text
|
| 31 |
+
*.wasm filter=lfs diff=lfs merge=lfs -text
|
| 32 |
+
*.xz filter=lfs diff=lfs merge=lfs -text
|
| 33 |
+
*.zip filter=lfs diff=lfs merge=lfs -text
|
| 34 |
+
*.zst filter=lfs diff=lfs merge=lfs -text
|
| 35 |
+
*tfevents* filter=lfs diff=lfs merge=lfs -text
|
| 36 |
+
autoencoder.jit filter=lfs diff=lfs merge=lfs -text
|
| 37 |
+
decoder.jit filter=lfs diff=lfs merge=lfs -text
|
| 38 |
+
encoder.jit filter=lfs diff=lfs merge=lfs -text
|
Meissonic/pretrained_ckpts/Cosmos-0.1-Tokenizer-DV4x8x8/README.md
ADDED
|
@@ -0,0 +1,326 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
---
|
| 2 |
+
license: other
|
| 3 |
+
license_name: nvidia-open-model-license
|
| 4 |
+
license_link: >-
|
| 5 |
+
https://developer.download.nvidia.com/licenses/nvidia-open-model-license-agreement-june-2024.pdf
|
| 6 |
+
library_name: nemo
|
| 7 |
+
---
|
| 8 |
+
# **Cosmos Tokenizer**: A suite of image and video tokenizers
|
| 9 |
+
|
| 10 |
+
[**Website**](https://research.nvidia.com/labs/dir/cosmos-tokenizer) | [**Code**](https://github.com/NVIDIA/Cosmos-Tokenizer) | [**Video**](https://youtu.be/Soy_myOfWIU)
|
| 11 |
+
|
| 12 |
+
|
| 13 |
+
# Model Overview
|
| 14 |
+
|
| 15 |
+
## Description:
|
| 16 |
+
**Cosmos Tokenizer** is a suite of visual tokenizers for images and videos that delivers various compression rates while maintaining high reconstruction quality. Cosmos Tokenizer can serve as an effective and efficient building block in both diffusion-based and autoregressive models for image and video generation.
|
| 17 |
+
|
| 18 |
+
|
| 19 |
+
Our tokenizers come in two types: **Continuous** (C) and **Discrete** (D), each with **Image** (I) and **Video** (V) variants:
|
| 20 |
+
* Continuous tokenizers encode visual data into continuous latent embeddings, as shown in latent diffusion models like [Stable Diffusion](https://github.com/CompVis/stable-diffusion). These embeddings are suitable for models that generate data by sampling from continuous distributions.
|
| 21 |
+
* Discrete tokenizers encode visual data into discrete latent codes, mapping them into quantized indices, as seen in autoregressive transformers such as [VideoPoet](https://sites.research.google/videopoet/). This discretization is required for models that generate data by optimizing the cross-entropy loss, such as the GPT models.
|
| 22 |
+
|
| 23 |
+
|
| 24 |
+
| | Continuous ( C ) | Discrete ( D ) |
|
| 25 |
+
| ------------------|---------------------|---------------------|
|
| 26 |
+
| **Images ( I )** | Cosmos-Tokenizer-CI | Cosmos-Tokenizer-DI |
|
| 27 |
+
| **Videos ( V )** | Cosmos-Tokenizer-CV | Cosmos-Tokenizer-DV |
|
| 28 |
+
|
| 29 |
+
|
| 30 |
+
Given an image or a video, Cosmos Tokenizer outputs either continuous latents or discrete tokens. Cosmos Tokenizer achieves spatial compression rates of 8x8 or 16x16 and temporal compression factors of 4x or 8x, resulting in a total compression factor of up to 2048x (=8x16x16). Cosmos Tokenizer delivers 8x more total compression than state-of-the-art (SOTA) methods while simultaneously maintaining higher image quality and running up to 12x faster than the best available SOTA tokenizers.
|
| 31 |
+
|
| 32 |
+
**Model Developer**: NVIDIA
|
| 33 |
+
|
| 34 |
+
## Model Versions
|
| 35 |
+
|
| 36 |
+
The initial release (v1.0) of Cosmos Tokenizer includes the following tokenizers:
|
| 37 |
+
* **Continuous Tokenizers**
|
| 38 |
+
* Continuous Image (CI) Tokenizer
|
| 39 |
+
* [Cosmos-Tokenizer-CI8x8](https://huggingface.co/nvidia/Cosmos-Tokenizer-CI8x8) (8x8 spatial compression)
|
| 40 |
+
* [Cosmos-Tokenizer-CI16x16](https://huggingface.co/nvidia/Cosmos-Tokenizer-CI16x16) (16x16 spatial compression)
|
| 41 |
+
* Continuous Video (CV) Tokenizer
|
| 42 |
+
* [Cosmos-Tokenizer-CV4x8x8](https://huggingface.co/nvidia/Cosmos-Tokenizer-CV4x8x8) (4x temporal compression, 8x8 spatial compression)
|
| 43 |
+
* [Cosmos-Tokenizer-CV8x8x8](https://huggingface.co/nvidia/Cosmos-Tokenizer-CV8x8x8) (8x temporal compression, 8x8 spatial compression)
|
| 44 |
+
* [Cosmos-Tokenizer-CV8x16x16](https://huggingface.co/nvidia/Cosmos-Tokenizer-CV8x16x16) (8x temporal compression, 16x16 spatial compression)
|
| 45 |
+
* **Discrete Tokenizers**
|
| 46 |
+
* Discrete Image (DI) Tokenizer
|
| 47 |
+
* [Cosmos-Tokenizer-DI8x8](https://huggingface.co/nvidia/Cosmos-Tokenizer-DI8x8) (8x8 spatial compression)
|
| 48 |
+
* [Cosmos-Tokenizer-DI16x16](https://huggingface.co/nvidia/Cosmos-Tokenizer-DI16x16) (16x16 spatial compression)
|
| 49 |
+
* Discrete Video (DV) Tokenizer
|
| 50 |
+
* [Cosmos-Tokenizer-DV4x8x8](https://huggingface.co/nvidia/Cosmos-Tokenizer-DV4x8x8) (4x temporal compression, 8x8 spatial compression)
|
| 51 |
+
* [Cosmos-Tokenizer-DV8x8x8](https://huggingface.co/nvidia/Cosmos-Tokenizer-DV8x8x8) (8x temporal compression, 8x8 spatial compression)
|
| 52 |
+
* [Cosmos-Tokenizer-DV8x16x16](https://huggingface.co/nvidia/Cosmos-Tokenizer-DV8x16x16) (8x temporal compression, 16x16 spatial compression)
|
| 53 |
+
|
| 54 |
+
|
| 55 |
+
### License/Terms of Use:
|
| 56 |
+
[NVIDIA Open Model License](https://developer.download.nvidia.com/licenses/nvidia-open-model-license-agreement-june-2024.pdf)
|
| 57 |
+
|
| 58 |
+
Under the NVIDIA Open Model License, NVIDIA confirms:
|
| 59 |
+
|
| 60 |
+
* Models are commercially usable.
|
| 61 |
+
* You are free to create and distribute Derivative Models.
|
| 62 |
+
* NVIDIA does not claim ownership to any outputs generated using the Models or Derivative Models.
|
| 63 |
+
|
| 64 |
+
## Model Architecture:
|
| 65 |
+
|
| 66 |
+
We designed Cosmos Tokenizer using a lightweight and computationally efficient architecture, featuring a temporally causal design. Specifically, we employ causal temporal convolution and causal temporal attention layers to preserve the natural temporal order of video frames, ensuring seamless tokenization of images and videos using a single unified network architecture. The encoder and decoder form a symmetrical pair, which are mirrors of each other. The encoder starts with a 2-level [Haar wavelet](https://link.springer.com/book/10.1007/978-3-319-04295-4) transform layer, which down-samples inputs by a factor of 4 in both spatial and temporal dimensions. Likewise, the decoder ends with an inverse wavelet transform. We employ the vanilla autoencoder (AE) formulation to model the latent space for continuous tokenizers. For discrete tokenizers, we adopt the [Finite-Scalar-Quantization](https://openreview.net/forum?id=8ishA3LxN8) (FSQ) as the latent space quantizer.
|
| 67 |
+
|
| 68 |
+

|
| 69 |
+
|
| 70 |
+
|
| 71 |
+
|
| 72 |
+
## Input/Output Specifications
|
| 73 |
+
|
| 74 |
+
### Encoder
|
| 75 |
+
* **Input**
|
| 76 |
+
* **Types:** Images or Videos
|
| 77 |
+
* **Format:** RGB (Red, Green, Blue)
|
| 78 |
+
* **Resolution:**
|
| 79 |
+
* Minimum: 256px (shorter side)
|
| 80 |
+
* Maximum: Up to 4K
|
| 81 |
+
* **Video Length:** Up to 8 seconds for 1080p videos (bounded by A100 80G GPU memory; higher resolutions will have shorter supported durations)
|
| 82 |
+
|
| 83 |
+
* **Output**
|
| 84 |
+
* **Types:** Tokens
|
| 85 |
+
* Continuous Image/Video Tokenizers: Continuous value feature vectors
|
| 86 |
+
* Discrete Image/Video Tokenizers: Integer indices
|
| 87 |
+
|
| 88 |
+
### Decoder
|
| 89 |
+
* **Input**
|
| 90 |
+
* **Types:** Tokens from encoder
|
| 91 |
+
|
| 92 |
+
* **Output**
|
| 93 |
+
* **Types:** Images or Videos (matching input type)
|
| 94 |
+
* **Format:** RGB (Red, Green, Blue)
|
| 95 |
+
* **Resolution:** Same as input resolution
|
| 96 |
+
* **Video Length:** Same as input video length
|
| 97 |
+
|
| 98 |
+
## Software Integration (Required For NVIDIA Models Only):
|
| 99 |
+
**Runtime Engine(s):**
|
| 100 |
+
* [Cosmos-Tokenizer](https://github.com/NVIDIA/Cosmos-Tokenizer)
|
| 101 |
+
* [NeMo](https://github.com/NVIDIA/NeMo) (please install the latest version from the GitHub main branch)
|
| 102 |
+
|
| 103 |
+
**Supported Hardware Microarchitecture Compatibility:**
|
| 104 |
+
* NVIDIA Ampere (e.g., A100)
|
| 105 |
+
* NVIDIA Hopper (e.g., H100)
|
| 106 |
+
|
| 107 |
+
Note: We have only tested Cosmos Tokenizer with BF16 precision on Ampere and Hopper GPUs. If you are using older versions of NVIDIA GPUs (e.g., NVIDIA Volta GPUs), you may need to switch to FP32 precision.
|
| 108 |
+
|
| 109 |
+
|
| 110 |
+
**Operating System(s):**
|
| 111 |
+
* Linux (We have not tested on other operating systems.)
|
| 112 |
+
|
| 113 |
+
# Usage
|
| 114 |
+
Inference Engines:
|
| 115 |
+
* [Cosmos-Tokenizer](https://github.com/NVIDIA/Cosmos-Tokenizer) (PyTorch)
|
| 116 |
+
* [NeMo](https://github.com/NVIDIA/NeMo)
|
| 117 |
+
|
| 118 |
+
## Inference with `Cosmos-Tokenizer` (PyTorch)
|
| 119 |
+
### Step-1: Installation of `Cosmos-Tokenizer`
|
| 120 |
+
Note: Currently, the `Cosmos-Tokenizer` code is only supported on Linux.
|
| 121 |
+
|
| 122 |
+
- Please clone the `Cosmos-Tokenizer` from GitHub repo [github.com/NVIDIA/Cosmos-Tokenizer](https://github.com/NVIDIA/Cosmos-Tokenizer).
|
| 123 |
+
|
| 124 |
+
```bash
|
| 125 |
+
git clone https://github.com/NVIDIA/Cosmos-Tokenizer.git
|
| 126 |
+
cd Cosmos-Tokenizer
|
| 127 |
+
```
|
| 128 |
+
- Install dependencies
|
| 129 |
+
|
| 130 |
+
```bash
|
| 131 |
+
pip3 install -r requirements.txt
|
| 132 |
+
apt-get install -y ffmpeg
|
| 133 |
+
```
|
| 134 |
+
|
| 135 |
+
- Preferably, you could build a docker image using our provided Dockerfile.
|
| 136 |
+
```bash
|
| 137 |
+
docker build -t cosmos-docker -f Dockerfile.
|
| 138 |
+
# You can run the container as:
|
| 139 |
+
docker run --gpus all -it --rm -v /home/${USER}:/home/${USER} \
|
| 140 |
+
--workdir ${PWD} cosmos-docker /bin/bash
|
| 141 |
+
```
|
| 142 |
+
|
| 143 |
+
### Step-2: Download Pre-trained Checkpoints
|
| 144 |
+
- Create a local directory for the pre-trained checkpoints and download the
|
| 145 |
+
pre-trained checkpoints from HuggingFace.
|
| 146 |
+
|
| 147 |
+
```python
|
| 148 |
+
from huggingface_hub import login, snapshot_download
|
| 149 |
+
import os
|
| 150 |
+
# You could get your Hugging Face token from https://huggingface.co/settings/tokens
|
| 151 |
+
login(token=<YOUT-HF-TOKEN>, add_to_git_credential=True)
|
| 152 |
+
# You could specify the tokenizers you want to download.
|
| 153 |
+
model_names = [
|
| 154 |
+
"Cosmos-Tokenizer-CI8x8",
|
| 155 |
+
"Cosmos-Tokenizer-CI16x16",
|
| 156 |
+
"Cosmos-Tokenizer-CV4x8x8",
|
| 157 |
+
"Cosmos-Tokenizer-CV8x8x8",
|
| 158 |
+
"Cosmos-Tokenizer-CV8x16x16",
|
| 159 |
+
"Cosmos-Tokenizer-DI8x8",
|
| 160 |
+
"Cosmos-Tokenizer-DI16x16",
|
| 161 |
+
"Cosmos-Tokenizer-DV4x8x8",
|
| 162 |
+
"Cosmos-Tokenizer-DV8x8x8",
|
| 163 |
+
"Cosmos-Tokenizer-DV8x16x16",
|
| 164 |
+
]
|
| 165 |
+
for model_name in model_names:
|
| 166 |
+
hf_repo = "nvidia/" + model_name
|
| 167 |
+
local_dir = "pretrained_ckpts/" + model_name
|
| 168 |
+
os.makedirs(local_dir, exist_ok=True)
|
| 169 |
+
print(f"downloading {model_name} to {local_dir}...")
|
| 170 |
+
snapshot_download(repo_id=hf_repo, local_dir=local_dir)
|
| 171 |
+
```
|
| 172 |
+
|
| 173 |
+
- Under the ech checkpoint directory `pretrained_ckpts/<model-name>`, we provide the encoder,
|
| 174 |
+
decoder and the full autoencoder JIT models.
|
| 175 |
+
|
| 176 |
+
```bash
|
| 177 |
+
├── pretrained_ckpts/
|
| 178 |
+
│ ├── Cosmos-Tokenizer-DV8x8x8/
|
| 179 |
+
│ │ ├── encoder.jit
|
| 180 |
+
│ │ ├── decoder.jit
|
| 181 |
+
│ │ ├── autoencoder.jit
|
| 182 |
+
│ ...
|
| 183 |
+
```
|
| 184 |
+
|
| 185 |
+
### Step-3: Run Inference
|
| 186 |
+
You can use the following example commands to encode and decode images or videos. For each, the same command works for both continuous and discrete tokenization. Simply provide the proper JIT-compiled ckpt to `checkpoint_enc`, `checkpoint_dec`, or the full autoencoder ckpt to `checkpoint`.
|
| 187 |
+
|
| 188 |
+
```python
|
| 189 |
+
import torch
|
| 190 |
+
from cosmos_tokenizer.video_lib import CausalVideoTokenizer
|
| 191 |
+
model_name = "Cosmos-Tokenizer-DV4x8x8"
|
| 192 |
+
input_tensor = torch.randn(1, 3, 9, 512, 512).to('cuda').to(torch.bfloat16)
|
| 193 |
+
encoder = CausalVideoTokenizer(checkpoint_enc=f'pretrained_ckpts/{model_name}/encoder.jit')
|
| 194 |
+
(indices, codes) = encoder.encode(input_tensor)
|
| 195 |
+
torch.testing.assert_close(indices.shape, (1, 3, 64, 64))
|
| 196 |
+
torch.testing.assert_close(codes.shape, (1, 6, 3, 64, 64))
|
| 197 |
+
|
| 198 |
+
# The input tensor can be reconstructed by the decoder as:
|
| 199 |
+
decoder = CausalVideoTokenizer(checkpoint_dec=f'pretrained_ckpts/{model_name}/decoder.jit')
|
| 200 |
+
reconstructed_tensor = decoder.decode(indices)
|
| 201 |
+
torch.testing.assert_close(reconstructed_tensor.shape, input_tensor.shape)
|
| 202 |
+
```
|
| 203 |
+
|
| 204 |
+
The `indices` will have the shape `(1, 3, 64, 64)` and contain integral values in the range `[1..64K]`, where the first of the three integral maps represents the first frame.
|
| 205 |
+
The `codes` will contain the pre-quantization continuous latent with shape `(1, 6, 3, 64, 64)`, where C=6 represents the number of FSQ levels.
|
| 206 |
+
|
| 207 |
+
**Note**: More inference usage commands, including both TorchScript (JIT) and PyTorch Inference APIs on real images and videos, can be found on our GitHub repository [github.com/NVIDIA/Cosmos-Tokenizer](https://github.com/NVIDIA/Cosmos-Tokenizer).
|
| 208 |
+
|
| 209 |
+
|
| 210 |
+
## Inference with NeMo
|
| 211 |
+
|
| 212 |
+
### Step-1: Install NeMo
|
| 213 |
+
Please install NeMo from the GitHub `main` branch following the instructions [here](https://github.com/NVIDIA/NeMo?tab=readme-ov-file#pip-from-a-source-branch).
|
| 214 |
+
|
| 215 |
+
### Step-2: Run Inference
|
| 216 |
+
Run the following code to tokenize the video:
|
| 217 |
+
|
| 218 |
+
```python
|
| 219 |
+
import torch
|
| 220 |
+
from nemo.collections.common.video_tokenizers.cosmos_vision_tokenizer import CausalVideoTokenizer
|
| 221 |
+
model_name = "Cosmos-Tokenizer-DV4x8x8"
|
| 222 |
+
model = CausalVideoTokenizer.from_pretrained(model_name)
|
| 223 |
+
input_tensor = torch.randn(1, 3, 9, 512, 512).to('cuda').to(torch.bfloat16)
|
| 224 |
+
(indices, codes) = model.encode(input_tensor)
|
| 225 |
+
```
|
| 226 |
+
Please see the [Cosmos Tokenizer README within the NeMo repository](https://github.com/NVIDIA/NeMo/tree/main/nemo/collections/common/video_tokenizers) for additional examples to create training datasets with the Cosmos Tokenizer.
|
| 227 |
+
|
| 228 |
+
|
| 229 |
+
# Evaluation
|
| 230 |
+
|
| 231 |
+
## TokenizationPerformance Comparison
|
| 232 |
+
We have extensively evaluated the **Cosmos Tokenizer** suite on various image and video benchmark datasets. In addition to commonly used datasets such as [MS-COCO](https://cocodataset.org/#home) and [DAVIS](https://davischallenge.org/), in order to cover a wide variety of visual data and standardize the evaluation, we created a benchmark called [TokenBench](https://github.com/NVlabs/Token-Bench), which is a mixed sampling of video data from diverse domains.
|
| 233 |
+
|
| 234 |
+
| Tokenizer | Compression Ratio | Quantization | PSNR (DAVIS) | SSIM (DAVIS) | rFVD (DAVIS) | PSNR (TokenBench) | SSIM (TokenBench) | rFVD (TokenBench) |
|
| 235 |
+
|-----------|------------------|--------------|--------------|--------------|--------------|------------------|------------------|------------------|
|
| 236 |
+
| VideoGPT | 4×4×4 | VQ | 32.23 | **0.850** | 72.33 | 35.11 | **0.914** | **13.85** |
|
| 237 |
+
| Omnitokenizer | 4×8×8 | VQ | 28.44 | 0.712 | 188.60 | 30.15 | 0.827 | 53.55 |
|
| 238 |
+
| Cosmos-Tokenizer-DV | 4×8×8 | FSQ | **32.98** | 0.818 | **37.36** | **35.13** | 0.887 | 19.67 |
|
| 239 |
+
| Cosmos-Tokenizer-DV | 8×8×8 | FSQ | 32.11 | 0.775 | 100.15 | 34.74 | 0.872 | 43.86 |
|
| 240 |
+
| Cosmos-Tokenizer-DV | 8×16×16 | FSQ | 31.42 | 0.716 | 241.52 | 33.71 | 0.828 | 113.48 |
|
| 241 |
+
|
| 242 |
+
* We compare with the state-of-the-art discrete video tokenizer, [OmniTokenizer](https://github.com/FoundationVision/OmniTokenizer).
|
| 243 |
+
* Evaluation metrics:
|
| 244 |
+
* Peak Signal-to-Noise Ratio (PSNR)
|
| 245 |
+
* Structural Similarity (SSIM)
|
| 246 |
+
* Reconstruction Fréchet Video Distance (rFVD)
|
| 247 |
+
|
| 248 |
+
## Runtime Comparison
|
| 249 |
+
|
| 250 |
+
The following table shows the number of parameters and the averaged encoding and decoding times per image or video frame, measured on a single A100 80GB GPU. For comparison, we also list the parameters and average speeds of prior state-of-the-art tokenizer(s) with the same compression ratio.
|
| 251 |
+
|
| 252 |
+
| Tokenizer | Resolution | Compression Ratio | Parameters | Time (ms) |
|
| 253 |
+
|----------------|------------|-------------------|------------|-----------|
|
| 254 |
+
| OmniTokenizer | 720x1280 | 4×8×8 | 54M | 53.2 |
|
| 255 |
+
| Cosmos-DV | 720x1280 | 4×8×8 | 105M | 51.5 |
|
| 256 |
+
|
| 257 |
+
Note: We benchmarked the runtime for images under the 8x8 compression and videos under the 4×8×8 compression. Tokenizers with different compression ratios are not included in this comparison.
|
| 258 |
+
|
| 259 |
+
## Ethical Considerations
|
| 260 |
+
NVIDIA believes Trustworthy AI is a shared responsibility and we have established policies and practices to enable development for a wide array of AI applications. When downloaded or used in accordance with our terms of service, developers should work with their internal model team to ensure this model meets requirements for the relevant industry and use case and addresses unforeseen product misuse.
|
| 261 |
+
|
| 262 |
+
For more detailed information on ethical considerations for this model, please see the subcards of Explainability, Bias, Safety & Security, and Privacy below. Please report security vulnerabilities or NVIDIA AI Concerns [here](https://www.nvidia.com/en-us/support/submit-security-vulnerability/).
|
| 263 |
+
|
| 264 |
+
### Bias
|
| 265 |
+
|
| 266 |
+
Field | Response
|
| 267 |
+
:---------------------------------------------------------------------------------------------------|:---------------
|
| 268 |
+
Participation considerations from adversely impacted groups [protected classes](https://www.senate.ca.gov/content/protected-classes) in model design and testing: | None
|
| 269 |
+
Measures taken to mitigate against unwanted bias: | None
|
| 270 |
+
|
| 271 |
+
|
| 272 |
+
### Explainability
|
| 273 |
+
|
| 274 |
+
Field | Response
|
| 275 |
+
:------------------------------------------------------------------------------------------------------|:---------------------------------------------------------------------------------
|
| 276 |
+
Intended Application & Domain: | Tokenization of images and videos
|
| 277 |
+
Model Type: | Auto-Encoder
|
| 278 |
+
Intended Users: | Generative AI developers for image and video generation models
|
| 279 |
+
Output: | Images/Videos and Latent Tokens
|
| 280 |
+
Describe how the model works: | Compresses and decompresses visual input (image/video).
|
| 281 |
+
Technical Limitations: | Due to tokenizer compression limitations, some visual information (such as small text and other structured fine details) may not be reconstructed accurately.
|
| 282 |
+
Verified to have met prescribed NVIDIA quality standards: | Yes
|
| 283 |
+
Performance Metrics: | Peak Signal-to-Noise Ratio (PSNR), Structural Similarity (SSIM), Reconstruction Fréchet Video Distance (rFVD), Reconstruction Fréchet Inception Distance (rFID), Latency
|
| 284 |
+
Potential Known Risks: | Tokenizer's output can parse all forms of input, including what may be considered toxic, offensive, or indecent.
|
| 285 |
+
Licensing: | [NVIDIA Open Model License](https://developer.download.nvidia.com/licenses/nvidia-open-model-license-agreement-june-2024.pdf)
|
| 286 |
+
|
| 287 |
+
|
| 288 |
+
### Privacy
|
| 289 |
+
Field | Response
|
| 290 |
+
:----------------------------------------------------------------------------------------------------------------------------------|:-----------------------------------------------
|
| 291 |
+
Generatable or reverse engineerable personal information? | No
|
| 292 |
+
Protected class data used to create this model? | None Known
|
| 293 |
+
Was consent obtained for any personal data used? | None Known
|
| 294 |
+
How often is dataset reviewed? | Before Release
|
| 295 |
+
Is a mechanism in place to honor data subject right of access or deletion of personal data? | Not Applicable
|
| 296 |
+
If personal collected for the development of the model, was it collected directly by NVIDIA? | Not Applicable
|
| 297 |
+
If personal collected for the development of the model by NVIDIA, do you maintain or have access to disclosures made to data subjects? | Not Applicable
|
| 298 |
+
If personal collected for the development of this AI model, was it minimized to only what was required? | Not Applicable
|
| 299 |
+
Is there provenance for all datasets used in training? | Yes
|
| 300 |
+
Does data labeling (annotation, metadata) comply with privacy laws? | Yes
|
| 301 |
+
Is data compliant with data subject requests for data correction or removal, if such a request was made? | Not Applicable
|
| 302 |
+
|
| 303 |
+
### Safety
|
| 304 |
+
|
| 305 |
+
Field | Response
|
| 306 |
+
:---------------------------------------------------|:----------------------------------
|
| 307 |
+
Model Application(s): | Tokenization of images and videos
|
| 308 |
+
Describe the life critical impact (if present). | None Known
|
| 309 |
+
Use Case Restrictions: | See [NVIDIA Open Model License](https://developer.download.nvidia.com/licenses/nvidia-open-model-license-agreement-june-2024.pdf)
|
| 310 |
+
Model and dataset restrictions: | The Principle of least privilege (PoLP) is applied limiting access for dataset generation and model development. Restrictions enforce dataset access during training, and dataset license constraints adhered to. Model checkpoints are made available on Hugging Face, and may become available on cloud providers' model catalog.
|
| 311 |
+
|
| 312 |
+
|
| 313 |
+
### Plus Plus (++) Promise
|
| 314 |
+
|
| 315 |
+
We value you, the datasets, the diversity they represent, and what we have been entrusted with. This model and its associated data have been:
|
| 316 |
+
* Verified to comply with current applicable disclosure laws, regulations, and industry standards.
|
| 317 |
+
* Verified to comply with applicable privacy labeling requirements.
|
| 318 |
+
* Annotated to describe the collector/source (NVIDIA or a third-party).
|
| 319 |
+
* Characterized for technical limitations.
|
| 320 |
+
* Reviewed to ensure proper disclosure is accessible to, maintained for, and in compliance with NVIDIA data subjects and their requests.
|
| 321 |
+
* Reviewed before release.
|
| 322 |
+
* Tagged for known restrictions and potential safety implications.
|
| 323 |
+
|
| 324 |
+
|
| 325 |
+
# Core Contributors
|
| 326 |
+
Fitsum Reda, Jinwei Gu, Xian Liu, Songwei Ge, Ting-Chun Wang, Haoxiang Wang, Ming-Yu Liu
|
Meissonic/pretrained_ckpts/Cosmos-0.1-Tokenizer-DV4x8x8/autoencoder.jit
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:eea104b84fee21d170fb20f99027c076ffd97e37b8d43a6a8f6135a2a61cfaf1
|
| 3 |
+
size 211093069
|
Meissonic/pretrained_ckpts/Cosmos-0.1-Tokenizer-DV4x8x8/config.json
ADDED
|
@@ -0,0 +1,6 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"architectures": [
|
| 3 |
+
"CosmosTokenizer"
|
| 4 |
+
],
|
| 5 |
+
}
|
| 6 |
+
|
Meissonic/pretrained_ckpts/Cosmos-0.1-Tokenizer-DV4x8x8/decoder.jit
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:a6b82dd6f4d489bbeb728e54c828d5a676f17e6eba9b9dfe2dc7839928bee73f
|
| 3 |
+
size 125210440
|
Meissonic/pretrained_ckpts/Cosmos-0.1-Tokenizer-DV4x8x8/encoder.jit
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:9a0e8459ab5e0ecfd0c00f215571de43e368f090c16adeb1a69fa835177bdea6
|
| 3 |
+
size 86641076
|
Meissonic/pretrained_ckpts/Cosmos-0.1-Tokenizer-DV4x8x8/model_config.yaml
ADDED
|
@@ -0,0 +1 @@
|
|
|
|
|
|
|
| 1 |
+
nemo_version: https://github.com/NVIDIA/NeMo/commit/6a5d4b5d19e05262a4182a83613753d424153a8f
|
Meissonic/pretrained_ckpts/Cosmos-0.1-Tokenizer-DV8x8x8/.gitattributes
ADDED
|
@@ -0,0 +1,38 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
*.7z filter=lfs diff=lfs merge=lfs -text
|
| 2 |
+
*.arrow filter=lfs diff=lfs merge=lfs -text
|
| 3 |
+
*.bin filter=lfs diff=lfs merge=lfs -text
|
| 4 |
+
*.bz2 filter=lfs diff=lfs merge=lfs -text
|
| 5 |
+
*.ckpt filter=lfs diff=lfs merge=lfs -text
|
| 6 |
+
*.ftz filter=lfs diff=lfs merge=lfs -text
|
| 7 |
+
*.gz filter=lfs diff=lfs merge=lfs -text
|
| 8 |
+
*.h5 filter=lfs diff=lfs merge=lfs -text
|
| 9 |
+
*.joblib filter=lfs diff=lfs merge=lfs -text
|
| 10 |
+
*.lfs.* filter=lfs diff=lfs merge=lfs -text
|
| 11 |
+
*.mlmodel filter=lfs diff=lfs merge=lfs -text
|
| 12 |
+
*.model filter=lfs diff=lfs merge=lfs -text
|
| 13 |
+
*.msgpack filter=lfs diff=lfs merge=lfs -text
|
| 14 |
+
*.npy filter=lfs diff=lfs merge=lfs -text
|
| 15 |
+
*.npz filter=lfs diff=lfs merge=lfs -text
|
| 16 |
+
*.onnx filter=lfs diff=lfs merge=lfs -text
|
| 17 |
+
*.ot filter=lfs diff=lfs merge=lfs -text
|
| 18 |
+
*.parquet filter=lfs diff=lfs merge=lfs -text
|
| 19 |
+
*.pb filter=lfs diff=lfs merge=lfs -text
|
| 20 |
+
*.pickle filter=lfs diff=lfs merge=lfs -text
|
| 21 |
+
*.pkl filter=lfs diff=lfs merge=lfs -text
|
| 22 |
+
*.pt filter=lfs diff=lfs merge=lfs -text
|
| 23 |
+
*.pth filter=lfs diff=lfs merge=lfs -text
|
| 24 |
+
*.rar filter=lfs diff=lfs merge=lfs -text
|
| 25 |
+
*.safetensors filter=lfs diff=lfs merge=lfs -text
|
| 26 |
+
saved_model/**/* filter=lfs diff=lfs merge=lfs -text
|
| 27 |
+
*.tar.* filter=lfs diff=lfs merge=lfs -text
|
| 28 |
+
*.tar filter=lfs diff=lfs merge=lfs -text
|
| 29 |
+
*.tflite filter=lfs diff=lfs merge=lfs -text
|
| 30 |
+
*.tgz filter=lfs diff=lfs merge=lfs -text
|
| 31 |
+
*.wasm filter=lfs diff=lfs merge=lfs -text
|
| 32 |
+
*.xz filter=lfs diff=lfs merge=lfs -text
|
| 33 |
+
*.zip filter=lfs diff=lfs merge=lfs -text
|
| 34 |
+
*.zst filter=lfs diff=lfs merge=lfs -text
|
| 35 |
+
*tfevents* filter=lfs diff=lfs merge=lfs -text
|
| 36 |
+
autoencoder.jit filter=lfs diff=lfs merge=lfs -text
|
| 37 |
+
decoder.jit filter=lfs diff=lfs merge=lfs -text
|
| 38 |
+
encoder.jit filter=lfs diff=lfs merge=lfs -text
|
Meissonic/pretrained_ckpts/Cosmos-0.1-Tokenizer-DV8x8x8/README.md
ADDED
|
@@ -0,0 +1,325 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
---
|
| 2 |
+
license: other
|
| 3 |
+
license_name: nvidia-open-model-license
|
| 4 |
+
license_link: >-
|
| 5 |
+
https://developer.download.nvidia.com/licenses/nvidia-open-model-license-agreement-june-2024.pdf
|
| 6 |
+
library_name: nemo
|
| 7 |
+
---
|
| 8 |
+
# **Cosmos Tokenizer**: A suite of image and video tokenizers
|
| 9 |
+
|
| 10 |
+
[**Website**](https://research.nvidia.com/labs/dir/cosmos-tokenizer) | [**Code**](https://github.com/NVIDIA/Cosmos-Tokenizer) | **Video**
|
| 11 |
+
|
| 12 |
+
|
| 13 |
+
# Model Overview
|
| 14 |
+
|
| 15 |
+
## Description:
|
| 16 |
+
**Cosmos Tokenizer** is a suite of visual tokenizers for images and videos that delivers various compression rates while maintaining high reconstruction quality. Cosmos Tokenizer can serve as an effective and efficient building block in both diffusion-based and autoregressive models for image and video generation.
|
| 17 |
+
|
| 18 |
+
|
| 19 |
+
Our tokenizers come in two types: **Continuous** (C) and **Discrete** (D), each with **Image** (I) and **Video** (V) variants:
|
| 20 |
+
* Continuous tokenizers encode visual data into continuous latent embeddings, as shown in latent diffusion models like [Stable Diffusion](https://github.com/CompVis/stable-diffusion). These embeddings are suitable for models that generate data by sampling from continuous distributions.
|
| 21 |
+
* Discrete tokenizers encode visual data into discrete latent codes, mapping them into quantized indices, as seen in autoregressive transformers such as [VideoPoet](https://sites.research.google/videopoet/). This discretization is required for models that generate data by optimizing the cross-entropy loss, such as the GPT models.
|
| 22 |
+
|
| 23 |
+
|
| 24 |
+
| | Continuous ( C ) | Discrete ( D ) |
|
| 25 |
+
| ------------------|---------------------|---------------------|
|
| 26 |
+
| **Images ( I )** | Cosmos-Tokenizer-CI | Cosmos-Tokenizer-DI |
|
| 27 |
+
| **Videos ( V )** | Cosmos-Tokenizer-CV | Cosmos-Tokenizer-DV |
|
| 28 |
+
|
| 29 |
+
|
| 30 |
+
Given an image or a video, Cosmos Tokenizer outputs either continuous latents or discrete tokens. Cosmos Tokenizer achieves spatial compression rates of 8x8 or 16x16 and temporal compression factors of 4x or 8x, resulting in a total compression factor of up to 2048x (=8x16x16). Cosmos Tokenizer delivers 8x more total compression than state-of-the-art (SOTA) methods while simultaneously maintaining higher image quality and running up to 12x faster than the best available SOTA tokenizers.
|
| 31 |
+
|
| 32 |
+
**Model Developer**: NVIDIA
|
| 33 |
+
|
| 34 |
+
## Model Versions
|
| 35 |
+
|
| 36 |
+
The initial release (v1.0) of Cosmos Tokenizer includes the following tokenizers:
|
| 37 |
+
* **Continuous Tokenizers**
|
| 38 |
+
* Continuous Image (CI) Tokenizer
|
| 39 |
+
* [Cosmos-Tokenizer-CI8x8](https://huggingface.co/nvidia/Cosmos-Tokenizer-CI8x8) (8x8 spatial compression)
|
| 40 |
+
* [Cosmos-Tokenizer-CI16x16](https://huggingface.co/nvidia/Cosmos-Tokenizer-CI16x16) (16x16 spatial compression)
|
| 41 |
+
* Continuous Video (CV) Tokenizer
|
| 42 |
+
* [Cosmos-Tokenizer-CV4x8x8](https://huggingface.co/nvidia/Cosmos-Tokenizer-CV4x8x8) (4x temporal compression, 8x8 spatial compression)
|
| 43 |
+
* [Cosmos-Tokenizer-CV8x8x8](https://huggingface.co/nvidia/Cosmos-Tokenizer-CV8x8x8) (8x temporal compression, 8x8 spatial compression)
|
| 44 |
+
* [Cosmos-Tokenizer-CV8x16x16](https://huggingface.co/nvidia/Cosmos-Tokenizer-CV8x16x16) (8x temporal compression, 16x16 spatial compression)
|
| 45 |
+
* **Discrete Tokenizers**
|
| 46 |
+
* Discrete Image (DI) Tokenizer
|
| 47 |
+
* [Cosmos-Tokenizer-DI8x8](https://huggingface.co/nvidia/Cosmos-Tokenizer-DI8x8) (8x8 spatial compression)
|
| 48 |
+
* [Cosmos-Tokenizer-DI16x16](https://huggingface.co/nvidia/Cosmos-Tokenizer-DI16x16) (16x16 spatial compression)
|
| 49 |
+
* Discrete Video (DV) Tokenizer
|
| 50 |
+
* [Cosmos-Tokenizer-DV4x8x8](https://huggingface.co/nvidia/Cosmos-Tokenizer-DV4x8x8) (4x temporal compression, 8x8 spatial compression)
|
| 51 |
+
* [Cosmos-Tokenizer-DV8x8x8](https://huggingface.co/nvidia/Cosmos-Tokenizer-DV8x8x8) (8x temporal compression, 8x8 spatial compression)
|
| 52 |
+
* [Cosmos-Tokenizer-DV8x16x16](https://huggingface.co/nvidia/Cosmos-Tokenizer-DV8x16x16) (8x temporal compression, 16x16 spatial compression)
|
| 53 |
+
|
| 54 |
+
|
| 55 |
+
### License/Terms of Use:
|
| 56 |
+
[NVIDIA Open Model License](https://developer.download.nvidia.com/licenses/nvidia-open-model-license-agreement-june-2024.pdf)
|
| 57 |
+
|
| 58 |
+
Under the NVIDIA Open Model License, NVIDIA confirms:
|
| 59 |
+
|
| 60 |
+
* Models are commercially usable.
|
| 61 |
+
* You are free to create and distribute Derivative Models.
|
| 62 |
+
* NVIDIA does not claim ownership to any outputs generated using the Models or Derivative Models.
|
| 63 |
+
|
| 64 |
+
## Model Architecture:
|
| 65 |
+
|
| 66 |
+
We designed Cosmos Tokenizer using a lightweight and computationally efficient architecture, featuring a temporally causal design. Specifically, we employ causal temporal convolution and causal temporal attention layers to preserve the natural temporal order of video frames, ensuring seamless tokenization of images and videos using a single unified network architecture. The encoder and decoder form a symmetrical pair, which are mirrors of each other. The encoder starts with a 2-level [Haar wavelet](https://link.springer.com/book/10.1007/978-3-319-04295-4) transform layer, which down-samples inputs by a factor of 4 in both spatial and temporal dimensions. Likewise, the decoder ends with an inverse wavelet transform. We employ the vanilla autoencoder (AE) formulation to model the latent space for continuous tokenizers. For discrete tokenizers, we adopt the [Finite-Scalar-Quantization](https://openreview.net/forum?id=8ishA3LxN8) (FSQ) as the latent space quantizer.
|
| 67 |
+
|
| 68 |
+

|
| 69 |
+
|
| 70 |
+
|
| 71 |
+
|
| 72 |
+
## Input/Output Specifications
|
| 73 |
+
|
| 74 |
+
### Encoder
|
| 75 |
+
* **Input**
|
| 76 |
+
* **Types:** Images or Videos
|
| 77 |
+
* **Format:** RGB (Red, Green, Blue)
|
| 78 |
+
* **Resolution:**
|
| 79 |
+
* Minimum: 256px (shorter side)
|
| 80 |
+
* Maximum: Up to 4K
|
| 81 |
+
* **Video Length:** Up to 8 seconds for 1080p videos (bounded by A100 80G GPU memory; higher resolutions will have shorter supported durations)
|
| 82 |
+
|
| 83 |
+
* **Output**
|
| 84 |
+
* **Types:** Tokens
|
| 85 |
+
* Continuous Image/Video Tokenizers: Continuous value feature vectors
|
| 86 |
+
* Discrete Image/Video Tokenizers: Integer indices
|
| 87 |
+
|
| 88 |
+
### Decoder
|
| 89 |
+
* **Input**
|
| 90 |
+
* **Types:** Tokens from encoder
|
| 91 |
+
|
| 92 |
+
* **Output**
|
| 93 |
+
* **Types:** Images or Videos (matching input type)
|
| 94 |
+
* **Format:** RGB (Red, Green, Blue)
|
| 95 |
+
* **Resolution:** Same as input resolution
|
| 96 |
+
* **Video Length:** Same as input video length
|
| 97 |
+
|
| 98 |
+
## Software Integration (Required For NVIDIA Models Only):
|
| 99 |
+
**Runtime Engine(s):**
|
| 100 |
+
* [Cosmos-Tokenizer](https://github.com/NVIDIA/Cosmos-Tokenizer)
|
| 101 |
+
* [NeMo](https://github.com/NVIDIA/NeMo) (please install the latest version from the GitHub main branch)
|
| 102 |
+
|
| 103 |
+
**Supported Hardware Microarchitecture Compatibility:**
|
| 104 |
+
* NVIDIA Ampere (e.g., A100)
|
| 105 |
+
* NVIDIA Hopper (e.g., H100)
|
| 106 |
+
|
| 107 |
+
Note: We have only tested Cosmos Tokenizer with BF16 precision on Ampere and Hopper GPUs. If you are using older versions of NVIDIA GPUs (e.g., NVIDIA Volta GPUs), you may need to switch to FP32 precision.
|
| 108 |
+
|
| 109 |
+
|
| 110 |
+
**Operating System(s):**
|
| 111 |
+
* Linux (We have not tested on other operating systems.)
|
| 112 |
+
|
| 113 |
+
# Usage
|
| 114 |
+
Inference Engines:
|
| 115 |
+
* [Cosmos-Tokenizer](https://github.com/NVIDIA/Cosmos-Tokenizer) (PyTorch)
|
| 116 |
+
* [NeMo](https://github.com/NVIDIA/NeMo)
|
| 117 |
+
|
| 118 |
+
## Inference with `Cosmos-Tokenizer` (PyTorch)
|
| 119 |
+
### Step-1: Installation of `Cosmos-Tokenizer`
|
| 120 |
+
Note: Currently, the `Cosmos-Tokenizer` code is only supported on Linux.
|
| 121 |
+
|
| 122 |
+
- Please clone the `Cosmos-Tokenizer` from GitHub repo [github.com/NVIDIA/Cosmos-Tokenizer](https://github.com/NVIDIA/Cosmos-Tokenizer).
|
| 123 |
+
|
| 124 |
+
```bash
|
| 125 |
+
git clone https://github.com/NVIDIA/Cosmos-Tokenizer.git
|
| 126 |
+
cd Cosmos-Tokenizer
|
| 127 |
+
```
|
| 128 |
+
- Install dependencies
|
| 129 |
+
|
| 130 |
+
```bash
|
| 131 |
+
pip3 install -r requirements.txt
|
| 132 |
+
apt-get install -y ffmpeg
|
| 133 |
+
```
|
| 134 |
+
|
| 135 |
+
- Preferably, you could build a docker image using our provided Dockerfile.
|
| 136 |
+
```bash
|
| 137 |
+
docker build -t cosmos-docker -f Dockerfile.
|
| 138 |
+
# You can run the container as:
|
| 139 |
+
docker run --gpus all -it --rm -v /home/${USER}:/home/${USER} \
|
| 140 |
+
--workdir ${PWD} cosmos-docker /bin/bash
|
| 141 |
+
```
|
| 142 |
+
|
| 143 |
+
### Step-2: Download Pre-trained Checkpoints
|
| 144 |
+
- Create a local directory for the pre-trained checkpoints and download the
|
| 145 |
+
pre-trained checkpoints from HuggingFace.
|
| 146 |
+
|
| 147 |
+
```python
|
| 148 |
+
from huggingface_hub import login, snapshot_download
|
| 149 |
+
import os
|
| 150 |
+
# You could get your Hugging Face token from https://huggingface.co/settings/tokens
|
| 151 |
+
login(token=<YOUT-HF-TOKEN>, add_to_git_credential=True)
|
| 152 |
+
# You could specify the tokenizers you want to download.
|
| 153 |
+
model_names = [
|
| 154 |
+
"Cosmos-Tokenizer-CI8x8",
|
| 155 |
+
"Cosmos-Tokenizer-CI16x16",
|
| 156 |
+
"Cosmos-Tokenizer-CV4x8x8",
|
| 157 |
+
"Cosmos-Tokenizer-CV8x8x8",
|
| 158 |
+
"Cosmos-Tokenizer-CV8x16x16",
|
| 159 |
+
"Cosmos-Tokenizer-DI8x8",
|
| 160 |
+
"Cosmos-Tokenizer-DI16x16",
|
| 161 |
+
"Cosmos-Tokenizer-DV4x8x8",
|
| 162 |
+
"Cosmos-Tokenizer-DV8x8x8",
|
| 163 |
+
"Cosmos-Tokenizer-DV8x16x16",
|
| 164 |
+
]
|
| 165 |
+
for model_name in model_names:
|
| 166 |
+
hf_repo = "nvidia/" + model_name
|
| 167 |
+
local_dir = "pretrained_ckpts/" + model_name
|
| 168 |
+
os.makedirs(local_dir, exist_ok=True)
|
| 169 |
+
print(f"downloading {model_name} to {local_dir}...")
|
| 170 |
+
snapshot_download(repo_id=hf_repo, local_dir=local_dir)
|
| 171 |
+
```
|
| 172 |
+
|
| 173 |
+
- Under the ech checkpoint directory `pretrained_ckpts/<model-name>`, we provide the encoder,
|
| 174 |
+
decoder and the full autoencoder JIT models.
|
| 175 |
+
|
| 176 |
+
```bash
|
| 177 |
+
├── pretrained_ckpts/
|
| 178 |
+
│ ├── Cosmos-Tokenizer-DV8x8x8/
|
| 179 |
+
│ │ ├── encoder.jit
|
| 180 |
+
│ │ ├── decoder.jit
|
| 181 |
+
│ │ ├── autoencoder.jit
|
| 182 |
+
│ ...
|
| 183 |
+
```
|
| 184 |
+
|
| 185 |
+
### Step-3: Run Inference
|
| 186 |
+
You can use the following example commands to encode and decode images or videos. For each, the same command works for both continuous and discrete tokenization. Simply provide the proper JIT-compiled ckpt to `checkpoint_enc`, `checkpoint_dec`, or the full autoencoder ckpt to `checkpoint`.
|
| 187 |
+
|
| 188 |
+
```python
|
| 189 |
+
import torch
|
| 190 |
+
from cosmos_tokenizer.video_lib import CausalVideoTokenizer
|
| 191 |
+
model_name = "Cosmos-Tokenizer-DV4x8x8"
|
| 192 |
+
input_tensor = torch.randn(1, 3, 9, 512, 512).to('cuda').to(torch.bfloat16)
|
| 193 |
+
encoder = CausalVideoTokenizer(checkpoint_enc=f'pretrained_ckpts/{model_name}/encoder.jit')
|
| 194 |
+
(indices, codes) = encoder.encode(input_tensor)
|
| 195 |
+
torch.testing.assert_close(indices.shape, (1, 3, 64, 64))
|
| 196 |
+
torch.testing.assert_close(codes.shape, (1, 6, 3, 64, 64))
|
| 197 |
+
|
| 198 |
+
# The input tensor can be reconstructed by the decoder as:
|
| 199 |
+
decoder = CausalVideoTokenizer(checkpoint_dec=f'pretrained_ckpts/{model_name}/decoder.jit')
|
| 200 |
+
reconstructed_tensor = decoder.decode(indices)
|
| 201 |
+
torch.testing.assert_close(reconstructed_tensor.shape, input_tensor.shape)
|
| 202 |
+
```
|
| 203 |
+
|
| 204 |
+
The `indices` will have the shape `(1, 3, 64, 64)` and contain integral values in the range `[1..64K]`, where the first of the three integral maps represents the first frame.
|
| 205 |
+
The `codes` will contain the pre-quantization continuous latent with shape `(1, 6, 3, 64, 64)`, where C=6 represents the number of FSQ levels.
|
| 206 |
+
|
| 207 |
+
**Note**: More inference usage commands, including both TorchScript (JIT) and PyTorch Inference APIs on real images and videos, can be found on our GitHub repository [github.com/NVIDIA/Cosmos-Tokenizer](https://github.com/NVIDIA/Cosmos-Tokenizer).
|
| 208 |
+
|
| 209 |
+
|
| 210 |
+
## Inference with NeMo
|
| 211 |
+
|
| 212 |
+
### Step-1: Install NeMo
|
| 213 |
+
Please install NeMo from the GitHub `main` branch following the instructions [here](https://github.com/NVIDIA/NeMo?tab=readme-ov-file#pip-from-a-source-branch).
|
| 214 |
+
|
| 215 |
+
### Step-2: Run Inference
|
| 216 |
+
Run the following code to tokenize the video:
|
| 217 |
+
|
| 218 |
+
```python
|
| 219 |
+
import torch
|
| 220 |
+
from nemo.collections.common.video_tokenizers.cosmos_vision_tokenizer import CausalVideoTokenizer
|
| 221 |
+
model_name = "Cosmos-Tokenizer-DV4x8x8"
|
| 222 |
+
model = CausalVideoTokenizer.from_pretrained(model_name)
|
| 223 |
+
input_tensor = torch.randn(1, 3, 9, 512, 512).to('cuda').to(torch.bfloat16)
|
| 224 |
+
(indices, codes) = model.encode(input_tensor)
|
| 225 |
+
```
|
| 226 |
+
Please see the [Cosmos Tokenizer README within the NeMo repository](https://github.com/NVIDIA/NeMo/tree/main/nemo/collections/common/video_tokenizers) for additional examples to create training datasets with the Cosmos Tokenizer.
|
| 227 |
+
|
| 228 |
+
# Evaluation
|
| 229 |
+
|
| 230 |
+
## TokenizationPerformance Comparison
|
| 231 |
+
We have extensively evaluated the **Cosmos Tokenizer** suite on various image and video benchmark datasets. In addition to commonly used datasets such as [MS-COCO](https://cocodataset.org/#home) and [DAVIS](https://davischallenge.org/), in order to cover a wide variety of visual data and standardize the evaluation, we created a benchmark called [TokenBench](https://github.com/NVlabs/Token-Bench), which is a mixed sampling of video data from diverse domains.
|
| 232 |
+
|
| 233 |
+
| Tokenizer | Compression Ratio | Quantization | PSNR (DAVIS) | SSIM (DAVIS) | rFVD (DAVIS) | PSNR (TokenBench) | SSIM (TokenBench) | rFVD (TokenBench) |
|
| 234 |
+
|-----------|------------------|--------------|--------------|--------------|--------------|------------------|------------------|------------------|
|
| 235 |
+
| VideoGPT | 4×4×4 | VQ | 32.23 | **0.850** | 72.33 | 35.11 | **0.914** | **13.85** |
|
| 236 |
+
| Omnitokenizer | 4×8×8 | VQ | 28.44 | 0.712 | 188.60 | 30.15 | 0.827 | 53.55 |
|
| 237 |
+
| Cosmos-Tokenizer-DV | 4×8×8 | FSQ | **32.98** | 0.818 | **37.36** | **35.13** | 0.887 | 19.67 |
|
| 238 |
+
| Cosmos-Tokenizer-DV | 8×8×8 | FSQ | 32.11 | 0.775 | 100.15 | 34.74 | 0.872 | 43.86 |
|
| 239 |
+
| Cosmos-Tokenizer-DV | 8×16×16 | FSQ | 31.42 | 0.716 | 241.52 | 33.71 | 0.828 | 113.48 |
|
| 240 |
+
|
| 241 |
+
* We compare with the state-of-the-art discrete video tokenizer, [OmniTokenizer](https://github.com/FoundationVision/OmniTokenizer).
|
| 242 |
+
* Evaluation metrics:
|
| 243 |
+
* Peak Signal-to-Noise Ratio (PSNR)
|
| 244 |
+
* Structural Similarity (SSIM)
|
| 245 |
+
* Reconstruction Fréchet Video Distance (rFVD)
|
| 246 |
+
|
| 247 |
+
## Runtime Comparison
|
| 248 |
+
|
| 249 |
+
The following table shows the number of parameters and the averaged encoding and decoding times per image or video frame, measured on a single A100 80GB GPU. For comparison, we also list the parameters and average speeds of prior state-of-the-art tokenizer(s) with the same compression ratio.
|
| 250 |
+
|
| 251 |
+
| Tokenizer | Resolution | Compression Ratio | Parameters | Time (ms) |
|
| 252 |
+
|----------------|------------|-------------------|------------|-----------|
|
| 253 |
+
| OmniTokenizer | 720x1280 | 4×8×8 | 54M | 53.2 |
|
| 254 |
+
| Cosmos-DV | 720x1280 | 4×8×8 | 105M | 51.5 |
|
| 255 |
+
|
| 256 |
+
Note: We benchmarked the runtime for images under the 8x8 compression and videos under the 4×8×8 compression. Tokenizers with different compression ratios are not included in this comparison.
|
| 257 |
+
|
| 258 |
+
## Ethical Considerations
|
| 259 |
+
NVIDIA believes Trustworthy AI is a shared responsibility and we have established policies and practices to enable development for a wide array of AI applications. When downloaded or used in accordance with our terms of service, developers should work with their internal model team to ensure this model meets requirements for the relevant industry and use case and addresses unforeseen product misuse.
|
| 260 |
+
|
| 261 |
+
For more detailed information on ethical considerations for this model, please see the subcards of Explainability, Bias, Safety & Security, and Privacy below. Please report security vulnerabilities or NVIDIA AI Concerns [here](https://www.nvidia.com/en-us/support/submit-security-vulnerability/).
|
| 262 |
+
|
| 263 |
+
### Bias
|
| 264 |
+
|
| 265 |
+
Field | Response
|
| 266 |
+
:---------------------------------------------------------------------------------------------------|:---------------
|
| 267 |
+
Participation considerations from adversely impacted groups [protected classes](https://www.senate.ca.gov/content/protected-classes) in model design and testing: | None
|
| 268 |
+
Measures taken to mitigate against unwanted bias: | None
|
| 269 |
+
|
| 270 |
+
|
| 271 |
+
### Explainability
|
| 272 |
+
|
| 273 |
+
Field | Response
|
| 274 |
+
:------------------------------------------------------------------------------------------------------|:---------------------------------------------------------------------------------
|
| 275 |
+
Intended Application & Domain: | Tokenization of images and videos
|
| 276 |
+
Model Type: | Auto-Encoder
|
| 277 |
+
Intended Users: | Generative AI developers for image and video generation models
|
| 278 |
+
Output: | Images/Videos and Latent Tokens
|
| 279 |
+
Describe how the model works: | Compresses and decompresses visual input (image/video).
|
| 280 |
+
Technical Limitations: | Due to tokenizer compression limitations, some visual information (such as small text and other structured fine details) may not be reconstructed accurately.
|
| 281 |
+
Verified to have met prescribed NVIDIA quality standards: | Yes
|
| 282 |
+
Performance Metrics: | Peak Signal-to-Noise Ratio (PSNR), Structural Similarity (SSIM), Reconstruction Fréchet Video Distance (rFVD), Reconstruction Fréchet Inception Distance (rFID), Latency
|
| 283 |
+
Potential Known Risks: | Tokenizer's output can parse all forms of input, including what may be considered toxic, offensive, or indecent.
|
| 284 |
+
Licensing: | [NVIDIA Open Model License](https://developer.download.nvidia.com/licenses/nvidia-open-model-license-agreement-june-2024.pdf)
|
| 285 |
+
|
| 286 |
+
|
| 287 |
+
### Privacy
|
| 288 |
+
Field | Response
|
| 289 |
+
:----------------------------------------------------------------------------------------------------------------------------------|:-----------------------------------------------
|
| 290 |
+
Generatable or reverse engineerable personal information? | No
|
| 291 |
+
Protected class data used to create this model? | None Known
|
| 292 |
+
Was consent obtained for any personal data used? | None Known
|
| 293 |
+
How often is dataset reviewed? | Before Release
|
| 294 |
+
Is a mechanism in place to honor data subject right of access or deletion of personal data? | Not Applicable
|
| 295 |
+
If personal collected for the development of the model, was it collected directly by NVIDIA? | Not Applicable
|
| 296 |
+
If personal collected for the development of the model by NVIDIA, do you maintain or have access to disclosures made to data subjects? | Not Applicable
|
| 297 |
+
If personal collected for the development of this AI model, was it minimized to only what was required? | Not Applicable
|
| 298 |
+
Is there provenance for all datasets used in training? | Yes
|
| 299 |
+
Does data labeling (annotation, metadata) comply with privacy laws? | Yes
|
| 300 |
+
Is data compliant with data subject requests for data correction or removal, if such a request was made? | Not Applicable
|
| 301 |
+
|
| 302 |
+
### Safety
|
| 303 |
+
|
| 304 |
+
Field | Response
|
| 305 |
+
:---------------------------------------------------|:----------------------------------
|
| 306 |
+
Model Application(s): | Tokenization of images and videos
|
| 307 |
+
Describe the life critical impact (if present). | None Known
|
| 308 |
+
Use Case Restrictions: | See [NVIDIA Open Model License](https://developer.download.nvidia.com/licenses/nvidia-open-model-license-agreement-june-2024.pdf)
|
| 309 |
+
Model and dataset restrictions: | The Principle of least privilege (PoLP) is applied limiting access for dataset generation and model development. Restrictions enforce dataset access during training, and dataset license constraints adhered to. Model checkpoints are made available on Hugging Face, and may become available on cloud providers' model catalog.
|
| 310 |
+
|
| 311 |
+
|
| 312 |
+
### Plus Plus (++) Promise
|
| 313 |
+
|
| 314 |
+
We value you, the datasets, the diversity they represent, and what we have been entrusted with. This model and its associated data have been:
|
| 315 |
+
* Verified to comply with current applicable disclosure laws, regulations, and industry standards.
|
| 316 |
+
* Verified to comply with applicable privacy labeling requirements.
|
| 317 |
+
* Annotated to describe the collector/source (NVIDIA or a third-party).
|
| 318 |
+
* Characterized for technical limitations.
|
| 319 |
+
* Reviewed to ensure proper disclosure is accessible to, maintained for, and in compliance with NVIDIA data subjects and their requests.
|
| 320 |
+
* Reviewed before release.
|
| 321 |
+
* Tagged for known restrictions and potential safety implications.
|
| 322 |
+
|
| 323 |
+
|
| 324 |
+
# Core Contributors
|
| 325 |
+
Fitsum Reda, Jinwei Gu, Xian Liu, Songwei Ge, Ting-Chun Wang, Haoxiang Wang, Ming-Yu Liu
|
Meissonic/pretrained_ckpts/Cosmos-0.1-Tokenizer-DV8x8x8/autoencoder.jit
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:ccf00856bc49c9e1c5ca6b01f47ef65d35bcdb37d58724641a3ea45751714724
|
| 3 |
+
size 213071541
|
Meissonic/pretrained_ckpts/Cosmos-0.1-Tokenizer-DV8x8x8/config.json
ADDED
|
@@ -0,0 +1,6 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"architectures": [
|
| 3 |
+
"CosmosTokenizer"
|
| 4 |
+
],
|
| 5 |
+
}
|
| 6 |
+
|
Meissonic/pretrained_ckpts/Cosmos-0.1-Tokenizer-DV8x8x8/decoder.jit
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:881f1f6317872fad3eeeaa1e595061aa3ee12590d14ce435ac9e9e5c883e797b
|
| 3 |
+
size 126792092
|
Meissonic/pretrained_ckpts/Cosmos-0.1-Tokenizer-DV8x8x8/encoder.jit
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:a014af9f0bfae97a29a5bf071ca58ac29be40d4ffae12ef08a11004b92f0fb8d
|
| 3 |
+
size 87042184
|
Meissonic/pretrained_ckpts/Cosmos-0.1-Tokenizer-DV8x8x8/model_config.yaml
ADDED
|
@@ -0,0 +1 @@
|
|
|
|
|
|
|
| 1 |
+
nemo_version: https://github.com/NVIDIA/NeMo/commit/6a5d4b5d19e05262a4182a83613753d424153a8f
|