h2oai / h2o4gpu

H2Oai GPU Edition
Apache License 2.0
456 stars 96 forks source link

AttributeError: 'NoneType' object has no attribute 'make_ptr_double' #860

Open monk1337 opened 3 years ago

monk1337 commented 3 years ago

I am working with h2o4gpu and trying to run the example provided on github.

import h2o4gpu
import sklearn
from sklearn.datasets import load_breast_cancer
from sklearn.model_selection import train_test_split
from sklearn import linear_model
from sklearn.metrics import accuracy_score
import numpy as np

def test_not_labels():
    data = load_breast_cancer()
    X = data.data
    y = data.target

    # convert class values to [0,2]
    # y = y * 2

    # Splitting data into train and test
    X_train, X_test, y_train, y_test = train_test_split(
        X, y, test_size=0.25, random_state=42)

    # sklearn
    clf_sklearn = linear_model.LogisticRegression()
    clf_sklearn.fit(X_train, y_train)
    y_pred_sklearn = clf_sklearn.predict(X_test)

    # h2o
    clf_h2o = h2o4gpu.LogisticRegression()
    clf_h2o.fit(X_train, y_train)
    y_pred_h2o = clf_h2o.predict(X_test)

    assert np.allclose(accuracy_score(y_test, y_pred_sklearn), accuracy_score(y_test, y_pred_h2o.squeeze()))

But it's giving me this error :

AttributeError                            Traceback (most recent call last)
<ipython-input-5-57ba0443136b> in <module>
----> 1 test_not_labels()

<ipython-input-4-2f003f7e0081> in test_not_labels()
     27     # h2o
     28     clf_h2o = h2o4gpu.LogisticRegression()
---> 29     clf_h2o.fit(X_train, y_train)
     30     y_pred_h2o = clf_h2o.predict(X_test)
     31 

~/h20/lib/python3.7/site-packages/h2o4gpu/solvers/logistic.py in fit(self, X, y, sample_weight)
    273 
    274     def fit(self, X, y=None, sample_weight=None):
--> 275         res = self.model.fit(X, y, sample_weight)
    276         self.set_attributes()
    277         return res

~/h20/lib/python3.7/site-packages/h2o4gpu/solvers/elastic_net.py in fit(self, train_x, train_y, valid_x, valid_y, sample_weight, free_input_data)
    301                 valid_y=valid_y,
    302                 sample_weight=sample_weight,
--> 303                 source_dev=source_dev)
    304 
    305         else:

~/h20/lib/python3.7/site-packages/h2o4gpu/solvers/utils.py in prepare_and_upload_data(self, train_x, train_y, valid_x, valid_y, sample_weight, source_dev)
    272     time_upload_data0 = time.time()
    273     (a, b, c, d, e) = upload_data(self, train_x_np, train_y_np, valid_x_np,
--> 274                                   valid_y_np, weight_np, source_dev)
    275 
    276     self.time_upload_data = time.time() - time_upload_data0

~/h20/lib/python3.7/site-packages/h2o4gpu/solvers/utils.py in upload_data(self, train_x, train_y, valid_x, valid_y, sample_weight, source_dev)
    376 
    377     if self.double_precision == 1:
--> 378         c_upload_data = self.lib.make_ptr_double
    379     elif self.double_precision == 0:
    380         c_upload_data = self.lib.make_ptr_float

AttributeError: 'NoneType' object has no attribute 'make_ptr_double'

I have installed h20 and h2o4gpu in separate python env with python 3.7 with cuda 10.1 How I can resolve this?

monk1337 commented 3 years ago

I had to set solver = 'lbfgs' in clf_sklearn = linear_model.LogisticRegression()

monk1337 commented 3 years ago

I checked with get_gpu_info_c it's not detecting gpu, So while setting solver = 'lbfgs' it's selecting backend='sklearn' but when I am setting backend='h2o4gpu', I am getting same error :

AttributeError: 'NoneType' object has no attribute 'make_ptr_float'

trebesh commented 3 years ago

I am having the same issue but at line 380 in OP error message with the Lasso example on github giving:

Getting data Reading Data with Pandas (999, 9733) Original m=999 n=9732 Size of Train rows=800 & valid rows=199 Size of Train cols=9732 valid cols=9732 Size of Train cols=9733 & valid cols=9733 after adding intercept column Creating model Training model Traceback (most recent call last): File "gpu_elastic_net_h2o.py", line 55, in model.fit(train_x, train_y) File "../h2o4gpu/solvers/elastic_net.py", line 302, in fit source_dev=source_dev) File "../h2o4gpu/solvers/utils.py", line 274, in prepare_and_upload_data valid_y_np, weight_np, source_dev) File "../h2o4gpu/solvers/utils.py", line 380, in upload_data c_upload_data = self.lib.make_ptr_float AttributeError: 'NoneType' object has no attribute 'make_ptr_float'

GeorgePearse commented 2 years ago

Hitting the same problem. Anyone had any luck with this?