Spaces:
Running
Running
[node] estimation
Browse files- README.md +131 -1
- app.py +361 -0
- requirements.txt +13 -0
README.md
CHANGED
@@ -1,6 +1,6 @@
|
|
1 |
---
|
2 |
title: Tp 1 Dgx Node Estimator
|
3 |
-
emoji:
|
4 |
colorFrom: purple
|
5 |
colorTo: yellow
|
6 |
sdk: gradio
|
@@ -12,3 +12,133 @@ short_description: for NVIDIA TRDC estimation
|
|
12 |
---
|
13 |
|
14 |
Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
---
|
2 |
title: Tp 1 Dgx Node Estimator
|
3 |
+
emoji: ⚙️
|
4 |
colorFrom: purple
|
5 |
colorTo: yellow
|
6 |
sdk: gradio
|
|
|
12 |
---
|
13 |
|
14 |
Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
|
15 |
+
|
16 |
+
# 🚀 H100 Node & CUDA Version Estimator
|
17 |
+
|
18 |
+
An interactive Gradio application for estimating H100 GPU node requirements and CUDA version recommendations based on your machine learning workload specifications.
|
19 |
+
|
20 |
+
## Features
|
21 |
+
|
22 |
+
- **Model Support**: Supports popular models including LLaMA-2/3/3.1, Nemotron-4, and Qwen2/2.5 variants
|
23 |
+
- **Smart Estimation**: Calculates memory requirements including model weights, KV cache, and operational overhead
|
24 |
+
- **Use Case Optimization**: Provides different estimates for inference, training, and fine-tuning scenarios
|
25 |
+
- **Precision Support**: Handles different precision formats (FP32, FP16, BF16, INT8, INT4)
|
26 |
+
- **Interactive Visualizations**: Memory breakdown charts and node utilization graphs
|
27 |
+
- **CUDA Recommendations**: Suggests optimal CUDA versions and driver requirements
|
28 |
+
|
29 |
+
## Installation
|
30 |
+
|
31 |
+
1. Clone the repository:
|
32 |
+
```bash
|
33 |
+
git clone <repository-url>
|
34 |
+
cd tp-1-dgx-node-estimator
|
35 |
+
```
|
36 |
+
|
37 |
+
2. Install dependencies:
|
38 |
+
```bash
|
39 |
+
pip install -r requirements.txt
|
40 |
+
```
|
41 |
+
|
42 |
+
## Usage
|
43 |
+
|
44 |
+
1. Run the application:
|
45 |
+
```bash
|
46 |
+
python app.py
|
47 |
+
```
|
48 |
+
|
49 |
+
2. Open your browser and navigate to `http://localhost:7860`
|
50 |
+
|
51 |
+
3. Configure your parameters:
|
52 |
+
- **Model**: Select from supported models (LLaMA, Nemotron, Qwen2)
|
53 |
+
- **Input Tokens**: Number of input tokens per request
|
54 |
+
- **Output Tokens**: Number of output tokens per request
|
55 |
+
- **Batch Size**: Number of concurrent requests
|
56 |
+
- **Use Case**: Choose between inference, training, or fine-tuning
|
57 |
+
- **Precision**: Select model precision/quantization level
|
58 |
+
|
59 |
+
4. Click "💡 Estimate Requirements" to get your recommendations
|
60 |
+
|
61 |
+
## Key Calculations
|
62 |
+
|
63 |
+
### Memory Estimation
|
64 |
+
- **Model Memory**: Base model weights adjusted for precision
|
65 |
+
- **KV Cache**: Calculated based on sequence length and model architecture
|
66 |
+
- **Overhead**: Use-case specific multipliers:
|
67 |
+
- Inference: 1.2x (20% overhead)
|
68 |
+
- Training: 3.0x (gradients + optimizer states)
|
69 |
+
- Fine-tuning: 2.5x (moderate overhead)
|
70 |
+
|
71 |
+
### Node Calculation
|
72 |
+
- **H100 Memory**: 80GB HBM3 per GPU (90% usable)
|
73 |
+
- **Model Parallelism**: Automatic consideration for large models
|
74 |
+
- **Memory Efficiency**: Optimal distribution across nodes
|
75 |
+
|
76 |
+
## Example Scenarios
|
77 |
+
|
78 |
+
| Model | Tokens (In/Out) | Batch Size | Use Case | Precision | Estimated Nodes |
|
79 |
+
|-------|----------------|------------|----------|-----------|----------------|
|
80 |
+
| LLaMA-3-8B | 2048/512 | 1 | Inference | FP16 | 1 |
|
81 |
+
| LLaMA-3-70B | 4096/1024 | 4 | Inference | FP16 | 3-4 |
|
82 |
+
| Qwen2.5-72B | 8192/2048 | 2 | Fine-tuning | BF16 | 4-5 |
|
83 |
+
| Nemotron-4-340B | 2048/1024 | 1 | Inference | INT8 | 6-8 |
|
84 |
+
|
85 |
+
## CUDA Recommendations
|
86 |
+
|
87 |
+
The application provides tailored CUDA version recommendations:
|
88 |
+
|
89 |
+
- **Optimal**: CUDA 12.4 + cuDNN 8.9+
|
90 |
+
- **Recommended**: CUDA 12.1+ + cuDNN 8.7+
|
91 |
+
- **Minimum**: CUDA 11.8 + cuDNN 8.5+
|
92 |
+
|
93 |
+
## Output Features
|
94 |
+
|
95 |
+
### 📊 Detailed Analysis
|
96 |
+
- Complete memory breakdown
|
97 |
+
- Parameter counts and model specifications
|
98 |
+
- Step-by-step calculation explanation
|
99 |
+
|
100 |
+
### 🔧 CUDA Recommendations
|
101 |
+
- Version compatibility matrix
|
102 |
+
- Driver requirements
|
103 |
+
- Compute capability information
|
104 |
+
|
105 |
+
### 📈 Memory Utilization
|
106 |
+
- Visual memory breakdown (pie chart)
|
107 |
+
- Node utilization distribution (bar chart)
|
108 |
+
- Efficiency metrics
|
109 |
+
|
110 |
+
## Technical Details
|
111 |
+
|
112 |
+
### Supported Models
|
113 |
+
- **LLaMA**: 2-7B, 2-13B, 2-70B, 3-8B, 3-70B, 3.1-8B, 3.1-70B, 3.1-405B
|
114 |
+
- **Nemotron**: 4-15B, 4-340B
|
115 |
+
- **Qwen2**: 0.5B, 1.5B, 7B, 72B
|
116 |
+
- **Qwen2.5**: 0.5B, 1.5B, 7B, 14B, 32B, 72B
|
117 |
+
|
118 |
+
### Precision Impact
|
119 |
+
- **FP32**: Full precision (4 bytes per parameter)
|
120 |
+
- **FP16/BF16**: Half precision (2 bytes per parameter)
|
121 |
+
- **INT8**: 8-bit quantization (1 byte per parameter)
|
122 |
+
- **INT4**: 4-bit quantization (0.5 bytes per parameter)
|
123 |
+
|
124 |
+
## Limitations
|
125 |
+
|
126 |
+
- Estimates are approximate and may vary based on:
|
127 |
+
- Specific model implementation details
|
128 |
+
- Framework overhead (PyTorch, TensorFlow, etc.)
|
129 |
+
- Hardware configuration
|
130 |
+
- Network topology for multi-node setups
|
131 |
+
|
132 |
+
## Contributing
|
133 |
+
|
134 |
+
Feel free to submit issues and enhancement requests!
|
135 |
+
|
136 |
+
## License
|
137 |
+
|
138 |
+
This project is licensed under the MIT License - see the LICENSE file for details.
|
139 |
+
|
140 |
+
## Notes
|
141 |
+
|
142 |
+
- For production deployments, consider adding a 10-20% buffer to estimates
|
143 |
+
- Network bandwidth and storage requirements are not included in calculations
|
144 |
+
- Estimates assume optimal memory layout and efficient implementations
|
app.py
ADDED
@@ -0,0 +1,361 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import gradio as gr
|
2 |
+
import pandas as pd
|
3 |
+
import matplotlib.pyplot as plt
|
4 |
+
import numpy as np
|
5 |
+
import json
|
6 |
+
from typing import Dict, Tuple, List
|
7 |
+
|
8 |
+
# Model specifications (approximate parameter counts and memory requirements)
|
9 |
+
MODEL_SPECS = {
|
10 |
+
"LLaMA-2-7B": {"params": 7e9, "base_memory_gb": 14},
|
11 |
+
"LLaMA-2-13B": {"params": 13e9, "base_memory_gb": 26},
|
12 |
+
"LLaMA-2-70B": {"params": 70e9, "base_memory_gb": 140},
|
13 |
+
"LLaMA-3-8B": {"params": 8e9, "base_memory_gb": 16},
|
14 |
+
"LLaMA-3-70B": {"params": 70e9, "base_memory_gb": 140},
|
15 |
+
"LLaMA-3.1-8B": {"params": 8e9, "base_memory_gb": 16},
|
16 |
+
"LLaMA-3.1-70B": {"params": 70e9, "base_memory_gb": 140},
|
17 |
+
"LLaMA-3.1-405B": {"params": 405e9, "base_memory_gb": 810},
|
18 |
+
"Nemotron-4-340B": {"params": 340e9, "base_memory_gb": 680},
|
19 |
+
"Nemotron-4-15B": {"params": 15e9, "base_memory_gb": 30},
|
20 |
+
"Qwen2-0.5B": {"params": 0.5e9, "base_memory_gb": 1},
|
21 |
+
"Qwen2-1.5B": {"params": 1.5e9, "base_memory_gb": 3},
|
22 |
+
"Qwen2-7B": {"params": 7e9, "base_memory_gb": 14},
|
23 |
+
"Qwen2-72B": {"params": 72e9, "base_memory_gb": 144},
|
24 |
+
"Qwen2.5-0.5B": {"params": 0.5e9, "base_memory_gb": 1},
|
25 |
+
"Qwen2.5-1.5B": {"params": 1.5e9, "base_memory_gb": 3},
|
26 |
+
"Qwen2.5-7B": {"params": 7e9, "base_memory_gb": 14},
|
27 |
+
"Qwen2.5-14B": {"params": 14e9, "base_memory_gb": 28},
|
28 |
+
"Qwen2.5-32B": {"params": 32e9, "base_memory_gb": 64},
|
29 |
+
"Qwen2.5-72B": {"params": 72e9, "base_memory_gb": 144},
|
30 |
+
}
|
31 |
+
|
32 |
+
# H100 specifications
|
33 |
+
H100_MEMORY_GB = 80
|
34 |
+
H100_COMPUTE_CAPABILITY = "9.0"
|
35 |
+
|
36 |
+
# CUDA version recommendations based on model and use case
|
37 |
+
CUDA_RECOMMENDATIONS = {
|
38 |
+
"inference": {
|
39 |
+
"recommended": "12.1+",
|
40 |
+
"minimum": "11.8",
|
41 |
+
"optimal": "12.4"
|
42 |
+
},
|
43 |
+
"training": {
|
44 |
+
"recommended": "12.1+",
|
45 |
+
"minimum": "11.8",
|
46 |
+
"optimal": "12.4"
|
47 |
+
},
|
48 |
+
"fine_tuning": {
|
49 |
+
"recommended": "12.1+",
|
50 |
+
"minimum": "11.8",
|
51 |
+
"optimal": "12.4"
|
52 |
+
}
|
53 |
+
}
|
54 |
+
|
55 |
+
def calculate_kv_cache_memory(num_tokens: int, model_params: float, num_layers: int = None) -> float:
|
56 |
+
"""Calculate KV cache memory requirements in GB"""
|
57 |
+
if num_layers is None:
|
58 |
+
# Estimate layers based on model size
|
59 |
+
if model_params < 1e9:
|
60 |
+
num_layers = 24
|
61 |
+
elif model_params < 10e9:
|
62 |
+
num_layers = 32
|
63 |
+
elif model_params < 100e9:
|
64 |
+
num_layers = 80
|
65 |
+
else:
|
66 |
+
num_layers = 96
|
67 |
+
|
68 |
+
# KV cache memory per token (approximate)
|
69 |
+
# 2 (K + V) * 2 (fp16) * hidden_dim * num_layers
|
70 |
+
hidden_dim = int((model_params / (num_layers * 4)) ** 0.5) * 64 # Rough estimate
|
71 |
+
kv_memory_per_token = 2 * 2 * hidden_dim * num_layers / (1024**3) # GB
|
72 |
+
|
73 |
+
return num_tokens * kv_memory_per_token
|
74 |
+
|
75 |
+
def estimate_h100_nodes(
|
76 |
+
model_name: str,
|
77 |
+
input_tokens: int,
|
78 |
+
output_tokens: int,
|
79 |
+
batch_size: int,
|
80 |
+
use_case: str,
|
81 |
+
precision: str
|
82 |
+
) -> Tuple[int, str, Dict]:
|
83 |
+
"""
|
84 |
+
Estimate the number of H100 nodes required
|
85 |
+
|
86 |
+
Returns:
|
87 |
+
- Number of nodes required
|
88 |
+
- Detailed explanation
|
89 |
+
- Dictionary with breakdown
|
90 |
+
"""
|
91 |
+
|
92 |
+
if model_name not in MODEL_SPECS:
|
93 |
+
return 1, f"Model {model_name} not found in specifications", {}
|
94 |
+
|
95 |
+
model_spec = MODEL_SPECS[model_name]
|
96 |
+
base_memory = model_spec["base_memory_gb"]
|
97 |
+
|
98 |
+
# Adjust memory based on precision
|
99 |
+
precision_multiplier = {
|
100 |
+
"FP32": 1.0,
|
101 |
+
"FP16": 0.5,
|
102 |
+
"BF16": 0.5,
|
103 |
+
"INT8": 0.25,
|
104 |
+
"INT4": 0.125
|
105 |
+
}
|
106 |
+
|
107 |
+
model_memory = base_memory * precision_multiplier.get(precision, 0.5)
|
108 |
+
|
109 |
+
# Calculate KV cache memory
|
110 |
+
total_tokens = input_tokens + output_tokens
|
111 |
+
kv_cache_memory = calculate_kv_cache_memory(total_tokens, model_spec["params"]) * batch_size
|
112 |
+
|
113 |
+
# Use case specific memory overhead
|
114 |
+
overhead_multiplier = {
|
115 |
+
"inference": 1.2, # 20% overhead
|
116 |
+
"training": 3.0, # 3x for gradients, optimizer states
|
117 |
+
"fine_tuning": 2.5 # 2.5x for fine-tuning
|
118 |
+
}
|
119 |
+
|
120 |
+
total_memory_per_instance = (model_memory + kv_cache_memory) * overhead_multiplier.get(use_case, 1.2)
|
121 |
+
|
122 |
+
# Calculate nodes needed
|
123 |
+
memory_per_node = H100_MEMORY_GB * 0.9 # Reserve 10% for system
|
124 |
+
nodes_needed = max(1, int(np.ceil(total_memory_per_instance / memory_per_node)))
|
125 |
+
|
126 |
+
# For very large models, consider model parallelism
|
127 |
+
if model_memory > memory_per_node:
|
128 |
+
min_nodes_for_model = int(np.ceil(model_memory / memory_per_node))
|
129 |
+
nodes_needed = max(nodes_needed, min_nodes_for_model)
|
130 |
+
|
131 |
+
# Generate explanation
|
132 |
+
explanation = f"""
|
133 |
+
**Estimation Breakdown:**
|
134 |
+
|
135 |
+
• **Model**: {model_name} ({model_spec['params']/1e9:.1f}B parameters)
|
136 |
+
• **Precision**: {precision}
|
137 |
+
• **Model Memory**: {model_memory:.1f} GB
|
138 |
+
• **KV Cache Memory**: {kv_cache_memory:.1f} GB (for {total_tokens:,} tokens × {batch_size} batch size)
|
139 |
+
• **Use Case Overhead**: {overhead_multiplier.get(use_case, 1.2):.1f}x ({use_case})
|
140 |
+
• **Total Memory Required**: {total_memory_per_instance:.1f} GB
|
141 |
+
• **H100 Usable Memory**: {memory_per_node:.1f} GB per node
|
142 |
+
|
143 |
+
**Recommendation**: {nodes_needed} H100 node(s)
|
144 |
+
"""
|
145 |
+
|
146 |
+
breakdown = {
|
147 |
+
"model_memory_gb": model_memory,
|
148 |
+
"kv_cache_memory_gb": kv_cache_memory,
|
149 |
+
"total_memory_gb": total_memory_per_instance,
|
150 |
+
"h100_memory_per_node_gb": memory_per_node,
|
151 |
+
"nodes_required": nodes_needed
|
152 |
+
}
|
153 |
+
|
154 |
+
return nodes_needed, explanation, breakdown
|
155 |
+
|
156 |
+
def get_cuda_recommendation(use_case: str) -> str:
|
157 |
+
"""Get CUDA version recommendation based on use case"""
|
158 |
+
cuda_info = CUDA_RECOMMENDATIONS.get(use_case, CUDA_RECOMMENDATIONS["inference"])
|
159 |
+
|
160 |
+
recommendation = f"""
|
161 |
+
**CUDA Version Recommendations for {use_case.title()}:**
|
162 |
+
|
163 |
+
• **Optimal**: CUDA {cuda_info['optimal']} + cuDNN 8.9+
|
164 |
+
• **Recommended**: CUDA {cuda_info['recommended']} + cuDNN 8.7+
|
165 |
+
• **Minimum**: CUDA {cuda_info['minimum']} + cuDNN 8.5+
|
166 |
+
|
167 |
+
**Additional Requirements:**
|
168 |
+
• **Driver Version**: 525.60.13+ (Linux) / 527.41+ (Windows)
|
169 |
+
• **Compute Capability**: {H100_COMPUTE_CAPABILITY} (H100 native)
|
170 |
+
• **Memory**: ECC enabled recommended for production
|
171 |
+
"""
|
172 |
+
|
173 |
+
return recommendation
|
174 |
+
|
175 |
+
def create_performance_chart(breakdown: Dict) -> plt.Figure:
|
176 |
+
"""Create a memory utilization chart"""
|
177 |
+
if not breakdown:
|
178 |
+
fig, ax = plt.subplots(figsize=(8, 6))
|
179 |
+
ax.text(0.5, 0.5, 'No data to display', ha='center', va='center')
|
180 |
+
ax.set_xlim(0, 1)
|
181 |
+
ax.set_ylim(0, 1)
|
182 |
+
return fig
|
183 |
+
|
184 |
+
fig, (ax1, ax2) = plt.subplots(1, 2, figsize=(12, 5))
|
185 |
+
|
186 |
+
# Memory breakdown pie chart
|
187 |
+
labels = ['Model Memory', 'KV Cache', 'Overhead']
|
188 |
+
model_mem = breakdown['model_memory_gb']
|
189 |
+
kv_mem = breakdown['kv_cache_memory_gb']
|
190 |
+
overhead_mem = breakdown['total_memory_gb'] - model_mem - kv_mem
|
191 |
+
sizes = [model_mem, kv_mem, overhead_mem]
|
192 |
+
|
193 |
+
colors = ['#ff9999', '#66b3ff', '#99ff99']
|
194 |
+
ax1.pie(sizes, labels=labels, colors=colors, autopct='%1.1f%%', startangle=90)
|
195 |
+
ax1.set_title('Memory Breakdown')
|
196 |
+
|
197 |
+
# Node utilization bar chart
|
198 |
+
nodes = breakdown['nodes_required']
|
199 |
+
total_memory = breakdown['total_memory_gb']
|
200 |
+
memory_per_node = breakdown['h100_memory_per_node_gb']
|
201 |
+
|
202 |
+
node_labels = [f'Node {i+1}' for i in range(nodes)]
|
203 |
+
utilization = []
|
204 |
+
|
205 |
+
for i in range(nodes):
|
206 |
+
if i < nodes - 1:
|
207 |
+
utilization.append(memory_per_node)
|
208 |
+
else:
|
209 |
+
remaining_memory = total_memory - (nodes - 1) * memory_per_node
|
210 |
+
utilization.append(remaining_memory)
|
211 |
+
|
212 |
+
utilization_pct = [u / memory_per_node * 100 for u in utilization]
|
213 |
+
|
214 |
+
bars = ax2.bar(node_labels, utilization_pct, color='skyblue', alpha=0.7)
|
215 |
+
ax2.axhline(y=100, color='red', linestyle='--', alpha=0.7, label='Max Capacity')
|
216 |
+
ax2.set_ylabel('Memory Utilization (%)')
|
217 |
+
ax2.set_title('H100 Node Memory Utilization')
|
218 |
+
ax2.set_ylim(0, 110)
|
219 |
+
ax2.legend()
|
220 |
+
|
221 |
+
# Add value labels on bars
|
222 |
+
for bar, pct in zip(bars, utilization_pct):
|
223 |
+
ax2.text(bar.get_x() + bar.get_width()/2, bar.get_height() + 1,
|
224 |
+
f'{pct:.1f}%', ha='center', va='bottom')
|
225 |
+
|
226 |
+
plt.tight_layout()
|
227 |
+
return fig
|
228 |
+
|
229 |
+
def estimate_nodes_interface(
|
230 |
+
model_name: str,
|
231 |
+
input_tokens: int,
|
232 |
+
output_tokens: int,
|
233 |
+
batch_size: int,
|
234 |
+
use_case: str,
|
235 |
+
precision: str
|
236 |
+
):
|
237 |
+
"""Main interface function"""
|
238 |
+
|
239 |
+
# Validate inputs
|
240 |
+
if input_tokens <= 0 or output_tokens <= 0:
|
241 |
+
return "Please enter valid token counts (> 0)", "", None, ""
|
242 |
+
|
243 |
+
if batch_size <= 0:
|
244 |
+
return "Please enter a valid batch size (> 0)", "", None, ""
|
245 |
+
|
246 |
+
# Calculate node requirements
|
247 |
+
nodes_needed, explanation, breakdown = estimate_h100_nodes(
|
248 |
+
model_name, input_tokens, output_tokens, batch_size, use_case, precision
|
249 |
+
)
|
250 |
+
|
251 |
+
# Get CUDA recommendations
|
252 |
+
cuda_rec = get_cuda_recommendation(use_case)
|
253 |
+
|
254 |
+
# Create performance chart
|
255 |
+
fig = create_performance_chart(breakdown)
|
256 |
+
|
257 |
+
return explanation, cuda_rec, fig, f"**Estimated H100 Nodes Required: {nodes_needed}**"
|
258 |
+
|
259 |
+
# Create Gradio interface
|
260 |
+
def create_interface():
|
261 |
+
with gr.Blocks(title="H100 Node Estimator", theme=gr.themes.Soft()) as demo:
|
262 |
+
gr.Markdown("# 🚀 H100 Node & CUDA Version Estimator")
|
263 |
+
gr.Markdown("Get recommendations for H100 node count and CUDA version based on your model and workload requirements.")
|
264 |
+
|
265 |
+
with gr.Row():
|
266 |
+
with gr.Column(scale=1):
|
267 |
+
gr.Markdown("## Input Parameters")
|
268 |
+
|
269 |
+
model_dropdown = gr.Dropdown(
|
270 |
+
choices=list(MODEL_SPECS.keys()),
|
271 |
+
value="LLaMA-3-8B",
|
272 |
+
label="Model",
|
273 |
+
info="Select the model you want to run"
|
274 |
+
)
|
275 |
+
|
276 |
+
input_tokens = gr.Number(
|
277 |
+
value=2048,
|
278 |
+
label="Input Tokens",
|
279 |
+
info="Number of input tokens per request"
|
280 |
+
)
|
281 |
+
|
282 |
+
output_tokens = gr.Number(
|
283 |
+
value=512,
|
284 |
+
label="Output Tokens",
|
285 |
+
info="Number of output tokens per request"
|
286 |
+
)
|
287 |
+
|
288 |
+
batch_size = gr.Number(
|
289 |
+
value=1,
|
290 |
+
label="Batch Size",
|
291 |
+
info="Number of concurrent requests"
|
292 |
+
)
|
293 |
+
|
294 |
+
use_case = gr.Dropdown(
|
295 |
+
choices=["inference", "training", "fine_tuning"],
|
296 |
+
value="inference",
|
297 |
+
label="Use Case",
|
298 |
+
info="What will you use the model for?"
|
299 |
+
)
|
300 |
+
|
301 |
+
precision = gr.Dropdown(
|
302 |
+
choices=["FP32", "FP16", "BF16", "INT8", "INT4"],
|
303 |
+
value="FP16",
|
304 |
+
label="Precision",
|
305 |
+
info="Model precision/quantization"
|
306 |
+
)
|
307 |
+
|
308 |
+
estimate_btn = gr.Button("💡 Estimate Requirements", variant="primary")
|
309 |
+
|
310 |
+
with gr.Column(scale=2):
|
311 |
+
gr.Markdown("## Results")
|
312 |
+
|
313 |
+
node_count = gr.Markdown("**Ready to estimate...**")
|
314 |
+
|
315 |
+
with gr.Tab("📊 Detailed Analysis"):
|
316 |
+
detailed_output = gr.Markdown()
|
317 |
+
|
318 |
+
with gr.Tab("🔧 CUDA Recommendations"):
|
319 |
+
cuda_output = gr.Markdown()
|
320 |
+
|
321 |
+
with gr.Tab("📈 Memory Utilization"):
|
322 |
+
chart_output = gr.Plot()
|
323 |
+
|
324 |
+
# Connect the interface
|
325 |
+
estimate_btn.click(
|
326 |
+
fn=estimate_nodes_interface,
|
327 |
+
inputs=[model_dropdown, input_tokens, output_tokens, batch_size, use_case, precision],
|
328 |
+
outputs=[detailed_output, cuda_output, chart_output, node_count]
|
329 |
+
)
|
330 |
+
|
331 |
+
# Add examples
|
332 |
+
gr.Markdown("## 💡 Example Scenarios")
|
333 |
+
|
334 |
+
examples = [
|
335 |
+
["LLaMA-3-8B", 2048, 512, 1, "inference", "FP16"],
|
336 |
+
["LLaMA-3-70B", 4096, 1024, 4, "inference", "FP16"],
|
337 |
+
["Qwen2.5-72B", 8192, 2048, 2, "fine_tuning", "BF16"],
|
338 |
+
["Nemotron-4-340B", 2048, 1024, 1, "inference", "INT8"],
|
339 |
+
]
|
340 |
+
|
341 |
+
gr.Examples(
|
342 |
+
examples=examples,
|
343 |
+
inputs=[model_dropdown, input_tokens, output_tokens, batch_size, use_case, precision],
|
344 |
+
outputs=[detailed_output, cuda_output, chart_output, node_count],
|
345 |
+
fn=estimate_nodes_interface,
|
346 |
+
cache_examples=False
|
347 |
+
)
|
348 |
+
|
349 |
+
gr.Markdown("""
|
350 |
+
## ℹ️ Notes
|
351 |
+
- Estimates are approximate and may vary based on actual implementation details
|
352 |
+
- Memory calculations include model weights, KV cache, and operational overhead
|
353 |
+
- Consider network bandwidth and storage requirements for multi-node setups
|
354 |
+
- For production deployments, add 10-20% buffer for optimal performance
|
355 |
+
""")
|
356 |
+
|
357 |
+
return demo
|
358 |
+
|
359 |
+
if __name__ == "__main__":
|
360 |
+
demo = create_interface()
|
361 |
+
demo.launch(share=True, server_name="0.0.0.0", server_port=7860)
|
requirements.txt
ADDED
@@ -0,0 +1,13 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
APScheduler
|
2 |
+
black
|
3 |
+
datasets
|
4 |
+
gradio>=4.0.0
|
5 |
+
gradio[oauth]
|
6 |
+
gradio_leaderboard==0.0.13
|
7 |
+
gradio_client
|
8 |
+
huggingface-hub>=0.18.0
|
9 |
+
matplotlib>=3.6.0
|
10 |
+
numpy>=1.24.0
|
11 |
+
pandas>=1.5.0
|
12 |
+
python-dateutil
|
13 |
+
tqdm
|