Skip to content

Commit 8a24af6

Browse files
committed
fix: always import xgboost and sklearn modules
- xgboost was only imported when RAPIDS not available - XGBoost is needed regardless of RAPIDS availability - Move sklearn imports outside conditional block - Resolves 'name xgb is not defined' error
1 parent 95b19fc commit 8a24af6

File tree

1 file changed

+10
-9
lines changed

1 file changed

+10
-9
lines changed

scripts/forecasting/rapids_gpu_forecasting.py

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,9 @@
1919
RAPIDS_AVAILABLE = False
2020
CUDA_AVAILABLE = False
2121

22+
# Always import xgboost (needed for XGBoost training regardless of RAPIDS)
23+
import xgboost as xgb
24+
2225
try:
2326
import cudf
2427
import cuml
@@ -36,15 +39,13 @@
3639
RAPIDS_AVAILABLE = False
3740
print("⚠️ RAPIDS cuML not available - checking for XGBoost GPU support...")
3841

39-
# CPU fallback imports
40-
if not RAPIDS_AVAILABLE:
41-
from sklearn.ensemble import RandomForestRegressor, GradientBoostingRegressor
42-
from sklearn.linear_model import LinearRegression, Ridge
43-
from sklearn.svm import SVR
44-
from sklearn.preprocessing import StandardScaler
45-
from sklearn.model_selection import train_test_split
46-
from sklearn.metrics import mean_squared_error, mean_absolute_error
47-
import xgboost as xgb
42+
# CPU fallback imports (always import these for fallback compatibility)
43+
from sklearn.ensemble import RandomForestRegressor, GradientBoostingRegressor
44+
from sklearn.linear_model import LinearRegression, Ridge
45+
from sklearn.svm import SVR
46+
from sklearn.preprocessing import StandardScaler
47+
from sklearn.model_selection import train_test_split
48+
from sklearn.metrics import mean_squared_error, mean_absolute_error
4849

4950
# Check if CUDA is available for XGBoost GPU support
5051
CUDA_AVAILABLE = False

0 commit comments

Comments
 (0)