[Python] XGBoost Bad Allocation

Discussão em 'Python' iniciado por Stack, Agosto 27, 2025.

  1. Stack

    Stack Membro Participativo

    When loading an XGBoost model and running it I get the following error:

    XGBoostError: bad allocation


    I read it might be a memory problem, I have 32Gb of RAM and the model is quite small. I only have 8Gb of memory on my C: drive which might be causing the problem?

    Code below:

    def workflow_funnel(embeddings, model, funneldf):
    xvalid_count_source = embeddings.transform(funneldf['cleaned_original_text'].apply(lambda x: np.str_(x)))
    funnel_predictions = model.predict(xvalid_count_source)

    funnel_model = xgboost.Booster(model_file = project_directory + language+funnel_model_load)


    Full error:

    ---------------------------------------------------------------------------
    XGBoostError Traceback (most recent call last)
    <ipython-input-47-40524e96ae70> in <module>
    1 # Funnel model application
    ----> 2 funnel_model = xgboost.Booster(model_file = project_directory + language+funnel_model_load)
    3
    4 funnel_embedding = pickle.load(open(project_directory + language+funnel_vectorizer_load, 'rb'))
    5

    ~\AppData\Roaming\Python\Python37\site-packages\xgboost\core.py in __init__(self, params, cache, model_file)
    1324 self.__dict__.update(state)
    1325 elif isinstance(model_file, (STRING_TYPES, os.PathLike, bytearray)):
    -> 1326 self.load_model(model_file)
    1327 elif model_file is None:
    1328 pass

    ~\AppData\Roaming\Python\Python37\site-packages\xgboost\core.py in load_model(self, fname)
    2160 fname = os.fspath(os.path.expanduser(fname))
    2161 _check_call(_LIB.XGBoosterLoadModel(
    -> 2162 self.handle, c_str(fname)))
    2163 elif isinstance(fname, bytearray):
    2164 buf = fname

    ~\AppData\Roaming\Python\Python37\site-packages\xgboost\core.py in _check_call(ret)
    216 """
    217 if ret != 0:
    --> 218 raise XGBoostError(py_str(_LIB.XGBGetLastError()))
    219
    220

    XGBoostError: bad allocation

    Continue reading...

Compartilhe esta Página