Create README.md
Browse files
README.md
ADDED
|
@@ -0,0 +1,131 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
---
|
| 2 |
+
license: apache-2.0
|
| 3 |
+
base_model:
|
| 4 |
+
- black-forest-labs/FLUX.1-dev
|
| 5 |
+
base_model_relation: quantized
|
| 6 |
+
---
|
| 7 |
+
|
| 8 |
+
# Elastic model: Fastest self-serving models. FLUX.1-schnell.
|
| 9 |
+
|
| 10 |
+
Elastic models are the models produced by TheStage AI ANNA: Automated Neural Networks Accelerator. ANNA allows you to control model size, latency and quality with a simple slider movement. For each model, ANNA produces a series of optimized models:
|
| 11 |
+
|
| 12 |
+
* __XL__: Mathematically equivalent neural network, optimized with our DNN compiler.
|
| 13 |
+
|
| 14 |
+
* __L__: Near lossless model, with less than 1% degradation obtained on corresponding benchmarks.
|
| 15 |
+
|
| 16 |
+
* __M__: Faster model, with accuracy degradation less than 1.5%.
|
| 17 |
+
|
| 18 |
+
* __S__: The fastest model, with accuracy degradation less than 2%.
|
| 19 |
+
|
| 20 |
+
|
| 21 |
+
__Goals of Elastic Models:__
|
| 22 |
+
|
| 23 |
+
* Provide the fastest models and service for self-hosting.
|
| 24 |
+
* Provide flexibility in cost vs quality selection for inference.
|
| 25 |
+
* Provide clear quality and latency benchmarks.
|
| 26 |
+
* Provide interface of HF libraries: transformers and diffusers with a single line of code.
|
| 27 |
+
* Provide models supported on a wide range of hardware, which are pre-compiled and require no JIT.
|
| 28 |
+
|
| 29 |
+
> It's important to note that specific quality degradation can vary from model to model. For instance, with an S model, you can have 0.5% degradation as well.
|
| 30 |
+
|
| 31 |
+
-----
|
| 32 |
+
|
| 33 |
+

|
| 34 |
+

|
| 35 |
+
|
| 36 |
+
## Inference
|
| 37 |
+
|
| 38 |
+
Currently, our demo model only supports 1024x1024 outputs without batching. This will be updated in the near future.
|
| 39 |
+
To infer our models, you just need to replace `diffusers` import with `elastic_models.diffusers`:
|
| 40 |
+
|
| 41 |
+
```python
|
| 42 |
+
import torch
|
| 43 |
+
from elastic_models.diffusers import FluxPipeline
|
| 44 |
+
|
| 45 |
+
mode_name = 'black-forest-labs/FLUX.1-dev'
|
| 46 |
+
hf_token = ''
|
| 47 |
+
device = torch.device("cuda")
|
| 48 |
+
|
| 49 |
+
pipeline = FluxPipeline.from_pretrained(
|
| 50 |
+
mode_name,
|
| 51 |
+
torch_dtype=torch.bfloat16,
|
| 52 |
+
token=hf_token
|
| 53 |
+
mode='S'
|
| 54 |
+
)
|
| 55 |
+
pipeline.to(device)
|
| 56 |
+
|
| 57 |
+
prompts = ["Kitten eating a banana"]
|
| 58 |
+
output = pipeline(prompt=prompts)
|
| 59 |
+
|
| 60 |
+
for prompt, output_image in zip(prompts, output.images):
|
| 61 |
+
output_image.save((prompt.replace(' ', '_') + '.png'))
|
| 62 |
+
```
|
| 63 |
+
|
| 64 |
+
### Installation
|
| 65 |
+
|
| 66 |
+
|
| 67 |
+
__System requirements:__
|
| 68 |
+
* GPUs: H100
|
| 69 |
+
* CPU: AMD, Intel
|
| 70 |
+
* Python: 3.10-3.12
|
| 71 |
+
|
| 72 |
+
|
| 73 |
+
To work with our models just run these lines in your terminal:
|
| 74 |
+
|
| 75 |
+
```shell
|
| 76 |
+
pip install thestage
|
| 77 |
+
pip install elastic_models==0.0.3\
|
| 78 |
+
--index-url https://thestage.jfrog.io/artifactory/api/pypi/pypi-thestage-ai-production/simple\
|
| 79 |
+
--extra-index-url https://pypi.nvidia.com\
|
| 80 |
+
--extra-index-url https://pypi.org/simple
|
| 81 |
+
|
| 82 |
+
pip install flash_attn==2.7.3 --no-build-isolation
|
| 83 |
+
pip uninstall apex
|
| 84 |
+
echo "{
|
| 85 |
+
"meta-llama/Llama-3.2-1B-Instruct": 6,
|
| 86 |
+
"mistralai/Mistral-7B-Instruct-v0.3": 7,
|
| 87 |
+
"black-forest-labs/FLUX.1-schnell": 1,
|
| 88 |
+
"black-forest-labs/FLUX.1-dev": 5
|
| 89 |
+
}" > model_name_id.json
|
| 90 |
+
export ELASTIC_MODEL_ID_MAPPING=./model_name_id.json
|
| 91 |
+
```
|
| 92 |
+
|
| 93 |
+
Then go to [app.thestage.ai](https://app.thestage.ai), login and generate API token from your profile page. Set up API token as follows:
|
| 94 |
+
|
| 95 |
+
```shell
|
| 96 |
+
thestage config set --api-token <YOUR_API_TOKEN>
|
| 97 |
+
```
|
| 98 |
+
|
| 99 |
+
Congrats, now you can use accelerated models!
|
| 100 |
+
|
| 101 |
+
----
|
| 102 |
+
|
| 103 |
+
## Benchmarks
|
| 104 |
+
|
| 105 |
+
Benchmarking is one of the most important procedures during model acceleration. We aim to provide clear performance metrics for models using our algorithms.
|
| 106 |
+
|
| 107 |
+
### Quality benchmarks
|
| 108 |
+
|
| 109 |
+
For quality evaluation we have used: PSNR, SSIM and CLIP score. PSNR and SSIM were computed using outputs of original model.
|
| 110 |
+
| Metric/Model | S | M | L | XL | Original |
|
| 111 |
+
|---------------|---|---|---|----|----------|
|
| 112 |
+
| PSNR | 29.9 | 30.2 | 31 | inf | inf |
|
| 113 |
+
| SSIM | 0.66 | 0.71 | 0.86 | 1.0 | 1.0 |
|
| 114 |
+
| CLIP | 11.5 | 11.6 | 11.8 | 11.9 | 11.9|
|
| 115 |
+
|
| 116 |
+
|
| 117 |
+
### Latency benchmarks
|
| 118 |
+
|
| 119 |
+
Time in seconds to generate one image 1024x1024
|
| 120 |
+
| GPU/Model | S | M | L | XL | Original |
|
| 121 |
+
|-----------|-----|---|---|----|----------|
|
| 122 |
+
| H100 | 0.5 | 0.58 | 0.65 | 0.75 | 1.05 |
|
| 123 |
+
| L40s | 1.4 | 1.6 | 1.9 | 2.1 | 2.5|
|
| 124 |
+
|
| 125 |
+
|
| 126 |
+
## Links
|
| 127 |
+
|
| 128 |
+
* __Platform__: [app.thestage.ai](https://app.thestage.ai)
|
| 129 |
+
<!-- * __Elastic models Github__: [app.thestage.ai](app.thestage.ai) -->
|
| 130 |
+
* __Subscribe for updates__: [TheStageAI X](https://x.com/TheStageAI)
|
| 131 |
+
* __Contact email__: [email protected]
|