Spaces:
Running on CPU Upgrade
Running on CPU Upgrade
Aditya Sahu commited on
Validation logs
Browse files
app.py
CHANGED
|
@@ -53,20 +53,64 @@ def compile_model(model_name, vmem_value, lpmem_value, uploaded_model):
|
|
| 53 |
vmem_size_limit = int(vmem_value * 1000)
|
| 54 |
lpmem_size_limit = int(lpmem_value * 1000)
|
| 55 |
|
| 56 |
-
# Run the model fitter
|
| 57 |
-
|
| 58 |
-
|
| 59 |
-
vmem_size_limit
|
| 60 |
-
|
| 61 |
-
|
| 62 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 63 |
|
| 64 |
output = []
|
| 65 |
|
| 66 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 67 |
output.append(
|
| 68 |
-
"<div style='color:#
|
| 69 |
-
"
|
|
|
|
| 70 |
)
|
| 71 |
output.append("<div style='margin-top:0.5em;color:#000;'>Compiler log:</div>")
|
| 72 |
output.append(
|
|
|
|
| 53 |
vmem_size_limit = int(vmem_value * 1000)
|
| 54 |
lpmem_size_limit = int(lpmem_value * 1000)
|
| 55 |
|
| 56 |
+
# Run the model fitter with better error handling
|
| 57 |
+
try:
|
| 58 |
+
print(f"Starting model optimization for {model_path}")
|
| 59 |
+
print(f"VMEM limit: {vmem_size_limit}, LPMEM limit: {lpmem_size_limit}")
|
| 60 |
+
|
| 61 |
+
success, results = sr100_model_compiler.sr100_model_optimizer(
|
| 62 |
+
model_file=model_path,
|
| 63 |
+
vmem_size_limit=vmem_size_limit,
|
| 64 |
+
lpmem_size_limit=lpmem_size_limit
|
| 65 |
+
)
|
| 66 |
+
|
| 67 |
+
print(f"Optimization complete. Success: {success}")
|
| 68 |
+
print(f"Results: {results}")
|
| 69 |
+
|
| 70 |
+
# Check if results is None or missing expected keys
|
| 71 |
+
if not results:
|
| 72 |
+
return (
|
| 73 |
+
"<div style='color:#d32f2f; font-weight:bold; font-size:1.2em;'>"
|
| 74 |
+
"❌ ERROR: Optimization returned empty results</div>"
|
| 75 |
+
)
|
| 76 |
+
|
| 77 |
+
except Exception as e:
|
| 78 |
+
error_message = str(e)
|
| 79 |
+
print(f"Exception during model optimization: {error_message}")
|
| 80 |
+
|
| 81 |
+
return (
|
| 82 |
+
"<div style='color:#d32f2f; font-weight:bold; font-size:1.2em;'>"
|
| 83 |
+
"❌ ERROR: Model optimization failed</div>"
|
| 84 |
+
"<div style='margin-top:0.5em;color:#000;'>Error details:</div>"
|
| 85 |
+
f"<pre style='white-space:pre-wrap; background:#f6f8fa; padding:8px; border-radius:6px; color:#000;'>{html.escape(error_message)}</pre>"
|
| 86 |
+
"<div style='margin-top:0.5em;color:#000;'>"
|
| 87 |
+
"Common reasons for failure:"
|
| 88 |
+
"<ul style='margin:0.5em 0 0 1.2em;'>"
|
| 89 |
+
"<li>Model contains unsupported operations for SR100 NPU</li>"
|
| 90 |
+
"<li>Model is not properly quantized to INT8</li>"
|
| 91 |
+
"<li>Memory limits are too restrictive for the model size</li>"
|
| 92 |
+
"</ul>"
|
| 93 |
+
"</div>"
|
| 94 |
+
)
|
| 95 |
|
| 96 |
output = []
|
| 97 |
|
| 98 |
+
# Check for specific failure cases from results
|
| 99 |
+
if not success:
|
| 100 |
+
print(f"Optimization reported failure. Reason: {results.get('failure_reason', 'Unknown')}")
|
| 101 |
+
|
| 102 |
+
# Check if NPU cycles is zero (CPU-only model)
|
| 103 |
+
npu_zero = results.get('cycles_npu', 0) == 0
|
| 104 |
+
|
| 105 |
+
if npu_zero:
|
| 106 |
+
output.append(
|
| 107 |
+
"<div style='color:#e65100; font-weight:bold; font-size:1.2em;'>"
|
| 108 |
+
"⚠️ CPU-ONLY: Model fits in memory but no operators mapped to the NPU</div>"
|
| 109 |
+
)
|
| 110 |
output.append(
|
| 111 |
+
"<div style='color:#000; margin-top:0.25em;'>"
|
| 112 |
+
"This typically means the model contains ops not supported by the SR100 NPU. "
|
| 113 |
+
"Please review/convert unsupported ops or choose an NPU-friendly model.</div>"
|
| 114 |
)
|
| 115 |
output.append("<div style='margin-top:0.5em;color:#000;'>Compiler log:</div>")
|
| 116 |
output.append(
|