SamPre commited on
Commit
604d2d3
·
verified ·
1 Parent(s): 4fc184b

Upload 3 files

Browse files
Files changed (3) hide show
  1. Dockerfile +17 -0
  2. app.py +343 -0
  3. requirements.txt +2 -0
Dockerfile ADDED
@@ -0,0 +1,17 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Read the doc: https://huggingface.co/docs/hub/spaces-sdks-docker
2
+ # you will also find guides on how best to write your Dockerfile
3
+
4
+ FROM python:3.9
5
+
6
+ RUN useradd -m -u 1000 user
7
+ USER user
8
+ ENV PATH="/home/user/.local/bin:$PATH"
9
+
10
+ WORKDIR /app
11
+
12
+ COPY --chown=user ./requirements.txt requirements.txt
13
+ RUN pip install --no-cache-dir --upgrade -r requirements.txt
14
+
15
+ COPY --chown=user . /app
16
+ CMD ["uvicorn", "app:app", "--host", "0.0.0.0", "--port", "7860"]
17
+
app.py ADDED
@@ -0,0 +1,343 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from fastapi import FastAPI
2
+ from fastapi.responses import HTMLResponse
3
+ from pydantic import BaseModel
4
+ from fastapi.staticfiles import StaticFiles
5
+
6
+
7
+ # Create FastAPI instance
8
+ app = FastAPI()
9
+
10
+ # Request model
11
+ class InputData(BaseModel):
12
+ text: str
13
+
14
+ # Mount the static folder
15
+ app.mount("/static", StaticFiles(directory="static"), name="static")
16
+
17
+ # Home Route with HTML page and description
18
+ @app.get("/", response_class=HTMLResponse)
19
+ async def home():
20
+ html_content = """
21
+ <html lang="en">
22
+ <head>
23
+ <meta charset="UTF-8">
24
+ <meta name="viewport" content="width=device-width, initial-scale=1.0">
25
+ <title>About the AI Model GPU Recommender</title>
26
+ <link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0-alpha1/dist/css/bootstrap.min.css" rel="stylesheet">
27
+ <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.4.0/css/all.min.css">
28
+ <style>
29
+ :root {
30
+ --primary-color: #4361ee;
31
+ --primary-dark: #3a56d4;
32
+ --secondary-color: #7209b7;
33
+ --accent-color: #f72585;
34
+ --light-bg: #f8f9fa;
35
+ --card-shadow: 0 8px 20px rgba(0, 0, 0, 0.08);
36
+ --section-shadow: 0 4px 12px rgba(0, 0, 0, 0.05);
37
+ --header-gradient: linear-gradient(135deg, var(--primary-color), var(--secondary-color));
38
+ }
39
+
40
+ body {
41
+ padding-top: 20px;
42
+ padding-bottom: 40px;
43
+ background-color: var(--light-bg);
44
+ color: #333;
45
+ font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
46
+ }
47
+
48
+ .content-container {
49
+ background: white;
50
+ padding: 30px;
51
+ border-radius: 16px;
52
+ box-shadow: var(--card-shadow);
53
+ margin-bottom: 30px;
54
+ }
55
+
56
+ .header {
57
+ margin-bottom: 40px;
58
+ padding: 40px 20px;
59
+ border-radius: 16px;
60
+ background: var(--header-gradient);
61
+ color: white;
62
+ box-shadow: var(--card-shadow);
63
+ }
64
+
65
+ .header h1 {
66
+ font-weight: 700;
67
+ font-size: 2.8rem;
68
+ margin-bottom: 10px;
69
+ }
70
+
71
+ .header .lead {
72
+ font-size: 1.3rem;
73
+ opacity: 0.9;
74
+ }
75
+
76
+ .section {
77
+ margin-bottom: 40px;
78
+ }
79
+
80
+ .section-title {
81
+ color: var(--primary-color);
82
+ font-weight: 600;
83
+ margin-bottom: 20px;
84
+ padding-bottom: 10px;
85
+ border-bottom: 2px solid var(--primary-color);
86
+ }
87
+
88
+ .section-content {
89
+ line-height: 1.7;
90
+ }
91
+
92
+ .benefit-card {
93
+ background-color: var(--light-bg);
94
+ border-radius: 12px;
95
+ padding: 20px;
96
+ margin-bottom: 20px;
97
+ border-left: 4px solid var(--primary-color);
98
+ box-shadow: var(--section-shadow);
99
+ transition: transform 0.2s, box-shadow 0.2s;
100
+ }
101
+
102
+ .benefit-card:hover {
103
+ transform: translateY(-5px);
104
+ box-shadow: 0 8px 15px rgba(0, 0, 0, 0.1);
105
+ }
106
+
107
+ .benefit-card h5 {
108
+ color: var(--primary-color);
109
+ font-weight: 600;
110
+ margin-bottom: 15px;
111
+ display: flex;
112
+ align-items: center;
113
+ }
114
+
115
+ .benefit-card h5 i {
116
+ margin-right: 10px;
117
+ }
118
+
119
+ .highlight {
120
+ background-color: rgba(67, 97, 238, 0.1);
121
+ padding: 3px 6px;
122
+ border-radius: 4px;
123
+ font-weight: 500;
124
+ color: var(--primary-dark);
125
+ }
126
+
127
+ .footer {
128
+ text-align: center;
129
+ padding: 15px;
130
+ color: #6c757d;
131
+ font-size: 0.9rem;
132
+ }
133
+
134
+ .btn-primary {
135
+ background-color: var(--primary-color);
136
+ border-color: var(--primary-color);
137
+ padding: 12px 25px;
138
+ border-radius: 8px;
139
+ font-weight: 600;
140
+ letter-spacing: 0.5px;
141
+ box-shadow: 0 4px 10px rgba(67, 97, 238, 0.3);
142
+ transition: all 0.3s;
143
+ }
144
+
145
+ .btn-primary:hover {
146
+ background-color: var(--primary-dark);
147
+ border-color: var(--primary-dark);
148
+ box-shadow: 0 6px 15px rgba(67, 97, 238, 0.4);
149
+ transform: translateY(-2px);
150
+ }
151
+
152
+ /* Animation */
153
+ @keyframes fadeIn {
154
+ from { opacity: 0; transform: translateY(20px); }
155
+ to { opacity: 1; transform: translateY(0); }
156
+ }
157
+
158
+ .animate-fade-in {
159
+ animation: fadeIn 0.5s ease-out forwards;
160
+ }
161
+
162
+ .delay-1 { animation-delay: 0.1s; }
163
+ .delay-2 { animation-delay: 0.2s; }
164
+ .delay-3 { animation-delay: 0.3s; }
165
+ .delay-4 { animation-delay: 0.4s; }
166
+ </style>
167
+ </head>
168
+ <body>
169
+ <div class="container">
170
+ <div class="row justify-content-center">
171
+ <div class="col-lg-10">
172
+ <div class="header text-center animate-fade-in">
173
+ <h1><i class="fas fa-microchip"></i> AI Model GPU Recommender</h1>
174
+ <p class="lead">A Critical Tool for AI Hardware Planning</p>
175
+ </div>
176
+
177
+ <div class="content-container animate-fade-in delay-1">
178
+ <div class="section">
179
+ <h2 class="section-title">Why Accurate Hardware Estimation Matters</h2>
180
+ <div class="section-content">
181
+ <p>The AI Model GPU Recommender provides essential guidance for one of the most challenging aspects of machine learning development: hardware planning. As AI models grow increasingly complex, selecting appropriate GPU hardware has become a critical but difficult decision with significant financial implications.</p>
182
+
183
+ <h3 class="mt-5 mb-4">Precision in Technical Requirements</h3>
184
+
185
+ <p>Our estimator brings precision to hardware planning through:</p>
186
+
187
+ <div class="row">
188
+ <div class="col-md-6">
189
+ <div class="benefit-card">
190
+ <h5><i class="fas fa-memory"></i> Accurate VRAM Calculation</h5>
191
+ <p>The tool employs sophisticated algorithms that consider model architecture, size, batch size, and precision to calculate memory requirements with high accuracy. For large language models (10B+ parameters), our calculations account for KV cache scaling, attention matrices, and architecture-specific memory patterns.</p>
192
+ </div>
193
+ </div>
194
+
195
+ <div class="col-md-6">
196
+ <div class="benefit-card">
197
+ <h5><i class="fas fa-brain"></i> Architecture-Specific Considerations</h5>
198
+ <p>Different model types (Transformers, CNNs, etc.) have vastly different memory access patterns and compute requirements. Our tool adjusts estimates based on architecture, recognizing that transformers with their attention mechanisms have different scaling properties than convolutional networks.</p>
199
+ </div>
200
+ </div>
201
+
202
+ <div class="col-md-6">
203
+ <div class="benefit-card">
204
+ <h5><i class="fas fa-cogs"></i> Training vs. Inference Optimization</h5>
205
+ <p>The recommender distinguishes between training and inference requirements, accounting for the additional memory needed during training for gradients, optimizer states, and activations. This prevents under-provisioning hardware for training workloads.</p>
206
+ </div>
207
+ </div>
208
+
209
+ <div class="col-md-6">
210
+ <div class="benefit-card">
211
+ <h5><i class="fas fa-calculator"></i> Precision-Aware Calculations</h5>
212
+ <p>By factoring in different numerical precision options (FP32, FP16, INT8), the tool provides realistic memory estimates that can help developers make informed trade-offs between accuracy and efficiency.</p>
213
+ </div>
214
+ </div>
215
+ </div>
216
+ </div>
217
+ </div>
218
+
219
+ <div class="section">
220
+ <h2 class="section-title">Financial Impact and Cost Optimization</h2>
221
+ <div class="section-content">
222
+ <p>Accurate hardware estimation directly translates to significant cost savings:</p>
223
+
224
+ <div class="row">
225
+ <div class="col-md-6">
226
+ <div class="benefit-card">
227
+ <h5><i class="fas fa-dollar-sign"></i> Capital Expenditure Reduction</h5>
228
+ <p>By recommending appropriately sized GPUs, the tool helps organizations avoid over-provisioning, which can save thousands to millions of dollars in hardware costs. For instance, purchasing an A100 ($10,000+) when an RTX 4090 (~$1,600) would suffice represents an <span class="highlight">84% cost reduction</span>.</p>
229
+ </div>
230
+ </div>
231
+
232
+ <div class="col-md-6">
233
+ <div class="benefit-card">
234
+ <h5><i class="fas fa-bolt"></i> Operational Cost Management</h5>
235
+ <p>Power consumption varies dramatically between GPU models (from 70W for a T4 to 700W for an H100). Our recommendations include power efficiency considerations that can result in substantial electricity savings over time.</p>
236
+ </div>
237
+ </div>
238
+
239
+ <div class="col-md-6">
240
+ <div class="benefit-card">
241
+ <h5><i class="fas fa-balance-scale"></i> Budget-Constrained Optimization</h5>
242
+ <p>The tool factors in budget constraints to find the most suitable GPU option within financial limitations, maximizing performance per dollar.</p>
243
+ </div>
244
+ </div>
245
+
246
+ <div class="col-md-6">
247
+ <div class="benefit-card">
248
+ <h5><i class="fas fa-expand-arrows-alt"></i> Scaling Guidance</h5>
249
+ <p>For very large models (20B+ parameters), the recommender provides guidance on multi-GPU setups and distributed training strategies, helping organizations plan their infrastructure scaling approach.</p>
250
+ </div>
251
+ </div>
252
+ </div>
253
+ </div>
254
+ </div>
255
+
256
+ <div class="section">
257
+ <h2 class="section-title">Real-World Value Proposition</h2>
258
+ <div class="section-content">
259
+ <p>The tangible benefits of the AI Model GPU Recommender include:</p>
260
+
261
+ <div class="row">
262
+ <div class="col-md-6">
263
+ <div class="benefit-card">
264
+ <h5><i class="fas fa-shield-alt"></i> Risk Mitigation</h5>
265
+ <p>Failed training runs due to out-of-memory errors represent wasted time and resources. Our accurate VRAM calculations help developers avoid these costly setbacks.</p>
266
+ </div>
267
+ </div>
268
+
269
+ <div class="col-md-6">
270
+ <div class="benefit-card">
271
+ <h5><i class="fas fa-rocket"></i> Time-to-Market Acceleration</h5>
272
+ <p>By quickly identifying the optimal hardware configuration, the tool eliminates lengthy trial-and-error processes that would otherwise delay development cycles.</p>
273
+ </div>
274
+ </div>
275
+
276
+ <div class="col-md-6">
277
+ <div class="benefit-card">
278
+ <h5><i class="fas fa-chart-line"></i> Hardware Utilization Optimization</h5>
279
+ <p>The suitability score helps identify GPUs that will achieve high utilization rates without waste, maximizing return on hardware investment.</p>
280
+ </div>
281
+ </div>
282
+
283
+ <div class="col-md-6">
284
+ <div class="benefit-card">
285
+ <h5><i class="fas fa-compass"></i> Strategic Planning Support</h5>
286
+ <p>The detailed analysis provides organizations with insights for long-term infrastructure planning, helping them prepare for model growth and evolution.</p>
287
+ </div>
288
+ </div>
289
+
290
+ <div class="col-md-12">
291
+ <div class="benefit-card">
292
+ <h5><i class="fas fa-users"></i> Democratization of AI Development</h5>
293
+ <p>By making hardware requirements more transparent, the tool helps smaller teams and organizations with limited AI experience make informed decisions about hardware investments.</p>
294
+ </div>
295
+ </div>
296
+ </div>
297
+ </div>
298
+ </div>
299
+
300
+ <div class="section">
301
+ <h2 class="section-title">Conclusion</h2>
302
+ <div class="section-content">
303
+ <p>In an era where AI model sizes are growing exponentially and hardware costs represent a significant portion of AI development budgets, the AI Model GPU Recommender serves as an invaluable planning tool. Its accuracy in technical requirements estimation and focus on cost-efficiency makes it essential for organizations seeking to optimize their AI hardware investments while ensuring their models have the resources needed to perform effectively.</p>
304
+
305
+ <div class="text-center mt-5 mb-3">
306
+ <a href="/" class="btn btn-primary btn-lg">
307
+ <i class="fas fa-tools me-2"></i> Try the GPU Recommender
308
+ </a>
309
+ </div>
310
+ </div>
311
+ </div>
312
+ </div>
313
+
314
+ <div class="footer">
315
+ <p>AI GPU Recommender Tool &copy; 2025 | <a href="/">Home</a> | <a href="/about">About</a></p>
316
+ </div>
317
+ </div>
318
+ </div>
319
+ </div>
320
+ <div class="container">
321
+
322
+ <Link Section>
323
+ <div class="link-container">
324
+ <p><a href="https://www.aicloudfarm.com" target="_blank">Try The Estimator</a></p>
325
+ </div>
326
+ </div>
327
+ <script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0-alpha1/dist/js/bootstrap.bundle.min.js"></script>
328
+ </body>
329
+ </html>
330
+
331
+
332
+
333
+
334
+ """
335
+ return HTMLResponse(content=html_content)
336
+
337
+ # Prediction Route
338
+ @app.post("/predict")
339
+ async def predict(data: InputData):
340
+ # Example: Simple text length prediction
341
+ result = {"prediction": len(data.text)}
342
+ return result
343
+
requirements.txt ADDED
@@ -0,0 +1,2 @@
 
 
 
1
+ fastapi
2
+ uvicorn[standard]