hinairo commited on
Commit
bc4e65a
·
verified ·
1 Parent(s): bd52943

Update README.md

Browse files
Files changed (1) hide show
  1. README.md +401 -56
README.md CHANGED
@@ -2,40 +2,61 @@
2
  license: apache-2.0
3
  base_model:
4
  - black-forest-labs/FLUX.1-schnell
 
 
5
  ---
6
 
7
- # Elastic model: Fastest self-serving models. FLUX.1-schnell.
8
 
9
- 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:
10
 
11
- * __XL__: Mathematically equivalent neural network, optimized with our DNN compiler.
12
 
13
- * __L__: Near lossless model, with less than 1% degradation obtained on corresponding benchmarks.
14
 
15
- * __M__: Faster model, with accuracy degradation less than 1.5%.
 
 
 
16
 
17
- * __S__: The fastest model, with accuracy degradation less than 2%.
18
 
 
 
 
 
 
 
 
 
 
 
 
 
19
 
20
- __Goals of Elastic Models:__
21
 
22
- * Provide the fastest models and service for self-hosting.
23
- * Provide flexibility in cost vs quality selection for inference.
24
- * Provide clear quality and latency benchmarks.
25
- * Provide interface of HF libraries: transformers and diffusers with a single line of code.
26
- * Provide models supported on a wide range of hardware, which are pre-compiled and require no JIT.
27
 
28
- > 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.
29
 
30
- -----
 
 
 
31
 
32
- ![image/jpeg](https://cdn-uploads.huggingface.co/production/uploads/6487003ecd55eec571d14f96/ouz3FYQzG8C7Fl3XpNe6t.jpeg)
33
- ![image/png](https://cdn-uploads.huggingface.co/production/uploads/6799fc8e150f5a4014b030ca/Zt16Ce2uT1GNcMHLO-6Yv.png)
34
 
35
- ## Inference
36
 
37
- Currently, our demo model supports 1024x1024, 768x768 and 512x512 outputs without batching (for B200 - only 1024x1024). This will be updated in the near future.
38
- To infer our models, you just need to replace `diffusers` import with `elastic_models.diffusers`:
 
 
 
 
 
 
 
 
39
 
40
  ```python
41
  import torch
@@ -49,6 +70,8 @@ pipeline = FluxPipeline.from_pretrained(
49
  mode_name,
50
  torch_dtype=torch.bfloat16,
51
  token=hf_token,
 
 
52
  mode='S'
53
  )
54
  pipeline.to(device)
@@ -60,67 +83,389 @@ for prompt, output_image in zip(prompts, output.images):
60
  output_image.save((prompt.replace(' ', '_') + '.png'))
61
  ```
62
 
63
- ### Installation
64
 
 
65
 
66
- __System requirements:__
67
- * GPUs: H100, L40s, B200, 5090
68
- * CPU: AMD, Intel
69
- * Python: 3.10-3.12
70
 
 
71
 
72
- To work with our models just run these lines in your terminal:
73
 
74
- ```shell
75
- pip install thestage
76
- pip install 'thestage-elastic-models[nvidia]' --extra-index-url https://thestage.jfrog.io/artifactory/api/pypi/pypi-thestage-ai-production/simple
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
77
 
78
- # or for blackwell support
79
- pip install 'thestage-elastic-models[blackwell]' --extra-index-url https://thestage.jfrog.io/artifactory/api/pypi/pypi-thestage-ai-production/simple
80
- pip install -U --pre torch --index-url https://download.pytorch.org/whl/nightly/cu128
81
- pip install -U --pre torchvision --index-url https://download.pytorch.org/whl/nightly/cu128
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
82
 
83
- pip install flash_attn==2.7.3 --no-build-isolation
84
- pip uninstall apex
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
85
  ```
86
 
87
- 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:
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
88
 
89
  ```shell
90
- thestage config set --api-token <YOUR_API_TOKEN>
 
91
  ```
92
 
93
- Congrats, now you can use accelerated models!
94
 
95
- ----
96
 
97
- ## Benchmarks
 
 
 
 
 
 
 
 
 
 
 
 
98
 
99
- Benchmarking is one of the most important procedures during model acceleration. We aim to provide clear performance metrics for models using our algorithms.
100
 
101
- ### Quality benchmarks
102
 
103
- For quality evaluation we have used: PSNR, SSIM and CLIP score. PSNR and SSIM were computed using outputs of original model.
104
- | Metric/Model | S | M | L | XL | Original |
105
- |---------------|---|---|---|----|----------|
106
- | PSNR | 29.9 | 30.2 | 31 | inf | inf |
107
- | SSIM | 0.66 | 0.71 | 0.86 | 1.0 | 1.0 |
108
- | CLIP | 11.5 | 11.6 | 11.8 | 11.9 | 11.9|
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
109
 
 
110
 
111
- ### Latency benchmarks
 
 
112
 
113
- Time in seconds to generate one image 1024x1024
114
- | GPU/Model | S | M | L | XL | Original |
115
- |-----------|-----|---|---|----|----------|
116
- | H100 | 0.5 | 0.57 | 0.65 | 0.7 | 1.04 |
117
- | L40s | 1.4 | 1.6 | 1.9 | 2.1 | 2.5|
118
- | B200 | 0.3 | 0.4 | 0.42 | 0.43 | 0.74|
119
- | GeForce RTX 5090 | 0.94 | - | - | - | -|
120
 
121
  ## Links
122
 
123
  * __Platform__: [app.thestage.ai](https://app.thestage.ai)
124
- <!-- * __Elastic models Github__: [app.thestage.ai](app.thestage.ai) -->
125
  * __Subscribe for updates__: [TheStageAI X](https://x.com/TheStageAI)
126
  * __Contact email__: contact@thestage.ai
 
2
  license: apache-2.0
3
  base_model:
4
  - black-forest-labs/FLUX.1-schnell
5
+ base_model_relation: quantized
6
+ pipeline_tag: text-to-image
7
  ---
8
 
9
+ # Elastic model: FLUX.1-schnell
10
 
 
11
 
12
+ ## Overview
13
 
14
+ ElasticModels 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, routing different compression algorithms to different layers. For each model, we have produced a series of optimized models:
15
 
16
+ - **XL**: Mathematically equivalent neural network, optimized with our DNN compiler.
17
+ - **L**: Near lossless model, with less than 1% degradation obtained on corresponding benchmarks.
18
+ - **M**: Faster model, with accuracy degradation less than 1.5%.
19
+ - **S**: The fastest model, with accuracy degradation less than 2%.
20
 
21
+ Models can be accessed via TheStage AI Python SDK: ElasticModels, or deployed as Docker containers with REST API endpoints (see Deploy section).
22
 
23
+ ---
24
+
25
+ ## Installation
26
+
27
+ ### System Requirements
28
+
29
+ | **Property**| **Value** |
30
+ | --- | --- |
31
+ | **GPU** | L40s, RTX 5090, H100, B200 |
32
+ | **Python Version** | 3.10-3.12 |
33
+ | **CPU** | Intel/AMD x86_64 |
34
+ | **CUDA Version** | 12.8+ |
35
 
 
36
 
37
+ ### TheStage AI Access token setup
 
 
 
 
38
 
39
+ Install TheStage AI CLI and setup API token:
40
 
41
+ ```bash
42
+ pip install thestage
43
+ thestage config set --access-token <YOUR_ACCESS_TOKEN>
44
+ ```
45
 
46
+ ### ElasticModels installation
 
47
 
48
+ Install TheStage Elastic Models package:
49
 
50
+ ```bash
51
+ pip install 'thestage-elastic-models[nvidia]' \
52
+ --extra-index-url https://thestage.jfrog.io/artifactory/api/pypi/pypi-thestage-ai-production/simple
53
+ ```
54
+
55
+ ---
56
+
57
+ ## Usage example
58
+
59
+ Elastic Models provides the same interface as HuggingFace Diffusers. Here is an example of how to use the FLUX.1-schnell model:
60
 
61
  ```python
62
  import torch
 
70
  mode_name,
71
  torch_dtype=torch.bfloat16,
72
  token=hf_token,
73
+ # 'original' for original model
74
+ # 'S', 'M', 'L', 'XL' for accelerated models
75
  mode='S'
76
  )
77
  pipeline.to(device)
 
83
  output_image.save((prompt.replace(' ', '_') + '.png'))
84
  ```
85
 
 
86
 
87
+ ---
88
 
89
+ ## Quality Benchmarks
 
 
 
90
 
91
+ We have used PartiPrompts and DrawBench datasets to evaluate the quality of images generated by different sizes of FLUX.1-schnell models (S, M, L, XL) compared to the original model. The evaluation metrics include ARNIQA, CLIP IQA, PSNR, SSIM, and VQA Faithfulness.
92
 
93
+ ![Quality Benchmarking](https://cdn.thestage.ai/production/cms_file_upload/1773422411-00a75174-9e7c-42b8-b396-408d18e80544/Flux_Schnell_PartiPrompts_Evaluation.png)
94
 
95
+ ### Quality Benchmark Results
96
+
97
+ | **Metric/Model Size**| **S**| **M**| **L**| **XL**| **Original** |
98
+ | --- | --- | --- | --- | --- | --- |
99
+ | **ARNIQA (PartiPrompts)** | 62.8 | 63.2 | 64.3 | 65.2 | 65.2 |
100
+ | **ARNIQA (DrawBench)** | 61.4 | 62.5 | 63.9 | 64 | 64 |
101
+ | **CLIP IQA (PartiPrompts)** | 83.6 | 84.1 | 84.9 | 85.7 | 85.7 |
102
+ | **CLIP IQA (DrawBench)** | 82.7 | 84 | 84.4 | 84.5 | 84.5 |
103
+ | **VQA Faithfulness (PartiPrompts)** | 87 | 86 | 86.2 | 85.7 | 85.7 |
104
+ | **VQA Faithfulness (DrawBench)** | 73.8 | 72.7 | 74.4 | 74.3 | 74.3 |
105
+ | **PSNR (PartiPrompts)** | 29.9 | 30.2 | 31 | N/A | N/A |
106
+ | **SSIM (PartiPrompts)** | 0.66 | 0.71 | 0.86 | 1.0 | 1.0 |
107
+
108
+
109
+ ---
110
+
111
+ ## Datasets
112
+
113
+ - **PartiPrompts**: A benchmark dataset created by Google Research, containing 1,632 diverse and challenging prompts that test various aspects of text-to-image generation models. It includes categories such as abstract concepts, complex compositions, properties and attributes, counting and numbers, text rendering, artistic styles, and fine-grained details.
114
+
115
+ - **DrawBench**: A comprehensive benchmark dataset developed by Google Research, containing 200 carefully curated prompts designed to test specific capabilities and challenge areas of diffusion models. It includes categories such as colors, counting, conflicting requirements, DALL-E inspired prompts, detailed descriptions, misspellings, positional relationships, rare words, Reddit user prompts, and text generation.
116
+
117
+ ---
118
+
119
+ ## Metrics
120
+
121
+ - **ARNIQA**: No-reference image quality assessment metric that predicts perceptual quality without reference images.
122
+ - **CLIP_IQA**: No-reference image quality metric using contrastive learning to assess image quality without references.
123
+ - **VQA Faithfulness**: Metric measuring how accurately generated images represent the text prompts.
124
+ - **PSNR**: Peak Signal-to-Noise Ratio measuring similarity between generated by accelerated model and original model images.
125
+ - **SSIM**: Structural Similarity Index measuring perceptual similarity between generated by accelerated model and original model images.
126
+
127
+
128
+ ---
129
+
130
+ ## Latency Benchmarks
131
 
132
+ We have measured the latency of different sizes of FLUX.1-schnell model (S, M, L, XL, original) on various GPUs. The measurements were taken for generating images of size 1024x1024 pixels.
133
+
134
+ ![Latency Benchmarking](https://cdn.thestage.ai/production/cms_file_upload/1773422541-6712ce0b-a602-47fb-9468-1c0cd18417b5/Flux_Schnell_1024x1024_image_generation.png)
135
+
136
+ ### Latency Benchmark Results
137
+
138
+ Latency (in seconds) for generating a 1024x1024 image using different model sizes on various hardware setups.
139
+
140
+ | **GPU/Model Size**| **S**| **M**| **L**| **XL**| **Original** |
141
+ | --- | --- | --- | --- | --- | --- |
142
+ | **H100** | 0.51 | 0.51 | 0.51 | 0.71 | 1.04 |
143
+ | **L40s** | 1.59 | 1.6 | 1.6 | 2.19 | 2.5 |
144
+ | **B200** | 0.38 | 0.38 | 0.38 | 0.39 | 0.75 |
145
+ | **GeForce RTX 5090** | 1.19 | N/A | N/A | N/A | N/A |
146
+
147
+
148
+ ---
149
+
150
+ ## Benchmarking Methodology
151
+
152
+ The benchmarking was performed on a single GPU with a batch size of 1. Each model was run for 10 iterations, and the average latency was calculated.
153
+
154
+ > **Algorithm summary:**
155
+ > 1. Load the FLUX.1-schnell model with the specified size (S, M, L, XL, original).
156
+ > 2. Move the model to the GPU.
157
+ > 3. Prepare a sample prompt for image generation.
158
+ > 4. Run the model for a number of iterations (e.g., 10) and measure the time taken for each iteration. On each iteration:
159
+ > - Synchronize the GPU to flush any previous operations.
160
+ > - Record the start time.
161
+ > - Generate the image using the model.
162
+ > - Synchronize the GPU again.
163
+ > - Record the end time and calculate the latency for that iteration.
164
+ > 5. Calculate the average latency over all iterations.
165
+
166
+ ---
167
+
168
+ ## Reproduce benchmarking
169
+
170
+ ```python
171
+ import torch
172
+ from elastic_models.diffusers import FluxPipeline
173
+
174
+ mode_name = 'black-forest-labs/FLUX.1-schnell'
175
+ hf_token = ''
176
+ device = torch.device("cuda")
177
+
178
+ pipeline = FluxPipeline.from_pretrained(
179
+ mode_name,
180
+ torch_dtype=torch.bfloat16,
181
+ token=hf_token,
182
+ # 'original' for original model
183
+ # 'S', 'M', 'L', 'XL' for accelerated models
184
+ mode='S'
185
+ )
186
+ pipeline.to(device)
187
 
188
+ prompt = ["Kitten eating a banana"]
189
+ generate_kwargs={
190
+ "height": 1024,
191
+ "width": 1024,
192
+ "num_inference_steps": 4,
193
+ "cfg_scale": 0.0
194
+ }
195
+
196
+ import time
197
+
198
+ def evaluate_pipeline():
199
+ torch.cuda.synchronize()
200
+ start_time = time.time()
201
+ output = pipeline(
202
+ prompt=prompt,
203
+ **generate_kwargs
204
+ )
205
+ torch.cuda.synchronize()
206
+ end_time = time.time()
207
+
208
+ return end_time - start_time
209
+
210
+ # Warm-up
211
+ for _ in range(5):
212
+ evaluate_pipeline()
213
+
214
+ # Benchmarking
215
+ num_runs = 10
216
+ total_time = 0.0
217
+
218
+ for _ in range(num_runs):
219
+ latency = evaluate_pipeline()
220
+ total_time += latency
221
+
222
+ average_latency = total_time / num_runs
223
+ print(f"Average Latency over {num_runs} runs: {average_latency} seconds")
224
  ```
225
 
226
+
227
+ ---
228
+
229
+ ## Serving with Docker Image
230
+
231
+ For serving with Nvidia GPUs, we provide ready-to-go Docker containers with OpenAI-compatible API endpoints.
232
+ Using our containers you can set up an inference endpoint on any desired cloud/serverless providers as well as on-premise servers.
233
+ You can also use this container to run inference through TheStage AI platform.
234
+
235
+ ### Prebuilt image from ECR
236
+
237
+ | **GPU** | **Docker image name** |
238
+ | --- | --- |
239
+ | H100, L40s | `public.ecr.aws/i3f7g5s7/thestage/elastic-models:0.1.2-diffusers-nvidia-24.09b` |
240
+ | B200, RTX 5090 | `public.ecr.aws/i3f7g5s7/thestage/elastic-models:0.1.2-diffusers-blackwell-24.09b` |
241
+
242
+ Pull docker image for your Nvidia GPU and start inference container:
243
+
244
+ ```bash
245
+ docker pull <IMAGE_NAME>
246
+ ```
247
+ ```bash
248
+ docker run --rm -ti \
249
+ --name serving_thestage_model \
250
+ -p 8000:80 \
251
+ -e AUTH_TOKEN=<AUTH_TOKEN> \
252
+ -e MODEL_REPO=black-forest-labs/FLUX.1-schnell \
253
+ -e MODEL_SIZE=<MODEL_SIZE> \
254
+ -e MODEL_BATCH=<MAX_BATCH_SIZE> \
255
+ -e HUGGINGFACE_ACCESS_TOKEN=<HUGGINGFACE_ACCESS_TOKEN> \
256
+ -e THESTAGE_AUTH_TOKEN=<THESTAGE_ACCESS_TOKEN> \
257
+ -v /mnt/hf_cache:/root/.cache/huggingface \
258
+ <IMAGE_NAME_DEPENDING_ON_YOUR_GPU>
259
+ ```
260
+
261
+ | **Parameter** | **Description** |
262
+ |----------------------------|------------------------------------------------------------------------------------------------------|
263
+ | `<MODEL_SIZE>` | Available: S, M, L, XL. |
264
+ | `<MAX_BATCH_SIZE>` | Maximum batch size to process in parallel. |
265
+ | `<HUGGINGFACE_ACCESS_TOKEN>` | Hugging Face access token. |
266
+ | `<THESTAGE_ACCESS_TOKEN>` | TheStage token generated on the platform (Profile -> Access tokens). |
267
+ | `<AUTH_TOKEN>` | Token for endpoint authentication. You can set it to any random string; it must match the value used by the client. |
268
+ | `<IMAGE_NAME>` | Image name which you have pulled. |
269
+
270
+ ---
271
+
272
+ ## Invocation
273
+
274
+ You can invoke the endpoint using CURL as follows:
275
+
276
+ ```bash
277
+ curl -X POST <http://127.0.0.1:8000/v1/images/generations> \
278
+ -H "Authorization: Bearer <AUTH_TOKEN>" \
279
+ -H "Content-Type: application/json" \
280
+ -H "X-Model-Name: flux-1-schnell-<MODEL_SIZE>-bs<MAX_BATCH_SIZE>" \
281
+ -d '{
282
+ "prompt": "Cat eating banana",
283
+ "seed": 12,
284
+ "aspect_ratio": "1:1",
285
+ "guidance_scale": 6.5,
286
+ "num_inference_steps": 4
287
+ }' \
288
+ --output sunset.webp -D -
289
+ ```
290
+
291
+ Or using Python requests:
292
+
293
+ ```python
294
+ import requests
295
+ import json
296
+ url = "http://127.0.0.1:8000/v1/images/generations"
297
+ payload = json.dumps({
298
+ "prompt": "sunset",
299
+ "seed": 12,
300
+ "aspect_ratio": "1:1",
301
+ "guidance_scale": 6.5,
302
+ "num_inference_steps": 4
303
+ })
304
+ headers = {
305
+ 'Authorization': 'Bearer <AUTH_TOKEN>',
306
+ 'Content-Type': 'application/json',
307
+ 'X-Model-Name': 'flux-1-schnell-<MODEL_SIZE>-bs<MAX_BATCH_SIZE>'
308
+ }
309
+ response = requests.request("POST", url, headers=headers, data=payload)
310
+ with open("sunset.webp", "wb") as f:
311
+ f.write(response.content)
312
+ ```
313
+
314
+ Or using OpenAI python client:
315
+
316
+ ```python
317
+ import os, base64, pathlib, json
318
+ from openai import OpenAI
319
+
320
+ BASE_URL = "http://<your_ip>/v1"
321
+ API_KEY = ""
322
+ MODEL = "flux-1-schnell-<MODEL_SIZE>-bs<MAX_BATCH_SIZE>"
323
+
324
+ client = OpenAI(
325
+ api_key=API_KEY,
326
+ base_url=BASE_URL,
327
+ default_headers={"X-Model-Name": MODEL}
328
+ )
329
+
330
+ response = client.with_raw_response.images.generate(
331
+ model=MODEL,
332
+ prompt="Cat eating banana",
333
+ n=1,
334
+ extra_body={
335
+ "seed": 111,
336
+ "aspect_ratio": "1:1",
337
+ "guidance_scale": 3.5,
338
+ "num_inference_steps": 4
339
+ },
340
+ )
341
+
342
+ with open("thestage_image.webp", "wb") as f:
343
+ f.write(response.content)
344
+ ```
345
+
346
+ ---
347
+
348
+ ## Endpoint Parameters
349
+
350
+ ### Method
351
+
352
+ > **POST** `/v1/images/generations`
353
+
354
+ ### Header Parameters
355
+
356
+ > `Authorization`: `string`
357
+ >
358
+ > Bearer token for authentication. Should match the `AUTH_TOKEN` set during container startup.
359
+
360
+ > `Content-Type`: `string`
361
+ >
362
+ > Must be set to `application/json`.
363
+
364
+ > `X-Model-Name`: `string`
365
+ >
366
+ > Specifies the model to use for generation. Format: `flux-1-schnell-<size>-bs<batch_size>`, where `<size>` is one of `S`, `M`, `L`, `XL`, `original` and `<batch_size>` is the maximum batch size configured during container startup.
367
+
368
+ ### Input Body
369
+
370
+ > `prompt` : `string`
371
+ >
372
+ > The text prompt to generate an image for.
373
+
374
+ > `seed`: `int32`
375
+ >
376
+ > Random seed for generation.
377
+
378
+ > `num_inference_steps`: `int32`
379
+ >
380
+ > Number of diffusion steps to use for generation. Higher values yield better quality but take longer. Default is 4
381
+
382
+ > `aspect_ratio`: `string`
383
+ >
384
+ > Aspect ratio of the generated image. Supported values:
385
+ > ```
386
+ > "1:1": (1024, 1024),
387
+ > "16:9": (1280, 736),
388
+ > "21:9": (1280, 544),
389
+ > "3:2": (1248, 832),
390
+ > "2:3": (832, 1248),
391
+ > "4:3": (1184, 896),
392
+ > "3:4": (896, 1184),
393
+ > "5:4": (1152, 928),
394
+ > "4:5": (928, 1152),
395
+ > "9:16": (736, 1280),
396
+ > "9:21": (544, 1280)
397
+ > ```
398
+
399
+ > `guidance_scale`: float32
400
+ >
401
+ > Guidance scale for classifier-free guidance. Higher values increase adherence to the prompt.
402
+
403
+ ---
404
+
405
+ ## Deploy on Modal
406
+
407
+ For more details please use the tutorial [Modal deployment](https://docs.thestage.ai/tutorials/source/modal_thestage.html)
408
+
409
+ ### Clone modal serving code
410
 
411
  ```shell
412
+ git clone https://github.com/TheStageAI/ElasticModels.git
413
+ cd ElasticModels/examples/modal
414
  ```
415
 
416
+ ### Configuration of environment variables
417
 
418
+ Set your environment variables in `modal_serving.py`:
419
 
420
+ ```python
421
+ # modal_serving.py
422
+
423
+ ENVS = {
424
+ "MODEL_REPO": "black-forest-labs/FLUX.1-schnell",
425
+ "MODEL_BATCH": "4",
426
+ "THESTAGE_AUTH_TOKEN": "",
427
+ "HUGGINGFACE_ACCESS_TOKEN": "",
428
+ "PORT": "80",
429
+ "PORT_HEALTH": "80",
430
+ "HF_HOME": "/cache/huggingface",
431
+ }
432
+ ```
433
 
434
+ ### Configuration of GPUs
435
 
436
+ Set your desired GPU type and autoscaling variables in `modal_serving.py`:
437
 
438
+ ```python
439
+ # modal_serving.py
440
+
441
+ @app.function(
442
+ image=image,
443
+ gpu="B200",
444
+ min_containers=8,
445
+ max_containers=8,
446
+ timeout=10000,
447
+ ephemeral_disk=600 * 1024,
448
+ volumes={"/opt/project/.cache": HF_CACHE},
449
+ startup_timeout=60*20
450
+ )
451
+ @modal.web_server(
452
+ 80,
453
+ label="black-forest-labs/FLUX.1-schnell-test",
454
+ startup_timeout=60*20
455
+ )
456
+ def serve():
457
+ pass
458
+ ```
459
 
460
+ ### Run serving
461
 
462
+ ```shell
463
+ modal serve modal_serving.py
464
+ ```
465
 
 
 
 
 
 
 
 
466
 
467
  ## Links
468
 
469
  * __Platform__: [app.thestage.ai](https://app.thestage.ai)
 
470
  * __Subscribe for updates__: [TheStageAI X](https://x.com/TheStageAI)
471
  * __Contact email__: contact@thestage.ai