Spaces:
Runtime error
Runtime error
GPU最適化の適用条件を強化し、`torch.nn.Module`の場合のみ最適化を行うように修正しました。エラーハンドリングを追加し、最適化のスキップ理由をログに出力するようにしました。
Browse files- api_server.py +10 -2
- app_optimized.py +10 -3
api_server.py
CHANGED
@@ -92,9 +92,17 @@ async def startup_event():
|
|
92 |
from stream_pipeline_offline import StreamSDK
|
93 |
SDK = StreamSDK(cfg_pkl, data_root)
|
94 |
|
95 |
-
# GPU
|
96 |
if hasattr(SDK, 'decode_f3d') and hasattr(SDK.decode_f3d, 'decoder'):
|
97 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
98 |
|
99 |
print("✅ SDK initialized with optimizations")
|
100 |
except Exception as e:
|
|
|
92 |
from stream_pipeline_offline import StreamSDK
|
93 |
SDK = StreamSDK(cfg_pkl, data_root)
|
94 |
|
95 |
+
# GPU最適化を適用(torch.nn.Moduleの場合のみ)
|
96 |
if hasattr(SDK, 'decode_f3d') and hasattr(SDK.decode_f3d, 'decoder'):
|
97 |
+
try:
|
98 |
+
import torch.nn as nn
|
99 |
+
if isinstance(SDK.decode_f3d.decoder, nn.Module):
|
100 |
+
SDK.decode_f3d.decoder = gpu_optimizer.optimize_model(SDK.decode_f3d.decoder)
|
101 |
+
print("✅ Decoder model optimized")
|
102 |
+
else:
|
103 |
+
print("ℹ️ Decoder is not nn.Module, skipping optimization")
|
104 |
+
except Exception as e:
|
105 |
+
print(f"⚠️ Skipping GPU optimization: {e}")
|
106 |
|
107 |
print("✅ SDK initialized with optimizations")
|
108 |
except Exception as e:
|
app_optimized.py
CHANGED
@@ -74,10 +74,17 @@ try:
|
|
74 |
SDK = StreamSDK(cfg_pkl, data_root)
|
75 |
print("✅ SDK初期化成功(最適化版)")
|
76 |
|
77 |
-
# GPU
|
78 |
if hasattr(SDK, 'decode_f3d') and hasattr(SDK.decode_f3d, 'decoder'):
|
79 |
-
|
80 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
81 |
|
82 |
except Exception as e:
|
83 |
print(f"❌ SDK初期化エラー: {e}")
|
|
|
74 |
SDK = StreamSDK(cfg_pkl, data_root)
|
75 |
print("✅ SDK初期化成功(最適化版)")
|
76 |
|
77 |
+
# GPU最適化を適用(torch.nn.Moduleの場合のみ)
|
78 |
if hasattr(SDK, 'decode_f3d') and hasattr(SDK.decode_f3d, 'decoder'):
|
79 |
+
try:
|
80 |
+
import torch.nn as nn
|
81 |
+
if isinstance(SDK.decode_f3d.decoder, nn.Module):
|
82 |
+
SDK.decode_f3d.decoder = gpu_optimizer.optimize_model(SDK.decode_f3d.decoder)
|
83 |
+
print("✅ デコーダーモデルに最適化を適用")
|
84 |
+
else:
|
85 |
+
print("ℹ️ デコーダーはnn.Moduleではないため、最適化をスキップ")
|
86 |
+
except Exception as e:
|
87 |
+
print(f"⚠️ GPU最適化の適用をスキップ: {e}")
|
88 |
|
89 |
except Exception as e:
|
90 |
print(f"❌ SDK初期化エラー: {e}")
|