-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrun_all.py
More file actions
275 lines (222 loc) · 8.28 KB
/
Copy pathrun_all.py
File metadata and controls
275 lines (222 loc) · 8.28 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
"""
MLflow Complete Tutorial - Master Script
This script runs all four MLflow components in sequence:
1. MLflow Tracking
2. MLflow Projects
3. MLflow Models
4. MLflow Model Registry
Run this script to see the complete MLflow workflow in action.
"""
import sys
import time
import subprocess
from datetime import datetime
def print_banner(text, char="=", width=80):
"""Print a formatted banner."""
print("\n" + char * width)
print(f" {text}")
print(char * width + "\n")
def print_component_header(number, name):
"""Print component header."""
print_banner(f"Component {number}: {name}", char="=")
print(f"Starting at: {datetime.now().strftime('%Y-%m-%d %H:%M:%S')}\n")
def print_status(message, status="info"):
"""Print status message."""
symbols = {
"info": "ℹ",
"success": "✓",
"error": "✗",
"warning": "⚠"
}
symbol = symbols.get(status, "•")
print(f"{symbol} {message}")
def run_component(script_name, component_name, component_number):
"""
Run a tutorial component.
Args:
script_name: Name of the Python script
component_name: Display name of the component
component_number: Component number (1-4)
Returns:
True if successful, False otherwise
"""
print_component_header(component_number, component_name)
try:
print_status(f"Executing {script_name}...", "info")
# Run the component
result = subprocess.run(
[sys.executable, script_name],
capture_output=False,
text=True
)
if result.returncode == 0:
print_status(f"{component_name} completed successfully!", "success")
return True
else:
print_status(f"{component_name} failed with return code {result.returncode}", "error")
return False
except Exception as e:
print_status(f"Error running {component_name}: {str(e)}", "error")
return False
def check_mlflow_ui():
"""Check if MLflow UI is running."""
print_status("Checking MLflow UI availability...", "info")
try:
import urllib.request
import urllib.error
try:
urllib.request.urlopen("http://localhost:5000", timeout=1)
print_status("MLflow UI is running at http://localhost:5000", "success")
return True
except urllib.error.URLError:
print_status("MLflow UI is not running", "warning")
print(" To start MLflow UI, run in a separate terminal:")
print(" $ mlflow ui")
print(" Then visit: http://localhost:5000")
return False
except Exception as e:
print_status(f"Could not check MLflow UI: {str(e)}", "warning")
return False
def print_summary(results):
"""Print execution summary."""
print_banner("Execution Summary", char="=")
total = len(results)
successful = sum(1 for r in results.values() if r)
failed = total - successful
print(f"Total Components: {total}")
print(f"Successful: {successful}")
print(f"Failed: {failed}")
print()
print("Component Results:")
print("-" * 80)
for component, success in results.items():
status = "✓ Success" if success else "✗ Failed"
print(f" {component:<40} {status}")
print("-" * 80)
if all(results.values()):
print_status("All components completed successfully!", "success")
return True
else:
print_status("Some components failed. Check the output above for details.", "error")
return False
def print_next_steps():
"""Print next steps and recommendations."""
print_banner("Next Steps", char="=")
print("1. Explore MLflow UI:")
print(" - Start the UI: mlflow ui")
print(" - Visit: http://localhost:5000")
print(" - Browse experiments, runs, and models")
print()
print("2. Review Individual Components:")
print(" - Component 1 (Tracking): python 1_tracking.py")
print(" - Component 2 (Projects): python 2_projects.py")
print(" - Component 3 (Models): python 3_models.py")
print(" - Component 4 (Registry): python 4_model_registry.py")
print()
print("3. Experiment Further:")
print(" - Modify hyperparameters in the scripts")
print(" - Try different ML algorithms")
print(" - Add your own datasets")
print(" - Explore MLflow's advanced features")
print()
print("4. Key Files to Review:")
print(" - README.md: Complete documentation")
print(" - MLproject: Project configuration")
print(" - requirements.txt: Python dependencies")
print(" - utils.py: Shared utility functions")
print()
print("5. Production Deployment:")
print(" - Set up remote tracking server")
print(" - Configure artifact storage (S3, Azure, GCS)")
print(" - Deploy models to production endpoints")
print(" - Implement CI/CD pipelines")
print()
def main():
"""Main execution function."""
# Print welcome message
print_banner("MLflow Complete Tutorial", char="=")
print("This script will run all four MLflow components in sequence.")
print("Each component demonstrates key MLflow features.")
print()
print("The tutorial covers:")
print(" 1. MLflow Tracking - Experiment tracking and logging")
print(" 2. MLflow Projects - Reproducible runs")
print(" 3. MLflow Models - Model packaging and deployment")
print(" 4. MLflow Model Registry - Model versioning and lifecycle")
print()
# Check MLflow UI
check_mlflow_ui()
print()
# Confirm execution
print("-" * 80)
response = input("Press Enter to continue or Ctrl+C to cancel... ")
print()
start_time = time.time()
# Define components
components = [
("1_tracking.py", "MLflow Tracking", 1),
("2_projects.py", "MLflow Projects", 2),
("3_models.py", "MLflow Models", 3),
("4_model_registry.py", "MLflow Model Registry", 4)
]
# Track results
results = {}
# Run each component
for script, name, number in components:
success = run_component(script, name, number)
results[f"Component {number}: {name}"] = success
if not success:
print_status(f"Component {number} failed. Continuing to next component...", "warning")
# Brief pause between components
if number < 4:
print("\n" + "." * 80)
time.sleep(2)
# Calculate execution time
end_time = time.time()
duration = end_time - start_time
minutes = int(duration // 60)
seconds = int(duration % 60)
# Print summary
print()
print_summary(results)
print()
print(f"Total execution time: {minutes} minutes, {seconds} seconds")
print()
# Print next steps
print_next_steps()
# Final message
print_banner("Tutorial Complete!", char="=")
if all(results.values()):
print("🎉 Congratulations! You've successfully completed the MLflow tutorial!")
print()
print("You now understand:")
print(" ✓ How to track experiments with MLflow Tracking")
print(" ✓ How to create reproducible projects with MLflow Projects")
print(" ✓ How to package models with MLflow Models")
print(" ✓ How to manage model lifecycle with MLflow Model Registry")
print()
print("Happy experimenting with MLflow! 🚀")
return 0
else:
print("⚠ The tutorial completed with some errors.")
print("Please review the output above for details.")
return 1
if __name__ == "__main__":
try:
exit_code = main()
sys.exit(exit_code)
except KeyboardInterrupt:
print("\n\n" + "=" * 80)
print(" Tutorial interrupted by user")
print("=" * 80)
print("\nYou can run individual components separately:")
print(" $ python 1_tracking.py")
print(" $ python 2_projects.py")
print(" $ python 3_models.py")
print(" $ python 4_model_registry.py")
sys.exit(1)
except Exception as e:
print(f"\n❌ Unexpected error: {str(e)}")
import traceback
traceback.print_exc()
sys.exit(1)