Comments (10)
I don't see a reference to Python in the crash report, why do you think this issue is related to Python?
from cpython.
I don't see a reference to Python in the crash report
I think it's because of src/toolkit/app.py
but I highly suspect that this is not an issue from the core library itself. Unless we know what src/toolkit/app.py
does, I don't think we can help.
from cpython.
I am running a Python code in Mac M3 Sonoma 14.5. And it gives me Segmentation fault 11. Can you guide me what us leading this fault? The code app.py is running a pytorch_lightning code. I crashes the moment it starts.
from cpython.
Without the source code, we cannot help you. It might be an issue with pytorch_lightning
and thus, the issue should be reported on their side (or it might also be an issue with what is written in that code).
from cpython.
I have run the same code on Windows and it worked, but failed in MacOs.
from cpython.
You are still not giving me the code. Without the content of src/toolkit/app.py
, we cannot help you at all. We don't know what your code is supposed to do.
from cpython.
`import pandas as pd
import concurrent.futures
from statsmodel import StatsForecastModels
import neuralmodel as nm
from neuralmodel import NeuralForecastModels
from utilsforecast.evaluation import evaluate
from utilsforecast.losses import smape, mape, mse, rmse, mae, rmae, mase
date_mapping = {
"MM/DD/YYYY": "%m-%d-%Y",
"DD/MM/YYYY": "%d-%m-%Y",
"DD-MM-YYYY": "%d-%m-%Y",
"MM-DD-YYYY": "%m-%d-%Y",
"YYYY/MM/DD": "%Y-%m-%d",
}
def rank_forecast(pred__, evaluate__):
df_tmp_transform_ = evaluate__.reset_index().T.reset_index()
headers = df_tmp_transform_.iloc[0]
df_tmp_rank_ = pd.DataFrame(df_tmp_transform_.values[1:], columns=headers)
df_tmp_rank_.rename(columns={"unique_id": "models"}, inplace=True)
df_tmp_rank_ = df_tmp_rank_[df_tmp_rank_["models"] != "best_model"].reset_index(
drop=True
)
df_int_ = pd.DataFrame()
for id_ in pred__["unique_id"].unique():
df_tmp_rank_[id_] = df_tmp_rank_[id_].astype(float)
df_tmp_ = df_tmp_rank_[["models", id_]].sort_values(by=id_)
df_tmp_pred = pd.DataFrame()
rank = 1
for mdl_ in df_tmp_["models"]:
df_tmp_pred = pred__[pred__["unique_id"] == id_].reset_index(drop=True)[
["unique_id", "ds"]
]
df_tmp_pred["model"] = mdl_
df_tmp_pred["forecast"] = pred__[mdl_]
df_tmp_pred["rank"] = rank
df_int_ = pd.concat([df_int_, df_tmp_pred], ignore_index=True)
rank += 1
return df_int_
def evaluate_cross_validation(df, metric):
error_metric = globals()[metric]
models = df.drop(columns=["unique_id", "ds", "cutoff", "y"]).columns.tolist()
evals = []
for cutoff in df["cutoff"].unique():
eval_ = evaluate(
df[df["cutoff"] == cutoff], metrics=[error_metric], models=models
)
evals.append(eval_)
evaluated = pd.concat(evals)
evaluated = evaluated.groupby("unique_id").mean(numeric_only=True)
evaluated.insert(0, "best_model", evaluated.idxmin(axis=1))
return evaluated
def train_statistical_model(df, model_type, seasonal_length, date_format, data_frequency, forecast_horizon,
ignore_neg_fcsts, error_metric, eval):
stats = StatsForecastModels(
model_type=[model_type],
seasonal_length=seasonal_length,
freq=data_frequency,
date_format=date_format,
)
stats.fit(df)
df_pred = stats.predict(horizon=forecast_horizon, ignore_neg_fcsts=ignore_neg_fcsts)
df_crossval = stats.crossvalidation(error_metric=error_metric, ) #ignore_neg_fcsts=ignore_neg_fcsts)
if eval:
df_performance = evaluate_cross_validation(df_crossval, error_metric)
df_rank = rank_forecast(df_pred, df_performance)
else:
df_performance, df_rank = pd.DataFrame(), pd.DataFrame()
return df_pred, df_performance, df_rank, df_crossval
def train_neural_model(df, model_type, date_format, data_frequency, forecast_horizon,
ignore_neg_fcsts, error_metric, eval):
neural = nm.NeuralForecastModels(
model_type=[model_type],
forecast_horizon=forecast_horizon,
freq=data_frequency,
date_format=date_format,
MDL_SPEED_MAPPING=nm.MDL_SPEED_MAPPING,
NEURAL_MDL=nm.NEURAL_MDL,
MDL_PARAMETERS=nm.MDL_PARAMETERS,
ENSEMBLE_MAPPING=nm.ENSEMBLE_MAPPING,
)
neural.fit(df)
df_pred = neural.predict(horizon=forecast_horizon, ignore_neg_fcsts=ignore_neg_fcsts)
df_crossval = neural.crossvalidation(
error_metric=error_metric, ignore_neg_fcsts=ignore_neg_fcsts
)
if eval:
df_performance = evaluate_cross_validation(df_crossval, error_metric)
df_rank = rank_forecast(df_pred, df_performance)
else:
df_performance, df_rank = pd.DataFrame(), pd.DataFrame()
return df_pred, df_performance, df_rank, df_crossval
def run_forecast(
seasonal_length,
data_frequency,
error_metric,
ignore_neg_fcsts,
date_format,
forecast_horizon,
df,
model_type,
):
# Define a helper function to train the models in parallel
def train_models(model_type, eval=True):
if model_type == "Statistical":
return train_statistical_model(df, model_type, seasonal_length, date_format, data_frequency, forecast_horizon,
ignore_neg_fcsts, error_metric, eval=eval)
elif model_type == "Machine-Learning":
return train_neural_model(df, model_type, date_format, data_frequency, forecast_horizon, ignore_neg_fcsts,
error_metric, eval=eval)
if model_type in ["Statistical & Machine-Learning", "Test"]:
if model_type=="Test":
type1 = "Test"
type2 = "Test"
else:
type1 = "Statistical"
type2 = "Machine-Learning"
with concurrent.futures.ThreadPoolExecutor() as executor:
future_s = executor.submit(train_statistical_model, df, type1, seasonal_length, date_format, data_frequency, forecast_horizon, ignore_neg_fcsts, error_metric, eval=False)
future_n = executor.submit(train_neural_model, df, type2, date_format, data_frequency, forecast_horizon, ignore_neg_fcsts, error_metric, eval=False)
df_pred_s, _, _, df_crossval_s = future_s.result()
df_pred_n, _, _, df_crossval_n = future_n.result()
df_pred = df_pred_s.merge(df_pred_n, on=["unique_id", "ds"], how="inner")
df_crossval_s["y"] = df_crossval_s["y"].astype("Float32")
df_crossval_n["y"] = df_crossval_n["y"].astype("float32")
df_crossval = pd.merge(df_crossval_s, df_crossval_n, on=["unique_id", "ds", "cutoff", "y"], how="inner")
ensemble_col_ = [
col
for col in df_pred.columns
if (("ensemble" not in col) & ("ds" not in col) & ("unique_id" not in col))
]
df_pred["Stats & ML ensemble"] = df_pred[ensemble_col_].mean(axis=1)
df_performance = evaluate_cross_validation(df_crossval, error_metric)
df_rank = rank_forecast(df_pred, df_performance)
return df_pred, df_performance, df_rank, df_crossval
else:
return train_models(model_type)
if name == "main":
df = pd.read_csv('./src/data/FakeProjectDailyData__.csv')
df_pred, df_performance, df_rank, df_crossval = run_forecast(
seasonal_length=12,
data_frequency="D",
error_metric="rmse",
ignore_neg_fcsts=False,
date_format="DD-MM-YYYY",
forecast_horizon=13,
df=df,
model_type="Machine-Learning",
)
print(df_pred)
`
from cpython.
The problem happens when i run the neuralmodel
, which is open source package called Nixtla which is a pytorch Lightning based Models like NHITS, RNN etc. The input data is like, Col 1 unique ID's, col2 is Dates and Col3 is values
, The code runs fine in windows machine, but have segmentation fault
in MacOs M3 Sonoma 14.5. For your reference attaching the nixtla link i used https://nixtlaverse.nixtla.io/neuralforecast/index.html. if you need some other code then please do let me know, i will be able to attach.
from cpython.
Mmh, so it's something related to a third-party library (probably). I would suggest you open an issue on neuralmodel
but you need to include the python traceback, not the system traceback. Like, if you run python src/toolkit/app.py
, do you simply get a message like "Segmentation fault" or do you get more?
By the way, I see that there is some ThreadPoolExecutor
being used, so before that I'd suggest you try to remove whatever parallelization code being used. I suspect that the issue is with this neuralmodel
library or maybe with statsmodel
(I don't know what is being implemented out there). Could you try to reproduce a crash with a smaller example and with that library? in addition, could we get the Python output (like, if there's an exception being thrown before the segmentation fault or something like that).
from cpython.
I have tried this without the ThreadPoolExecutor
and it still does not work. I simply get "Segmentation fault" without anything else. The stats model run without any issue but the problem is only with neural model. I can also send you the neural model code if needed, Its simple code.
from cpython.
Related Issues (20)
- [C API] Add PySet_NextEntry() function HOT 10
- Self-documenting f-string in conversion specifier throws ValueError HOT 7
- Setting the line number is ignored in `INSTRUMENTED_YIELD_VALUE`
- Missing PyDECREF calls for ADDITEMS opcode of _pickle.c HOT 1
- riscv64: Python/perf_jit_trampoline.c:491:6: error: #error "Unsupported target architecture" HOT 2
- Support copy.replace() on AST nodes HOT 6
- Mac M1: ctypes crashes Blender application when I load and run my dylib. HOT 6
- 'And' functionality between lists HOT 4
- Specialization for accurate complex summation in sum()? HOT 4
- argparse: usage text of arguments in mutually exclusive groups no longer wraps in Python 3.13
- Incorrect use of _PyLong_CompactValue()
- subprocess.run timeout does not function if shell=True and capture_output=True
- `readline.set_history_length` corrupts history files when used in a libedit build HOT 8
- Consider support "all" as an valid action for ``warnings.filterswarnings/simplefilter``. HOT 1
- Use `do-while(0)` to protect `ADJUST_INDICES` macro
- wrong number sorting HOT 4
- Wrong extract version set in local headers for files located beyond zip64 limit HOT 4
- LZMA filtering documentation very poor
- Test suite interrupted by xml.etree.ElementTree.ParseError: not well-formed (invalid token) HOT 8
- Support `allow_nan` for `json.load[s]()` for JSON compliance HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from cpython.