Skip to content

[MacOS] Segmentation Fault on LightGBM w/ Torch #1442

Description

@Innixma

LightGBM Issue: lightgbm-org/LightGBM#4897

MacOS segmentation faults if torch is imported before LightGBM and LightGBM trains:

import torch
import lightgbm
lightgbm.train(...)  # <--- Segmentation Fault

OS Details:

macOS Big Sur
Version 11.6

MacBook Pro (16-inch, 2019)
Processor: 2.6 GHz 6-Core Intel Core i7
Memory: 16 GB 2667 MHz DDR4

Minimal Reproducible Script:

First create python venv, then:

pip install lightgbm
pip install torch

import sys
python_version = f'{sys.version_info.major}.{sys.version_info.minor}.{sys.version_info.micro}'
print(f'\nPython Version: {python_version}')
import platform
print(f'Operating System: {platform.system()}\n')

from pip._internal.operations import freeze
x = freeze.freeze()
for p in x:
    print(p)

import numpy as np
data = np.random.rand(50_000, 10)
label = np.random.randint(2, size=50_000)
test_data = np.random.rand(50_000, 10)

# This import order works:
# import lightgbm as lgb
# import torch

# This import order fails on MacOS when calling lgb.train: Process finished with exit code 139 (interrupted by signal 11: SIGSEGV)
import torch
import lightgbm as lgb

train_data = lgb.Dataset(data, label=label)
print('\nStarting Train')
model = lgb.train({}, train_data)
print('Training Finished')

Example output:

Python Version: 3.8.10
Operating System: Darwin

joblib==1.1.0
lightgbm==3.3.1
numpy==1.21.5
pip==21.1.2
scikit-learn==1.0.1
scipy==1.7.3
setuptools==57.0.0
threadpoolctl==3.0.0
torch==1.10.1
typing-extensions==4.0.1
wheel==0.36.2

Starting Train

Process finished with exit code 139 (interrupted by signal 11: SIGSEGV)

This is problematic in AutoGluon because depending on the order models train, if a torch model trains before LightGBM, LightGBM will cause a segmentation fault.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions