gregm123456 commited on
Commit
758e1bd
·
verified ·
1 Parent(s): 62a0dd4

Upload folder using huggingface_hub

Browse files
.gitattributes CHANGED
@@ -1,35 +1,3 @@
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
 
1
+ *.axmodel filter=lfs diff=lfs merge=lfs -text
2
+ assets/sample_serene.png filter=lfs diff=lfs merge=lfs -text
3
+ time_input_txt2img.npy filter=lfs diff=lfs merge=lfs -text
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
Disclaimer.md ADDED
@@ -0,0 +1,7 @@
 
 
 
 
 
 
 
 
1
+ # Disclaimer
2
+
3
+ All models exported by SD1.5-LCM.Axera have inherent limitations and may produce incorrect, harmful, offensive, or otherwise undesirable outputs. Users should exercise caution and must not rely on these models in critical or high-risk situations where their use could lead to personal injury, property damage, or significant loss. Examples of such situations include, but are not limited to, medical applications, control of software or hardware systems where failure could cause harm, and making important financial or legal decisions.
4
+
5
+ SD1.5-LCM.Axera is provided for open-source projects "as is" and comes with no express or implied warranties of any kind, including but not limited to implied warranties of merchantability, fitness for a particular purpose, or noninfringement. In no event shall the authors, contributors, or copyright holders be liable for any claim, damages, or other liability, whether in an action of contract, tort, or otherwise, arising from, out of, or in connection with the software or the use or other dealings in the software.
6
+
7
+ By using SD1.5-LCM.Axera you agree to these terms and conditions and acknowledge that you understand the potential risks associated with its use. You also agree to indemnify and hold the authors, contributors, and copyright holders harmless from any claims, damages, or liabilities arising from your use of SD1.5-LCM.Axera.
LICENSE ADDED
@@ -0,0 +1,88 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ Copyright (c) 2022 Robin Rombach and Patrick Esser and contributors
2
+
3
+ CreativeML Open RAIL-M
4
+ dated August 22, 2022
5
+
6
+ Section I: PREAMBLE
7
+
8
+ Multimodal generative models are being widely adopted and used, and have the potential to transform the way artists, among other individuals, conceive and benefit from AI or ML technologies as a tool for content creation.
9
+
10
+ Notwithstanding the current and potential benefits that these artifacts can bring to society at large, there are also concerns about potential misuses of them, either due to their technical limitations or ethical considerations.
11
+
12
+ In short, this license strives for both the open and responsible downstream use of the accompanying model. When it comes to the open character, we took inspiration from open source permissive licenses regarding the grant of IP rights. Referring to the downstream responsible use, we added use-based restrictions not permitting the use of the Model in very specific scenarios, in order for the licensor to be able to enforce the license in case potential misuses of the Model may occur. At the same time, we strive to promote open and responsible research on generative models for art and content generation.
13
+
14
+ Even though downstream derivative versions of the model could be released under different licensing terms, the latter will always have to include - at minimum - the same use-based restrictions as the ones in the original license (this license). We believe in the intersection between open and responsible AI development; thus, this License aims to strike a balance between both in order to enable responsible open-science in the field of AI.
15
+
16
+ This License governs the use of the model (and its derivatives) and is informed by the model card associated with the model.
17
+
18
+ NOW THEREFORE, You and Licensor agree as follows:
19
+
20
+ 1. Definitions
21
+
22
+ - "License" means the terms and conditions for use, reproduction, and Distribution as defined in this document.
23
+ - "Data" means a collection of information and/or content extracted from the dataset used with the Model, including to train, pretrain, or otherwise evaluate the Model. The Data is not licensed under this License.
24
+ - "Output" means the results of operating a Model as embodied in informational content resulting therefrom.
25
+ - "Model" means any accompanying machine-learning based assemblies (including checkpoints), consisting of learnt weights, parameters (including optimizer states), corresponding to the model architecture as embodied in the Complementary Material, that have been trained or tuned, in whole or in part on the Data, using the Complementary Material.
26
+ - "Derivatives of the Model" means all modifications to the Model, works based on the Model, or any other model which is created or initialized by transfer of patterns of the weights, parameters, activations or output of the Model, to the other model, in order to cause the other model to perform similarly to the Model, including - but not limited to - distillation methods entailing the use of intermediate data representations or methods based on the generation of synthetic data by the Model for training the other model.
27
+ - "Complementary Material" means the accompanying source code and scripts used to define, run, load, benchmark or evaluate the Model, and used to prepare data for training or evaluation, if any. This includes any accompanying documentation, tutorials, examples, etc, if any.
28
+ - "Distribution" means any transmission, reproduction, publication or other sharing of the Model or Derivatives of the Model to a third party, including providing the Model as a hosted service made available by electronic or other remote means - e.g. API-based or web access.
29
+ - "Licensor" means the copyright owner or entity authorized by the copyright owner that is granting the License, including the persons or entities that may have rights in the Model and/or distributing the Model.
30
+ - "You" (or "Your") means an individual or Legal Entity exercising permissions granted by this License and/or making use of the Model for whichever purpose and in any field of use, including usage of the Model in an end-use application - e.g. chatbot, translator, image generator.
31
+ - "Third Parties" means individuals or legal entities that are not under common control with Licensor or You.
32
+ - "Contribution" means any work of authorship, including the original version of the Model and any modifications or additions to that Model or Derivatives of the Model thereof, that is intentionally submitted to Licensor for inclusion in the Model by the copyright owner or by an individual or Legal Entity authorized to submit on behalf of the copyright owner. For the purposes of this definition, "submitted" means any form of electronic, verbal, or written communication sent to the Licensor or its representatives, including but not limited to communication on electronic mailing lists, source code control systems, and issue tracking systems that are managed by, or on behalf of, the Licensor for the purpose of discussing and improving the Model, but excluding communication that is conspicuously marked or otherwise designated in writing by the copyright owner as "Not a Contribution."
33
+ - "Contributor" means Licensor and any individual or Legal Entity on behalf of whom a Contribution has been received by Licensor and subsequently incorporated within the Model.
34
+
35
+ Section II: INTELLECTUAL PROPERTY RIGHTS
36
+
37
+ Both copyright and patent grants apply to the Model, Derivatives of the Model and Complementary Material. The Model and Derivatives of the Model are subject to additional terms as described in Section III.
38
+
39
+ 2. Grant of Copyright License. Subject to the terms and conditions of this License, each Contributor hereby grants to You a perpetual, worldwide, non-exclusive, no-charge, royalty-free, irrevocable copyright license to reproduce, prepare, publicly display, publicly perform, sublicense, and distribute the Complementary Material, the Model, and Derivatives of the Model.
40
+
41
+ 3. Grant of Patent License. Subject to the terms and conditions of this License and where and as applicable, each Contributor hereby grants to You a perpetual, worldwide, non-exclusive, no-charge, royalty-free, irrevocable (except as stated in this paragraph) patent license to make, have made, use, offer to sell, sell, import, and otherwise transfer the Model and the Complementary Material, where such license applies only to those patent claims licensable by such Contributor that are necessarily infringed by their Contribution(s) alone or by combination of their Contribution(s) with the Model to which such Contribution(s) was submitted. If You institute patent litigation against any entity (including a cross-claim or counterclaim in a lawsuit) alleging that the Model and/or a Contribution incorporated within the Model constitutes direct or contributory patent infringement, then any patent licenses granted to You under this License for the Model and/or Contribution shall terminate as of the date such litigation is filed.
42
+
43
+ Section III: CONDITIONS OF USAGE, DISTRIBUTION AND REDISTRIBUTION
44
+
45
+ 4. Distribution and Redistribution. You may host for Third Party remote access purposes (e.g. software-as-a-service), reproduce and distribute copies of the Model or Derivatives of the Model thereof in any medium, with or without modifications, provided that You meet the following conditions:
46
+ a. Use-based restrictions as referenced in paragraph 5 MUST be included as an enforceable provision by You in any type of legal agreement (e.g. a license) governing the use and/or distribution of the Model or Derivatives of the Model, and You shall give notice to subsequent users You Distribute to, that the Model or Derivatives of the Model are subject to paragraph 5. This provision does not apply to the use of Complementary Material.
47
+ b. You must give any Third Party recipients of the Model or Derivatives of the Model a copy of this License;
48
+ c. You must cause any modified files to carry prominent notices stating that You changed the files;
49
+ d. You must retain all copyright, patent, trademark, and attribution notices excluding those notices that do not pertain to any part of the Model, Derivatives of the Model.
50
+
51
+ You may add Your own copyright statement to Your modifications and may provide additional or different license terms and conditions - respecting paragraph 4.a. - for use, reproduction, or Distribution of Your modifications, or for any such Derivatives of the Model as a whole, provided Your use, reproduction, and Distribution of the Model otherwise complies with the conditions stated in this License.
52
+
53
+ 5. Use-based restrictions. The restrictions set forth in Attachment A are considered Use-based restrictions. Therefore You cannot use the Model and the Derivatives of the Model for the specified restricted uses. You may use the Model subject to this License, including only for lawful purposes and in accordance with the License. Use may include creating any content with, finetuning, updating, running, training, evaluating and/or reparametrizing the Model. You shall require all of Your users who use the Model or a Derivative of the Model to comply with the terms of this paragraph (paragraph 5).
54
+
55
+ 6. The Output You Generate. Except as set forth herein, Licensor claims no rights in the Output You generate using the Model. You are accountable for the Output you generate and its subsequent uses. No use of the output can contravene any provision as stated in the License.
56
+
57
+ Section IV: OTHER PROVISIONS
58
+
59
+ 7. Updates and Runtime Restrictions. To the maximum extent permitted by law, Licensor reserves the right to restrict (remotely or otherwise) usage of the Model in violation of this License, update the Model through electronic means, or modify the Output of the Model based on updates. You shall undertake reasonable efforts to use the latest version of the Model.
60
+
61
+ 8. Trademarks and related. Nothing in this License permits You to make use of Licensors’ trademarks, trade names, logos or to otherwise suggest endorsement or misrepresent the relationship between the parties; and any rights not expressly granted herein are reserved by the Licensors.
62
+
63
+ 9. Disclaimer of Warranty. Unless required by applicable law or agreed to in writing, Licensor provides the Model and the Complementary Material (and each Contributor provides its Contributions) on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied, including, without limitation, any warranties or conditions of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A PARTICULAR PURPOSE. You are solely responsible for determining the appropriateness of using or redistributing the Model, Derivatives of the Model, and the Complementary Material and assume any risks associated with Your exercise of permissions under this License.
64
+
65
+ 10. Limitation of Liability. In no event and under no legal theory, whether in tort (including negligence), contract, or otherwise, unless required by applicable law (such as deliberate and grossly negligent acts) or agreed to in writing, shall any Contributor be liable to You for damages, including any direct, indirect, special, incidental, or consequential damages of any character arising as a result of this License or out of the use or inability to use the Model and the Complementary Material (including but not limited to damages for loss of goodwill, work stoppage, computer failure or malfunction, or any and all other commercial damages or losses), even if such Contributor has been advised of the possibility of such damages.
66
+
67
+ 11. Accepting Warranty or Additional Liability. While redistributing the Model, Derivatives of the Model and the Complementary Material thereof, You may choose to offer, and charge a fee for, acceptance of support, warranty, indemnity, or other liability obligations and/or rights consistent with this License. However, in accepting such obligations, You may act only on Your own behalf and on Your sole responsibility, not on behalf of any other Contributor, and only if You agree to indemnify, defend, and hold each Contributor harmless for any liability incurred by, or claims asserted against, such Contributor by reason of your accepting any such warranty or additional liability.
68
+
69
+ 12. If any provision of this License is held to be invalid, illegal or unenforceable, the remaining provisions shall be unaffected thereby and remain valid as if such provision had not been set forth herein.
70
+
71
+ END OF TERMS AND CONDITIONS
72
+
73
+ Attachment A
74
+
75
+ Use Restrictions
76
+
77
+ You agree not to use the Model or Derivatives of the Model:
78
+ - In any way that violates any applicable national, federal, state, local or international law or regulation;
79
+ - For the purpose of exploiting, harming or attempting to exploit or harm minors in any way;
80
+ - To generate or disseminate verifiably false information and/or content with the purpose of harming others;
81
+ - To generate or disseminate personal identifiable information that can be used to harm an individual;
82
+ - To defame, disparage or otherwise harass others;
83
+ - For fully automated decision making that adversely impacts an individual’s legal rights or otherwise creates or modifies a binding, enforceable obligation;
84
+ - For any use intended to or which has the effect of discriminating against or harming individuals or groups based on online or offline social behavior or known or predicted personal or personality characteristics;
85
+ - To exploit any of the vulnerabilities of a specific group of persons based on their age, social, physical or mental characteristics, in order to materially distort the behavior of a person pertaining to that group in a manner that causes or is likely to cause that person or another person physical or psychological harm;
86
+ - For any use intended to or which has the effect of discriminating against individuals or groups based on legally protected characteristics or categories;
87
+ - To provide medical advice and medical results interpretation;
88
+ - To generate or disseminate information for the purpose to be used for administration of justice, law enforcement, immigration or asylum processes, such as predicting an individual will commit fraud/crime commitment (e.g. by text profiling, drawing causal relationships between assertions made in documents, indiscriminate and arbitrarily-targeted use).
LICENSE_AXERA ADDED
@@ -0,0 +1,32 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # License for Axera Conversion Tools and Scripts
2
+
3
+ This license applies to the conversion tools and scripts derived from the [sd1.5-lcm.axera](https://github.com/AXERA-TECH/sd1.5-lcm.axera) project.
4
+
5
+ BSD 3-Clause License
6
+
7
+ Copyright (c) 2024, BUG1989
8
+
9
+ Redistribution and use in source and binary forms, with or without
10
+ modification, are permitted provided that the following conditions are met:
11
+
12
+ 1. Redistributions of source code must retain the above copyright notice, this
13
+ list of conditions and the following disclaimer.
14
+
15
+ 2. Redistributions in binary form must reproduce the above copyright notice,
16
+ this list of conditions and the following disclaimer in the documentation
17
+ and/or other materials provided with the distribution.
18
+
19
+ 3. Neither the name of the copyright holder nor the names of its
20
+ contributors may be used to endorse or promote products derived from
21
+ this software without specific prior written permission.
22
+
23
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
24
+ AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
25
+ IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
26
+ DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
27
+ FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
28
+ DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
29
+ SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
30
+ CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
31
+ OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
32
+ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
README.md ADDED
@@ -0,0 +1,90 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ---
2
+ license: creativeml-openrail-m
3
+ tags:
4
+ - stable-diffusion
5
+ - stable-diffusion-diffusers
6
+ - text-to-image
7
+ - axera
8
+ - ax650n
9
+ - nPU
10
+ - raspberry-pi
11
+ - lcm
12
+ ---
13
+
14
+ # Realistic Vision V6.0 B1 (Axera Optimized)
15
+
16
+ This repository contains an **optimized derivative** of **Realistic Vision V6.0 B1**, fused with **LCM-LoRA** for high-performance inference on Axera hardware (AX650N / LLM8850).
17
+
18
+ **Note**: This repository is a compilation of existing open-source works. The maintainer of this repository is not the original creator of the base models or the conversion tools, but has performed the compilation, graph surgery, and quantization for the Axera NPU platform.
19
+
20
+ ## Model Description
21
+
22
+ - **Base Model**: [Realistic Vision V6.0 B1 (noVAE)](https://huggingface.co/SG161222/Realistic_Vision_V6.0_B1_noVAE)
23
+ - **VAE**: [sd-vae-ft-mse](https://huggingface.co/stabilityai/sd-vae-ft-mse)
24
+ - **Acceleration**: [LCM-LoRA (Fused)](https://huggingface.co/latent-consistency/lcm-lora-sdv1-5)
25
+ - **Target Hardware**: Axera AX650N / LLM8850 (NPU3)
26
+ - **Primary Hardware Targets**:
27
+ - **Raspberry Pi 5** (via Axera M.2 Accelerator Card)
28
+ - **M5Stack LLM-8850 Card** ([Documentation](https://docs.m5stack.com/en/ai_hardware/LLM-8850_Card))
29
+ - **Format**: Axera `.axmodel` (compiled via Pulsar2 v5.1)
30
+
31
+ ## Performance Metrics
32
+
33
+ Benchmarks performed on a **Raspberry Pi 5 (8GB)** with an **Axera AX650N M.2 Accelerator**:
34
+
35
+ | Component | Latency |
36
+ |-----------|---------|
37
+ | **Text Encoder** | ~14 ms |
38
+ | **U-Net (4 steps)** | ~1716 ms |
39
+ | **VAE Decoder** | ~936 ms |
40
+ | **Total Inference** | **~2.7 seconds** |
41
+ | **Model Loading** | ~15.7 seconds |
42
+
43
+ *Note: Inference time is for a 512x512 image with 4 steps.*
44
+
45
+ ## Sample Gallery
46
+
47
+ ![Sample Image](assets/sample_serene.png)
48
+ *Prompt: A serene portrait of an elderly man with silver hair and a warm smile, wearing traditional embroidered clothing, sitting in a lush greenhouse surrounded by tropical plants, soft morning sunlight, 8k, highly detailed, realistic*
49
+
50
+ ## Conversion Workflow Summary
51
+
52
+ 1. **Export**: Components exported from PyTorch/Diffusers to ONNX with LoRA fusion.
53
+ 2. **Graph Surgery**: Modified U-Net to expose the 1280-dim time embedding input (`/down_blocks.0/resnets.0/act_1/Mul_output_0`).
54
+ 3. **Quantization**: Compiled using Pulsar2 with u16/int8 mixed precision and representative calibration data.
55
+
56
+ ## Usage Instructions
57
+
58
+ To run this model on Axera hardware, you will need the `axengine` Python library.
59
+
60
+ ### 1. Install Dependencies
61
+ ```bash
62
+ pip install axengine transformers torch pillow numpy
63
+ ```
64
+
65
+ ### 2. Run Inference
66
+ Use the provided `sample_inference.py` script:
67
+ ```bash
68
+ python sample_inference.py --prompt "A beautiful landscape, oil painting"
69
+ ```
70
+
71
+ ## Credits and Citations
72
+
73
+ This work is made possible by the following upstream projects:
74
+
75
+ - **Realistic Vision V6.0 B1**: Created by [SG161222](https://huggingface.co/SG161222/Realistic_Vision_V6.0_B1_noVAE).
76
+ - **LCM-LoRA**: Developed by [latent-consistency](https://huggingface.co/latent-consistency/lcm-lora-sdv1-5).
77
+ - **Stable Diffusion 1.5**: Developed by [CompVis](https://huggingface.co/CompVis/stable-diffusion-v-1-5) and [Stability AI](https://stability.ai/).
78
+ - **Conversion Tools**: The [AXERA-TECH/sd1.5-lcm.axera](https://github.com/AXERA-TECH/sd1.5-lcm.axera) project (forked from [BUG1989](https://github.com/BUG1989/sd1.5-lcm.axera)).
79
+
80
+ **Optimization & Compilation**: The artifacts in this repository were compiled and optimized for the Axera NPU using the Pulsar2 toolchain.
81
+
82
+ ## Additional Resources
83
+
84
+ - **Project Repository**: [AXERA-TECH/sd1.5-lcm.axera](https://github.com/AXERA-TECH/sd1.5-lcm.axera) - Tools and scripts for Axera SD1.5 LCM deployment.
85
+ - **Toolchain Documentation**: [Axera Pulsar2 Docs](https://pulsar2-docs.readthedocs.io/zh-cn/latest/) - Official documentation for the Pulsar2 compilation toolchain.
86
+ - **Hardware Guide**: [M5Stack LLM-8850 Card](https://docs.m5stack.com/en/ai_hardware/LLM-8850_Card) - Specifications and quick start for the AX650N-based M.2 card.
87
+
88
+ ## Licensing and Restrictions
89
+
90
+ This model is subject to the [CreativeML Open RAIL-M](LICENSE) license. Please review the license for usage restrictions and safety guidelines.
assets/sample_serene.png ADDED

Git LFS Details

  • SHA256: cc5144cd6d67369b43453bde4b21790bd3ef171ad07329f6b56b7d7f6a97ab21
  • Pointer size: 131 Bytes
  • Size of remote file: 402 kB
sample_inference.py ADDED
@@ -0,0 +1,99 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import os
2
+ import time
3
+ import argparse
4
+ import numpy as np
5
+ import torch
6
+ import axengine
7
+ from PIL import Image
8
+ from transformers import CLIPTokenizer
9
+
10
+ def get_args():
11
+ parser = argparse.ArgumentParser(description="Axera Realistic Vision V6.0 B1 Inference")
12
+ parser.add_argument("--prompt", type=str, default="A serene portrait of an elderly man with silver hair, warm smile, greenhouse background, highly detailed", help="Text prompt")
13
+ parser.add_argument("--output", type=str, default="output.png", help="Output image path")
14
+ return parser.parse_args()
15
+
16
+ def get_alphas_cumprod():
17
+ betas = torch.linspace(0.00085 ** 0.5, 0.012 ** 0.5, 1000, dtype=torch.float32) ** 2
18
+ alphas = 1.0 - betas
19
+ alphas_cumprod = torch.cumprod(alphas, dim=0).detach().numpy()
20
+ final_alphas_cumprod = alphas_cumprod[0]
21
+ return alphas_cumprod, final_alphas_cumprod
22
+
23
+ def main():
24
+ args = get_args()
25
+
26
+ # Paths
27
+ base_dir = os.path.dirname(__file__)
28
+ tokenizer_dir = os.path.join(base_dir, "tokenizer")
29
+ text_encoder_model = os.path.join(base_dir, "sd15_text_encoder_sim.axmodel")
30
+ unet_model = os.path.join(base_dir, "unet.axmodel")
31
+ vae_decoder_model = os.path.join(base_dir, "vae_decoder.axmodel")
32
+ time_input_path = os.path.join(base_dir, "time_input_txt2img.npy")
33
+
34
+ print(f"Loading models...")
35
+ tokenizer = CLIPTokenizer.from_pretrained(tokenizer_dir)
36
+ text_encoder = axengine.InferenceSession(text_encoder_model)
37
+ unet_session = axengine.InferenceSession(unet_model)
38
+ vae_decoder = axengine.InferenceSession(vae_decoder_model)
39
+ time_embeddings = np.load(time_input_path)
40
+
41
+ alphas_cumprod, final_alphas_cumprod = get_alphas_cumprod()
42
+ timesteps = np.array([999, 759, 499, 259]).astype(np.int64)
43
+
44
+ # 1. Text Encoding
45
+ print(f"Encoding prompt: {args.prompt}")
46
+ text_inputs = tokenizer(args.prompt, padding="max_length", max_length=77, truncation=True, return_tensors="pt")
47
+ prompt_embeds = text_encoder.run(None, {"input_ids": text_inputs.input_ids.numpy().astype(np.int32)})[0]
48
+
49
+ # 2. Latent Initialization
50
+ latents = torch.randn([1, 4, 64, 64]).numpy()
51
+
52
+ # 3. UNet Denoising Loop (LCM 4-step)
53
+ print("Running UNet denoising...")
54
+ start_time = time.time()
55
+ for i, t in enumerate(timesteps):
56
+ noise_pred = unet_session.run(None, {
57
+ "sample": latents.astype(np.float32),
58
+ "/down_blocks.0/resnets.0/act_1/Mul_output_0": np.expand_dims(time_embeddings[i], axis=0),
59
+ "encoder_hidden_states": prompt_embeds
60
+ })[0]
61
+
62
+ # LCM Step Logic
63
+ alpha_prod_t = alphas_cumprod[t]
64
+ prev_t = timesteps[i + 1] if i < 3 else t
65
+ alpha_prod_t_prev = alphas_cumprod[prev_t] if i < 3 else final_alphas_cumprod
66
+
67
+ beta_prod_t = 1 - alpha_prod_t
68
+
69
+ # Boundary conditions
70
+ scaled_t = t * 10
71
+ c_skip = 0.5 ** 2 / (scaled_t ** 2 + 0.5 ** 2)
72
+ c_out = scaled_t / (scaled_t ** 2 + 0.5 ** 2) ** 0.5
73
+
74
+ pred_x0 = (latents - (beta_prod_t ** 0.5) * noise_pred) / (alpha_prod_t ** 0.5)
75
+ denoised = c_out * pred_x0 + c_skip * latents
76
+
77
+ if i < 3:
78
+ noise = torch.randn(noise_pred.shape).numpy()
79
+ latents = (alpha_prod_t_prev ** 0.5) * denoised + ((1 - alpha_prod_t_prev) ** 0.5) * noise
80
+ else:
81
+ latents = denoised
82
+
83
+ print(f"Denoising finished in {time.time() - start_time:.2f}s")
84
+
85
+ # 4. VAE Decoding
86
+ print("Decoding latents...")
87
+ latents = latents / 0.18215
88
+ image = vae_decoder.run(None, {"x": latents.astype(np.float32)})[0]
89
+
90
+ # 5. Post-processing & Save
91
+ image = np.transpose(image, (0, 2, 3, 1)).squeeze(0)
92
+ image = np.clip(image / 2 + 0.5, 0, 1)
93
+ image = (image * 255).astype("uint8")
94
+ pil_img = Image.fromarray(image)
95
+ pil_img.save(args.output)
96
+ print(f"Image saved to {args.output}")
97
+
98
+ if __name__ == "__main__":
99
+ main()
sd15_text_encoder_sim.axmodel ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:2b77862d29409a9fe7cf3ff3b94e6c9eb756cfd88c43c35d1bed10a5918deaf0
3
+ size 247693048
time_input_txt2img.npy ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:a48a430879c6a81a907889a6bb2b73f48cc9dc45b52f047ad2ee5c2dddcd2d10
3
+ size 20608
tokenizer/merges.txt ADDED
The diff for this file is too large to render. See raw diff
 
tokenizer/special_tokens_map.json ADDED
@@ -0,0 +1,24 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "bos_token": {
3
+ "content": "<|startoftext|>",
4
+ "lstrip": false,
5
+ "normalized": true,
6
+ "rstrip": false,
7
+ "single_word": false
8
+ },
9
+ "eos_token": {
10
+ "content": "<|endoftext|>",
11
+ "lstrip": false,
12
+ "normalized": true,
13
+ "rstrip": false,
14
+ "single_word": false
15
+ },
16
+ "pad_token": "<|endoftext|>",
17
+ "unk_token": {
18
+ "content": "<|endoftext|>",
19
+ "lstrip": false,
20
+ "normalized": true,
21
+ "rstrip": false,
22
+ "single_word": false
23
+ }
24
+ }
tokenizer/tokenizer_config.json ADDED
@@ -0,0 +1,33 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "add_prefix_space": false,
3
+ "bos_token": {
4
+ "__type": "AddedToken",
5
+ "content": "<|startoftext|>",
6
+ "lstrip": false,
7
+ "normalized": true,
8
+ "rstrip": false,
9
+ "single_word": false
10
+ },
11
+ "clean_up_tokenization_spaces": true,
12
+ "do_lower_case": true,
13
+ "eos_token": {
14
+ "__type": "AddedToken",
15
+ "content": "<|endoftext|>",
16
+ "lstrip": false,
17
+ "normalized": true,
18
+ "rstrip": false,
19
+ "single_word": false
20
+ },
21
+ "errors": "replace",
22
+ "model_max_length": 77,
23
+ "pad_token": "<|endoftext|>",
24
+ "tokenizer_class": "CLIPTokenizer",
25
+ "unk_token": {
26
+ "__type": "AddedToken",
27
+ "content": "<|endoftext|>",
28
+ "lstrip": false,
29
+ "normalized": true,
30
+ "rstrip": false,
31
+ "single_word": false
32
+ }
33
+ }
tokenizer/vocab.json ADDED
The diff for this file is too large to render. See raw diff
 
unet.axmodel ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:726d5248dc030f6cc622433388cdffd3d99aab1fad0f37b6157b5346700ad571
3
+ size 939725622
vae_decoder.axmodel ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:90517d282406fe4cab95ac99d4ea5c9cebed5a84497f2b0c0523a04ac962275b
3
+ size 69426618
vae_encoder.axmodel ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:0545fd7d7bd4847dcbfdf61e26711fa20759b616306baefd8338b19ea0570d5f
3
+ size 46032345