hinairo commited on
Commit
fe2fe7e
·
verified ·
1 Parent(s): e6ceda1

Update README.md

Browse files
Files changed (1) hide show
  1. README.md +398 -59
README.md CHANGED
@@ -1,45 +1,62 @@
1
  ---
2
- license: apache-2.0
3
  base_model:
4
  - black-forest-labs/FLUX.1-dev
5
  base_model_relation: quantized
6
  pipeline_tag: text-to-image
7
  ---
8
 
 
9
 
10
- # Elastic model: Fastest self-serving models. FLUX.1-dev.
11
 
12
- 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:
13
 
14
- * __XL__: Mathematically equivalent neural network, optimized with our DNN compiler.
15
 
16
- * __L__: Near lossless model, with less than 1% degradation obtained on corresponding benchmarks.
 
 
 
17
 
18
- * __M__: Faster model, with accuracy degradation less than 1.5%.
19
 
20
- * __S__: The fastest model, with accuracy degradation less than 2%.
 
 
 
 
 
 
 
 
 
 
 
21
 
22
 
23
- __Goals of Elastic Models:__
24
 
25
- * Provide the fastest models and service for self-hosting.
26
- * Provide flexibility in cost vs quality selection for inference.
27
- * Provide clear quality and latency benchmarks.
28
- * Provide interface of HF libraries: transformers and diffusers with a single line of code.
29
- * Provide models supported on a wide range of hardware, which are pre-compiled and require no JIT.
30
 
31
- > 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.
 
 
 
32
 
33
- -----
34
 
 
35
 
36
- ![image/png](https://cdn-uploads.huggingface.co/production/uploads/67991798ae62bd1f17cc22ed/2FXY0tqSGqZq76j5Tz4Vi.png)
37
- ![image/png](https://cdn-uploads.huggingface.co/production/uploads/6799fc8e150f5a4014b030ca/CuuzzA_csoRnzbaZq1U1x.png)
 
 
38
 
39
- ## Inference
40
 
41
- Currently, our demo model only supports 1024x1024, 768x768 and 512x512 outputs without batching (for B200 - only 1024x1024). This will be updated in the near future.
42
- To infer our models, you just need to replace `diffusers` import with `elastic_models.diffusers`:
 
43
 
44
  ```python
45
  import torch
@@ -53,6 +70,8 @@ pipeline = FluxPipeline.from_pretrained(
53
  mode_name,
54
  torch_dtype=torch.bfloat16,
55
  token=hf_token,
 
 
56
  mode='S'
57
  )
58
  pipeline.to(device)
@@ -64,69 +83,389 @@ for prompt, output_image in zip(prompts, output.images):
64
  output_image.save((prompt.replace(' ', '_') + '.png'))
65
  ```
66
 
67
- ### Installation
68
 
 
69
 
70
- __System requirements:__
71
- * GPUs: H100, L40s, B200, 5090
72
- * CPU: AMD, Intel
73
- * Python: 3.10-3.12
74
 
 
75
 
76
- To work with our models just run these lines in your terminal:
77
 
78
- ```shell
79
- pip install thestage
80
- pip install 'thestage-elastic-models[nvidia]' --extra-index-url https://thestage.jfrog.io/artifactory/api/pypi/pypi-thestage-ai-production/simple
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
81
 
82
- # or for blackwell support
83
- pip install 'thestage-elastic-models[blackwell]' --extra-index-url https://thestage.jfrog.io/artifactory/api/pypi/pypi-thestage-ai-production/simple
84
- pip install -U --pre torch --index-url https://download.pytorch.org/whl/nightly/cu128
85
- pip install -U --pre torchvision --index-url https://download.pytorch.org/whl/nightly/cu128
86
 
 
87
 
88
- pip install flash_attn==2.7.3 --no-build-isolation
89
- pip uninstall apex
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
90
  ```
91
 
92
- 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:
93
 
94
- ```shell
95
- thestage config set --api-token <YOUR_API_TOKEN>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
96
  ```
97
 
98
- Congrats, now you can use accelerated models!
 
 
99
 
100
- ----
101
 
102
- ## Benchmarks
103
 
104
- Benchmarking is one of the most important procedures during model acceleration. We aim to provide clear performance metrics for models using our algorithms.
105
 
106
- ### Quality benchmarks
 
 
107
 
108
- For quality evaluation we have used: PSNR, SSIM and CLIP score. PSNR and SSIM were computed using outputs of original model.
109
- | Metric/Model | S | M | L | XL | Original |
110
- |---------------|---|---|---|----|----------|
111
- | PSNR | 30.22 | 30.24 | 30.38 | inf | inf |
112
- | SSIM | 0.72 | 0.72 | 0.76 | 1.0 | 1.0 |
113
- | CLIP | 12.49 | 12.51 | 12.69 | 12.41 | 12.41|
114
 
 
 
 
115
 
116
- ### Latency benchmarks
117
 
118
- Time in seconds to generate one image 1024x1024
119
- | GPU/Model | S | M | L | XL | Original |
120
- |-----------|-----|---|---|----|----------|
121
- | H100 | 2.71 | 3.0 | 3.18 | 4.17 | 6.46 |
122
- | L40s | 8.5 | 9.29 | 9.29 | 13.2 | 16|
123
- | B200 | 1.89 | 2.04 | 2.12 | 2.23 | 4.4|
124
- | GeForce RTX 5090 | 5.53 | - | - | - | -|
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
125
 
126
 
127
  ## Links
128
 
129
  * __Platform__: [app.thestage.ai](https://app.thestage.ai)
130
- <!-- * __Elastic models Github__: [app.thestage.ai](app.thestage.ai) -->
131
  * __Subscribe for updates__: [TheStageAI X](https://x.com/TheStageAI)
132
- * __Contact email__: contact@thestage.ai
 
1
  ---
2
+ license: other
3
  base_model:
4
  - black-forest-labs/FLUX.1-dev
5
  base_model_relation: quantized
6
  pipeline_tag: text-to-image
7
  ---
8
 
9
+ # Elastic model: FLUX.1-dev
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-dev 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-dev 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/1773422498-f1062c24-2904-4d56-b05b-a4d62f629a26/Flux_Dev_PartiPrompts_Evaluation.png)
94
 
95
+ ### Quality Benchmark Results
96
+
97
+ | **Metric/Model Size**| **S**| **M**| **L**| **XL**| **Original** |
98
+ | --- | --- | --- | --- | --- | --- |
99
+ | **ARNIQA (PartiPrompts)** | 64.1 | 63.2 | 61.9 | 66.8 | 66.9 |
100
+ | **ARNIQA (DrawBench)** | 64.3 | 63.5 | 63.6 | 68.2 | 68.5 |
101
+ | **CLIP IQA (PartiPrompts)** | 85.5 | 86.4 | 83.8 | 88.3 | 87.9 |
102
+ | **CLIP IQA (DrawBench)** | 86.4 | 86.5 | 84.5 | 89.5 | 90.0 |
103
+ | **VQA Faithfulness (PartiPrompts)** | 87.5 | 85.5 | 85.5 | 85.5 | 88.6 |
104
+ | **VQA Faithfulness (DrawBench)** | 69.3 | 64.7 | 64.8 | 67.8 | 65.2 |
105
+ | **PSNR (PartiPrompts)** | 30.22 | 30.24 | 30.38 | N/A | N/A |
106
+ | **SSIM (PartiPrompts)** | 0.72 | 0.72 | 0.76 | 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-dev 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/1773422520-f2e2dedd-f475-4609-8277-b28fe5629623/Flux_Dev_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** | 2.88 | 3.06 | 3.25 | 4.18 | 6.46 |
143
+ | **L40s** | 9.22 | 10.07 | 10.67 | 14.39 | 16 |
144
+ | **B200** | 1.93 | 2.04 | 2.15 | 2.77 | 4.52 |
145
+ | **GeForce RTX 5090** | 5.79 | 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-dev 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-dev'
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": 28,
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-dev \
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-dev-<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": 28
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": 28
303
+ })
304
+ headers = {
305
+ 'Authorization': 'Bearer <AUTH_TOKEN>',
306
+ 'Content-Type': 'application/json',
307
+ 'X-Model-Name': 'flux-1-dev-<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-dev-<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": 28
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-dev-<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 28
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-dev",
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-dev-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